All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
aggregateTree.h
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 TRACE_AGGREGATE_TREE_H
26 #define TRACE_AGGREGATE_TREE_H
27 
28 #include "pxr/pxr.h"
29 
30 #include "pxr/base/trace/api.h"
31 #include "pxr/base/trace/aggregateNode.h"
32 
33 PXR_NAMESPACE_OPEN_SCOPE
34 
35 class TraceCollection;
36 
39 
47 
48 class TraceAggregateTree : public TfRefBase, public TfWeakBase {
49 public:
50  using This = TraceAggregateTree;
51  using ThisPtr = TraceAggregateTreePtr;
52  using ThisRefPtr = TraceAggregateTreeRefPtr;
53 
54  using TimeStamp = TraceEvent::TimeStamp;
55  using EventTimes = std::map<TfToken, TimeStamp>;
56  using CounterMap = TfHashMap<TfToken, double, TfToken::HashFunctor>;
57 
59  static ThisRefPtr New() {
60  return TfCreateRefPtr(new This());
61  }
62 
64  TraceAggregateNodePtr GetRoot() { return _root; }
65 
67  const EventTimes& GetEventTimes() const { return _eventTimes; }
68 
72  const CounterMap& GetCounters() const { return _counters; }
73 
76  TRACE_API int GetCounterIndex(const TfToken &key) const;
77 
82  TRACE_API bool AddCounter(const TfToken &key, int index, double totalValue);
83 
85  TRACE_API void Clear();
86 
89  TRACE_API void Append(
90  const TraceEventTreeRefPtr& eventTree,
91  const TraceCollection& collection);
92 
93 private:
94  TRACE_API TraceAggregateTree();
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 
104  friend class Trace_AggregateTreeBuilder;
105 };
106 
107 PXR_NAMESPACE_CLOSE_SCOPE
108 
109 #endif // TRACE_AGGREGATE_TREE_H
TRACE_API int GetCounterIndex(const TfToken &key) const
Returns the numeric index associated with a counter key.
static ThisRefPtr New()
Create an empty tree.
Definition: aggregateTree.h:59
A representation of a call tree.
Definition: aggregateTree.h:48
This class contains a timeline call tree and a map of counters to their values over time...
Definition: eventTree.h:58
const CounterMap & GetCounters() const
Returns a map of counters (counter keys), associated with their total accumulated value...
Definition: aggregateTree.h:72
TraceAggregateNodePtr GetRoot()
Returns the root node of the tree.
Definition: aggregateTree.h:64
uint64_t TimeStamp
Time in &quot;ticks&quot;.
Definition: event.h:50
const EventTimes & GetEventTimes() const
Returns a map of event keys to total inclusive time.
Definition: aggregateTree.h:67
This class populates a tree of TraceAggregateTree instances from TraceCollection instances.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
TRACE_API void Append(const TraceEventTreeRefPtr &eventTree, const TraceCollection &collection)
Creates new nodes and counter data from data in eventTree and collection.
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:72
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
TRACE_API void Clear()
Removes all data and nodes from the tree.
This class owns lists of TraceEvent instances per thread, and allows read access to them...
Definition: collection.h:49
TRACE_API bool AddCounter(const TfToken &key, int index, double totalValue)
Add a counter to the tree.
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:142