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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_BASE_TRACE_EVENT_NODE_H
9 #define PXR_BASE_TRACE_EVENT_NODE_H
10 
11 #include "pxr/pxr.h"
12 
13 #include "pxr/base/trace/api.h"
14 #include "pxr/base/trace/event.h"
16 
17 #include "pxr/base/tf/refBase.h"
18 #include "pxr/base/tf/refPtr.h"
19 #include "pxr/base/tf/token.h"
21 
22 #include <vector>
23 
25 
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// \class TraceEventNode
30 ///
31 /// TraceEventNode is used to represents call tree of a trace. Each node
32 /// represents a Begin-End trace event pair, or a single Timespan event. This is
33 /// useful for timeline views of a trace.
34 ///
35 
36 class TraceEventNode : public TfRefBase {
37 public:
38 
41  using AttributeMap = std::multimap<TfToken, AttributeData>;
42 
43  /// Creates a new root node.
44  ///
45  static TraceEventNodeRefPtr New() {
46  return TraceEventNode::New(
47  TfToken("root"), TraceCategory::Default, 0.0, 0.0, {}, false);
48  }
49 
50  /// Creates a new node with \p key, \p category, \p beginTime and
51  /// \p endTime.
52  static TraceEventNodeRefPtr New(const TfToken &key,
53  const TraceCategoryId category,
54  const TimeStamp beginTime,
55  const TimeStamp endTime,
56  TraceEventNodeRefPtrVector&& children,
57  const bool separateEvents) {
58  return TfCreateRefPtr(
59  new TraceEventNode(
60  key,
61  category,
62  beginTime,
63  endTime,
64  std::move(children),
65  separateEvents));
66  }
67 
68  /// Appends a new child node with \p key, \p category, \p beginTime and
69  /// \p endTime.
70  TraceEventNodeRefPtr Append(const TfToken &key,
71  TraceCategoryId category,
72  TimeStamp beginTime,
73  TimeStamp endTime,
74  bool separateEvents);
75 
76  /// Appends \p node as a child node.
77  void Append(TraceEventNodeRefPtr node);
78 
79  /// Returns the name of this node.
80  TfToken GetKey() { return _key;}
81 
82  /// Returns the category of this node.
83  TraceCategoryId GetCategory() const { return _category; }
84 
85  /// Sets this node's begin and end time to the time extents of its direct
86  /// children.
88 
89  /// \name Profile Data Accessors
90  /// @{
91 
92  /// Returns the time that this scope started.
93  TimeStamp GetBeginTime() { return _beginTime; }
94 
95  /// Returns the time that this scope ended.
96  TimeStamp GetEndTime() { return _endTime; }
97 
98  /// @}
99 
100  /// \name Children Accessors
101  /// @{
102 
103  /// Returns references to the children of this node.
104  const TraceEventNodeRefPtrVector &GetChildrenRef() {
105  return _children;
106  }
107 
108  /// @}
109 
110  /// Return the data associated with this node.
111  const AttributeMap& GetAttributes() const { return _attributes; }
112 
113  /// Add data to this node.
114  void AddAttribute(const TfToken& key, const AttributeData& attr);
115 
116  /// Returns whether this node was created from a Begin-End pair or a single
117  /// Timespan event.
118  bool IsFromSeparateEvents() const {
119  return _fromSeparateEvents;
120  }
121 
122 private:
123 
125  const TfToken &key,
126  TraceCategoryId category,
127  TimeStamp beginTime,
128  TimeStamp endTime,
129  TraceEventNodeRefPtrVector&& children,
130  bool separateEvents)
131 
132  : _key(key)
133  , _category(category)
134  , _beginTime(beginTime)
135  , _endTime(endTime)
136  , _children(std::move(children))
137  , _fromSeparateEvents(separateEvents)
138  {}
139 
140 
141  TfToken _key;
142  TraceCategoryId _category;
143  TimeStamp _beginTime;
144  TimeStamp _endTime;
145  TraceEventNodeRefPtrVector _children;
146  bool _fromSeparateEvents;
147 
148  AttributeMap _attributes;
149 };
150 
152 
153 #endif // PXR_BASE_TRACE_EVENT_NODE_H
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1190
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:93
static TraceEventNodeRefPtr New(const TfToken &key, const TraceCategoryId category, const TimeStamp beginTime, const TimeStamp endTime, TraceEventNodeRefPtrVector &&children, const bool separateEvents)
Definition: eventNode.h:52
bool IsFromSeparateEvents() const
Definition: eventNode.h:118
TfToken GetKey()
Returns the name of this node.
Definition: eventNode.h:80
Definition: token.h:70
static TraceEventNodeRefPtr New()
Definition: eventNode.h:45
TraceCategoryId GetCategory() const
Returns the category of this node.
Definition: eventNode.h:83
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:39
TimeStamp GetEndTime()
Returns the time that this scope ended.
Definition: eventNode.h:96
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
uint64_t TimeStamp
Time in "ticks".
Definition: event.h:33
std::multimap< TfToken, AttributeData > AttributeMap
Definition: eventNode.h:41
void SetBeginAndEndTimesFromChildren()
TraceEventData AttributeData
Definition: eventNode.h:40
uint32_t TraceCategoryId
Categories that a TraceReporter can use to filter events.
Definition: category.h:27
const AttributeMap & GetAttributes() const
Return the data associated with this node.
Definition: eventNode.h:111
const TraceEventNodeRefPtrVector & GetChildrenRef()
Returns references to the children of this node.
Definition: eventNode.h:104