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
57namespace
58{
59template <typename Rep, typename Period>
60void
61dataStore(std::ostream & stream, std::chrono::duration<Rep, Period> & v, void * ctx)
62{
63 Rep tick_count = v.count();
64 ::dataStore(stream, tick_count, ctx);
65}
66
67template <typename Rep, typename Period>
68void
69dataLoad(std::istream & stream, std::chrono::duration<Rep, Period> & v, void * ctx)
70{
71 Rep tick_count;
72 ::dataLoad(stream, tick_count, ctx);
73 v = std::chrono::duration<Rep, Period>(tick_count);
74}
75}
76
77void
78dataStore(std::ostream & stream, const std::unique_ptr<PerfNode> & node, void *)
79{
80 // We store the name instead of the ID because the ID could change in recover
81 std::string name = moose::internal::getPerfGraphRegistry().sectionInfo(node->id())._name;
82 dataStore(stream, name, nullptr);
83
84 dataStore(stream, node->_total_time, nullptr);
85 dataStore(stream, node->_num_calls, nullptr);
86 dataStore(stream, node->_total_memory, nullptr);
87
88 // Recursively add all of the children
89 std::size_t num_children = node->children().size();
90 dataStore(stream, num_children, nullptr);
91 for (auto & id_child_pair : node->_children)
92 {
93 const auto & child = id_child_pair.second;
94 dataStore(stream, child, nullptr);
95 }
96}
97
98void
99dataLoad(std::istream & stream, const std::unique_ptr<PerfNode> & node, void * perf_graph)
100{
101 std::string name;
102 // When we recursively add children, we grab the name before recursing into
103 // dataLoad(), so only load the name if we're on the root
104 if (node.get() == &static_cast<PerfGraph *>(perf_graph)->rootNode())
105 dataLoad(stream, name, nullptr);
106
107 std::chrono::steady_clock::duration total_time;
108 dataLoad(stream, total_time, nullptr);
109 node->_total_time += total_time;
110
111 long unsigned int num_calls;
112 dataLoad(stream, num_calls, nullptr);
113 node->_num_calls += num_calls;
114
115 long unsigned int total_memory;
116 dataLoad(stream, total_memory, nullptr);
117 node->_total_memory += total_memory;
118
119 // Recursively add the children
120 // If a matching child exists with the same name, the time/calls/memory will be appended
121 // to said node. If a node does not exist with the same name, it will be created
122 std::size_t num_children;
123 dataLoad(stream, num_children, nullptr);
124 std::size_t i = 0;
125 while (i++ < num_children)
126 {
127 dataLoad(stream, name, nullptr);
128 const auto id = moose::internal::getPerfGraphRegistry().sectionID(name);
129 node->getChild(id); // creates the child if it does not exist
130
131 const auto & child = node->_children[id];
132 dataLoad(stream, child, perf_graph);
133 }
134}
void dataLoad(std::istream &stream, const std::unique_ptr< PerfNode > &node, void *perf_graph)
Definition PerfNode.C:99
void dataStore(std::ostream &stream, const std::unique_ptr< PerfNode > &node, void *)
Definition PerfNode.C:78
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.