25 #ifndef PXR_BASE_TRACE_COLLECTOR_H
26 #define PXR_BASE_TRACE_COLLECTOR_H
38 #include "pxr/base/tf/mallocTag.h"
40 #ifdef PXR_PYTHON_SUPPORT_ENABLED
42 #endif // PXR_PYTHON_SUPPORT_ENABLED
54 #include <tbb/spin_mutex.h>
58 class TraceScopeHolder;
95 return (_isEnabled.load(std::memory_order_acquire) == 1);
107 #ifdef PXR_PYTHON_SUPPORT_ENABLED
109 bool IsPythonTracingEnabled()
const {
110 return _isPythonTracingEnabled.load(std::memory_order_acquire) != 0;
115 #endif // PXR_PYTHON_SUPPORT_ENABLED
132 template <
typename Category = DefaultCategory>
137 return _BeginEvent(key, Category::GetId());
145 template <
typename Category = DefaultCategory>
150 _BeginEventAtTime(key, ms, Category::GetId());
161 template <
typename Category = DefaultCategory>
166 return _EndEvent(key, Category::GetId());
174 template <
typename Category = DefaultCategory>
179 _EndEventAtTime(key, ms, Category::GetId());
187 template <
typename Category = DefaultCategory>
192 return _MarkerEvent(key, Category::GetId());
200 template <
typename Category = DefaultCategory>
205 _MarkerEventAtTime(key, ms, Category::GetId());
213 template <
typename Category = DefaultCategory>
218 _BeginScope(_key, Category::GetId());
226 template <
typename Category,
typename... Args>
229 static_assert(
sizeof...(Args) %2 == 0,
230 "Data arguments must come in pairs");
235 _PerThreadData *threadData = _GetThreadData();
236 threadData->BeginScope(key, Category::GetId());
237 _StoreDataRec(threadData, Category::GetId(), std::forward<Args>(
args)...);
244 template <
typename... Args>
246 static_assert(
sizeof...(Args) %2 == 0,
247 "Data arguments must come in pairs");
251 BeginScope<DefaultCategory>(key,
252 std::forward<Args>(
args)...);
259 template <
typename Category = DefaultCategory>
264 _EndScope(key, Category::GetId());
273 template <
typename Category = DefaultCategory>
278 _PerThreadData *threadData = _GetThreadData();
279 threadData->EmplaceEvent(
286 template <
typename Category,
typename... Args>
288 static_assert(
sizeof...(Args) %2 == 0,
289 "Data arguments must come in pairs");
294 _PerThreadData *threadData = _GetThreadData();
295 _StoreDataRec(threadData, Category::GetId(), std::forward<Args>(
args)...);
304 template <
typename... Args>
306 static_assert(
sizeof...(Args) %2 == 0,
307 "Data arguments must come in pairs");
309 ScopeArgs<DefaultCategory>(std::forward<Args>(
args)...);
319 template <
typename Category = DefaultCategory>
324 _PerThreadData *threadData = _GetThreadData();
325 threadData->EmplaceEvent(
333 template <
typename Category = DefaultCategory,
typename T>
336 _StoreData(_GetThreadData(), key, Category::GetId(), value);
341 template <
typename Category = DefaultCategory>
346 _PerThreadData *threadData = _GetThreadData();
347 threadData->EmplaceEvent(
353 template <
typename Category = DefaultCategory>
356 _PerThreadData *threadData = _GetThreadData();
357 threadData->CounterDelta(key, delta, Category::GetId());
362 template <
typename Category = DefaultCategory>
366 _PerThreadData *threadData = _GetThreadData();
367 threadData->EmplaceEvent(
374 template <
typename Category = DefaultCategory>
378 _PerThreadData *threadData = _GetThreadData();
379 threadData->CounterValue(key, value, Category::GetId());
402 class _PerThreadData;
406 TRACE_API _PerThreadData* _GetThreadData();
428 _PerThreadData *threadData = _GetThreadData();
429 threadData->BeginScope(key, cat);
436 #ifdef PXR_PYTHON_SUPPORT_ENABLED
439 #endif // PXR_PYTHON_SUPPORT_ENABLED
442 template <
typename T,
443 typename std::enable_if<
446 void _StoreData(_PerThreadData* threadData,
const TraceKey &key,
448 threadData->StoreData(key, value, cat);
452 template <
typename T,
453 typename std::enable_if<
456 void _StoreData(_PerThreadData* threadData,
const TraceKey &key,
458 threadData->StoreLargeData(key, value, cat);
463 _PerThreadData* threadData,
467 threadData->StoreLargeData(key, value, cat);
472 _PerThreadData* threadData,
476 threadData->StoreLargeData(key, value.c_str(), cat);
480 template <
typename K,
typename T,
typename... Args>
483 const T& value, Args&&...
args) {
484 _StoreData(threadData, std::forward<K>(key), cat, value);
485 _StoreDataRec(threadData, cat, std::forward<Args>(
args)...);
494 class _PerThreadData {
515 AtomicRef lock(_writing);
516 _BeginScope(key, cat);
520 AtomicRef lock(_writing);
530 template <
typename T>
533 AtomicRef lock(_writing);
534 _events.load(std::memory_order_acquire)->EmplaceBack(
538 template <
typename T>
541 AtomicRef lock(_writing);
542 EventList* events = _events.load(std::memory_order_acquire);
543 const auto* cached = events->StoreData(data);
547 template <
typename... Args>
548 void EmplaceEvent(Args&&...
args) {
549 AtomicRef lock(_writing);
550 _events.load(std::memory_order_acquire)->EmplaceBack(
551 std::forward<Args>(
args)...);
554 #ifdef PXR_PYTHON_SUPPORT_ENABLED
555 void PushPyScope(
const Key& key,
bool enabled);
557 #endif // PXR_PYTHON_SUPPORT_ENABLED
561 std::unique_ptr<EventList> GetCollectionData();
566 _events.load(std::memory_order_acquire)->EmplaceBack(
573 mutable std::atomic<bool> _writing;
574 std::atomic<EventList*> _events;
578 AtomicRef(std::atomic<bool>&
b) : _bool(b) {
579 _bool.store(
true, std::memory_order_release);
582 _bool.store(
false, std::memory_order_release);
585 std::atomic<bool>& _bool;
594 #ifdef PXR_PYTHON_SUPPORT_ENABLED
599 std::vector<PyScope> _pyScopes;
600 #endif // PXR_PYTHON_SUPPORT_ENABLED
603 TRACE_API static std::atomic<int> _isEnabled;
610 #ifdef PXR_PYTHON_SUPPORT_ENABLED
611 std::atomic<int> _isPythonTracingEnabled;
613 #endif // PXR_PYTHON_SUPPORT_ENABLED
620 #endif // PXR_BASE_TRACE_COLLECTOR_H
static TRACE_API TraceCollector & GetInstance()
Returns the singleton instance.
TRACE_API ~TraceCollector()
void Scope(const TraceKey &key, TimeStamp start)
void RecordCounterValue(const TraceKey &key, double value)
Record a counter value for a name key if Category is enabled.
GLboolean GLboolean GLboolean b
void RecordCounterValue(const Key &key, double value)
TF_MALLOC_TAG_NEW("Trace","TraceCollector")
TRACE_API void SetEnabled(bool isEnabled)
Enables or disables collection of events for DefaultCategory.
fallback_uintptr uintptr_t
GLenum GLenum GLsizei const GLuint GLboolean enabled
void EndEventAtTime(const Key &key, double ms)
TimeStamp MarkerEvent(const Key &key)
void ScopeArgs(Args &&...args)
TraceCollectorPtr ThisPtr
void MarkerEventStatic(const TraceKey &key)
void MarkerEventAtTime(const Key &key, double ms)
std::shared_ptr< TfPyTraceFn > TfPyTraceFnId
GLint GLint GLsizei GLint GLenum GLenum type
static bool IsEnabled()
Returns whether collection of events is enabled for DefaultCategory.
void BeginScope(const TraceKey &key, Args &&...args)
void EndScope(const TraceKey &key)
GLsizei const GLchar *const * string
void ScopeArgs(Args &&...args)
void RecordCounterDelta(const Key &key, double delta)
Record a counter delta for a name key if Category is enabled.
void BeginScope(const TraceKey &key, Args &&...args)
TimeStamp EndEvent(const Key &key)
TRACE_API void CreateCollection()
static bool IsEnabled()
Returns the result of TraceCollector::IsEnabled.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
void BeginScope(const TraceKey &_key)
#define PXR_NAMESPACE_CLOSE_SCOPE
void StoreData(const TraceKey &key, const T &value)
TimeStamp BeginEvent(const Key &key)
TF_DECLARE_WEAK_AND_REF_PTRS(TraceScope)
GLsizei const GLfloat * value
uint64_t TimeStamp
Time in "ticks".
**If you just want to fire and args
TRACE_API_TEMPLATE_CLASS(TfSingleton< TraceCollector >)
static constexpr TraceCategoryId GetId()
Returns TraceCategory::Default.
TF_DECLARE_WEAK_PTRS(TraceCollector)
void BeginEventAtTime(const Key &key, double ms)
uint32_t TraceCategoryId
Categories that a TraceReporter can use to filter events.
TraceEvent::TimeStamp TimeStamp
void RecordCounterDelta(const TraceKey &key, double delta)
Record a counter delta for a name key if Category is enabled.
const std::string & GetLabel()
Return the label associated with this collector.