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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef PXR_BASE_TRACE_AGGREGATE_TREE_H
26 #define PXR_BASE_TRACE_AGGREGATE_TREE_H
27 
28 #include "pxr/pxr.h"
29 
30 #include "pxr/base/trace/api.h"
32 
34 
35 class TraceCollection;
36 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// \class TraceAggregateTree
42 ///
43 /// A representation of a call tree. Each node represents one or more calls that
44 /// occurred in the trace. Multiple calls to a child node are aggregated into one
45 /// node.
46 ///
47 
48 class TraceAggregateTree : public TfRefBase, public TfWeakBase {
49 public:
51  using ThisPtr = TraceAggregateTreePtr;
52  using ThisRefPtr = TraceAggregateTreeRefPtr;
53 
55  using EventTimes = std::map<TfToken, TimeStamp>;
57 
58  /// Create an empty tree
59  static ThisRefPtr New() {
60  return TfCreateRefPtr(new This());
61  }
62 
63  /// Returns the root node of the tree.
64  TraceAggregateNodePtr GetRoot() { return _root; }
65 
66  /// Returns a map of event keys to total inclusive time.
67  const EventTimes& GetEventTimes() const { return _eventTimes; }
68 
69  /// Returns a map of counters (counter keys), associated with their total
70  /// accumulated value. Each individual event node in the tree may also hold
71  /// on to an inclusive and exclusive value for the given counter.
72  const CounterMap& GetCounters() const { return _counters; }
73 
74  /// Returns the numeric index associated with a counter key. Counter values
75  /// on the event nodes will have to be looked up by the numeric index.
76  TRACE_API int GetCounterIndex(const TfToken &key) const;
77 
78  /// Add a counter to the tree. This method can be used to restore a
79  /// previous trace state and tree. Note, that the counter being added must
80  /// have a unique key and index. The method will return false if a key or
81  /// index already exists.
82  TRACE_API bool AddCounter(const TfToken &key, int index, double totalValue);
83 
84  /// Removes all data and nodes from the tree.
85  TRACE_API void Clear();
86 
87  /// Creates new nodes and counter data from data in \p eventTree and \p
88  /// collection.
89  TRACE_API void Append(
90  const TraceEventTreeRefPtr& eventTree,
91  const TraceCollection& collection);
92 
93 private:
95 
96  using _CounterIndexMap =TfHashMap<TfToken, int, TfToken::HashFunctor>;
97 
98  TraceAggregateNodeRefPtr _root;
99  EventTimes _eventTimes;
100  CounterMap _counters;
101  _CounterIndexMap _counterIndexMap;
102  int _counterIndex;
103 
105 };
106 
108 
109 #endif // PXR_BASE_TRACE_AGGREGATE_TREE_H
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1248
TraceEvent::TimeStamp TimeStamp
Definition: aggregateTree.h:54
TraceAggregateTree This
Definition: aggregateTree.h:50
std::map< TfToken, TimeStamp > EventTimes
Definition: aggregateTree.h:55
TF_DECLARE_WEAK_AND_REF_PTRS(TraceAggregateTree)
TRACE_API bool AddCounter(const TfToken &key, int index, double totalValue)
Definition: token.h:87
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:67
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
GLuint index
Definition: glcorearb.h:785
TraceAggregateNodePtr GetRoot()
Returns the root node of the tree.
Definition: aggregateTree.h:64
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
const CounterMap & GetCounters() const
Definition: aggregateTree.h:72
uint64_t TimeStamp
Time in "ticks".
Definition: event.h:50
TRACE_API void Append(const TraceEventTreeRefPtr &eventTree, const TraceCollection &collection)
TraceAggregateTreeRefPtr ThisRefPtr
Definition: aggregateTree.h:52
friend class Trace_AggregateTreeBuilder
static ThisRefPtr New()
Create an empty tree.
Definition: aggregateTree.h:59
TraceAggregateTreePtr ThisPtr
Definition: aggregateTree.h:51
#define TRACE_API
Definition: api.h:40
TfHashMap< TfToken, double, TfToken::HashFunctor > CounterMap
Definition: aggregateTree.h:56