Loading...
Searching...
No Matches
aggregateNode.h
1//
2// Copyright 2018 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7
8#ifndef PXR_BASE_TRACE_AGGREGATE_NODE_H
9#define PXR_BASE_TRACE_AGGREGATE_NODE_H
10
11#include "pxr/pxr.h"
12
13#include "pxr/base/trace/api.h"
14#include "pxr/base/trace/event.h"
15#include "pxr/base/trace/threads.h"
16
17#include "pxr/base/tf/refBase.h"
18#include "pxr/base/tf/refPtr.h"
19#include "pxr/base/tf/token.h"
21#include "pxr/base/tf/weakPtr.h"
24
25#include <vector>
27
28PXR_NAMESPACE_OPEN_SCOPE
29
31
39
40class TraceAggregateNode : public TfRefBase, public TfWeakBase {
41public:
42
44 using ThisPtr = TraceAggregateNodePtr;
45 using ThisRefPtr = TraceAggregateNodeRefPtr;
46
47 using TimeStamp = TraceEvent::TimeStamp;
48
49 static ThisRefPtr New() {
50 return This::New(TfToken("root"), 0, 0);
51 }
52
53 static ThisRefPtr New(const TfToken &key,
54 const TimeStamp ts,
55 const int count = 1,
56 const int exclusiveCount = 1) {
57 return TfCreateRefPtr(new This(key, ts, count, exclusiveCount));
58 }
59
60 TRACE_API TraceAggregateNodeRefPtr
61 Append(const TfToken &key, TimeStamp ts,int c = 1, int xc = 1);
62
63 // Same as Append() but return nothing.
64 TRACE_API void
65 AppendBlind(const TfToken &key, TimeStamp ts, int c = 1, int xc = 1);
66
67 TRACE_API void Append(TraceAggregateNodeRefPtr child);
68
70 const TfToken& GetKey() { return _key;}
71
74
76 TimeStamp GetInclusiveTime() { return _ts; }
77
79 TRACE_API TimeStamp GetExclusiveTime(bool recursive = false);
80
83 int GetCount(bool recursive = false) const {
84 return recursive ? _recursiveCount : _count;
85 }
86
88 int GetExclusiveCount() const { return _exclusiveCount; }
89
91
92
95
96 TRACE_API void AppendInclusiveCounterValue(int index, double value);
97
98 TRACE_API double GetInclusiveCounterValue(int index) const;
99
100 TRACE_API void AppendExclusiveCounterValue(int index, double value);
101
102 TRACE_API double GetExclusiveCounterValue(int index) const;
103
105
109
110
113 const TraceAggregateNodePtrVector GetChildren() {
114 // convert to a vector of weak ptrs
115 return TraceAggregateNodePtrVector( _children.begin(),_children.end() );
116 }
117
118 const TraceAggregateNodeRefPtrVector &GetChildrenRef() {
119 return _children;
120 }
121
122 TRACE_API TraceAggregateNodeRefPtr GetChild(const TfToken &key);
123 TraceAggregateNodeRefPtr GetChild(const std::string &key) {
124 return GetChild(TfToken(key));
125 }
126
128
129
131 void SetExpanded(bool expanded) {
132 _expanded = expanded;
133 }
134
136 bool IsExpanded() {
137 return _expanded;
138 }
139
149 TimeStamp scopeOverhead, TimeStamp timerQuantum,
150 uint64_t *numDescendantNodes = nullptr);
151
154
160 TRACE_API void MarkRecursiveChildren();
161
167 bool IsRecursionMarker() const { return _isRecursionMarker; }
168
174 bool IsRecursionHead() const { return _isRecursionHead; }
175
177
178
179private:
180
181 TraceAggregateNode(const TfToken &key, TimeStamp ts,
182 int count, int exclusiveCount) :
183 _key(key), _ts(ts), _exclusiveTs(ts),
184 _count(count), _exclusiveCount(exclusiveCount),
185 _recursiveCount(count), _recursiveExclusiveTs(ts), _expanded(false),
186 _isRecursionMarker(false), _isRecursionHead(false),
187 _isRecursionProcessed(false) {}
188
189 using _ChildDictionary = TfDenseHashMap<TfToken, size_t, TfHash>;
190
191 void _MergeRecursive(const TraceAggregateNodeRefPtr &node);
192
193 void _SetAsRecursionMarker(TraceAggregateNodePtr parent);
194
195 TraceAggregateNode *_GetChildRaw(const TfToken &key);
196
197 const TfToken _key;
198 TimeStamp _ts;
199 TimeStamp _exclusiveTs;
200 int _count;
201 int _exclusiveCount;
202
203 // We keep the recursive counts separate so that we don't mess with
204 // the collected data.
205 int _recursiveCount;
206 TraceAggregateNodePtr _recursionParent;
207 TimeStamp _recursiveExclusiveTs;
208
209 TraceAggregateNodeRefPtrVector _children;
210 _ChildDictionary _childrenByKey;
211
212 // A structure that holds on to the inclusive and exclusive counter
213 // values. These values are usually populated together, so it's beneficial
214 // to maintain them in a tightly packed structure.
215 struct _CounterValue {
216 _CounterValue() : inclusive(0.0), exclusive(0.0) {}
217 double inclusive;
218 double exclusive;
219 };
220
221 using _CounterValues = TfDenseHashMap<int, _CounterValue, TfHash>;
222
223 // The counter values associated with specific counter indices
224 _CounterValues _counterValues;
225
226 unsigned int
227 // If multiple Trace Editors are to be pointed at the same Reporter, this
228 // might have to be changed
229 _expanded:1,
230
231 // This flag keeps track of whether or not this node is simply intended
232 // as a marker for the start of a recursive call tree.
233 _isRecursionMarker:1,
234
235 // This flag keeps track of whether or not a node is the head of a
236 // recursive call tree. In other words, if it is a function that has been
237 // called recursively.
238 _isRecursionHead:1,
239
240 // This flag is used during recursive traversal to mark the node as having
241 // been visited and avoid too much processing.
242 _isRecursionProcessed:1;
243};
244
245PXR_NAMESPACE_CLOSE_SCOPE
246
247#endif // PXR_BASE_TRACE_AGGREGATE_NODE_H
This is a space efficient container that mimics the TfHashMap API that uses a vector for storage when...
Definition: denseHashMap.h:41
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:56
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:124
A representation of a call tree.
Definition: aggregateNode.h:40
int GetExclusiveCount() const
Returns the exclusive count.
Definition: aggregateNode.h:88
int GetCount(bool recursive=false) const
Returns the call count of this node.
Definition: aggregateNode.h:83
bool IsExpanded()
Returns whether this node is expanded in a gui.
TRACE_API void CalculateInclusiveCounterValues()
Recursively calculates the inclusive counter values from the inclusive and exclusive counts of child ...
bool IsRecursionHead() const
Returns true if this node is the head of a recursive call tree (i.e.
TRACE_API void AdjustForOverheadAndNoise(TimeStamp scopeOverhead, TimeStamp timerQuantum, uint64_t *numDescendantNodes=nullptr)
Subtract scopeOverhead cost times the number of descendant nodes from the inclusive time of each node...
TRACE_API void MarkRecursiveChildren()
Scans the tree for recursive calls and updates the recursive counts.
TRACE_API TimeStamp GetExclusiveTime(bool recursive=false)
Returns the time spent in this node but not its children.
TimeStamp GetInclusiveTime()
Returns the total time of this node ands its children.
Definition: aggregateNode.h:76
const TfToken & GetKey()
Returns the node's key.
Definition: aggregateNode.h:70
void SetExpanded(bool expanded)
Sets whether or not this node is expanded in a gui.
bool IsRecursionMarker() const
Returns true if this node is simply a marker for a merged recursive subtree; otherwise returns false.
uint64_t TimeStamp
Time in "ticks".
Definition: event.h:35
Standard pointer typedefs.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:72
Reference counting.
High-resolution, low-cost timing routines.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
Pointer storage with deletion detection.