Skip to content
Merged
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
6 changes: 4 additions & 2 deletions src/gpgmm/common/BuddyMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ namespace gpgmm {

ResultOrError<std::unique_ptr<MemoryAllocation>> BuddyMemoryAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::kDefault, "BuddyMemoryAllocator.TryAllocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"BuddyMemoryAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -101,7 +102,8 @@ namespace gpgmm {
void BuddyMemoryAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> subAllocation) {
std::lock_guard<std::mutex> lock(mMutex);

TRACE_EVENT0(TraceEventCategory::kDefault, "BuddyMemoryAllocator.DeallocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"BuddyMemoryAllocator.DeallocateMemory");

ASSERT(subAllocation != nullptr);

Expand Down
3 changes: 2 additions & 1 deletion src/gpgmm/common/ConditionalMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace gpgmm {

ResultOrError<std::unique_ptr<MemoryAllocation>> 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 {
Expand Down
6 changes: 4 additions & 2 deletions src/gpgmm/common/DedicatedMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace gpgmm {

ResultOrError<std::unique_ptr<MemoryAllocation>> DedicatedMemoryAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::kDefault, "DedicatedMemoryAllocator.TryAllocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"DedicatedMemoryAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -56,7 +57,8 @@ namespace gpgmm {
}

void DedicatedMemoryAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) {
TRACE_EVENT0(TraceEventCategory::kDefault, "DedicatedMemoryAllocator.DeallocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"DedicatedMemoryAllocator.DeallocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down
6 changes: 4 additions & 2 deletions src/gpgmm/common/PooledMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace gpgmm {

ResultOrError<std::unique_ptr<MemoryAllocation>> PooledMemoryAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::kDefault, "PooledMemoryAllocator.TryAllocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"PooledMemoryAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -65,7 +66,8 @@ namespace gpgmm {
}

void PooledMemoryAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) {
TRACE_EVENT0(TraceEventCategory::kDefault, "PooledMemoryAllocator.DeallocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"PooledMemoryAllocator.DeallocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down
6 changes: 4 additions & 2 deletions src/gpgmm/common/SegmentedMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ namespace gpgmm {

ResultOrError<std::unique_ptr<MemoryAllocation>> SegmentedMemoryAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::kDefault, "SegmentedMemoryAllocator.TryAllocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"SegmentedMemoryAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -155,7 +156,8 @@ namespace gpgmm {
}

void SegmentedMemoryAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) {
TRACE_EVENT0(TraceEventCategory::kDefault, "SegmentedMemoryAllocator.DeallocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"SegmentedMemoryAllocator.DeallocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down
12 changes: 8 additions & 4 deletions src/gpgmm/common/SlabMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ namespace gpgmm {

ResultOrError<std::unique_ptr<MemoryAllocation>> SlabMemoryAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::kDefault, "SlabMemoryAllocator.TryAllocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"SlabMemoryAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -400,7 +401,8 @@ namespace gpgmm {
}

void SlabMemoryAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> subAllocation) {
TRACE_EVENT0(TraceEventCategory::kDefault, "SlabMemoryAllocator.DeallocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"SlabMemoryAllocator.DeallocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -511,7 +513,8 @@ namespace gpgmm {

ResultOrError<std::unique_ptr<MemoryAllocation>> SlabCacheAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::kDefault, "SlabCacheAllocator.TryAllocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"SlabCacheAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -545,7 +548,8 @@ namespace gpgmm {
}

void SlabCacheAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> subAllocation) {
TRACE_EVENT0(TraceEventCategory::kDefault, "SlabCacheAllocator.DeallocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"SlabCacheAllocator.DeallocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down
5 changes: 2 additions & 3 deletions src/gpgmm/common/ThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(mMutex);
mCondition.wait(lock, [this] { return mIsSignaled; });
Expand Down Expand Up @@ -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();
}));
}
Expand Down
3 changes: 1 addition & 2 deletions src/gpgmm/common/TraceEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 8 additions & 6 deletions src/gpgmm/common/TraceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions src/gpgmm/d3d12/BufferAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ namespace gpgmm::d3d12 {

ResultOrError<std::unique_ptr<MemoryAllocation>> BufferAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::kDefault, "BufferAllocator.TryAllocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"BufferAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -87,7 +88,8 @@ namespace gpgmm::d3d12 {
}

void BufferAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) {
TRACE_EVENT0(TraceEventCategory::kDefault, "BufferAllocator.DeallocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"BufferAllocator.DeallocateMemory");
std::lock_guard<std::mutex> lock(mMutex);

mStats.UsedMemoryUsage -= allocation->GetSize();
Expand Down
12 changes: 7 additions & 5 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1633,7 +1636,8 @@ namespace gpgmm::d3d12 {
}

void ResourceAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) {
TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceAllocator.DeallocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"ResourceAllocator.DeallocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down
6 changes: 4 additions & 2 deletions src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ namespace gpgmm::d3d12 {

ResultOrError<std::unique_ptr<MemoryAllocation>> ResourceHeapAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceHeapAllocator.TryAllocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"ResourceHeapAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down Expand Up @@ -97,7 +98,8 @@ namespace gpgmm::d3d12 {
void ResourceHeapAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) {
std::lock_guard<std::mutex> lock(mMutex);

TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceHeapAllocator.DeallocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"ResourceHeapAllocator.DeallocateMemory");

mStats.UsedMemoryUsage -= allocation->GetSize();
mStats.UsedMemoryCount--;
Expand Down
6 changes: 4 additions & 2 deletions src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace gpgmm::vk {

ResultOrError<std::unique_ptr<MemoryAllocation>> DeviceMemoryAllocator::TryAllocateMemory(
const MemoryAllocationRequest& request) {
TRACE_EVENT0(TraceEventCategory::kDefault, "DeviceMemoryAllocator.TryAllocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"DeviceMemoryAllocator.TryAllocateMemory");

if (request.NeverAllocate) {
return {};
Expand Down Expand Up @@ -72,7 +73,8 @@ namespace gpgmm::vk {
}

void DeviceMemoryAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) {
TRACE_EVENT0(TraceEventCategory::kDefault, "DeviceMemoryAllocator.DeallocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"DeviceMemoryAllocator.DeallocateMemory");

VkDeviceMemory deviceMemory =
static_cast<DeviceMemory*>(allocation->GetMemory())->GetDeviceMemory();
Expand Down
6 changes: 4 additions & 2 deletions src/tests/DummyMemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ namespace gpgmm {

ResultOrError<std::unique_ptr<MemoryAllocation>> TryAllocateMemory(
const MemoryAllocationRequest& request) override {
TRACE_EVENT0(TraceEventCategory::kDefault, "DummyMemoryAllocator.TryAllocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"DummyMemoryAllocator.TryAllocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand All @@ -53,7 +54,8 @@ namespace gpgmm {
}

void DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) override {
TRACE_EVENT0(TraceEventCategory::kDefault, "DummyMemoryAllocator.DeallocateMemory");
GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault,
"DummyMemoryAllocator.DeallocateMemory");

std::lock_guard<std::mutex> lock(mMutex);

Expand Down