LCOV - code coverage report
Current view: top level - src/utils - PerfNode.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 47 47 100.0 %
Date: 2025-07-17 01:28:37 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    18631291 : PerfNode::selfTime() const
      17             : {
      18    18631291 :   return _total_time - childrenTime();
      19             : }
      20             : 
      21             : std::chrono::steady_clock::duration
      22    56393193 : PerfNode::totalTime() const
      23             : {
      24             :   // Note that all of the children's time is already
      25             :   // accounted for in the total time
      26    56393193 :   return _total_time;
      27             : }
      28             : 
      29             : std::chrono::steady_clock::duration
      30    34829553 : PerfNode::childrenTime() const
      31             : {
      32    34829553 :   std::chrono::steady_clock::duration children_time(0);
      33             : 
      34    70976025 :   for (auto & child_it : _children)
      35    36146472 :     children_time += child_it.second->totalTime();
      36             : 
      37    34829553 :   return children_time;
      38             : }
      39             : 
      40             : long int
      41    17012517 : PerfNode::selfMemory() const
      42             : {
      43    17012517 :   return _total_memory - childrenMemory();
      44             : }
      45             : 
      46             : long int
      47    33210779 : PerfNode::childrenMemory() const
      48             : {
      49    33210779 :   long int children_memory = 0;
      50             : 
      51    66723089 :   for (auto & child_it : _children)
      52    33512310 :     children_memory += child_it.second->totalMemory();
      53             : 
      54    33210779 :   return children_memory;
      55             : }
      56             : 
      57             : void
      58     6213278 : 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     6213278 :   std::string name = moose::internal::getPerfGraphRegistry().sectionInfo(node->id())._name;
      62     6213278 :   dataStore(stream, name, nullptr);
      63             : 
      64     6213278 :   dataStore(stream, node->_total_time, nullptr);
      65     6213278 :   dataStore(stream, node->_num_calls, nullptr);
      66     6213278 :   dataStore(stream, node->_total_memory, nullptr);
      67             : 
      68             :   // Recursively add all of the children
      69     6213278 :   std::size_t num_children = node->children().size();
      70     6213278 :   dataStore(stream, num_children, nullptr);
      71    12384717 :   for (auto & id_child_pair : node->_children)
      72             :   {
      73     6171439 :     const auto & child = id_child_pair.second;
      74     6171439 :     dataStore(stream, child, nullptr);
      75             :   }
      76     6213278 : }
      77             : 
      78             : void
      79     2014429 : dataLoad(std::istream & stream, const std::unique_ptr<PerfNode> & node, void * perf_graph)
      80             : {
      81     2014429 :   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     2014429 :   if (node.get() == &static_cast<PerfGraph *>(perf_graph)->rootNode())
      85       12748 :     dataLoad(stream, name, nullptr);
      86             : 
      87             :   std::chrono::steady_clock::duration total_time;
      88     2014429 :   dataLoad(stream, total_time, nullptr);
      89     2014429 :   node->_total_time += total_time;
      90             : 
      91             :   long unsigned int num_calls;
      92     2014429 :   dataLoad(stream, num_calls, nullptr);
      93     2014429 :   node->_num_calls += num_calls;
      94             : 
      95             :   long unsigned int total_memory;
      96     2014429 :   dataLoad(stream, total_memory, nullptr);
      97     2014429 :   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     2014429 :   dataLoad(stream, num_children, nullptr);
     104     2014429 :   std::size_t i = 0;
     105     4016110 :   while (i++ < num_children)
     106             :   {
     107     2001681 :     dataLoad(stream, name, nullptr);
     108     2001681 :     const auto id = moose::internal::getPerfGraphRegistry().sectionID(name);
     109     2001681 :     node->getChild(id); // creates the child if it does not exist
     110             : 
     111     2001681 :     const auto & child = node->_children[id];
     112     2001681 :     dataLoad(stream, child, perf_graph);
     113             :   }
     114     2014429 : }

Generated by: LCOV version 1.14