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,
62 int c = 1, int xc = 1);
63
64 TRACE_API void Append(TraceAggregateNodeRefPtr child);
65
67 const TfToken& GetKey() { return _key;}
68
71
73 TimeStamp GetInclusiveTime() { return _ts; }
74
76 TRACE_API TimeStamp GetExclusiveTime(bool recursive = false);
77
80 int GetCount(bool recursive = false) const {
81 return recursive ? _recursiveCount : _count;
82 }
83
85 int GetExclusiveCount() const { return _exclusiveCount; }
86
88
89
92
93 TRACE_API void AppendInclusiveCounterValue(int index, double value);
94
95 TRACE_API double GetInclusiveCounterValue(int index) const;
96
97 TRACE_API void AppendExclusiveCounterValue(int index, double value);
98
99 TRACE_API double GetExclusiveCounterValue(int index) const;
100
102
106
107
110 const TraceAggregateNodePtrVector GetChildren() {
111 // convert to a vector of weak ptrs
112 return TraceAggregateNodePtrVector( _children.begin(),_children.end() );
113 }
114
115 const TraceAggregateNodeRefPtrVector &GetChildrenRef() {
116 return _children;
117 }
118
119 TRACE_API TraceAggregateNodeRefPtr GetChild(const TfToken &key);
120 TraceAggregateNodeRefPtr GetChild(const std::string &key) {
121 return GetChild(TfToken(key));
122 }
123
125
126
128 void SetExpanded(bool expanded) {
129 _expanded = expanded;
130 }
131
133 bool IsExpanded() {
134 return _expanded;
135 }
136
146 TimeStamp scopeOverhead, TimeStamp timerQuantum,
147 uint64_t *numDescendantNodes = nullptr);
148
151
157 TRACE_API void MarkRecursiveChildren();
158
164 bool IsRecursionMarker() const { return _isRecursionMarker; }
165
171 bool IsRecursionHead() const { return _isRecursionHead; }
172
174
175
176private:
177
178 TraceAggregateNode(const TfToken &key, TimeStamp ts,
179 int count, int exclusiveCount) :
180 _key(key), _ts(ts), _exclusiveTs(ts),
181 _count(count), _exclusiveCount(exclusiveCount),
182 _recursiveCount(count), _recursiveExclusiveTs(ts), _expanded(false),
183 _isRecursionMarker(false), _isRecursionHead(false),
184 _isRecursionProcessed(false) {}
185
186 using _ChildDictionary = TfDenseHashMap<TfToken, size_t, TfHash>;
187
188 void _MergeRecursive(const TraceAggregateNodeRefPtr &node);
189
190 void _SetAsRecursionMarker(TraceAggregateNodePtr parent);
191
192 const TfToken _key;
193 TimeStamp _ts;
194 TimeStamp _exclusiveTs;
195 int _count;
196 int _exclusiveCount;
197
198 // We keep the recursive counts separate so that we don't mess with
199 // the collected data.
200 int _recursiveCount;
201 TraceAggregateNodePtr _recursionParent;
202 TimeStamp _recursiveExclusiveTs;
203
204 TraceAggregateNodeRefPtrVector _children;
205 _ChildDictionary _childrenByKey;
206
207 // A structure that holds on to the inclusive and exclusive counter
208 // values. These values are usually populated together, so it's beneficial
209 // to maintain them in a tightly packed structure.
210 struct _CounterValue {
211 _CounterValue() : inclusive(0.0), exclusive(0.0) {}
212 double inclusive;
213 double exclusive;
214 };
215
216 using _CounterValues = TfDenseHashMap<int, _CounterValue, TfHash>;
217
218 // The counter values associated with specific counter indices
219 _CounterValues _counterValues;
220
221 unsigned int
222 // If multiple Trace Editors are to be pointed at the same Reporter, this
223 // might have to be changed
224 _expanded:1,
225
226 // This flag keeps track of whether or not this node is simply intended
227 // as a marker for the start of a recursive call tree.
228 _isRecursionMarker:1,
229
230 // This flag keeps track of whether or not a node is the head of a
231 // recursive call tree. In other words, if it is a function that has been
232 // called recursively.
233 _isRecursionHead:1,
234
235 // This flag is used during recursive traversal to mark the node as having
236 // been visited and avoid too much processing.
237 _isRecursionProcessed:1;
238};
239
240PXR_NAMESPACE_CLOSE_SCOPE
241
242#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:85
int GetCount(bool recursive=false) const
Returns the call count of this node.
Definition: aggregateNode.h:80
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:73
const TfToken & GetKey()
Returns the node's key.
Definition: aggregateNode.h:67
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:33
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.