LCOV - code coverage report
Current view: top level - src/reporters - PerfGraphReporter.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 39 40 97.5 %
Date: 2026-05-29 20:35:17 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          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             : const std::vector<ReporterValueName> PerfGraphReporter::value_names{
      17             :     "graph", "max_memory_this_rank", "max_memory_per_rank", "version"};
      18             : 
      19             : InputParameters
      20        3169 : PerfGraphReporter::validParams()
      21             : {
      22        3169 :   InputParameters params = GeneralReporter::validParams();
      23        3169 :   params.addClassDescription("Reports the full performance graph from the PerfGraph.");
      24        3169 :   return params;
      25           0 : }
      26             : 
      27          54 : PerfGraphReporter::PerfGraphReporter(const InputParameters & parameters)
      28             :   : GeneralReporter(parameters),
      29          54 :     _graph(declareValueByName<PerfGraphJSON>("graph", REPORTER_MODE_DISTRIBUTED)),
      30          54 :     _max_memory_this_rank(
      31          54 :         declareValueByName<std::size_t>("max_memory_this_rank", REPORTER_MODE_DISTRIBUTED, 0)),
      32          54 :     _max_memory_per_rank(declareValueByName<std::vector<std::size_t>>(
      33         162 :         "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          54 :   declareValueByName<unsigned int>("version", REPORTER_MODE_DISTRIBUTED, 1);
      49          54 : }
      50             : 
      51             : void
      52          42 : PerfGraphReporter::finalize()
      53             : {
      54          42 :   auto & perf_graph = perfGraph();
      55             : 
      56             :   // Build the graph
      57          42 :   _graph.value.clear();
      58             :   // Function for recursing through nodes
      59          42 :   std::function<void(nlohmann::json & json, const PerfNode &)> recurse_node;
      60        5444 :   recurse_node = [&recurse_node](nlohmann::json & json, const PerfNode & node)
      61             :   {
      62        5360 :     const auto & info = moose::internal::getPerfGraphRegistry().sectionInfo(node.id());
      63             : 
      64        5360 :     auto & node_json = json[info._name];
      65        5360 :     node_json["level"] = info._level;
      66        5360 :     node_json["num_calls"] = node.numCalls();
      67        5360 :     node_json["time"] = node.selfTimeSec();
      68             : 
      69             :     // Recursively add the children
      70        5360 :     if (node.children().size())
      71             :     {
      72        1280 :       auto & children = node_json["children"];
      73        6598 :       for (const auto & id_child_pair : node.children())
      74        5318 :         recurse_node(children, *id_child_pair.second);
      75             :     }
      76        5402 :   };
      77             :   // Update the timings in each node before we output them
      78          42 :   perf_graph.update();
      79             :   // Recurse through the nodes to add
      80          42 :   recurse_node(_graph.value, perf_graph.rootNode());
      81             : 
      82             :   // Memory on this rank
      83          42 :   _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
      87          42 :   comm().gather(0, _max_memory_this_rank, _max_memory_per_rank);
      88          42 : }
      89             : 
      90             : void
      91          47 : to_json(nlohmann::json & json, const PerfGraphReporter::PerfGraphJSON & perf_graph_json)
      92             : {
      93          47 :   json = perf_graph_json.value;
      94          47 : }
      95             : 
      96             : void
      97          12 : dataStore(std::ostream &, PerfGraphReporter::PerfGraphJSON &, void *)
      98             : {
      99          12 : }
     100             : 
     101             : void
     102          12 : dataLoad(std::istream &, PerfGraphReporter::PerfGraphJSON &, void *)
     103             : {
     104          12 : }

Generated by: LCOV version 1.14