Loading...
Searching...
No Matches
eventNode.h
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"
15#include "pxr/base/trace/eventData.h"
16
18#include "pxr/base/tf/pointerAndBits.h"
19#include "pxr/base/tf/refBase.h"
20#include "pxr/base/tf/refPtr.h"
22#include "pxr/base/tf/span.h"
23#include "pxr/base/tf/token.h"
24
25PXR_NAMESPACE_OPEN_SCOPE
26
28
36
38public:
39
40 using TimeStamp = TraceEvent::TimeStamp;
42 using AttributeMap = std::multimap<TfToken, AttributeData>;
43
46 TRACE_API static TraceEventNodeRefPtr New();
47
50 static TraceEventNodeRefPtr New(const TfToken &key,
51 const TraceCategoryId category,
52 const TimeStamp beginTime,
53 const TimeStamp endTime,
54 TraceEventNodeRefPtrVector&& children,
55 const bool separateEvents) {
56 return TfCreateRefPtr(
58 key,
59 category,
60 beginTime,
61 endTime,
62 std::move(children),
63 separateEvents));
64 }
65
68 TRACE_API TraceEventNodeRefPtr Append(const TfToken &key,
69 TraceCategoryId category,
70 TimeStamp beginTime,
71 TimeStamp endTime,
72 bool separateEvents);
73
75 TRACE_API void Append(TraceEventNodeRefPtr node);
76
78 const TfToken &GetKey() const { return _key; }
79
81 TraceCategoryId GetCategory() const { return _category; }
82
86
89
91 TimeStamp GetBeginTime() const { return _beginTime; }
92
94 TimeStamp GetEndTime() const { return _endTime; }
95
97
100
103 return _children;
104 }
105
107
109 TRACE_API const AttributeMap& GetAttributes() const;
110
112 TRACE_API void AddAttribute(const TfToken& key, AttributeData&& attr);
113
116 bool IsFromSeparateEvents() const {
117 return _attributesAndSeparateEvents.BitsAs<bool>();
118 }
119
121 if (AttributeMap *attrMap = _attributesAndSeparateEvents.Get()) {
122 _DeleteAttrMap(attrMap);
123 }
124 }
125
126private:
127
129 const TfToken &key,
130 TraceCategoryId category,
131 TimeStamp beginTime,
132 TimeStamp endTime,
133 TraceEventNodeRefPtrVector&& children,
134 bool separateEvents)
135
136 : _category(category)
137 , _key(key)
138 , _beginTime(beginTime)
139 , _endTime(endTime)
140 , _children(std::make_move_iterator(children.begin()),
141 std::make_move_iterator(children.end()))
142 , _attributesAndSeparateEvents(nullptr, separateEvents)
143 {
144 }
145
146 // Out-of-line to avoid inlining the multimap dtor code.
147 TRACE_API void _DeleteAttrMap(AttributeMap *attrMap);
148
149 // _category (4 bytes) is first so it packs with TfRefBase's 4-byte count.
150 const TraceCategoryId _category;
151 const TfToken _key;
152 TimeStamp _beginTime;
153 TimeStamp _endTime;
154 // Empirical results show ~85% of nodes have < 2 children.
156 TfPointerAndBits<AttributeMap> _attributesAndSeparateEvents;
157};
158
159PXR_NAMESPACE_CLOSE_SCOPE
160
161#endif // PXR_BASE_TRACE_EVENT_NODE_H
uint32_t TraceCategoryId
Categories that a TraceReporter can use to filter events.
Definition: category.h:27
This class stores a T * and a small integer in the space of a T *.
constexpr T * Get() const noexcept
Retrieve the pointer.
constexpr Integral BitsAs() const noexcept
Retrieve the stored bits as the integral type Integral.
Enable a concrete base class for use with TfRefPtr that inhibits the "unique changed" facility of TfR...
Definition: refBase.h:139
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:157
Represents a range of contiguous elements.
Definition: span.h:71
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
This class holds data that can be stored in TraceEvents.
Definition: eventData.h:28
uint64_t TimeStamp
Time in "ticks".
Definition: event.h:33
TraceEventNode is used to represents call tree of a trace.
Definition: eventNode.h:37
TRACE_API void Append(TraceEventNodeRefPtr node)
Appends node as a child node.
bool IsFromSeparateEvents() const
Returns whether this node was created from a Begin-End pair or a single Timespan event.
Definition: eventNode.h:116
TRACE_API const AttributeMap & GetAttributes() const
Return the data associated with this node.
TRACE_API TraceEventNodeRefPtr Append(const TfToken &key, TraceCategoryId category, TimeStamp beginTime, TimeStamp endTime, bool separateEvents)
Appends a new child node with key, category, beginTime and endTime.
TimeStamp GetBeginTime() const
Returns the time that this scope started.
Definition: eventNode.h:91
TfSpan< const TraceEventNodeRefPtr > GetChildrenRef() const
Returns a TfSpan of references to the children of this node.
Definition: eventNode.h:102
TRACE_API void AddAttribute(const TfToken &key, AttributeData &&attr)
Add data to this node.
TraceCategoryId GetCategory() const
Returns the category of this node.
Definition: eventNode.h:81
const TfToken & GetKey() const
Returns the name of this node.
Definition: eventNode.h:78
TimeStamp GetEndTime() const
Returns the time that this scope ended.
Definition: eventNode.h:94
TRACE_API void SetBeginAndEndTimesFromChildren()
Sets this node'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:50
static TRACE_API TraceEventNodeRefPtr New()
Creates a new root node.
Standard pointer typedefs.
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:58
STL namespace.
Reference counting.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...