LCOV - code coverage report
Current view: top level - src/utils - PerfNode.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: fef103 Lines: 47 47 100.0 %
Date: 2025-09-03 20:01:23 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 "PerfNode.h"
      11             : #include "PerfGraph.h"
      12             : 
      13             : #include "DataIO.h"
      14             : 
      15             : std::chrono::steady_clock::duration
      16    20484162 : PerfNode::selfTime() const
      17             : {
      18    20484162 :   return _total_time - childrenTime();
      19             : }
      20             : 
      21             : std::chrono::steady_clock::duration
      22    62017266 : PerfNode::totalTime() const
      23             : {
      24             :   // Note that all of the children's time is already
      25             :   // accounted for in the total time
      26    62017266 :   return _total_time;
      27             : }
      28             : 
      29             : std::chrono::steady_clock::duration
      30    38279996 : PerfNode::childrenTime() const
      31             : {
      32    38279996 :   std::chrono::steady_clock::duration children_time(0);
      33             : 
      34    78028049 :   for (auto & child_it : _children)
      35    39748053 :     children_time += child_it.second->totalTime();
      36             : 
      37    38279996 :   return children_time;
      38             : }
      39             : 
      40             : long int
      41    18695460 : PerfNode::selfMemory() const
      42             : {
      43    18695460 :   return _total_memory - childrenMemory();
      44             : }
      45             : 
      46             : long int
      47    36491294 : PerfNode::childrenMemory() const
      48             : {
      49    36491294 :   long int children_memory = 0;
      50             : 
      51    73321331 :   for (auto & child_it : _children)
      52    36830037 :     children_memory += child_it.second->totalMemory();
      53             : 
      54    36491294 :   return children_memory;
      55             : }
      56             : 
      57             : void
      58     6728567 : dataStore(std::ostream & stream, const std::unique_ptr<PerfNode> & node, void *)
      59             : {
      60             :   // We store the name instead of the ID because the ID could change in recover
      61     6728567 :   std::string name = moose::internal::getPerfGraphRegistry().sectionInfo(node->id())._name;
      62     6728567 :   dataStore(stream, name, nullptr);
      63             : 
      64     6728567 :   dataStore(stream, node->_total_time, nullptr);
      65     6728567 :   dataStore(stream, node->_num_calls, nullptr);
      66     6728567 :   dataStore(stream, node->_total_memory, nullptr);
      67             : 
      68             :   // Recursively add all of the children
      69     6728567 :   std::size_t num_children = node->children().size();
      70     6728567 :   dataStore(stream, num_children, nullptr);
      71    13411736 :   for (auto & id_child_pair : node->_children)
      72             :   {
      73     6683169 :     const auto & child = id_child_pair.second;
      74     6683169 :     dataStore(stream, child, nullptr);
      75             :   }
      76     6728567 : }
      77             : 
      78             : void
      79     2177057 : dataLoad(std::istream & stream, const std::unique_ptr<PerfNode> & node, void * perf_graph)
      80             : {
      81     2177057 :   std::string name;
      82             :   // When we recursively add children, we grab the name before recursing into
      83             :   // dataLoad(), so only load the name if we're on the root
      84     2177057 :   if (node.get() == &static_cast<PerfGraph *>(perf_graph)->rootNode())
      85       13851 :     dataLoad(stream, name, nullptr);
      86             : 
      87             :   std::chrono::steady_clock::duration total_time;
      88     2177057 :   dataLoad(stream, total_time, nullptr);
      89     2177057 :   node->_total_time += total_time;
      90             : 
      91             :   long unsigned int num_calls;
      92     2177057 :   dataLoad(stream, num_calls, nullptr);
      93     2177057 :   node->_num_calls += num_calls;
      94             : 
      95             :   long unsigned int total_memory;
      96     2177057 :   dataLoad(stream, total_memory, nullptr);
      97     2177057 :   node->_total_memory += total_memory;
      98             : 
      99             :   // Recursively add the children
     100             :   // If a matching child exists with the same name, the time/calls/memory will be appended
     101             :   // to said node. If a node does not exist with the same name, it will be created
     102             :   std::size_t num_children;
     103     2177057 :   dataLoad(stream, num_children, nullptr);
     104     2177057 :   std::size_t i = 0;
     105     4340263 :   while (i++ < num_children)
     106             :   {
     107     2163206 :     dataLoad(stream, name, nullptr);
     108     2163206 :     const auto id = moose::internal::getPerfGraphRegistry().sectionID(name);
     109     2163206 :     node->getChild(id); // creates the child if it does not exist
     110             : 
     111     2163206 :     const auto & child = node->_children[id];
     112     2163206 :     dataLoad(stream, child, perf_graph);
     113             :   }
     114     2177057 : }

Generated by: LCOV version 1.14