Line data Source code
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 : 14 : registerMooseObject("MooseApp", PerfGraphReporter); 15 : 16 : InputParameters 17 14377 : PerfGraphReporter::validParams() 18 : { 19 14377 : InputParameters params = GeneralReporter::validParams(); 20 14377 : 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 14377 : params.set<bool>("_always_store") = false; 26 : 27 14377 : return params; 28 0 : } 29 : 30 56 : PerfGraphReporter::PerfGraphReporter(const InputParameters & parameters) 31 : : GeneralReporter(parameters), 32 56 : _graph(declareValueByName<const PerfGraph *>("graph", REPORTER_MODE_DISTRIBUTED, &perfGraph())) 33 : { 34 56 : } 35 : 36 : void 37 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 37 : const_cast<PerfGraph *>(perf_graph)->update(); 43 : 44 : // Recurse through the nodes starting with the root to fill the graph 45 37 : to_json(json, perf_graph->rootNode()); 46 37 : } 47 : 48 : void 49 4868 : to_json(nlohmann::json & json, const PerfNode & node) 50 : { 51 4868 : const auto & info = moose::internal::getPerfGraphRegistry().sectionInfo(node.id()); 52 : 53 4868 : auto & node_json = json[info._name]; 54 4868 : node_json["level"] = info._level; 55 4868 : node_json["num_calls"] = node.numCalls(); 56 4868 : node_json["memory"] = node.selfMemory(); 57 4868 : node_json["time"] = node.selfTimeSec(); 58 : 59 : // Recursively add the children 60 9699 : for (const auto & id_child_pair : node.children()) 61 4831 : to_json(node_json, *id_child_pair.second); 62 4868 : }