HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eventNode.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_EVENT_NODE_H
26 #define PXR_BASE_TRACE_EVENT_NODE_H
27 
28 #include "pxr/pxr.h"
29 
30 #include "pxr/base/trace/api.h"
31 #include "pxr/base/trace/event.h"
33 
34 #include "pxr/base/tf/refBase.h"
35 #include "pxr/base/tf/refPtr.h"
36 #include "pxr/base/tf/token.h"
38 
39 #include <vector>
40 
42 
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// \class TraceEventNode
47 ///
48 /// TraceEventNode is used to represents call tree of a trace. Each node
49 /// represents a Begin-End trace event pair, or a single Timespan event. This is
50 /// useful for timeline views of a trace.
51 ///
52 
53 class TraceEventNode : public TfRefBase {
54 public:
55 
58  using AttributeMap = std::multimap<TfToken, AttributeData>;
59 
60  /// Creates a new root node.
61  ///
62  static TraceEventNodeRefPtr New() {
63  return TraceEventNode::New(
64  TfToken("root"), TraceCategory::Default, 0.0, 0.0, {}, false);
65  }
66 
67  /// Creates a new node with \p key, \p category, \p beginTime and
68  /// \p endTime.
69  static TraceEventNodeRefPtr New(const TfToken &key,
70  const TraceCategoryId category,
71  const TimeStamp beginTime,
72  const TimeStamp endTime,
73  TraceEventNodeRefPtrVector&& children,
74  const bool separateEvents) {
75  return TfCreateRefPtr(
76  new TraceEventNode(
77  key,
78  category,
79  beginTime,
80  endTime,
81  std::move(children),
82  separateEvents));
83  }
84 
85  /// Appends a new child node with \p key, \p category, \p beginTime and
86  /// \p endTime.
87  TraceEventNodeRefPtr Append(const TfToken &key,
88  TraceCategoryId category,
89  TimeStamp beginTime,
90  TimeStamp endTime,
91  bool separateEvents);
92 
93  /// Appends \p node as a child node.
94  void Append(TraceEventNodeRefPtr node);
95 
96  /// Returns the name of this node.
97  TfToken GetKey() { return _key;}
98 
99  /// Returns the category of this node.
100  TraceCategoryId GetCategory() const { return _category; }
101 
102  /// Sets this node's begin and end time to the time extents of its direct
103  /// children.
105 
106  /// \name Profile Data Accessors
107  /// @{
108 
109  /// Returns the time that this scope started.
110  TimeStamp GetBeginTime() { return _beginTime; }
111 
112  /// Returns the time that this scope ended.
113  TimeStamp GetEndTime() { return _endTime; }
114 
115  /// @}
116 
117  /// \name Children Accessors
118  /// @{
119 
120  /// Returns references to the children of this node.
121  const TraceEventNodeRefPtrVector &GetChildrenRef() {
122  return _children;
123  }
124 
125  /// @}
126 
127  /// Return the data associated with this node.
128  const AttributeMap& GetAttributes() const { return _attributes; }
129 
130  /// Add data to this node.
131  void AddAttribute(const TfToken& key, const AttributeData& attr);
132 
133  /// Returns whether this node was created from a Begin-End pair or a single
134  /// Timespan event.
135  bool IsFromSeparateEvents() const {
136  return _fromSeparateEvents;
137  }
138 
139 private:
140 
142  const TfToken &key,
143  TraceCategoryId category,
144  TimeStamp beginTime,
145  TimeStamp endTime,
146  TraceEventNodeRefPtrVector&& children,
147  bool separateEvents)
148 
149  : _key(key)
150  , _category(category)
151  , _beginTime(beginTime)
152  , _endTime(endTime)
153  , _children(std::move(children))
154  , _fromSeparateEvents(separateEvents)
155  {}
156 
157 
158  TfToken _key;
159  TraceCategoryId _category;
160  TimeStamp _beginTime;
161  TimeStamp _endTime;
162  TraceEventNodeRefPtrVector _children;
163  bool _fromSeparateEvents;
164 
165  AttributeMap _attributes;
166 };
167 
169 
170 #endif // PXR_BASE_TRACE_EVENT_NODE_H
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1248
void AddAttribute(const TfToken &key, const AttributeData &attr)
Add data to this node.
TimeStamp GetBeginTime()
Returns the time that this scope started.
Definition: eventNode.h:110
static TraceEventNodeRefPtr New(const TfToken &key, const TraceCategoryId category, const TimeStamp beginTime, const TimeStamp endTime, TraceEventNodeRefPtrVector &&children, const bool separateEvents)
Definition: eventNode.h:69
bool IsFromSeparateEvents() const
Definition: eventNode.h:135
TfToken GetKey()
Returns the name of this node.
Definition: eventNode.h:97
Definition: token.h:87
static TraceEventNodeRefPtr New()
Definition: eventNode.h:62
TraceCategoryId GetCategory() const
Returns the category of this node.
Definition: eventNode.h:100
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_REF_PTRS(TraceEventNode)
TraceEventNodeRefPtr Append(const TfToken &key, TraceCategoryId category, TimeStamp beginTime, TimeStamp endTime, bool separateEvents)
TraceEvent::TimeStamp TimeStamp
Definition: eventNode.h:56
TimeStamp GetEndTime()
Returns the time that this scope ended.
Definition: eventNode.h:113
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
uint64_t TimeStamp
Time in "ticks".
Definition: event.h:50
std::multimap< TfToken, AttributeData > AttributeMap
Definition: eventNode.h:58
void SetBeginAndEndTimesFromChildren()
TraceEventData AttributeData
Definition: eventNode.h:57
uint32_t TraceCategoryId
Categories that a TraceReporter can use to filter events.
Definition: category.h:44
const AttributeMap & GetAttributes() const
Return the data associated with this node.
Definition: eventNode.h:128
const TraceEventNodeRefPtrVector & GetChildrenRef()
Returns references to the children of this node.
Definition: eventNode.h:121