All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eventNode.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 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"
32 #include "pxr/base/trace/eventData.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 
41 PXR_NAMESPACE_OPEN_SCOPE
42 
44 
52 
53 class TraceEventNode : public TfRefBase {
54 public:
55 
56  using TimeStamp = TraceEvent::TimeStamp;
58  using AttributeMap = std::multimap<TfToken, AttributeData>;
59 
62  static TraceEventNodeRefPtr New() {
63  return TraceEventNode::New(
64  TfToken("root"), TraceCategory::Default, 0.0, 0.0, {}, false);
65  }
66 
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 
87  TraceEventNodeRefPtr Append(const TfToken &key,
88  TraceCategoryId category,
89  TimeStamp beginTime,
90  TimeStamp endTime,
91  bool separateEvents);
92 
94  void Append(TraceEventNodeRefPtr node);
95 
97  TfToken GetKey() { return _key;}
98 
100  TraceCategoryId GetCategory() const { return _category; }
101 
105 
108 
110  TimeStamp GetBeginTime() { return _beginTime; }
111 
113  TimeStamp GetEndTime() { return _endTime; }
114 
116 
119 
121  const TraceEventNodeRefPtrVector &GetChildrenRef() {
122  return _children;
123  }
124 
126 
128  const AttributeMap& GetAttributes() const { return _attributes; }
129 
131  void AddAttribute(const TfToken& key, const AttributeData& attr);
132 
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 
168 PXR_NAMESPACE_CLOSE_SCOPE
169 
170 #endif // PXR_BASE_TRACE_EVENT_NODE_H
Standard pointer typedefs.
const TraceEventNodeRefPtrVector & GetChildrenRef()
Returns references to the children of this node.
Definition: eventNode.h:121
TraceEventNode is used to represents call tree of a trace.
Definition: eventNode.h:53
uint64_t TimeStamp
Time in &quot;ticks&quot;.
Definition: event.h:50
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:71
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
TimeStamp GetBeginTime()
Returns the time that this scope started.
Definition: eventNode.h:110
static TraceEventNodeRefPtr New()
Creates a new root node.
Definition: eventNode.h:62
TraceEventNodeRefPtr Append(const TfToken &key, TraceCategoryId category, TimeStamp beginTime, TimeStamp endTime, bool separateEvents)
Appends a new child node with key, category, beginTime and endTime.
void AddAttribute(const TfToken &key, const AttributeData &attr)
Add data to this node.
This class holds data that can be stored in TraceEvents.
Definition: eventData.h:45
TimeStamp GetEndTime()
Returns the time that this scope ended.
Definition: eventNode.h:113
TfToken GetKey()
Returns the name of this node.
Definition: eventNode.h:97
const AttributeMap & GetAttributes() const
Return the data associated with this node.
Definition: eventNode.h:128
void SetBeginAndEndTimesFromChildren()
Sets this node&#39;s begin and end time to the time extents of its direct children.
static TraceEventNodeRefPtr New(const TfToken &key, const TraceCategoryId category, const TimeStamp beginTime, const TimeStamp endTime, TraceEventNodeRefPtrVector &&children, const bool separateEvents)
Creates a new node with key, category, beginTime and endTime.
Definition: eventNode.h:69
Reference counting.
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
bool IsFromSeparateEvents() const
Returns whether this node was created from a Begin-End pair or a single Timespan event.
Definition: eventNode.h:135
TraceCategoryId GetCategory() const
Returns the category of this node.
Definition: eventNode.h:100
uint32_t TraceCategoryId
Categories that a TraceReporter can use to filter events.
Definition: category.h:44
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...