Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pxr/base/trace/overview.dox
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Adding trace instrumentation macros has the following overhead:
The dynamic versions of the macros TRACE_FUNCTION_DYNAMIC(), TRACE_SCOPE_DYNAMIC() have a much higher overhead than the static versions. The reason for this is that for the static versions, the names of the scopes are compiled as constexpr data, but the dynamic versions construct strings at runtime. This overhead of dynamic macros is true whether tracing is enabled or not. Because of this, the static versions should be preferred whenever possible.
</li>
</ul>
It is possible to disable TRACE macros from generating code by defining TRACE_DISABLE in the preprocessor.
It is possible to enable TRACE macros from generating code by defining TRACE_ENABLE in the preprocessor.

The TraceCollector class and TRACE macros are thread-safe.

Expand Down
10 changes: 7 additions & 3 deletions pxr/base/trace/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

#include <atomic>

#if !defined(TRACE_DISABLE)
#if !defined(TRACE_ENABLE)
#define TRACE_ENABLE 1
#endif

#if TRACE_ENABLE

/// Records a timestamp when constructed and a timespan event when destructed,
/// using the name of the function or method as the key.
Expand Down Expand Up @@ -166,7 +170,7 @@ PXR_NS::TraceAuto TF_PP_CAT(TraceAuto_, instance)(str)
#define _TRACE_MARKER_DYNAMIC_INSTANCE(instance, name) \
TraceCollector::GetInstance().MarkerEvent(name);

#else // TRACE_DISABLE
#else // TRACE_ENABLE

#define TRACE_FUNCTION()
#define TRACE_FUNCTION_DYNAMIC(name)
Expand All @@ -176,7 +180,7 @@ PXR_NS::TraceAuto TF_PP_CAT(TraceAuto_, instance)(str)
#define TRACE_MARKER(name)
#define TRACE_MARKER_DYNAMIC(name)

#endif // TRACE_DISABLE
#endif // TRACE_ENABLE

PXR_NAMESPACE_OPEN_SCOPE

Expand Down
3 changes: 2 additions & 1 deletion pxr/imaging/hd/perfLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
PXR_NAMESPACE_OPEN_SCOPE


#if HD_PERF_ENABLE
TF_INSTANTIATE_SINGLETON(HdPerfLog);

static
Expand Down Expand Up @@ -241,7 +242,7 @@ HdPerfLog::GetResourceRegistryVector()
{
return _resourceRegistryVector;
}

#endif // HD_PERF_ENABLE

PXR_NAMESPACE_CLOSE_SCOPE

22 changes: 22 additions & 0 deletions pxr/imaging/hd/perfLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@

PXR_NAMESPACE_OPEN_SCOPE

#if !defined(HD_PERF_ENABLE)
#define HD_PERF_ENABLE 1
#endif

class SdfPath;
class HdResourceRegistry;

// XXX: it would be nice to move this into Trace or use the existing Trace
// counter mechanism, however we are restricted to TraceLite in the rocks.

#if HD_PERF_ENABLE
//----------------------------------------------------------------------------//
// PERFORMANCE INSTURMENTATION MACROS //
//----------------------------------------------------------------------------//
Expand Down Expand Up @@ -217,6 +221,24 @@ class HdPerfLog
};

HD_API_TEMPLATE_CLASS(TfSingleton<HdPerfLog>);
#else // HD_PERF_ENABLE

#define HD_TRACE_FUNCTION()
#define HD_TRACE_SCOPE(tag)

#define HD_PERF_CACHE_HIT(name, id)
#define HD_PERF_CACHE_HIT_TAG(name, id, tag)

#define HD_PERF_CACHE_MISS(name, id)
#define HD_PERF_CACHE_MISS_TAG(name, id, tag)

#define HD_PERF_COUNTER_INCR(name)
#define HD_PERF_COUNTER_DECR(name)
#define HD_PERF_COUNTER_SET(name, value)
#define HD_PERF_COUNTER_ADD(name, value)
#define HD_PERF_COUNTER_SUBTRACT(name, value)

#endif // HD_PERF_ENABLE

PXR_NAMESPACE_CLOSE_SCOPE

Expand Down
6 changes: 4 additions & 2 deletions pxr/imaging/hdSt/renderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,10 @@ class _HgiToResourceRegistryMap final :
// Insert into map.
registry = result;

#if HD_PERF_ENABLE
// Also register with HdPerfLog.
HdPerfLog::GetInstance().AddResourceRegistry(result.get());

#endif
return result;
}

Expand All @@ -155,8 +156,9 @@ class _HgiToResourceRegistryMap final :

std::lock_guard<std::mutex> guard(_mutex);

#if HD_PERF_ENABLE
HdPerfLog::GetInstance().RemoveResourceRegistry(registry);
#endif
_map.erase(registry->GetHgi());
}

Expand Down
Loading