24 #ifndef PXR_IMAGING_HD_PERF_LOG_H 25 #define PXR_IMAGING_HD_PERF_LOG_H 28 #include "pxr/imaging/hd/api.h" 29 #include "pxr/imaging/hd/version.h" 30 #include "pxr/imaging/hd/debugCodes.h" 38 #include "pxr/base/tf/hashmap.h" 43 PXR_NAMESPACE_OPEN_SCOPE
57 #define HD_TRACE_FUNCTION() TRACE_FUNCTION() 59 #define HD_TRACE_SCOPE(tag) TRACE_SCOPE(tag) 63 #define HD_PERF_CACHE_HIT(name, id) \ 64 HdPerfLog::GetInstance().AddCacheHit(name, id); 65 #define HD_PERF_CACHE_HIT_TAG(name, id, tag) \ 66 HdPerfLog::GetInstance().AddCacheHit(name, id, tag); 70 #define HD_PERF_CACHE_MISS(name, id) \ 71 HdPerfLog::GetInstance().AddCacheMiss(name, id); 72 #define HD_PERF_CACHE_MISS_TAG(name, id, tag) \ 73 HdPerfLog::GetInstance().AddCacheMiss(name, id, tag); 77 #define HD_PERF_COUNTER_INCR(name) \ 78 HdPerfLog::GetInstance().IncrementCounter(name); 79 #define HD_PERF_COUNTER_DECR(name) \ 80 HdPerfLog::GetInstance().DecrementCounter(name); 81 #define HD_PERF_COUNTER_SET(name, value) \ 82 HdPerfLog::GetInstance().SetCounter(name, value); 83 #define HD_PERF_COUNTER_ADD(name, value) \ 84 HdPerfLog::GetInstance().AddCounter(name, value); 85 #define HD_PERF_COUNTER_SUBTRACT(name, value) \ 86 HdPerfLog::GetInstance().SubtractCounter(name, value); 119 void ResetCache(
TfToken const& name);
202 _CacheEntry() : _hits(0), _misses(0) { }
204 void AddHit() {++_hits;}
205 size_t GetHits() {
return _hits;}
207 void AddMiss() {++_misses;}
208 size_t GetMisses() {
return _misses;}
210 size_t GetTotal() {
return _hits+_misses;}
211 double GetHitRatio() {
return (
double)_hits / GetTotal();}
213 void Reset() { _hits = 0; _misses = 0; }
220 typedef TfHashMap<TfToken, _CacheEntry, TfToken::HashFunctor> _CacheMap;
224 typedef TfHashMap<TfToken, double, TfToken::HashFunctor> _CounterMap;
225 _CounterMap _counterMap;
228 std::vector<HdResourceRegistry *> _resourceRegistryVector;
233 typedef std::lock_guard<std::mutex> _Lock;
238 PXR_NAMESPACE_CLOSE_SCOPE
240 #endif // PXR_IMAGING_HD_PERF_LOG_H HD_API void AddCacheMiss(TfToken const &name, SdfPath const &id, TfToken const &tag=TfToken())
Tracks a cache miss for the named cache, the id and tag are reported when debug logging is enabled.
Manage a single instance of an object.
Manage a single instance of an object (see.
HD_API void DecrementCounter(TfToken const &name)
Decrements a named counter by 1.0.
HD_API void RemoveResourceRegistry(HdResourceRegistry *resourceRegistry)
Remove Resource Registry from the tracking.
HD_API size_t GetCacheMisses(TfToken const &name)
Gets the number of hit misses for a cache performance counter.
void Disable()
Disable performance logging.
void Enable()
Enable performance logging.
HD_API double GetCacheHitRatio(TfToken const &name)
Gets the hit ratio (numHits / totalRequests) of a cache performance counter.
HD_API void AddCacheHit(TfToken const &name, SdfPath const &id, TfToken const &tag=TfToken())
Tracks a cache hit for the named cache, the id and tag are reported when debug logging is enabled.
Token for efficient comparison, assignment, and hashing of known strings.
HD_API TfTokenVector GetCounterNames()
Returns a vector of all performance counter names.
HD_API size_t GetCacheHits(TfToken const &name)
Gets the number of hit hits for a cache performance counter.
A central registry for resources.
std::vector< TfToken > TfTokenVector
Convenience types.
HD_API void ResetCounters()
Reset all conter values to 0.0.
A path value used to locate objects in layers or scenegraphs.
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
HD_API void SetCounter(TfToken const &name, double value)
Sets the value of a named counter.
HD_API std::vector< HdResourceRegistry * > const & GetResourceRegistryVector()
Returns a vector of resource registry.
HD_API TfTokenVector GetCacheNames()
Returns the names of all cache performance counters.
HD_API double GetCounter(TfToken const &name)
Returns the current value of a named counter.
HD_API void AddCounter(TfToken const &name, double value)
Adds value to a named counter.
HD_API void AddResourceRegistry(HdResourceRegistry *resourceRegistry)
Add a resource registry to the tracking.
Performance counter monitoring.
HD_API void SubtractCounter(TfToken const &name, double value)
Subtracts value to a named counter.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
HD_API void IncrementCounter(TfToken const &name)
Increments a named counter by 1.0.