25 #ifndef PXR_BASE_TRACE_COLLECTOR_H
26 #define PXR_BASE_TRACE_COLLECTOR_H
38 #include "pxr/base/tf/mallocTag.h"
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
135 template <
typename Category = DefaultCategory>
140 return _BeginEvent(key, Category::GetId());
148 template <
typename Category = DefaultCategory>
153 _BeginEventAtTime(key, ms, Category::GetId());
164 template <
typename Category = DefaultCategory>
169 return _EndEvent(key, Category::GetId());
177 template <
typename Category = DefaultCategory>
182 _EndEventAtTime(key, ms, Category::GetId());
190 template <
typename Category = DefaultCategory>
195 return _MarkerEvent(key, Category::GetId());
203 template <
typename Category = DefaultCategory>
208 _MarkerEventAtTime(key, ms, Category::GetId());
216 template <
typename Category = DefaultCategory>
221 _BeginScope(_key, Category::GetId());
229 template <
typename Category,
typename... Args>
232 static_assert(
sizeof...(Args) %2 == 0,
233 "Data arguments must come in pairs");
238 _PerThreadData *threadData = _GetThreadData();
239 threadData->BeginScope(key, Category::GetId());
240 _StoreDataRec(threadData, Category::GetId(), std::forward<Args>(
args)...);
247 template <
typename... Args>
249 static_assert(
sizeof...(Args) %2 == 0,
250 "Data arguments must come in pairs");
254 BeginScope<DefaultCategory>(key,
255 std::forward<Args>(
args)...);
262 template <
typename Category = DefaultCategory>
267 _EndScope(key, Category::GetId());
286 template <
typename Category = DefaultCategory>
290 _PerThreadData *threadData = _GetThreadData();
291 threadData->EmplaceEvent(
298 template <
typename Category,
typename... Args>
300 static_assert(
sizeof...(Args) %2 == 0,
301 "Data arguments must come in pairs");
306 _PerThreadData *threadData = _GetThreadData();
307 _StoreDataRec(threadData, Category::GetId(), std::forward<Args>(
args)...);
316 template <
typename... Args>
318 static_assert(
sizeof...(Args) %2 == 0,
319 "Data arguments must come in pairs");
321 ScopeArgs<DefaultCategory>(std::forward<Args>(
args)...);
331 template <
typename Category = DefaultCategory>
336 _PerThreadData *threadData = _GetThreadData();
337 threadData->EmplaceEvent(
345 template <
typename Category = DefaultCategory,
typename T>
348 _StoreData(_GetThreadData(), key, Category::GetId(), value);
353 template <
typename Category = DefaultCategory>
358 _PerThreadData *threadData = _GetThreadData();
359 threadData->EmplaceEvent(
365 template <
typename Category = DefaultCategory>
368 _PerThreadData *threadData = _GetThreadData();
369 threadData->CounterDelta(key, delta, Category::GetId());
374 template <
typename Category = DefaultCategory>
378 _PerThreadData *threadData = _GetThreadData();
379 threadData->EmplaceEvent(
386 template <
typename Category = DefaultCategory>
390 _PerThreadData *threadData = _GetThreadData();
391 threadData->CounterValue(key, value, Category::GetId());
414 class _PerThreadData;
418 TRACE_API _PerThreadData* _GetThreadData() noexcept;
440 _PerThreadData *threadData = _GetThreadData();
441 threadData->BeginScope(key, cat);
450 #ifdef PXR_PYTHON_SUPPORT_ENABLED
453 #endif // PXR_PYTHON_SUPPORT_ENABLED
456 template <
typename T,
457 typename std::enable_if<
460 void _StoreData(_PerThreadData* threadData,
const TraceKey &key,
462 threadData->StoreData(key, value, cat);
466 template <
typename T,
467 typename std::enable_if<
470 void _StoreData(_PerThreadData* threadData,
const TraceKey &key,
472 threadData->StoreLargeData(key, value, cat);
477 _PerThreadData* threadData,
481 threadData->StoreLargeData(key, value, cat);
486 _PerThreadData* threadData,
490 threadData->StoreLargeData(key, value.c_str(), cat);
494 template <
typename K,
typename T,
typename... Args>
497 const T& value, Args&&...
args) {
498 _StoreData(threadData, std::forward<K>(key), cat, value);
499 _StoreDataRec(threadData, cat, std::forward<Args>(
args)...);
508 class _PerThreadData {
529 AtomicRef lock(_writing);
530 _BeginScope(key, cat);
534 AtomicRef lock(_writing);
544 template <
typename T>
547 AtomicRef lock(_writing);
548 _events.load(std::memory_order_acquire)->EmplaceBack(
552 template <
typename T>
555 AtomicRef lock(_writing);
556 EventList* events = _events.load(std::memory_order_acquire);
557 const auto* cached = events->StoreData(data);
561 template <
typename... Args>
562 void EmplaceEvent(Args&&...
args) {
563 AtomicRef lock(_writing);
564 _events.load(std::memory_order_acquire)->EmplaceBack(
565 std::forward<Args>(
args)...);
568 #ifdef PXR_PYTHON_SUPPORT_ENABLED
569 void PushPyScope(
const Key& key,
bool enabled);
571 #endif // PXR_PYTHON_SUPPORT_ENABLED
575 std::unique_ptr<EventList> GetCollectionData();
580 _events.load(std::memory_order_acquire)->EmplaceBack(
587 mutable std::atomic<bool> _writing;
588 std::atomic<EventList*> _events;
592 AtomicRef(std::atomic<bool>&
b) : _bool(b) {
593 _bool.store(
true, std::memory_order_release);
596 _bool.store(
false, std::memory_order_release);
599 std::atomic<bool>& _bool;
612 std::vector<PyScope> _pyScopes;
615 TRACE_API static std::atomic<int> _isEnabled;
627 #ifndef PXR_PYTHON_SUPPORT_ENABLED
631 std::atomic<int> _isPythonTracingEnabled;
633 #ifndef PXR_PYTHON_SUPPORT_ENABLED
642 #endif // PXR_BASE_TRACE_COLLECTOR_H
static TRACE_API TraceCollector & GetInstance()
Returns the singleton instance.
TRACE_API ~TraceCollector()
void RecordCounterValue(const TraceKey &key, double value)
Record a counter value for a name key if Category is enabled.
void RecordCounterValue(const Key &key, double value)
#define ARCH_PRAGMA_UNUSED_PRIVATE_FIELD
GLsizei const GLchar *const * string
GLsizei const GLfloat * 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
unsigned int GetThreadId()
GLenum GLenum GLsizei const GLuint GLboolean enabled
void EndEventAtTime(const Key &key, double ms)
TimeStamp MarkerEvent(const Key &key)
void ScopeArgs(Args &&...args)
void Scope(const TraceKey &key, TimeStamp start, TimeStamp stop)
TraceCollectorPtr ThisPtr
void MarkerEventStatic(const TraceKey &key)
void MarkerEventAtTime(const Key &key, double ms)
std::shared_ptr< TfPyTraceFn > TfPyTraceFnId
TRACE_API TimeStamp GetScopeOverhead() const
Return the overhead cost to measure a scope.
static bool IsEnabled()
Returns whether collection of events is enabled for DefaultCategory.
void BeginScope(const TraceKey &key, Args &&...args)
void EndScope(const TraceKey &key)
void ScopeArgs(Args &&...args)
void RecordCounterDelta(const Key &key, double delta)
Record a counter delta for a name key if Category is enabled.
GLboolean GLboolean GLboolean b
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)
static TRACE_API void Scope(const TraceKey &key, TimeStamp start, TimeStamp stop) noexcept
TF_DECLARE_WEAK_AND_REF_PTRS(TraceScope)
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.