diff --git a/src/gpgmm/common/BuddyMemoryAllocator.cpp b/src/gpgmm/common/BuddyMemoryAllocator.cpp index 5bafd4f30..9bc6c3442 100644 --- a/src/gpgmm/common/BuddyMemoryAllocator.cpp +++ b/src/gpgmm/common/BuddyMemoryAllocator.cpp @@ -43,7 +43,8 @@ namespace gpgmm { ResultOrError> BuddyMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::kDefault, "BuddyMemoryAllocator.TryAllocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "BuddyMemoryAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -101,7 +102,8 @@ namespace gpgmm { void BuddyMemoryAllocator::DeallocateMemory(std::unique_ptr subAllocation) { std::lock_guard lock(mMutex); - TRACE_EVENT0(TraceEventCategory::kDefault, "BuddyMemoryAllocator.DeallocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "BuddyMemoryAllocator.DeallocateMemory"); ASSERT(subAllocation != nullptr); diff --git a/src/gpgmm/common/ConditionalMemoryAllocator.cpp b/src/gpgmm/common/ConditionalMemoryAllocator.cpp index 813e7cdd4..697c5f130 100644 --- a/src/gpgmm/common/ConditionalMemoryAllocator.cpp +++ b/src/gpgmm/common/ConditionalMemoryAllocator.cpp @@ -30,7 +30,8 @@ namespace gpgmm { ResultOrError> ConditionalMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::kDefault, "ConditionalMemoryAllocator.TryAllocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "ConditionalMemoryAllocator.TryAllocateMemory"); if (request.SizeInBytes <= mConditionalSize) { return mFirstAllocator->TryAllocateMemory(request); } else { diff --git a/src/gpgmm/common/DedicatedMemoryAllocator.cpp b/src/gpgmm/common/DedicatedMemoryAllocator.cpp index ea52bede6..c16dcc0cc 100644 --- a/src/gpgmm/common/DedicatedMemoryAllocator.cpp +++ b/src/gpgmm/common/DedicatedMemoryAllocator.cpp @@ -28,7 +28,8 @@ namespace gpgmm { ResultOrError> DedicatedMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::kDefault, "DedicatedMemoryAllocator.TryAllocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "DedicatedMemoryAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -56,7 +57,8 @@ namespace gpgmm { } void DedicatedMemoryAllocator::DeallocateMemory(std::unique_ptr allocation) { - TRACE_EVENT0(TraceEventCategory::kDefault, "DedicatedMemoryAllocator.DeallocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "DedicatedMemoryAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); diff --git a/src/gpgmm/common/PooledMemoryAllocator.cpp b/src/gpgmm/common/PooledMemoryAllocator.cpp index 4de6e99d0..b09b64736 100644 --- a/src/gpgmm/common/PooledMemoryAllocator.cpp +++ b/src/gpgmm/common/PooledMemoryAllocator.cpp @@ -36,7 +36,8 @@ namespace gpgmm { ResultOrError> PooledMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::kDefault, "PooledMemoryAllocator.TryAllocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "PooledMemoryAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -65,7 +66,8 @@ namespace gpgmm { } void PooledMemoryAllocator::DeallocateMemory(std::unique_ptr allocation) { - TRACE_EVENT0(TraceEventCategory::kDefault, "PooledMemoryAllocator.DeallocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "PooledMemoryAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); diff --git a/src/gpgmm/common/SegmentedMemoryAllocator.cpp b/src/gpgmm/common/SegmentedMemoryAllocator.cpp index 989a21394..206b6a6c9 100644 --- a/src/gpgmm/common/SegmentedMemoryAllocator.cpp +++ b/src/gpgmm/common/SegmentedMemoryAllocator.cpp @@ -121,7 +121,8 @@ namespace gpgmm { ResultOrError> SegmentedMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::kDefault, "SegmentedMemoryAllocator.TryAllocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "SegmentedMemoryAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -155,7 +156,8 @@ namespace gpgmm { } void SegmentedMemoryAllocator::DeallocateMemory(std::unique_ptr allocation) { - TRACE_EVENT0(TraceEventCategory::kDefault, "SegmentedMemoryAllocator.DeallocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "SegmentedMemoryAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); diff --git a/src/gpgmm/common/SlabMemoryAllocator.cpp b/src/gpgmm/common/SlabMemoryAllocator.cpp index fd83799d0..61d5cb751 100644 --- a/src/gpgmm/common/SlabMemoryAllocator.cpp +++ b/src/gpgmm/common/SlabMemoryAllocator.cpp @@ -197,7 +197,8 @@ namespace gpgmm { ResultOrError> SlabMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::kDefault, "SlabMemoryAllocator.TryAllocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "SlabMemoryAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -400,7 +401,8 @@ namespace gpgmm { } void SlabMemoryAllocator::DeallocateMemory(std::unique_ptr subAllocation) { - TRACE_EVENT0(TraceEventCategory::kDefault, "SlabMemoryAllocator.DeallocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "SlabMemoryAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); @@ -511,7 +513,8 @@ namespace gpgmm { ResultOrError> SlabCacheAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::kDefault, "SlabCacheAllocator.TryAllocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "SlabCacheAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -545,7 +548,8 @@ namespace gpgmm { } void SlabCacheAllocator::DeallocateMemory(std::unique_ptr subAllocation) { - TRACE_EVENT0(TraceEventCategory::kDefault, "SlabCacheAllocator.DeallocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "SlabCacheAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); diff --git a/src/gpgmm/common/ThreadPool.cpp b/src/gpgmm/common/ThreadPool.cpp index a1cbf525f..f5e432b77 100644 --- a/src/gpgmm/common/ThreadPool.cpp +++ b/src/gpgmm/common/ThreadPool.cpp @@ -39,7 +39,7 @@ namespace gpgmm { AsyncEventImpl() = default; void Wait() override { - TRACE_EVENT0(TraceEventCategory::kDefault, "Event.Wait"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, "Event.Wait"); std::unique_lock lock(mMutex); mCondition.wait(lock, [this] { return mIsSignaled; }); @@ -105,8 +105,7 @@ namespace gpgmm { mThreads.push_back(std::thread([this, threadNameWithIndex]() { SetThreadName(threadNameWithIndex.c_str()); - TRACE_EVENT_METADATA1(TraceEventCategory::kMetadata, "thread_name", "name", - threadNameWithIndex.c_str()); + GPGMM_TRACE_EVENT_THREAD_NEW(threadNameWithIndex.c_str()); RunExecutionLoop(); })); } diff --git a/src/gpgmm/common/TraceEvent.cpp b/src/gpgmm/common/TraceEvent.cpp index fc8b394d6..00e877b1e 100644 --- a/src/gpgmm/common/TraceEvent.cpp +++ b/src/gpgmm/common/TraceEvent.cpp @@ -50,8 +50,7 @@ namespace gpgmm { #endif GetInstance()->SetConfiguration(traceFile, ignoreMask); - TRACE_EVENT_METADATA1(TraceEventCategory::kMetadata, "thread_name", "name", - "GPGMM_MainThread"); + GPGMM_TRACE_EVENT_THREAD_NEW("GPGMM_MainThread"); } void FlushEventTraceToDisk() { diff --git a/src/gpgmm/common/TraceEvent.h b/src/gpgmm/common/TraceEvent.h index ea2fcc05e..cb130665f 100644 --- a/src/gpgmm/common/TraceEvent.h +++ b/src/gpgmm/common/TraceEvent.h @@ -38,17 +38,16 @@ #ifdef GPGMM_DISABLE_TRACING -#define TRACE_EVENT0(category_group, name) TRACE_EMPTY -#define TRACE_EVENT_INSTANT0(category_group, name) TRACE_EMPTY -#define TRACE_EVENT_INSTANT1(category_group, name, args) TRACE_EMPTY -#define TRACE_COUNTER1(category_group, name, value) TRACE_EMPTY -#define TRACE_EVENT_METADATA1(category_group, name, arg1_name, arg1_value) TRACE_EMPTY - #define GPGMM_TRACE_EVENT_OBJECT_NEW(objPtr) TRACE_EMPTY #define GPGMM_TRACE_EVENT_OBJECT_DESTROY(objPtr) TRACE_EMPTY #define GPGMM_TRACE_EVENT_OBJECT_SNAPSHOT(objPtr, desc) TRACE_EMPTY #define GPGMM_TRACE_EVENT_OBJECT_CALL(name, desc) TRACE_EMPTY #define GPGMM_TRACE_EVENT_METRIC(name, value) TRACE_EMPTY +#define GPGMM_TRACE_EVENT_DURATION(name, value) TRACE_EMPTY +#define GPGMM_TRACE_EVENT_THREAD_NEW(name) TRACE_EMPTY + +// For testing purposes only +#define TRACE_EVENT_INSTANT0(category_group, name) TRACE_EMPTY #else // !GPGMM_DISABLE_TRACING @@ -155,6 +154,9 @@ const uint64_t kNoId = 0; TRACE_COUNTER1(TraceEventCategory::kDefault, name, value); \ } while (false) +#define GPGMM_TRACE_EVENT_DURATION(category_group, name) TRACE_EVENT0(category_group, name) +#define GPGMM_TRACE_EVENT_THREAD_NEW(name) TRACE_EVENT_METADATA1(TraceEventCategory::kMetadata, "thread_name", "name", name) + #endif namespace gpgmm { diff --git a/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp b/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp index e8014660c..17fa1ff3c 100644 --- a/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp @@ -38,7 +38,8 @@ namespace gpgmm::d3d12 { ResultOrError> BufferAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::kDefault, "BufferAllocator.TryAllocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "BufferAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -87,7 +88,8 @@ namespace gpgmm::d3d12 { } void BufferAllocator::DeallocateMemory(std::unique_ptr allocation) { - TRACE_EVENT0(TraceEventCategory::kDefault, "BufferAllocator.DeallocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "BufferAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); mStats.UsedMemoryUsage -= allocation->GetSize(); diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index e46f5874a..30e26ef70 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -460,7 +460,8 @@ namespace gpgmm::d3d12 { const DXGI_MEMORY_SEGMENT_GROUP& heapSegment, uint64_t availableForReservation, uint64_t* pCurrentReservationOut) { - TRACE_EVENT0(TraceEventCategory::kDefault, "ResidencyManager.SetVideoMemoryReservation"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "ResidencyManager.SetVideoMemoryReservation"); std::lock_guard lock(mMutex); @@ -618,7 +619,7 @@ namespace gpgmm::d3d12 { HRESULT ResidencyManager::EvictInternal(uint64_t bytesToEvict, const DXGI_MEMORY_SEGMENT_GROUP& heapSegment, uint64_t* bytesEvictedOut) { - TRACE_EVENT0(TraceEventCategory::kDefault, "ResidencyManager.Evict"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, "ResidencyManager.Evict"); DXGI_QUERY_VIDEO_MEMORY_INFO* pVideoMemoryInfo = GetVideoMemoryInfo(heapSegment); if (IsBudgetNotificationUpdatesDisabled()) { @@ -720,7 +721,8 @@ namespace gpgmm::d3d12 { ID3D12CommandList* const* ppCommandLists, IResidencyList* const* ppResidencyLists, uint32_t count) { - TRACE_EVENT0(TraceEventCategory::kDefault, "ResidencyManager.ExecuteCommandLists"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "ResidencyManager.ExecuteCommandLists"); std::lock_guard lock(mMutex); @@ -858,7 +860,7 @@ namespace gpgmm::d3d12 { uint64_t sizeToMakeResident, uint32_t numberOfObjectsToMakeResident, ID3D12Pageable** allocations) { - TRACE_EVENT0(TraceEventCategory::kDefault, "ResidencyManager.MakeResident"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, "ResidencyManager.MakeResident"); ReturnIfFailed(EvictInternal(sizeToMakeResident, heapSegment, nullptr)); @@ -908,7 +910,7 @@ namespace gpgmm::d3d12 { } HRESULT ResidencyManager::QueryStatsInternal(RESIDENCY_MANAGER_STATS* pResidencyManagerStats) { - TRACE_EVENT0(TraceEventCategory::kDefault, "ResidencyManager.GetStats"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, "ResidencyManager.GetStats"); // Heaps inserted into the residency cache are not resident until MakeResident() is called // on them. This occurs if the heap was created resident, heap gets locked, or call to diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index e5ddea15b..0c02279fb 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -987,7 +987,8 @@ namespace gpgmm::d3d12 { D3D12_RESOURCE_STATES initialResourceState, const D3D12_CLEAR_VALUE* clearValue, IResourceAllocation** ppResourceAllocationOut) { - TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceAllocator.CreateResource"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "ResourceAllocator.CreateResource"); // If d3d tells us the resource size is invalid, treat the error as OOM. // Otherwise, creating a very large resource could overflow the allocator. @@ -1444,7 +1445,8 @@ namespace gpgmm::d3d12 { const D3D12_CLEAR_VALUE* clearValue, D3D12_RESOURCE_STATES initialResourceState, ID3D12Resource** placedResourceOut) { - TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceAllocator.CreatePlacedResource"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "ResourceAllocator.CreatePlacedResource"); // Before calling CreatePlacedResource, we must ensure the target heap is resident or // CreatePlacedResource will fail. @@ -1475,7 +1477,8 @@ namespace gpgmm::d3d12 { D3D12_RESOURCE_STATES initialResourceState, ID3D12Resource** commitedResourceOut, Heap** resourceHeapOut) { - TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceAllocator.CreateCommittedResource"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "ResourceAllocator.CreateCommittedResource"); HEAP_DESC resourceHeapDesc = {}; resourceHeapDesc.SizeInBytes = info.SizeInBytes; @@ -1519,7 +1522,7 @@ namespace gpgmm::d3d12 { HRESULT ResourceAllocator::QueryStatsInternal( RESOURCE_ALLOCATOR_STATS* pResourceAllocatorStats) { - TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceAllocator.QueryStats"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, "ResourceAllocator.QueryStats"); // ResourceAllocator itself could call CreateCommittedResource directly. MemoryAllocatorStats result = mStats; @@ -1633,7 +1636,8 @@ namespace gpgmm::d3d12 { } void ResourceAllocator::DeallocateMemory(std::unique_ptr allocation) { - TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceAllocator.DeallocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "ResourceAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); diff --git a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp index 6df730f7e..5b037425c 100644 --- a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp @@ -43,7 +43,8 @@ namespace gpgmm::d3d12 { ResultOrError> ResourceHeapAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceHeapAllocator.TryAllocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "ResourceHeapAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -97,7 +98,8 @@ namespace gpgmm::d3d12 { void ResourceHeapAllocator::DeallocateMemory(std::unique_ptr allocation) { std::lock_guard lock(mMutex); - TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceHeapAllocator.DeallocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "ResourceHeapAllocator.DeallocateMemory"); mStats.UsedMemoryUsage -= allocation->GetSize(); mStats.UsedMemoryCount--; diff --git a/src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp b/src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp index 9539341f4..ec12fa396 100644 --- a/src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp +++ b/src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp @@ -30,7 +30,8 @@ namespace gpgmm::vk { ResultOrError> DeviceMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::kDefault, "DeviceMemoryAllocator.TryAllocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "DeviceMemoryAllocator.TryAllocateMemory"); if (request.NeverAllocate) { return {}; @@ -72,7 +73,8 @@ namespace gpgmm::vk { } void DeviceMemoryAllocator::DeallocateMemory(std::unique_ptr allocation) { - TRACE_EVENT0(TraceEventCategory::kDefault, "DeviceMemoryAllocator.DeallocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "DeviceMemoryAllocator.DeallocateMemory"); VkDeviceMemory deviceMemory = static_cast(allocation->GetMemory())->GetDeviceMemory(); diff --git a/src/tests/DummyMemoryAllocator.h b/src/tests/DummyMemoryAllocator.h index 7390a19de..12c740ea2 100644 --- a/src/tests/DummyMemoryAllocator.h +++ b/src/tests/DummyMemoryAllocator.h @@ -37,7 +37,8 @@ namespace gpgmm { ResultOrError> TryAllocateMemory( const MemoryAllocationRequest& request) override { - TRACE_EVENT0(TraceEventCategory::kDefault, "DummyMemoryAllocator.TryAllocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "DummyMemoryAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -53,7 +54,8 @@ namespace gpgmm { } void DeallocateMemory(std::unique_ptr allocation) override { - TRACE_EVENT0(TraceEventCategory::kDefault, "DummyMemoryAllocator.DeallocateMemory"); + GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, + "DummyMemoryAllocator.DeallocateMemory"); std::lock_guard lock(mMutex);