www.mooseframework.org
PerfNode.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 #pragma once
11 
19 #include "MooseTypes.h"
20 
21 #include <map>
22 
23 class PerfNode
24 {
25 public:
29  PerfNode(const PerfID id) : _id(id), _total_time(0), _num_calls(0) {}
30 
34  PerfID id() const { return _id; }
35 
39  void setStartTime(const std::chrono::time_point<std::chrono::steady_clock> time)
40  {
41  _start_time = time;
42  }
43 
47  void addTime(const std::chrono::time_point<std::chrono::steady_clock> time)
48  {
49  _total_time += time - _start_time;
50  }
51 
56 
60  void addTime(const std::chrono::steady_clock::duration time) { _total_time += time; }
61 
72  PerfNode * getChild(const PerfID id)
73  {
74  // RHS insertion on purpose
75  auto & child_node = _children[id];
76 
77  if (!child_node)
78  child_node.reset(new PerfNode(id));
79 
80  return child_node.get();
81  }
82 
86  const std::map<PerfID, std::unique_ptr<PerfNode>> & children() const { return _children; }
87 
91  std::chrono::steady_clock::duration selfTime() const;
92 
96  std::chrono::steady_clock::duration totalTime() const;
97 
101  std::chrono::steady_clock::duration childrenTime() const;
102 
106  unsigned long int numCalls() { return _num_calls; }
107 
108 protected:
111 
113  std::chrono::time_point<std::chrono::steady_clock> _start_time;
114 
116  std::chrono::steady_clock::duration _total_time;
117 
119  long unsigned int _num_calls;
120 
122  std::map<PerfID, std::unique_ptr<PerfNode>> _children;
123 };
124 
void setStartTime(const std::chrono::time_point< std::chrono::steady_clock > time)
Set the current start time.
Definition: PerfNode.h:39
void addTime(const std::chrono::time_point< std::chrono::steady_clock > time)
Add some time into this Node by taking the difference with the time passed in.
Definition: PerfNode.h:47
long unsigned int _num_calls
Number of times this node has been called.
Definition: PerfNode.h:119
void addTime(const std::chrono::steady_clock::duration time)
Add some time into this Node.
Definition: PerfNode.h:60
std::chrono::steady_clock::duration childrenTime() const
Get the time this nodes children took.
Definition: PerfNode.C:27
unsigned int PerfID
Definition: MooseTypes.h:163
void incrementNumCalls()
Increments the number of calls.
Definition: PerfNode.h:55
std::chrono::steady_clock::duration _total_time
The total elapsed time for this node.
Definition: PerfNode.h:116
const std::map< PerfID, std::unique_ptr< PerfNode > > & children() const
Get the children.
Definition: PerfNode.h:86
PerfID id() const
Get the ID of this Node.
Definition: PerfNode.h:34
PerfID _id
The unique ID for the section this Node corresponds to.
Definition: PerfNode.h:110
std::chrono::steady_clock::duration totalTime() const
The time this Node plus all of it&#39;s children took.
Definition: PerfNode.C:19
std::map< PerfID, std::unique_ptr< PerfNode > > _children
Timers that are directly underneath this node.
Definition: PerfNode.h:122
PerfNode * getChild(const PerfID id)
Get a child node with the unique id given.
Definition: PerfNode.h:72
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:113
std::chrono::steady_clock::duration selfTime() const
Get the time this node took.
Definition: PerfNode.C:13
unsigned long int numCalls()
Get the number of times this node was called.
Definition: PerfNode.h:106
PerfNode(const PerfID id)
Create a PerfNode with the given ID.
Definition: PerfNode.h:29
A node in the PerfGraph.
Definition: PerfNode.h:23