All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eventTreeBuilder.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_EVENT_TREE_BUILDER_H
26 #define TRACE_EVENT_TREE_BUILDER_H
27 
28 #include "pxr/pxr.h"
29 
30 #include "pxr/base/trace/collection.h"
31 #include "pxr/base/trace/counterAccumulator.h"
32 #include "pxr/base/trace/eventNode.h"
33 #include "pxr/base/trace/eventTree.h"
34 
35 PXR_NAMESPACE_OPEN_SCOPE
36 
45  : protected TraceCollection::Visitor {
46 public:
49 
51  TraceEventTreeRefPtr GetTree() { return _tree; }
52 
54  TRACE_API void CreateTree(const TraceCollection& collection);
55 
58  const TraceEventTree::CounterMap& counterValues) {
59  _counterAccum.SetCurrentValues(counterValues);
60  }
61 
62 protected:
65  virtual void OnBeginCollection() override;
66  virtual void OnEndCollection() override;
67  virtual bool AcceptsCategory(TraceCategoryId) override;
68  virtual void OnBeginThread(const TraceThreadId&) override;
69  virtual void OnEndThread(const TraceThreadId&) override;
70  virtual void OnEvent(
71  const TraceThreadId&, const TfToken&, const TraceEvent&) override;
73 
74 private:
75 
76  // Helper class for event graph creation.
77  struct _PendingEventNode {
78  using TimeStamp = TraceEvent::TimeStamp;
79 
80  struct AttributeData {
81  TimeStamp time;
82  TfToken key;
84  };
85 
86  _PendingEventNode( const TfToken& key,
87  TraceCategoryId category,
88  TimeStamp start,
89  TimeStamp end,
90  bool separateEvents,
91  bool isComplete);
92  TraceEventNodeRefPtr Close();
93 
94  // Can move this, but not copy it
95  _PendingEventNode(const _PendingEventNode&) = delete;
96  _PendingEventNode& operator= (const _PendingEventNode&) = delete;
97 
98  _PendingEventNode(_PendingEventNode&&) = default;
99  _PendingEventNode& operator= (_PendingEventNode&&) = default;
100 
101  TfToken key;
102  TraceCategoryId category;
103  TimeStamp start;
104  TimeStamp end;
105  bool separateEvents;
106  bool isComplete;
107  std::vector<TraceEventNodeRefPtr> children;
108  std::vector<AttributeData> attributes;
109  };
110 
111  void _OnBegin(const TraceThreadId&, const TfToken&, const TraceEvent&);
112  void _OnEnd(const TraceThreadId&, const TfToken&, const TraceEvent&);
113  void _OnData(const TraceThreadId&, const TfToken&, const TraceEvent&);
114  void _OnTimespan(const TraceThreadId&, const TfToken&, const TraceEvent&);
115  void _OnMarker(const TraceThreadId&, const TfToken&, const TraceEvent&);
116 
117  using _PendingNodeStack = std::vector<_PendingEventNode>;
118  using _ThreadStackMap = std::map<TraceThreadId, _PendingNodeStack>;
119 
120  void _PopAndClose(_PendingNodeStack& stack);
121 
122  TraceEventNodeRefPtr _root;
123  _ThreadStackMap _threadStacks;
124  TraceEventTreeRefPtr _tree;
125 
126  class _CounterAccumulator : public TraceCounterAccumulator {
127  protected:
128  bool _AcceptsCategory(TraceCategoryId) override;
129  };
130  _CounterAccumulator _counterAccum;
131 
132  TraceEventTree::MarkerValuesMap _markersMap;
133 };
134 
135 PXR_NAMESPACE_CLOSE_SCOPE
136 
137 #endif // TRACE_EVENT_TREE_BUILDER_H
virtual bool AcceptsCategory(TraceCategoryId) override
Called before an event with categoryId is visited.
virtual void OnEndThread(const TraceThreadId &) override
Called after the last event of from the thread with threadId is encountered.
TraceEventTreeRefPtr GetTree()
Returns the created tree.
uint64_t TimeStamp
Time in &quot;ticks&quot;.
Definition: event.h:50
virtual void OnBeginThread(const TraceThreadId &) override
Called before the first event of from the thread with threadId is encountered.
TRACE_API void CreateTree(const TraceCollection &collection)
Creates a TraceEventTree from the data in /p collection.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
This represents an event recorded by a TraceCollector.
Definition: event.h:47
virtual void OnEndCollection() override
Called at the end of an iteration.
This class holds data that can be stored in TraceEvents.
Definition: eventData.h:45
This interface provides a way to access data a TraceCollection.
Definition: collection.h:83
virtual void OnEvent(const TraceThreadId &, const TfToken &, const TraceEvent &) override
Called for every event event with key on thread threadId if AcceptsCategory returns true...
virtual void OnBeginCollection() override
Called at the beginning of an iteration.
This class creates a tree of TraceEventTree instances from TraceCollection instances.
This class owns lists of TraceEvent instances per thread, and allows read access to them...
Definition: collection.h:49
This class accumulates counter values from TraceCollection instances.
Trace_EventTreeBuilder()
Constructor.
uint32_t TraceCategoryId
Categories that a TraceReporter can use to filter events.
Definition: category.h:44
void SetCounterValues(const TraceEventTree::CounterMap &counterValues)
Set the value of the counters.