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 19822281 : PerfNode::selfTime() const 17 : { 18 19822281 : return _total_time - childrenTime(); 19 : } 20 : 21 : std::chrono::steady_clock::duration 22 60786543 : PerfNode::totalTime() const 23 : { 24 : // Note that all of the children's time is already 25 : // accounted for in the total time 26 60786543 : return _total_time; 27 : } 28 : 29 : std::chrono::steady_clock::duration 30 37602088 : PerfNode::childrenTime() const 31 : { 32 37602088 : std::chrono::steady_clock::duration children_time(0); 33 : 34 77212164 : for (auto & child_it : _children) 35 39610076 : children_time += child_it.second->totalTime(); 36 : 37 37602088 : return children_time; 38 : } 39 : 40 : long int 41 18458845 : PerfNode::selfMemory() const 42 : { 43 18458845 : return _total_memory - childrenMemory(); 44 : } 45 : 46 : long int 47 36238652 : PerfNode::childrenMemory() const 48 : { 49 36238652 : long int children_memory = 0; 50 : 51 72993842 : for (auto & child_it : _children) 52 36755190 : children_memory += child_it.second->totalMemory(); 53 : 54 36238652 : return children_memory; 55 : } 56 : 57 : void 58 6833390 : 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 6833390 : std::string name = moose::internal::getPerfGraphRegistry().sectionInfo(node->id())._name; 62 6833390 : dataStore(stream, name, nullptr); 63 : 64 6833390 : dataStore(stream, node->_total_time, nullptr); 65 6833390 : dataStore(stream, node->_num_calls, nullptr); 66 6833390 : dataStore(stream, node->_total_memory, nullptr); 67 : 68 : // Recursively add all of the children 69 6833390 : std::size_t num_children = node->children().size(); 70 6833390 : dataStore(stream, num_children, nullptr); 71 13620167 : for (auto & id_child_pair : node->_children) 72 : { 73 6786777 : const auto & child = id_child_pair.second; 74 6786777 : dataStore(stream, child, nullptr); 75 : } 76 6833390 : } 77 : 78 : void 79 2030260 : dataLoad(std::istream & stream, const std::unique_ptr<PerfNode> & node, void * perf_graph) 80 : { 81 2030260 : 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 2030260 : if (node.get() == &static_cast<PerfGraph *>(perf_graph)->rootNode()) 85 12932 : dataLoad(stream, name, nullptr); 86 : 87 : std::chrono::steady_clock::duration total_time; 88 2030260 : dataLoad(stream, total_time, nullptr); 89 2030260 : node->_total_time += total_time; 90 : 91 : long unsigned int num_calls; 92 2030260 : dataLoad(stream, num_calls, nullptr); 93 2030260 : node->_num_calls += num_calls; 94 : 95 : long unsigned int total_memory; 96 2030260 : dataLoad(stream, total_memory, nullptr); 97 2030260 : 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 2030260 : dataLoad(stream, num_children, nullptr); 104 2030260 : std::size_t i = 0; 105 4047588 : while (i++ < num_children) 106 : { 107 2017328 : dataLoad(stream, name, nullptr); 108 2017328 : const auto id = moose::internal::getPerfGraphRegistry().sectionID(name); 109 2017328 : node->getChild(id); // creates the child if it does not exist 110 : 111 2017328 : const auto & child = node->_children[id]; 112 2017328 : dataLoad(stream, child, perf_graph); 113 : } 114 2030260 : }