25 #ifndef PXR_BASE_TRACE_TRACE_H
26 #define PXR_BASE_TRACE_TRACE_H
39 #if !defined(TRACE_DISABLE)
43 #define TRACE_FUNCTION() \
44 _TRACE_FUNCTION_INSTANCE(__LINE__, __ARCH_FUNCTION__, __ARCH_PRETTY_FUNCTION__)
48 #define TRACE_SCOPE(name) \
49 _TRACE_SCOPE_INSTANCE(__LINE__, name)
53 #define TRACE_FUNCTION_SCOPE(name) \
54 _TRACE_FUNCTION_SCOPE_INSTANCE( \
55 __LINE__, __ARCH_FUNCTION__, __ARCH_PRETTY_FUNCTION__, name)
58 #define TRACE_MARKER(name) \
59 _TRACE_MARKER_INSTANCE(__LINE__, name)
62 #define TRACE_MARKER_DYNAMIC(name) \
63 _TRACE_MARKER_DYNAMIC_INSTANCE(__LINE__, name)
70 #define TRACE_COUNTER_DELTA(name, delta) \
71 _TRACE_COUNTER_INSTANCE(__LINE__, name, delta, true)
77 #define TRACE_COUNTER_DELTA_DYNAMIC(name, delta) \
78 TraceCollector::GetInstance().RecordCounterDelta(name, delta);
83 #define TRACE_COUNTER_VALUE(name, value) \
84 _TRACE_COUNTER_INSTANCE(__LINE__, name, value, false)
90 #define TRACE_COUNTER_VALUE_DYNAMIC(name, value) \
91 TraceCollector::GetInstance().RecordCounterValue(name, value);
111 #define TRACE_COUNTER_DELTA_CODE(name, code) \
112 _TRACE_COUNTER_CODE_INSTANCE(__LINE__, name, code, true)
119 #define TRACE_FUNCTION_DYNAMIC(name) \
120 _TRACE_FUNCTION_DYNAMIC_INSTANCE(__LINE__, __ARCH_FUNCTION__, __ARCH_PRETTY_FUNCTION__, name)
127 #define TRACE_SCOPE_DYNAMIC(name) \
128 _TRACE_SCOPE_DYNAMIC_INSTANCE(__LINE__, name)
137 #define _TRACE_FUNCTION_INSTANCE(instance, name, prettyName) \
138 constexpr static PXR_NS::TraceStaticKeyData \
139 TF_PP_CAT(TraceKeyData_, instance)(name, prettyName); \
140 PXR_NS::TraceScopeAuto TF_PP_CAT(TraceScopeAuto_, instance)(\
141 TF_PP_CAT(TraceKeyData_, instance));
143 #define _TRACE_SCOPE_INSTANCE(instance, name) \
144 constexpr static PXR_NS::TraceStaticKeyData \
145 TF_PP_CAT(TraceKeyData_, instance)(name); \
146 PXR_NS::TraceScopeAuto TF_PP_CAT(TraceScopeAuto_, instance)(\
147 TF_PP_CAT(TraceKeyData_, instance));
149 #define _TRACE_FUNCTION_SCOPE_INSTANCE(instance, name, prettyName, scopeName) \
150 constexpr static PXR_NS::TraceStaticKeyData \
151 TF_PP_CAT(TraceKeyData_, instance)(name, prettyName, scopeName); \
152 PXR_NS::TraceScopeAuto TF_PP_CAT(TraceScopeAuto_, instance)(\
153 TF_PP_CAT(TraceKeyData_, instance));
155 #define _TRACE_MARKER_INSTANCE(instance, name) \
156 constexpr static PXR_NS::TraceStaticKeyData \
157 TF_PP_CAT(TraceKeyData_, instance)(name); \
158 TraceCollector::GetInstance().MarkerEventStatic(TF_PP_CAT(TraceKeyData_, instance));
160 #define _TRACE_COUNTER_INSTANCE(instance, name, value, isDelta) \
161 constexpr static PXR_NS::TraceStaticKeyData \
162 TF_PP_CAT(TraceKeyData_, instance)(name); \
163 static PXR_NS::TraceCounterHolder \
164 TF_PP_CAT(TraceCounterHolder_, instance) \
165 (TF_PP_CAT(TraceKeyData_, instance)); \
166 TF_PP_CAT(TraceCounterHolder_, instance).Record(value, isDelta);
168 #define _TRACE_COUNTER_CODE_INSTANCE(instance, name, code, isDelta) \
169 static PXR_NS::TraceCounterHolder \
170 TF_PP_CAT(TraceCounterHolder_, instance)(name); \
171 if (TF_PP_CAT(TraceCounterHolder_, instance).IsEnabled()) { \
172 double value = 0.0; \
174 TF_PP_CAT(TraceCounterHolder_, instance).RecordDelta(value, isDelta); \
177 #define _TRACE_FUNCTION_DYNAMIC_INSTANCE(instance, fnName, fnPrettyName, name) \
178 PXR_NS::TraceAuto TF_PP_CAT(TraceAuto_, instance)(fnName, fnPrettyName, name)
180 #define _TRACE_SCOPE_DYNAMIC_INSTANCE(instance, str) \
181 PXR_NS::TraceAuto TF_PP_CAT(TraceAuto_, instance)(str)
183 #define _TRACE_MARKER_DYNAMIC_INSTANCE(instance, name) \
184 TraceCollector::GetInstance().MarkerEvent(name);
186 #else // TRACE_DISABLE
188 #define TRACE_FUNCTION()
189 #define TRACE_FUNCTION_DYNAMIC(name)
190 #define TRACE_SCOPE(name)
191 #define TRACE_SCOPE_DYNAMIC(name)
192 #define TRACE_FUNCTION_SCOPE(name)
193 #define TRACE_MARKER(name)
194 #define TRACE_MARKER_DYNAMIC(name)
196 #endif // TRACE_DISABLE
217 template <
typename... Args>
220 , _intervalTimer(false) {
222 _intervalTimer.
Start();
258 TraceAuto(
const char *funcName,
const char *prettyFuncName,
260 : _key(_CreateKeyString(funcName, prettyFuncName, name)) {
261 std::atomic_thread_fence(std::memory_order_seq_cst);
264 std::atomic_thread_fence(std::memory_order_seq_cst);
271 std::atomic_thread_fence(std::memory_order_seq_cst);
274 std::atomic_thread_fence(std::memory_order_seq_cst);
295 std::atomic_thread_fence(std::memory_order_seq_cst);
297 std::atomic_thread_fence(std::memory_order_seq_cst);
302 const char *funcName,
303 const char *prettyFuncName,
351 #endif // PXR_BASE_TRACE_TRACE_H
static TRACE_API TraceCollector & GetInstance()
Returns the singleton instance.
void RecordCounterValue(const TraceKey &key, double value)
Record a counter value for a name key if Category is enabled.
~TraceScopeAuto() noexcept
GLsizei const GLchar *const * string
TraceAuto(const char *funcName, const char *prettyFuncName, const std::string &name)
TraceAuto(const TfToken &key)
void ScopeArgs(Args &&...args)
static bool IsEnabled()
Returns whether collection of events is enabled for DefaultCategory.
uint64_t GetCurrentTicks()
TraceAuto & operator=(const TraceAuto &)=delete
uint64_t GetStartTicks() const
GLuint const GLchar * name
void Record(double value, bool delta)
TimeStamp EndEvent(const Key &key)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE
TimeStamp BeginEvent(const Key &key)
static TRACE_API void Scope(const TraceKey &key, TimeStamp start, TimeStamp stop) noexcept
**If you just want to fire and args
TraceCounterHolder(const TraceKey &key)
TraceAuto(const std::string &key)
TraceScopeAuto(const TraceStaticKeyData &key) noexcept
PXR_NAMESPACE_OPEN_SCOPE ARCH_API std::string ArchGetPrettierFunctionName(const std::string &function, const std::string &prettyFunction)
TraceScopeAuto(const TraceStaticKeyData &key, Args &&...args)
TraceEvent::TimeStamp TimeStamp
void RecordCounterDelta(const TraceKey &key, double delta)
Record a counter delta for a name key if Category is enabled.