Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | Private Attributes | Friends | List of all members
PerfNode Class Reference

A node in the PerfGraph. More...

#include <PerfNode.h>

Public Member Functions

 PerfNode (const PerfID id)
 Create a PerfNode with the given ID. More...
 
PerfID id () const
 Get the ID of this Node. More...
 
void setStartTimeAndMemory (const std::chrono::time_point< std::chrono::steady_clock > time, const long int memory)
 Set the current start time. More...
 
const std::chrono::time_point< std::chrono::steady_clock > & startTime () const
 Get the currnet start time Only makes sense if this node is running. More...
 
const long unsigned intstartMemory () const
 Get the current start memory Only makes sense if this node is running. More...
 
void addTimeAndMemory (const std::chrono::time_point< std::chrono::steady_clock > time, const long int memory)
 Add some time into this Node by taking the difference with the time passed in. More...
 
void incrementNumCalls ()
 Increments the number of calls. More...
 
void addTimeAndMemory (const std::chrono::steady_clock::duration time)
 Add some time into this Node. More...
 
PerfNodegetChild (const PerfID id)
 Get a child node with the unique id given. More...
 
const std::map< PerfID, std::unique_ptr< PerfNode > > & children () const
 Get the children. More...
 
std::chrono::steady_clock::duration selfTime () const
 Get the time this node took. More...
 
Real selfTimeSec () const
 Get the time this node took in seconds. More...
 
Real selfTimeAvg () const
 The average time this node took in seconds. More...
 
std::chrono::steady_clock::duration totalTime () const
 The time this Node plus all of it's children took. More...
 
Real totalTimeSec () const
 The time this Node plus all of its children took in seconds. More...
 
Real totalTimeAvg () const
 The average time this Node plus all of its children took in seconds. More...
 
std::chrono::steady_clock::duration childrenTime () const
 Get the time this nodes children took. More...
 
Real childrenTimeSec () const
 The time this node's children took in seconds. More...
 
unsigned long int numCalls () const
 Get the number of times this node was called. More...
 
long int selfMemory () const
 Get the amount of memory added by this node. More...
 
long int childrenMemory () const
 Get the amount of memory added by this node. More...
 
long int totalMemory () const
 Get the amount of memory added by this node. More...
 

Private Attributes

const PerfID _id
 The unique ID for the section this Node corresponds to. More...
 
std::chrono::time_point< std::chrono::steady_clock > _start_time
 The current start_time for this node (if it's on the stack) More...
 
std::chrono::steady_clock::duration _total_time
 The total elapsed time for this node. More...
 
long unsigned int _start_memory
 The starting memory for this node. More...
 
long unsigned int _num_calls
 Number of times this node has been called. More...
 
long unsigned int _total_memory
 The total memory added while this node is active. More...
 
std::map< PerfID, std::unique_ptr< PerfNode > > _children
 Timers that are directly underneath this node. More...
 

Friends

void dataStore (std::ostream &, const std::unique_ptr< PerfNode > &, void *)
 
void dataLoad (std::istream &, const std::unique_ptr< PerfNode > &, void *)
 

Detailed Description

A node in the PerfGraph.

Stores the timing for a particular section of code.

The design here is that _children are automatically added and kept track of within the Node - and only raw pointers are handed back out.

Definition at line 24 of file PerfNode.h.

Constructor & Destructor Documentation

◆ PerfNode()

PerfNode::PerfNode ( const PerfID  id)
inline

Create a PerfNode with the given ID.

Definition at line 30 of file PerfNode.h.

30 : _id(id), _total_time(0), _num_calls(0), _total_memory(0) {}
const PerfID _id
The unique ID for the section this Node corresponds to.
Definition: PerfNode.h:165
long unsigned int _num_calls
Number of times this node has been called.
Definition: PerfNode.h:177
std::chrono::steady_clock::duration _total_time
The total elapsed time for this node.
Definition: PerfNode.h:171
long unsigned int _total_memory
The total memory added while this node is active.
Definition: PerfNode.h:180

Member Function Documentation

◆ addTimeAndMemory() [1/2]

void PerfNode::addTimeAndMemory ( const std::chrono::time_point< std::chrono::steady_clock >  time,
const long int  memory 
)
inline

Add some time into this Node by taking the difference with the time passed in.

Definition at line 65 of file PerfNode.h.

67  {
68  _total_time += time - _start_time;
69  _total_memory += memory - _start_memory;
70  }
long unsigned int _start_memory
The starting memory for this node.
Definition: PerfNode.h:174
std::chrono::steady_clock::duration _total_time
The total elapsed time for this node.
Definition: PerfNode.h:171
long unsigned int _total_memory
The total memory added while this node is active.
Definition: PerfNode.h:180
std::chrono::time_point< std::chrono::steady_clock > _start_time
The current start_time for this node (if it&#39;s on the stack)
Definition: PerfNode.h:168

◆ addTimeAndMemory() [2/2]

void PerfNode::addTimeAndMemory ( const std::chrono::steady_clock::duration  time)
inline

Add some time into this Node.

Definition at line 80 of file PerfNode.h.

80 { _total_time += time; }
std::chrono::steady_clock::duration _total_time
The total elapsed time for this node.
Definition: PerfNode.h:171

◆ children()

const std::map<PerfID, std::unique_ptr<PerfNode> >& PerfNode::children ( ) const
inline

Get the children.

Definition at line 106 of file PerfNode.h.

Referenced by PerfGraph::recursivelyUpdate(), to_json(), and PerfGraph::treeRecurseInternal().

106 { return _children; }
std::map< PerfID, std::unique_ptr< PerfNode > > _children
Timers that are directly underneath this node.
Definition: PerfNode.h:183

◆ childrenMemory()

long int PerfNode::childrenMemory ( ) const

Get the amount of memory added by this node.

Definition at line 47 of file PerfNode.C.

Referenced by PerfGraph::recursivelyUpdate(), and selfMemory().

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 }
std::map< PerfID, std::unique_ptr< PerfNode > > _children
Timers that are directly underneath this node.
Definition: PerfNode.h:183

◆ childrenTime()

std::chrono::steady_clock::duration PerfNode::childrenTime ( ) const

Get the time this nodes children took.

Definition at line 30 of file PerfNode.C.

Referenced by childrenTimeSec(), and selfTime().

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 }
std::map< PerfID, std::unique_ptr< PerfNode > > _children
Timers that are directly underneath this node.
Definition: PerfNode.h:183

◆ childrenTimeSec()

Real PerfNode::childrenTimeSec ( ) const
inline

The time this node's children took in seconds.

Definition at line 141 of file PerfNode.h.

Referenced by PerfGraph::recursivelyUpdate().

141 { return std::chrono::duration<Real>(childrenTime()).count(); }
std::chrono::steady_clock::duration childrenTime() const
Get the time this nodes children took.
Definition: PerfNode.C:30

◆ getChild()

PerfNode* PerfNode::getChild ( const PerfID  id)
inline

Get a child node with the unique id given.

Note: this will automatically create the Node internally if it needs to.

Implemented in header to allow for more optimization

Parameters
idThe unique ID of the child node
Returns
The pointer to the child node

Definition at line 92 of file PerfNode.h.

93  {
94  // RHS insertion on purpose
95  auto & child_node = _children[id];
96 
97  if (!child_node)
98  child_node = std::make_unique<PerfNode>(id);
99 
100  return child_node.get();
101  }
PerfID id() const
Get the ID of this Node.
Definition: PerfNode.h:35
std::map< PerfID, std::unique_ptr< PerfNode > > _children
Timers that are directly underneath this node.
Definition: PerfNode.h:183

◆ id()

PerfID PerfNode::id ( ) const
inline

Get the ID of this Node.

Definition at line 35 of file PerfNode.h.

Referenced by getChild(), PerfGraph::recursivelyUpdate(), to_json(), and PerfGraph::treeRecurseInternal().

35 { return _id; }
const PerfID _id
The unique ID for the section this Node corresponds to.
Definition: PerfNode.h:165

◆ incrementNumCalls()

void PerfNode::incrementNumCalls ( )
inline

Increments the number of calls.

Definition at line 75 of file PerfNode.h.

Referenced by PerfGraph::push().

75 { _num_calls++; }
long unsigned int _num_calls
Number of times this node has been called.
Definition: PerfNode.h:177

◆ numCalls()

unsigned long int PerfNode::numCalls ( ) const
inline

Get the number of times this node was called.

Definition at line 146 of file PerfNode.h.

Referenced by PerfGraph::recursivelyUpdate(), selfTimeAvg(), to_json(), totalTimeAvg(), and PerfGraph::treeTable().

146 { return _num_calls; }
long unsigned int _num_calls
Number of times this node has been called.
Definition: PerfNode.h:177

◆ selfMemory()

long int PerfNode::selfMemory ( ) const

Get the amount of memory added by this node.

Definition at line 41 of file PerfNode.C.

Referenced by PerfGraph::recursivelyUpdate(), to_json(), and PerfGraph::treeTable().

42 {
43  return _total_memory - childrenMemory();
44 }
long int childrenMemory() const
Get the amount of memory added by this node.
Definition: PerfNode.C:47
long unsigned int _total_memory
The total memory added while this node is active.
Definition: PerfNode.h:180

◆ selfTime()

std::chrono::steady_clock::duration PerfNode::selfTime ( ) const

Get the time this node took.

Definition at line 16 of file PerfNode.C.

Referenced by selfTimeSec().

17 {
18  return _total_time - childrenTime();
19 }
std::chrono::steady_clock::duration childrenTime() const
Get the time this nodes children took.
Definition: PerfNode.C:30
std::chrono::steady_clock::duration _total_time
The total elapsed time for this node.
Definition: PerfNode.h:171

◆ selfTimeAvg()

Real PerfNode::selfTimeAvg ( ) const
inline

The average time this node took in seconds.

Definition at line 119 of file PerfNode.h.

Referenced by PerfGraph::treeTable().

119 { return selfTimeSec() / static_cast<Real>(numCalls()); }
Real selfTimeSec() const
Get the time this node took in seconds.
Definition: PerfNode.h:115
unsigned long int numCalls() const
Get the number of times this node was called.
Definition: PerfNode.h:146
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ selfTimeSec()

Real PerfNode::selfTimeSec ( ) const
inline

Get the time this node took in seconds.

Definition at line 115 of file PerfNode.h.

Referenced by PerfGraph::recursivelyUpdate(), selfTimeAvg(), to_json(), and PerfGraph::treeTable().

115 { return std::chrono::duration<Real>(selfTime()).count(); }
std::chrono::steady_clock::duration selfTime() const
Get the time this node took.
Definition: PerfNode.C:16

◆ setStartTimeAndMemory()

void PerfNode::setStartTimeAndMemory ( const std::chrono::time_point< std::chrono::steady_clock >  time,
const long int  memory 
)
inline

Set the current start time.

Definition at line 40 of file PerfNode.h.

Referenced by PerfGraph::push().

42  {
43  _start_time = time;
44  _start_memory = memory;
45  }
long unsigned int _start_memory
The starting memory for this node.
Definition: PerfNode.h:174
std::chrono::time_point< std::chrono::steady_clock > _start_time
The current start_time for this node (if it&#39;s on the stack)
Definition: PerfNode.h:168

◆ startMemory()

const long unsigned int& PerfNode::startMemory ( ) const
inline

Get the current start memory Only makes sense if this node is running.

Definition at line 60 of file PerfNode.h.

60 { return _start_memory; }
long unsigned int _start_memory
The starting memory for this node.
Definition: PerfNode.h:174

◆ startTime()

const std::chrono::time_point<std::chrono::steady_clock>& PerfNode::startTime ( ) const
inline

Get the currnet start time Only makes sense if this node is running.

Definition at line 51 of file PerfNode.h.

52  {
53  return _start_time;
54  }
std::chrono::time_point< std::chrono::steady_clock > _start_time
The current start_time for this node (if it&#39;s on the stack)
Definition: PerfNode.h:168

◆ totalMemory()

long int PerfNode::totalMemory ( ) const
inline

Get the amount of memory added by this node.

Definition at line 161 of file PerfNode.h.

Referenced by PerfGraph::recursivelyUpdate(), and PerfGraph::treeTable().

161 { return _total_memory; }
long unsigned int _total_memory
The total memory added while this node is active.
Definition: PerfNode.h:180

◆ totalTime()

std::chrono::steady_clock::duration PerfNode::totalTime ( ) const

The time this Node plus all of it's children took.

Definition at line 22 of file PerfNode.C.

Referenced by totalTimeSec(), and PerfGraph::treeRecurseInternal().

23 {
24  // Note that all of the children's time is already
25  // accounted for in the total time
26  return _total_time;
27 }
std::chrono::steady_clock::duration _total_time
The total elapsed time for this node.
Definition: PerfNode.h:171

◆ totalTimeAvg()

Real PerfNode::totalTimeAvg ( ) const
inline

The average time this Node plus all of its children took in seconds.

Definition at line 132 of file PerfNode.h.

Referenced by PerfGraph::treeTable().

132 { return totalTimeSec() / static_cast<Real>(numCalls()); }
Real totalTimeSec() const
The time this Node plus all of its children took in seconds.
Definition: PerfNode.h:128
unsigned long int numCalls() const
Get the number of times this node was called.
Definition: PerfNode.h:146
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ totalTimeSec()

Real PerfNode::totalTimeSec ( ) const
inline

The time this Node plus all of its children took in seconds.

Definition at line 128 of file PerfNode.h.

Referenced by PerfGraph::recursivelyUpdate(), totalTimeAvg(), and PerfGraph::treeTable().

128 { return std::chrono::duration<Real>(totalTime()).count(); }
std::chrono::steady_clock::duration totalTime() const
The time this Node plus all of it&#39;s children took.
Definition: PerfNode.C:22

Friends And Related Function Documentation

◆ dataLoad

void dataLoad ( std::istream &  stream,
const std::unique_ptr< PerfNode > &  node,
void context 
)
friend

Definition at line 79 of file PerfNode.C.

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 }
std::string name(const ElemQuality q)
friend void dataLoad(std::istream &, const std::unique_ptr< PerfNode > &, void *)
Definition: PerfNode.C:79
PerfID id() const
Get the ID of this Node.
Definition: PerfNode.h:35
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID The name of the section.
The PerfGraph will hold the master list of all registered performance segments and the head PerfNode...
Definition: PerfGraph.h:43
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.

◆ dataStore

void dataStore ( std::ostream &  stream,
const std::unique_ptr< PerfNode > &  node,
void context 
)
friend

Definition at line 58 of file PerfNode.C.

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 }
std::string name(const ElemQuality q)
const PerfGraphSectionInfo & sectionInfo(const PerfID section_id) const
Given a PerfID return the PerfGraphSectionInfo The ID.
friend void dataStore(std::ostream &, const std::unique_ptr< PerfNode > &, void *)
Definition: PerfNode.C:58
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.

Member Data Documentation

◆ _children

std::map<PerfID, std::unique_ptr<PerfNode> > PerfNode::_children
private

Timers that are directly underneath this node.

Definition at line 183 of file PerfNode.h.

Referenced by children(), childrenMemory(), childrenTime(), and getChild().

◆ _id

const PerfID PerfNode::_id
private

The unique ID for the section this Node corresponds to.

Definition at line 165 of file PerfNode.h.

Referenced by id().

◆ _num_calls

long unsigned int PerfNode::_num_calls
private

Number of times this node has been called.

Definition at line 177 of file PerfNode.h.

Referenced by incrementNumCalls(), and numCalls().

◆ _start_memory

long unsigned int PerfNode::_start_memory
private

The starting memory for this node.

Definition at line 174 of file PerfNode.h.

Referenced by addTimeAndMemory(), setStartTimeAndMemory(), and startMemory().

◆ _start_time

std::chrono::time_point<std::chrono::steady_clock> PerfNode::_start_time
private

The current start_time for this node (if it's on the stack)

Definition at line 168 of file PerfNode.h.

Referenced by addTimeAndMemory(), setStartTimeAndMemory(), and startTime().

◆ _total_memory

long unsigned int PerfNode::_total_memory
private

The total memory added while this node is active.

Definition at line 180 of file PerfNode.h.

Referenced by addTimeAndMemory(), selfMemory(), and totalMemory().

◆ _total_time

std::chrono::steady_clock::duration PerfNode::_total_time
private

The total elapsed time for this node.

Definition at line 171 of file PerfNode.h.

Referenced by addTimeAndMemory(), selfTime(), and totalTime().


The documentation for this class was generated from the following files: