https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PerfNode.C
Go to the documentation of this file.
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
15std::chrono::steady_clock::duration
17{
18 return _total_time - childrenTime();
19}
20
21std::chrono::steady_clock::duration
23{
24 // Note that all of the children's time is already
25 // accounted for in the total time
26 return _total_time;
27}
28
29std::chrono::steady_clock::duration
31{
32 std::chrono::steady_clock::duration children_time(0);
33
34 for (auto & child_it : _children)
35 children_time += child_it.second->totalTime();
36
37 return children_time;
38}
39
40long int
42{
44}
45
46long int
48{
49 long int children_memory = 0;
50
51 for (auto & child_it : _children)
52 children_memory += child_it.second->totalMemory();
53
54 return children_memory;
55}
56
57void
58dataStore(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 std::string name = moose::internal::getPerfGraphRegistry().sectionInfo(node->id())._name;
62 dataStore(stream, name, nullptr);
63
64 dataStore(stream, node->_total_time, nullptr);
65 dataStore(stream, node->_num_calls, nullptr);
66 dataStore(stream, node->_total_memory, nullptr);
67
68 // Recursively add all of the children
69 std::size_t num_children = node->children().size();
70 dataStore(stream, num_children, nullptr);
71 for (auto & id_child_pair : node->_children)
72 {
73 const auto & child = id_child_pair.second;
74 dataStore(stream, child, nullptr);
75 }
76}
77
78void
79dataLoad(std::istream & stream, const std::unique_ptr<PerfNode> & node, void * perf_graph)
80{
81 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 if (node.get() == &static_cast<PerfGraph *>(perf_graph)->rootNode())
85 dataLoad(stream, name, nullptr);
86
87 std::chrono::steady_clock::duration total_time;
88 dataLoad(stream, total_time, nullptr);
89 node->_total_time += total_time;
90
91 long unsigned int num_calls;
92 dataLoad(stream, num_calls, nullptr);
93 node->_num_calls += num_calls;
94
95 long unsigned int total_memory;
96 dataLoad(stream, total_memory, nullptr);
97 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 dataLoad(stream, num_children, nullptr);
104 std::size_t i = 0;
105 while (i++ < num_children)
106 {
107 dataLoad(stream, name, nullptr);
108 const auto id = moose::internal::getPerfGraphRegistry().sectionID(name);
109 node->getChild(id); // creates the child if it does not exist
110
111 const auto & child = node->_children[id];
112 dataLoad(stream, child, perf_graph);
113 }
114}
void dataLoad(std::istream &stream, const std::unique_ptr< PerfNode > &node, void *perf_graph)
Definition PerfNode.C:79
void dataStore(std::ostream &stream, const std::unique_ptr< PerfNode > &node, void *)
Definition PerfNode.C:58
The PerfGraph will hold the master list of all registered performance segments and the head PerfNode.
Definition PerfGraph.h:44
const PerfNode & rootNode() const
Definition PerfGraph.h:193
std::chrono::steady_clock::duration totalTime() const
The time this Node plus all of it's children took.
Definition PerfNode.C:22
std::chrono::steady_clock::duration childrenTime() const
Get the time this nodes children took.
Definition PerfNode.C:30
long int selfMemory() const
Get the amount of memory added by this node.
Definition PerfNode.C:41
long int childrenMemory() const
Get the amount of memory added by this node.
Definition PerfNode.C:47
std::map< PerfID, std::unique_ptr< PerfNode > > _children
Timers that are directly underneath this node.
Definition PerfNode.h:184
long unsigned int _total_memory
The total memory added while this node is active.
Definition PerfNode.h:181
std::chrono::steady_clock::duration _total_time
The total elapsed time for this node.
Definition PerfNode.h:172
std::chrono::steady_clock::duration selfTime() const
Get the time this node took.
Definition PerfNode.C:16
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID @section_name The name of the section.
const PerfGraphSectionInfo & sectionInfo(const PerfID section_id) const
Given a PerfID return the PerfGraphSectionInfo @section_id The ID.
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.