HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
aggregateTree.h
Go to the documentation of this file.
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_TREE_H
9 #define PXR_BASE_TRACE_AGGREGATE_TREE_H
10 
11 #include "pxr/pxr.h"
12 
13 #include "pxr/base/trace/api.h"
15 
17 
18 class TraceCollection;
19 
22 
23 ////////////////////////////////////////////////////////////////////////////////
24 /// \class TraceAggregateTree
25 ///
26 /// A representation of a call tree. Each node represents one or more calls that
27 /// occurred in the trace. Multiple calls to a child node are aggregated into one
28 /// node.
29 ///
30 
31 class TraceAggregateTree : public TfRefBase, public TfWeakBase {
32 public:
34  using ThisPtr = TraceAggregateTreePtr;
35  using ThisRefPtr = TraceAggregateTreeRefPtr;
36 
38  using EventTimes = std::map<TfToken, TimeStamp>;
40 
41  /// Create an empty tree
42  static ThisRefPtr New() {
43  return TfCreateRefPtr(new This());
44  }
45 
46  /// Returns the root node of the tree.
47  TraceAggregateNodePtr GetRoot() { return _root; }
48 
49  /// Returns a map of event keys to total inclusive time.
50  const EventTimes& GetEventTimes() const { return _eventTimes; }
51 
52  /// Returns a map of counters (counter keys), associated with their total
53  /// accumulated value. Each individual event node in the tree may also hold
54  /// on to an inclusive and exclusive value for the given counter.
55  const CounterMap& GetCounters() const { return _counters; }
56 
57  /// Returns the numeric index associated with a counter key. Counter values
58  /// on the event nodes will have to be looked up by the numeric index.
59  TRACE_API int GetCounterIndex(const TfToken &key) const;
60 
61  /// Add a counter to the tree. This method can be used to restore a
62  /// previous trace state and tree. Note, that the counter being added must
63  /// have a unique key and index. The method will return false if a key or
64  /// index already exists.
65  TRACE_API bool AddCounter(const TfToken &key, int index, double totalValue);
66 
67  /// Removes all data and nodes from the tree.
68  TRACE_API void Clear();
69 
70  /// Creates new nodes and counter data from data in \p eventTree and \p
71  /// collection.
72  TRACE_API void Append(
73  const TraceEventTreeRefPtr& eventTree,
74  const TraceCollection& collection);
75 
76 private:
78 
79  using _CounterIndexMap =TfHashMap<TfToken, int, TfToken::HashFunctor>;
80 
81  TraceAggregateNodeRefPtr _root;
82  EventTimes _eventTimes;
83  CounterMap _counters;
84  _CounterIndexMap _counterIndexMap;
85  int _counterIndex;
86 
88 };
89 
91 
92 #endif // PXR_BASE_TRACE_AGGREGATE_TREE_H
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1190
TraceEvent::TimeStamp TimeStamp
Definition: aggregateTree.h:37
TraceAggregateTree This
Definition: aggregateTree.h:33
std::map< TfToken, TimeStamp > EventTimes
Definition: aggregateTree.h:38
TF_DECLARE_WEAK_AND_REF_PTRS(TraceAggregateTree)
TRACE_API bool AddCounter(const TfToken &key, int index, double totalValue)
Definition: token.h:70
TRACE_API void Clear()
Removes all data and nodes from the tree.
TRACE_API int GetCounterIndex(const TfToken &key) const
const EventTimes & GetEventTimes() const
Returns a map of event keys to total inclusive time.
Definition: aggregateTree.h:50
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLuint index
Definition: glcorearb.h:786
TraceAggregateNodePtr GetRoot()
Returns the root node of the tree.
Definition: aggregateTree.h:47
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
const CounterMap & GetCounters() const
Definition: aggregateTree.h:55
uint64_t TimeStamp
Time in "ticks".
Definition: event.h:33
TRACE_API void Append(const TraceEventTreeRefPtr &eventTree, const TraceCollection &collection)
TraceAggregateTreeRefPtr ThisRefPtr
Definition: aggregateTree.h:35
friend class Trace_AggregateTreeBuilder
Definition: aggregateTree.h:87
static ThisRefPtr New()
Create an empty tree.
Definition: aggregateTree.h:42
TraceAggregateTreePtr ThisPtr
Definition: aggregateTree.h:34
#define TRACE_API
Definition: api.h:23
TfHashMap< TfToken, double, TfToken::HashFunctor > CounterMap
Definition: aggregateTree.h:39