https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PerfGraphReporter.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#include "PerfGraphReporter.h"
11
12#include "PerfGraph.h"
13
15
16const std::vector<ReporterValueName> PerfGraphReporter::value_names{
17 "graph", "max_memory_this_rank", "max_memory_per_rank", "version"};
18
21{
23 params.addClassDescription("Reports the full performance graph from the PerfGraph.");
24 return params;
25}
26
28 : GeneralReporter(parameters),
29 _graph(declareValueByName<PerfGraphJSON>("graph", REPORTER_MODE_DISTRIBUTED)),
30 _max_memory_this_rank(
31 declareValueByName<std::size_t>("max_memory_this_rank", REPORTER_MODE_DISTRIBUTED, 0)),
32 _max_memory_per_rank(declareValueByName<std::vector<std::size_t>>(
33 "max_memory_per_rank", REPORTER_MODE_ROOT, std::vector<std::size_t>()))
34{
35 // Store the version schema so at a later date we can use this version
36 // to know what data we should expect. This value is never changed during
37 // execute() as it is static and is saved as distributed so that we can
38 // store off each processor's data individually and know of the version
39 // without needing the context of the root process output.
40 //
41 // Version 0:
42 // - Initial version when version wasn't set
43 // Version 1:
44 // - Store children in separate "children" key per node
45 // - Removed "memory" key for each node
46 // - Add "max_memory_this_rank" top-level key
47 // - Add "max_memory_per_rank" top-level key
48 declareValueByName<unsigned int>("version", REPORTER_MODE_DISTRIBUTED, 1);
49}
50
51void
53{
54 auto & perf_graph = perfGraph();
55
56 // Build the graph
57 _graph.value.clear();
58 // Function for recursing through nodes
59 std::function<void(nlohmann::json & json, const PerfNode &)> recurse_node;
60 recurse_node = [&recurse_node](nlohmann::json & json, const PerfNode & node)
61 {
62 const auto & info = moose::internal::getPerfGraphRegistry().sectionInfo(node.id());
63
64 auto & node_json = json[info._name];
65 node_json["level"] = info._level;
66 node_json["num_calls"] = node.numCalls();
67 node_json["time"] = node.selfTimeSec();
68
69 // Recursively add the children
70 if (node.children().size())
71 {
72 auto & children = node_json["children"];
73 for (const auto & id_child_pair : node.children())
74 recurse_node(children, *id_child_pair.second);
75 }
76 };
77 // Update the timings in each node before we output them
78 perf_graph.update();
79 // Recurse through the nodes to add
80 recurse_node(_graph.value, perf_graph.rootNode());
81
82 // Memory on this rank
83 _max_memory_this_rank = perf_graph.getMaxMemory();
84 // Memory across all ranks on rank 0; we keep this separate so
85 // that we can store data for rank 0 in a database but still
86 // have a general idea of memory usage across all ranks
88}
89
90void
91to_json(nlohmann::json & json, const PerfGraphReporter::PerfGraphJSON & perf_graph_json)
92{
93 json = perf_graph_json.value;
94}
95
96void
98{
99}
100
101void
103{
104}
void dataStore(std::ostream &, PerfGraphReporter::PerfGraphJSON &, void *)
Store and load methods for const PerfGraph *, used in the PerfGraphReporter, which do nothing.
registerMooseObject("MooseApp", PerfGraphReporter)
void to_json(nlohmann::json &json, const PerfGraphReporter::PerfGraphJSON &perf_graph_json)
void dataLoad(std::istream &, PerfGraphReporter::PerfGraphJSON &, void *)
const ReporterMode REPORTER_MODE_DISTRIBUTED
const ReporterMode REPORTER_MODE_ROOT
Reporter object that has a single execution of the "execute" method for each execute flag.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
PerfGraph & perfGraph()
Get the PerfGraph.
Reports the full graph from the PerfGraph.
static InputParameters validParams()
static const std::vector< ReporterValueName > value_names
The reporter values that this object declares; used within the CommonOutputAction to single out value...
PerfGraphReporter(const InputParameters &parameters)
std::size_t & _max_memory_this_rank
"_max_memory_this_proc" entry in the reporter; max memory for this rank
void finalize() override
Finalize.
PerfGraphJSON & _graph
"graph" entry in the reporter; the actual graph
std::vector< std::size_t > & _max_memory_per_rank
"max_memory_per_proc" entry in the reporter; max memory across all ranks
A node in the PerfGraph.
Definition PerfNode.h:26
void gather(const unsigned int root_id, const T &send_data, std::vector< T, A > &recv) const
const Parallel::Communicator & comm() const
const PerfGraphSectionInfo & sectionInfo(const PerfID section_id) const
Given a PerfID return the PerfGraphSectionInfo @section_id The ID.
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.
Structure that holds the PerfGraph in JSON.