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 
16 const 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 
51 void
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 
90 void
91 to_json(nlohmann::json & json, const PerfGraphReporter::PerfGraphJSON & perf_graph_json)
92 {
93  json = perf_graph_json.value;
94 }
95 
96 void
97 dataStore(std::ostream &, PerfGraphReporter::PerfGraphJSON &, void *)
98 {
99 }
100 
101 void
102 dataLoad(std::istream &, PerfGraphReporter::PerfGraphJSON &, void *)
103 {
104 }
static const std::vector< ReporterValueName > value_names
The reporter values that this object declares; used within the CommonOutputAction to single out value...
static InputParameters validParams()
std::vector< std::size_t > & _max_memory_per_rank
"max_memory_per_proc" entry in the reporter; max memory across all ranks
MPI_Info info
Reporter object that has a single execution of the "execute" method for each execute flag...
const ReporterMode REPORTER_MODE_ROOT
void gather(const unsigned int root_id, const T &send_data, std::vector< T, A > &recv) const
registerMooseObject("MooseApp", PerfGraphReporter)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Parallel::Communicator & comm() const
void dataStore(std::ostream &, PerfGraphReporter::PerfGraphJSON &, void *)
Store and load methods for const PerfGraph *, used in the PerfGraphReporter, which do nothing...
std::size_t & _max_memory_this_rank
"_max_memory_this_proc" entry in the reporter; max memory for this rank
static InputParameters validParams()
void dataLoad(std::istream &, PerfGraphReporter::PerfGraphJSON &, void *)
unsigned int _level
Print level (verbosity level)
Reports the full graph from the PerfGraph.
const ReporterMode REPORTER_MODE_DISTRIBUTED
const PerfGraphSectionInfo & sectionInfo(const PerfID section_id) const
Given a PerfID return the PerfGraphSectionInfo The ID.
PerfGraphJSON & _graph
"graph" entry in the reporter; the actual graph
void finalize() override
Finalize.
PerfGraph & perfGraph()
Get the PerfGraph.
PerfGraphReporter(const InputParameters &parameters)
Structure that holds the PerfGraph in JSON.
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...
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.
void to_json(nlohmann::json &json, const PerfGraphReporter::PerfGraphJSON &perf_graph_json)
A node in the PerfGraph.
Definition: PerfNode.h:25