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 const bool separateEvents) {
55 return TfCreateRefPtr(
57 key, category, beginTime, endTime, separateEvents)
58 );
59 }
60
62 TRACE_API void Append(TraceEventNodeRefPtr &&node);
63
65 void Append(const TraceEventNodeRefPtr &node) {
66 Append(TraceEventNodeRefPtr { node });
67 }
68
70 const TfToken &GetKey() const { return _key; }
71
73 TraceCategoryId GetCategory() const { return _category; }
74
78
81
83 TimeStamp GetBeginTime() const { return _beginTime; }
84
86 TimeStamp GetEndTime() const { return _endTime; }
87
89 TimeStamp GetTimeDuration() const { return _endTime - _beginTime; }
90
92
95
98 return _children;
99 }
100
102
104 TRACE_API const AttributeMap& GetAttributes() const;
105
108 TRACE_API void AddAttribute(const TfToken& key, AttributeData&& attr);
109
112 bool IsFromSeparateEvents() const {
113 return _attributesAndSeparateEvents.BitsAs<bool>();
114 }
115
116 ~TraceEventNode() override;
117
118private:
119 friend class Trace_EventTreeBuilder;
120
121 void _SetIsSeparateEvents(bool isSeparate) {
122 _attributesAndSeparateEvents.SetBits(isSeparate);
123 }
124
125 TraceEventNode(const TfToken &key,
126 TraceCategoryId category,
127 TimeStamp beginTime,
128 TimeStamp endTime,
129 bool separateEvents)
130 : _category(category)
131 , _key(key)
132 , _beginTime(beginTime)
133 , _endTime(endTime)
134 , _attributesAndSeparateEvents(nullptr, separateEvents)
135 {
136 }
137
138 // _category (4 bytes) is first so it packs with TfRefBase's 4-byte count.
139 const TraceCategoryId _category;
140 const TfToken _key;
141 TimeStamp _beginTime;
142 TimeStamp _endTime;
143 // Empirical results show ~85% of nodes have < 2 children.
145 TfPointerAndBits<AttributeMap> _attributesAndSeparateEvents;
146};
147
148PXR_NAMESPACE_CLOSE_SCOPE
149
150#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 *.
void SetBits(Integral val) noexcept
Set the stored bits. No static range checking is performed.
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:35
TraceEventNode is used to represents call tree of a trace.
Definition: eventNode.h:37
void Append(const TraceEventNodeRefPtr &node)
Appends node as a child node.
Definition: eventNode.h:65
bool IsFromSeparateEvents() const
Returns whether this node was created from a Begin-End pair or a single Timespan event.
Definition: eventNode.h:112
TRACE_API const AttributeMap & GetAttributes() const
Return the data associated with this node.
TimeStamp GetTimeDuration() const
Returns the time duration of this scope as GetEndTime() - GetBeginTime()
Definition: eventNode.h:89
TimeStamp GetBeginTime() const
Returns the time that this scope started.
Definition: eventNode.h:83
TfSpan< const TraceEventNodeRefPtr > GetChildrenRef() const
Returns a TfSpan of references to the children of this node.
Definition: eventNode.h:97
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:73
const TfToken & GetKey() const
Returns the name of this node.
Definition: eventNode.h:70
TRACE_API void Append(TraceEventNodeRefPtr &&node)
Appends node as a child node.
TimeStamp GetEndTime() const
Returns the time that this scope ended.
Definition: eventNode.h:86
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, 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
Reference counting.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...