https://mooseframework.inl.gov
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 
18 {
20  params.addClassDescription("Reports the full performance graph from the PerfGraph.");
21 
22  // Because the PerfGraphReporter does all of its execution within the
23  // to_json specialization (does not fill the structure within execute()),
24  // this allows us to obey the user's request for execute_on
25  params.set<bool>("_always_store") = false;
26 
27  return params;
28 }
29 
31  : GeneralReporter(parameters),
32  _graph(declareValueByName<const PerfGraph *>("graph", REPORTER_MODE_DISTRIBUTED, &perfGraph()))
33 {
34 }
35 
36 void
37 to_json(nlohmann::json & json, const PerfGraph * const & perf_graph)
38 {
39  mooseAssert(perf_graph, "perf_graph is not set");
40 
41  // Update the timings in each node before we output them
42  const_cast<PerfGraph *>(perf_graph)->update();
43 
44  // Recurse through the nodes starting with the root to fill the graph
45  to_json(json, perf_graph->rootNode());
46 }
47 
48 void
49 to_json(nlohmann::json & json, const PerfNode & node)
50 {
52 
53  auto & node_json = json[info._name];
54  node_json["level"] = info._level;
55  node_json["num_calls"] = node.numCalls();
56  node_json["memory"] = node.selfMemory();
57  node_json["time"] = node.selfTimeSec();
58 
59  // Recursively add the children
60  for (const auto & id_child_pair : node.children())
61  to_json(node_json, *id_child_pair.second);
62 }
Real selfTimeSec() const
Get the time this node took in seconds.
Definition: PerfNode.h:115
static InputParameters validParams()
long int selfMemory() const
Get the amount of memory added by this node.
Definition: PerfNode.C:41
MPI_Info info
Reporter object that has a single execution of the "execute" method for for each execute flag...
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
registerMooseObject("MooseApp", PerfGraphReporter)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
unsigned int _level
Print level (verbosity level)
unsigned long int numCalls() const
Get the number of times this node was called.
Definition: PerfNode.h:146
Reports the full graph from the PerfGraph.
const std::map< PerfID, std::unique_ptr< PerfNode > > & children() const
Get the children.
Definition: PerfNode.h:106
PerfID id() const
Get the ID of this Node.
Definition: PerfNode.h:35
const ReporterMode REPORTER_MODE_DISTRIBUTED
const PerfGraphSectionInfo & sectionInfo(const PerfID section_id) const
Given a PerfID return the PerfGraphSectionInfo The ID.
void to_json(nlohmann::json &json, const PerfGraph *const &perf_graph)
PerfGraphReporter(const InputParameters &parameters)
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...
The PerfGraph will hold the master list of all registered performance segments and the head PerfNode...
Definition: PerfGraph.h:43
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.
const PerfNode & rootNode() const
Definition: PerfGraph.h:186
A node in the PerfGraph.
Definition: PerfNode.h:24