From f6c1e48c1e097189f412332d400f329cc89827e3 Mon Sep 17 00:00:00 2001 From: Bryan Bernhart Date: Fri, 30 Sep 2022 19:42:21 -0700 Subject: [PATCH] Rename RESIDENCY_INFO to RESIDENCY_STATS and RESOURCE_ALLOCATOR_INFO to RESOURCE_ALLOCATOR_STATS. --- src/fuzzers/D3D12ResidencyManagerFuzzer.cpp | 2 +- src/gpgmm/common/BuddyMemoryAllocator.cpp | 14 +- src/gpgmm/common/BuddyMemoryAllocator.h | 2 +- .../common/ConditionalMemoryAllocator.cpp | 8 +- src/gpgmm/common/ConditionalMemoryAllocator.h | 2 +- src/gpgmm/common/DedicatedMemoryAllocator.cpp | 14 +- src/gpgmm/common/DedicatedMemoryAllocator.h | 2 +- src/gpgmm/common/JSONSerializer.cpp | 2 +- src/gpgmm/common/JSONSerializer.h | 4 +- src/gpgmm/common/MemoryAllocator.cpp | 16 +- src/gpgmm/common/MemoryAllocator.h | 6 +- src/gpgmm/common/MemoryPool.cpp | 2 +- src/gpgmm/common/MemoryPool.h | 2 +- src/gpgmm/common/PooledMemoryAllocator.cpp | 14 +- src/gpgmm/common/SegmentedMemoryAllocator.cpp | 14 +- src/gpgmm/common/SlabMemoryAllocator.cpp | 32 ++-- src/gpgmm/common/SlabMemoryAllocator.h | 4 +- src/gpgmm/d3d12/BufferAllocatorD3D12.cpp | 8 +- src/gpgmm/d3d12/JSONSerializerD3D12.cpp | 2 +- src/gpgmm/d3d12/JSONSerializerD3D12.h | 2 +- src/gpgmm/d3d12/ResidencyManagerD3D12.cpp | 16 +- src/gpgmm/d3d12/ResidencyManagerD3D12.h | 4 +- src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp | 34 ++-- src/gpgmm/d3d12/ResourceAllocatorD3D12.h | 4 +- .../d3d12/ResourceHeapAllocatorD3D12.cpp | 8 +- src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp | 12 +- src/include/gpgmm.h | 6 +- src/include/gpgmm_d3d12.h | 12 +- src/mvi/gpgmm_d3d12_mvi.cpp | 18 +- src/mvi/gpgmm_d3d12_mvi.h | 4 +- src/mvi/gpgmm_mvi.cpp | 4 +- src/mvi/gpgmm_mvi.h | 4 +- src/tests/DummyMemoryAllocator.h | 8 +- .../D3D12EventTraceReplay.cpp | 2 +- .../end2end/D3D12ResidencyManagerTests.cpp | 38 ++--- .../end2end/D3D12ResourceAllocatorTests.cpp | 154 +++++++++--------- .../unittests/BuddyMemoryAllocatorTests.cpp | 86 +++++----- .../ConditionalMemoryAllocatorTests.cpp | 10 +- src/tests/unittests/MemoryPoolTests.cpp | 18 +- .../unittests/PooledMemoryAllocatorTests.cpp | 36 ++-- .../SegmentedMemoryAllocatorTests.cpp | 20 +-- .../unittests/SlabMemoryAllocatorTests.cpp | 130 +++++++-------- 42 files changed, 390 insertions(+), 390 deletions(-) diff --git a/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp b/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp index bef687375..fb071cd0a 100644 --- a/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp +++ b/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp @@ -90,7 +90,7 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { // Keep allocating until we reach the budget. uint64_t memoryUnderBudget = GetBudgetLeft(gResidencyManager.Get(), bufferMemorySegment); - while (gResourceAllocator->GetInfo().UsedMemoryUsage + kBufferMemorySize < memoryUnderBudget) { + while (gResourceAllocator->GetStats().UsedMemoryUsage + kBufferMemorySize < memoryUnderBudget) { ComPtr allocation; if (FAILED(gResourceAllocator->CreateResource({}, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation))) { diff --git a/src/gpgmm/common/BuddyMemoryAllocator.cpp b/src/gpgmm/common/BuddyMemoryAllocator.cpp index f5a81cd4e..1e95d6bd5 100644 --- a/src/gpgmm/common/BuddyMemoryAllocator.cpp +++ b/src/gpgmm/common/BuddyMemoryAllocator.cpp @@ -86,8 +86,8 @@ namespace gpgmm { subAllocation); MemoryBlock* block = subAllocation->GetBlock(); - mInfo.UsedBlockCount++; - mInfo.UsedBlockUsage += block->Size; + mStats.UsedBlockCount++; + mStats.UsedBlockUsage += block->Size; // Memory allocation offset is always memory-relative. const uint64_t memoryOffset = block->Offset % mMemorySize; @@ -104,8 +104,8 @@ namespace gpgmm { ASSERT(subAllocation != nullptr); - mInfo.UsedBlockCount--; - mInfo.UsedBlockUsage -= subAllocation->GetSize(); + mStats.UsedBlockCount--; + mStats.UsedBlockUsage -= subAllocation->GetSize(); const uint64_t memoryIndex = GetMemoryIndex(subAllocation->GetBlock()->Offset); @@ -132,11 +132,11 @@ namespace gpgmm { return mMemoryAlignment; } - MemoryAllocatorInfo BuddyMemoryAllocator::GetInfo() const { + MemoryAllocatorStats BuddyMemoryAllocator::GetStats() const { std::lock_guard lock(mMutex); - MemoryAllocatorInfo result = mInfo; - const MemoryAllocatorInfo& memoryInfo = GetNextInChain()->GetInfo(); + MemoryAllocatorStats result = mStats; + const MemoryAllocatorStats& memoryInfo = GetNextInChain()->GetStats(); result.UsedMemoryCount = memoryInfo.UsedMemoryCount; result.UsedMemoryUsage = memoryInfo.UsedMemoryUsage; result.FreeMemoryUsage = memoryInfo.FreeMemoryUsage; diff --git a/src/gpgmm/common/BuddyMemoryAllocator.h b/src/gpgmm/common/BuddyMemoryAllocator.h index da76d9fc9..6991da756 100644 --- a/src/gpgmm/common/BuddyMemoryAllocator.h +++ b/src/gpgmm/common/BuddyMemoryAllocator.h @@ -49,7 +49,7 @@ namespace gpgmm { uint64_t GetMemorySize() const override; uint64_t GetMemoryAlignment() const override; - MemoryAllocatorInfo GetInfo() const override; + MemoryAllocatorStats GetStats() const override; const char* GetTypename() const override; private: diff --git a/src/gpgmm/common/ConditionalMemoryAllocator.cpp b/src/gpgmm/common/ConditionalMemoryAllocator.cpp index 4f2952dd4..7f21264cc 100644 --- a/src/gpgmm/common/ConditionalMemoryAllocator.cpp +++ b/src/gpgmm/common/ConditionalMemoryAllocator.cpp @@ -44,10 +44,10 @@ namespace gpgmm { allocation->GetAllocator()->DeallocateMemory(std::move(allocation)); } - MemoryAllocatorInfo ConditionalMemoryAllocator::GetInfo() const { - MemoryAllocatorInfo result = {}; - result += mFirstAllocator->GetInfo(); - result += mSecondAllocator->GetInfo(); + MemoryAllocatorStats ConditionalMemoryAllocator::GetStats() const { + MemoryAllocatorStats result = {}; + result += mFirstAllocator->GetStats(); + result += mSecondAllocator->GetStats(); return result; } diff --git a/src/gpgmm/common/ConditionalMemoryAllocator.h b/src/gpgmm/common/ConditionalMemoryAllocator.h index b84a8d011..a57ef89c3 100644 --- a/src/gpgmm/common/ConditionalMemoryAllocator.h +++ b/src/gpgmm/common/ConditionalMemoryAllocator.h @@ -34,7 +34,7 @@ namespace gpgmm { const MemoryAllocationRequest& request) override; void DeallocateMemory(std::unique_ptr allocation) override; - MemoryAllocatorInfo GetInfo() const override; + MemoryAllocatorStats GetStats() const override; const char* GetTypename() const override; MemoryAllocator* GetFirstAllocatorForTesting() const; diff --git a/src/gpgmm/common/DedicatedMemoryAllocator.cpp b/src/gpgmm/common/DedicatedMemoryAllocator.cpp index 324a8f8d0..0399bfd5c 100644 --- a/src/gpgmm/common/DedicatedMemoryAllocator.cpp +++ b/src/gpgmm/common/DedicatedMemoryAllocator.cpp @@ -35,8 +35,8 @@ namespace gpgmm { std::unique_ptr allocation; GPGMM_TRY_ASSIGN(GetNextInChain()->TryAllocateMemory(request), allocation); - mInfo.UsedBlockCount++; - mInfo.UsedBlockUsage += allocation->GetSize(); + mStats.UsedBlockCount++; + mStats.UsedBlockUsage += allocation->GetSize(); return std::make_unique( this, allocation->GetMemory(), /*offset*/ 0, allocation->GetMethod(), @@ -49,17 +49,17 @@ namespace gpgmm { std::lock_guard lock(mMutex); MemoryBlock* block = allocation->GetBlock(); - mInfo.UsedBlockCount--; - mInfo.UsedBlockUsage -= block->Size; + mStats.UsedBlockCount--; + mStats.UsedBlockUsage -= block->Size; SafeDelete(block); GetNextInChain()->DeallocateMemory(std::move(allocation)); } - MemoryAllocatorInfo DedicatedMemoryAllocator::GetInfo() const { + MemoryAllocatorStats DedicatedMemoryAllocator::GetStats() const { std::lock_guard lock(mMutex); - MemoryAllocatorInfo result = mInfo; - result += GetNextInChain()->GetInfo(); + MemoryAllocatorStats result = mStats; + result += GetNextInChain()->GetStats(); return result; } diff --git a/src/gpgmm/common/DedicatedMemoryAllocator.h b/src/gpgmm/common/DedicatedMemoryAllocator.h index 63f641be4..984203265 100644 --- a/src/gpgmm/common/DedicatedMemoryAllocator.h +++ b/src/gpgmm/common/DedicatedMemoryAllocator.h @@ -33,7 +33,7 @@ namespace gpgmm { void DeallocateMemory(std::unique_ptr subAllocation) override; uint64_t GetMemoryAlignment() const override; - MemoryAllocatorInfo GetInfo() const override; + MemoryAllocatorStats GetStats() const override; private: const char* GetTypename() const override; diff --git a/src/gpgmm/common/JSONSerializer.cpp b/src/gpgmm/common/JSONSerializer.cpp index b39ecdb98..937702671 100644 --- a/src/gpgmm/common/JSONSerializer.cpp +++ b/src/gpgmm/common/JSONSerializer.cpp @@ -42,7 +42,7 @@ namespace gpgmm { } // static - JSONDict JSONSerializer::Serialize(const MemoryAllocatorInfo& info) { + JSONDict JSONSerializer::Serialize(const MemoryAllocatorStats& info) { JSONDict dict; dict.AddItem("UsedBlockCount", info.UsedBlockCount); dict.AddItem("UsedMemoryCount", info.UsedMemoryCount); diff --git a/src/gpgmm/common/JSONSerializer.h b/src/gpgmm/common/JSONSerializer.h index 8b40cfc25..fe52148d3 100644 --- a/src/gpgmm/common/JSONSerializer.h +++ b/src/gpgmm/common/JSONSerializer.h @@ -21,7 +21,7 @@ namespace gpgmm { // Forward declare common types. struct MemoryPoolInfo; - struct MemoryAllocatorInfo; + struct MemoryAllocatorStats; struct MemoryAllocationInfo; struct MemoryAllocationRequest; struct EventMessageInfo; @@ -30,7 +30,7 @@ namespace gpgmm { public: static JSONDict Serialize(); static JSONDict Serialize(const EventMessageInfo& info); - static JSONDict Serialize(const MemoryAllocatorInfo& info); + static JSONDict Serialize(const MemoryAllocatorStats& info); static JSONDict Serialize(const MemoryAllocationRequest& desc); static JSONDict Serialize(const MemoryAllocationInfo& info); static JSONDict Serialize(const MemoryPoolInfo& desc); diff --git a/src/gpgmm/common/MemoryAllocator.cpp b/src/gpgmm/common/MemoryAllocator.cpp index 4b14a31b3..f8c11f6af 100644 --- a/src/gpgmm/common/MemoryAllocator.cpp +++ b/src/gpgmm/common/MemoryAllocator.cpp @@ -43,9 +43,9 @@ namespace gpgmm { std::unique_ptr mAllocation; }; - // MemoryAllocatorInfo + // MemoryAllocatorStats - MemoryAllocatorInfo& MemoryAllocatorInfo::operator+=(const MemoryAllocatorInfo& rhs) { + MemoryAllocatorStats& MemoryAllocatorStats::operator+=(const MemoryAllocatorStats& rhs) { UsedBlockCount += rhs.UsedBlockCount; UsedBlockUsage += rhs.UsedBlockUsage; FreeMemoryUsage += rhs.FreeMemoryUsage; @@ -98,10 +98,10 @@ namespace gpgmm { #if defined(GPGMM_ENABLE_ALLOCATOR_LEAK_CHECKS) // If memory cannot be reused by a (parent) allocator, ensure no used memory leaked. if (GetParent() == nullptr) { - ASSERT(mInfo.UsedBlockUsage == 0u); - ASSERT(mInfo.UsedBlockCount == 0u); - ASSERT(mInfo.UsedMemoryCount == 0u); - ASSERT(mInfo.UsedMemoryUsage == 0u); + ASSERT(mStats.UsedBlockUsage == 0u); + ASSERT(mStats.UsedBlockCount == 0u); + ASSERT(mStats.UsedMemoryCount == 0u); + ASSERT(mStats.UsedMemoryUsage == 0u); } #endif @@ -145,9 +145,9 @@ namespace gpgmm { return kNoRequiredAlignment; } - MemoryAllocatorInfo MemoryAllocator::GetInfo() const { + MemoryAllocatorStats MemoryAllocator::GetStats() const { std::lock_guard lock(mMutex); - return mInfo; + return mStats; } const char* MemoryAllocator::GetTypename() const { diff --git a/src/gpgmm/common/MemoryAllocator.h b/src/gpgmm/common/MemoryAllocator.h index 0291931ad..6cea45342 100644 --- a/src/gpgmm/common/MemoryAllocator.h +++ b/src/gpgmm/common/MemoryAllocator.h @@ -207,9 +207,9 @@ namespace gpgmm { Should be overridden when a child or block allocator is used to avoid over-counting. - \return A MemoryAllocatorInfo struct containing the current usage. + \return A MemoryAllocatorStats struct containing the current usage. */ - virtual MemoryAllocatorInfo GetInfo() const; + virtual MemoryAllocatorStats GetStats() const; /** \brief Identifies the allocator type. @@ -278,7 +278,7 @@ namespace gpgmm { void CheckAndReportAllocationMisalignment(const MemoryAllocation& allocation); - MemoryAllocatorInfo mInfo = {}; + MemoryAllocatorStats mStats = {}; mutable std::mutex mMutex; std::shared_ptr mThreadPool; diff --git a/src/gpgmm/common/MemoryPool.cpp b/src/gpgmm/common/MemoryPool.cpp index d949b7e55..ae4feea04 100644 --- a/src/gpgmm/common/MemoryPool.cpp +++ b/src/gpgmm/common/MemoryPool.cpp @@ -30,7 +30,7 @@ namespace gpgmm { return mMemorySize; } - MemoryPoolInfo MemoryPool::GetInfo() const { + MemoryPoolInfo MemoryPool::GetStats() const { return {GetPoolSize() * mMemorySize}; } diff --git a/src/gpgmm/common/MemoryPool.h b/src/gpgmm/common/MemoryPool.h index bba3f4c5a..89386d1df 100644 --- a/src/gpgmm/common/MemoryPool.h +++ b/src/gpgmm/common/MemoryPool.h @@ -89,7 +89,7 @@ namespace gpgmm { \return A MemoryPoolInfo struct containing the information. */ - MemoryPoolInfo GetInfo() const; + MemoryPoolInfo GetStats() const; /** \brief Returns the class name of this allocation. diff --git a/src/gpgmm/common/PooledMemoryAllocator.cpp b/src/gpgmm/common/PooledMemoryAllocator.cpp index 1fd150cf5..95b50e45b 100644 --- a/src/gpgmm/common/PooledMemoryAllocator.cpp +++ b/src/gpgmm/common/PooledMemoryAllocator.cpp @@ -48,11 +48,11 @@ namespace gpgmm { GPGMM_TRY_ASSIGN(GetNextInChain()->TryAllocateMemory(request), allocationPtr); allocation = *allocationPtr; } else { - mInfo.FreeMemoryUsage -= allocation.GetSize(); + mStats.FreeMemoryUsage -= allocation.GetSize(); } - mInfo.UsedMemoryCount++; - mInfo.UsedMemoryUsage += allocation.GetSize(); + mStats.UsedMemoryCount++; + mStats.UsedMemoryUsage += allocation.GetSize(); IMemoryObject* memory = allocation.GetMemory(); ASSERT(memory != nullptr); @@ -66,9 +66,9 @@ namespace gpgmm { std::lock_guard lock(mMutex); const uint64_t& allocationSize = allocation->GetSize(); - mInfo.FreeMemoryUsage += allocationSize; - mInfo.UsedMemoryCount--; - mInfo.UsedMemoryUsage -= allocationSize; + mStats.FreeMemoryUsage += allocationSize; + mStats.UsedMemoryCount--; + mStats.UsedMemoryUsage -= allocationSize; IMemoryObject* memory = allocation->GetMemory(); ASSERT(memory != nullptr); @@ -79,7 +79,7 @@ namespace gpgmm { uint64_t PooledMemoryAllocator::ReleaseMemory(uint64_t bytesToRelease) { const uint64_t bytesReleased = mPool->ReleasePool(bytesToRelease); - mInfo.FreeMemoryUsage -= bytesReleased; + mStats.FreeMemoryUsage -= bytesReleased; return bytesReleased; } diff --git a/src/gpgmm/common/SegmentedMemoryAllocator.cpp b/src/gpgmm/common/SegmentedMemoryAllocator.cpp index 348d80b3a..4ff371d23 100644 --- a/src/gpgmm/common/SegmentedMemoryAllocator.cpp +++ b/src/gpgmm/common/SegmentedMemoryAllocator.cpp @@ -137,11 +137,11 @@ namespace gpgmm { GPGMM_TRY_ASSIGN(GetNextInChain()->TryAllocateMemory(request), allocationPtr); allocation = *allocationPtr; } else { - mInfo.FreeMemoryUsage -= allocation.GetSize(); + mStats.FreeMemoryUsage -= allocation.GetSize(); } - mInfo.UsedMemoryCount++; - mInfo.UsedMemoryUsage += allocation.GetSize(); + mStats.UsedMemoryCount++; + mStats.UsedMemoryUsage += allocation.GetSize(); IMemoryObject* memory = allocation.GetMemory(); ASSERT(memory != nullptr); @@ -158,9 +158,9 @@ namespace gpgmm { ASSERT(allocation != nullptr); const uint64_t& allocationSize = allocation->GetSize(); - mInfo.FreeMemoryUsage += allocationSize; - mInfo.UsedMemoryCount--; - mInfo.UsedMemoryUsage -= allocationSize; + mStats.FreeMemoryUsage += allocationSize; + mStats.UsedMemoryCount--; + mStats.UsedMemoryUsage -= allocationSize; IMemoryObject* memory = allocation->GetMemory(); ASSERT(memory != nullptr); @@ -181,7 +181,7 @@ namespace gpgmm { ASSERT(segment != nullptr); const uint64_t bytesReleasedPerSegment = segment->ReleasePool(bytesToRelease); bytesToRelease -= bytesReleasedPerSegment; - mInfo.FreeMemoryUsage -= bytesReleasedPerSegment; + mStats.FreeMemoryUsage -= bytesReleasedPerSegment; totalBytesReleased += bytesReleasedPerSegment; if (totalBytesReleased >= bytesToRelease) { diff --git a/src/gpgmm/common/SlabMemoryAllocator.cpp b/src/gpgmm/common/SlabMemoryAllocator.cpp index e68eed44c..086113829 100644 --- a/src/gpgmm/common/SlabMemoryAllocator.cpp +++ b/src/gpgmm/common/SlabMemoryAllocator.cpp @@ -276,7 +276,7 @@ namespace gpgmm { if (prefetchedSlabAllocation != nullptr && prefetchedSlabAllocation->GetSize() == slabSize) { pFreeSlab->Allocation = *prefetchedSlabAllocation; - mInfo.PrefetchedMemoryMissesEliminated++; + mStats.PrefetchedMemoryMissesEliminated++; return pFreeSlab->Allocation.GetMemory(); } @@ -286,7 +286,7 @@ namespace gpgmm { << prefetchedSlabAllocation->GetSize() << " bytes."; } - mInfo.PrefetchedMemoryMisses++; + mStats.PrefetchedMemoryMisses++; mMemoryAllocator->DeallocateMemory(std::move(prefetchedSlabAllocation)); } @@ -373,8 +373,8 @@ namespace gpgmm { // offset must be made relative to the slab's underlying memory and not the slab itself. const uint64_t offsetFromMemory = pFreeSlab->Allocation.GetOffset() + blockInSlab->Offset; - mInfo.UsedBlockCount++; - mInfo.UsedBlockUsage += blockInSlab->Size; + mStats.UsedBlockCount++; + mStats.UsedBlockUsage += blockInSlab->Size; return std::make_unique(this, subAllocation->GetMemory(), offsetFromMemory, AllocationMethod::kSubAllocated, @@ -401,8 +401,8 @@ namespace gpgmm { /*pDstList*/ &pCache->FreeList); } - mInfo.UsedBlockCount--; - mInfo.UsedBlockUsage -= blockInSlab->Size; + mStats.UsedBlockCount--; + mStats.UsedBlockUsage -= blockInSlab->Size; pSlab->Allocator.DeallocateBlock(blockInSlab); pSlab->UsedBlocksPerSlab--; @@ -435,10 +435,10 @@ namespace gpgmm { return pSlab; } - MemoryAllocatorInfo SlabMemoryAllocator::GetInfo() const { + MemoryAllocatorStats SlabMemoryAllocator::GetStats() const { std::lock_guard lock(mMutex); - MemoryAllocatorInfo result = mInfo; - const MemoryAllocatorInfo& info = mMemoryAllocator->GetInfo(); + MemoryAllocatorStats result = mStats; + const MemoryAllocatorStats& info = mMemoryAllocator->GetStats(); result.UsedMemoryCount = info.UsedMemoryCount; result.UsedMemoryUsage = info.UsedMemoryUsage; result.FreeMemoryUsage = info.FreeMemoryUsage; @@ -450,13 +450,13 @@ namespace gpgmm { } bool SlabMemoryAllocator::IsPrefetchCoverageBelowThreshold() const { - if (mInfo.PrefetchedMemoryMissesEliminated >= mInfo.PrefetchedMemoryMisses) { + if (mStats.PrefetchedMemoryMissesEliminated >= mStats.PrefetchedMemoryMisses) { return true; } const double currentCoverage = - SafeDivide(mInfo.PrefetchedMemoryMissesEliminated, - mInfo.PrefetchedMemoryMissesEliminated + mInfo.PrefetchedMemoryMisses); + SafeDivide(mStats.PrefetchedMemoryMissesEliminated, + mStats.PrefetchedMemoryMissesEliminated + mStats.PrefetchedMemoryMisses); if (currentCoverage < kPrefetchCoverageWarnMinThreshold) { WarnEvent(GetTypename(), EventMessageId::kPrefetchFailed) << "Prefetch coverage is below threshold (%): " << currentCoverage * 100 << " vs " @@ -543,12 +543,12 @@ namespace gpgmm { entry->Unref(); } - MemoryAllocatorInfo SlabCacheAllocator::GetInfo() const { + MemoryAllocatorStats SlabCacheAllocator::GetStats() const { std::lock_guard lock(mMutex); - MemoryAllocatorInfo result = {}; + MemoryAllocatorStats result = {}; for (const auto& entry : mSizeCache) { - const MemoryAllocatorInfo& info = entry->GetValue().SlabAllocator->GetInfo(); + const MemoryAllocatorStats& info = entry->GetValue().SlabAllocator->GetStats(); result.UsedBlockCount += info.UsedBlockCount; result.UsedBlockUsage += info.UsedBlockUsage; result.PrefetchedMemoryMisses += info.PrefetchedMemoryMisses; @@ -556,7 +556,7 @@ namespace gpgmm { } // Memory allocator is common across slab allocators. - const MemoryAllocatorInfo& info = GetNextInChain()->GetInfo(); + const MemoryAllocatorStats& info = GetNextInChain()->GetStats(); result.FreeMemoryUsage = info.FreeMemoryUsage; result.UsedMemoryCount = info.UsedMemoryCount; result.UsedMemoryUsage = info.UsedMemoryUsage; diff --git a/src/gpgmm/common/SlabMemoryAllocator.h b/src/gpgmm/common/SlabMemoryAllocator.h index 712212dc9..1dc5556fe 100644 --- a/src/gpgmm/common/SlabMemoryAllocator.h +++ b/src/gpgmm/common/SlabMemoryAllocator.h @@ -59,7 +59,7 @@ namespace gpgmm { const MemoryAllocationRequest& request) override; void DeallocateMemory(std::unique_ptr allocation) override; - MemoryAllocatorInfo GetInfo() const override; + MemoryAllocatorStats GetStats() const override; const char* GetTypename() const override; @@ -125,7 +125,7 @@ namespace gpgmm { const MemoryAllocationRequest& request) override; void DeallocateMemory(std::unique_ptr allocation) override; - MemoryAllocatorInfo GetInfo() const override; + MemoryAllocatorStats GetStats() const override; uint64_t GetMemorySize() const override; diff --git a/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp b/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp index 1e759f0e9..5aeaca700 100644 --- a/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp @@ -80,8 +80,8 @@ namespace gpgmm::d3d12 { return {}; } - mInfo.UsedMemoryUsage += resourceHeap->GetSize(); - mInfo.UsedMemoryCount++; + mStats.UsedMemoryUsage += resourceHeap->GetSize(); + mStats.UsedMemoryCount++; return std::make_unique(this, resourceHeap, request.SizeInBytes); } @@ -90,8 +90,8 @@ namespace gpgmm::d3d12 { TRACE_EVENT0(TraceEventCategory::kDefault, "BufferAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); - mInfo.UsedMemoryUsage -= allocation->GetSize(); - mInfo.UsedMemoryCount--; + mStats.UsedMemoryUsage -= allocation->GetSize(); + mStats.UsedMemoryCount--; SafeRelease(allocation); } diff --git a/src/gpgmm/d3d12/JSONSerializerD3D12.cpp b/src/gpgmm/d3d12/JSONSerializerD3D12.cpp index b16b6dd59..1a703e07c 100644 --- a/src/gpgmm/d3d12/JSONSerializerD3D12.cpp +++ b/src/gpgmm/d3d12/JSONSerializerD3D12.cpp @@ -31,7 +31,7 @@ namespace gpgmm::d3d12 { } // static - JSONDict JSONSerializer::Serialize(const RESOURCE_ALLOCATOR_INFO& info) { + JSONDict JSONSerializer::Serialize(const RESOURCE_ALLOCATOR_STATS& info) { return gpgmm::JSONSerializer::Serialize(info); } diff --git a/src/gpgmm/d3d12/JSONSerializerD3D12.h b/src/gpgmm/d3d12/JSONSerializerD3D12.h index c1bac4388..89651b7c4 100644 --- a/src/gpgmm/d3d12/JSONSerializerD3D12.h +++ b/src/gpgmm/d3d12/JSONSerializerD3D12.h @@ -41,7 +41,7 @@ namespace gpgmm::d3d12 { class JSONSerializer final : public gpgmm::JSONSerializer { public: static JSONDict Serialize(); - static JSONDict Serialize(const RESOURCE_ALLOCATOR_INFO& info); + static JSONDict Serialize(const RESOURCE_ALLOCATOR_STATS& info); static JSONDict Serialize(const ALLOCATOR_DESC& desc); static JSONDict Serialize(const CREATE_RESOURCE_DESC& desc); static JSONDict Serialize(const ALLOCATION_DESC& desc); diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index f754654e1..715096b79 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -323,8 +323,8 @@ namespace gpgmm::d3d12 { // Untracked heaps, created not resident, are not already attributed toward residency // usage because they are not in the residency cache. - mInfo.CurrentMemoryCount++; - mInfo.CurrentMemoryUsage += heap->GetSize(); + mStats.CurrentMemoryCount++; + mStats.CurrentMemoryUsage += heap->GetSize(); } // Since we can't evict the heap, it's unnecessary to track the heap in the LRU Cache. @@ -334,8 +334,8 @@ namespace gpgmm::d3d12 { // Untracked heaps, previously made resident, are not attributed toward residency usage // because they will be removed from the residency cache. if (heap->mState == RESIDENCY_STATUS_CURRENT_RESIDENT) { - mInfo.CurrentMemoryCount++; - mInfo.CurrentMemoryUsage += heap->GetSize(); + mStats.CurrentMemoryCount++; + mStats.CurrentMemoryUsage += heap->GetSize(); } } @@ -373,8 +373,8 @@ namespace gpgmm::d3d12 { ReturnIfFailed(InsertHeapInternal(heap)); // Heaps inserted into the residency cache are already attributed in residency usage. - mInfo.CurrentMemoryCount--; - mInfo.CurrentMemoryUsage -= heap->GetSize(); + mStats.CurrentMemoryCount--; + mStats.CurrentMemoryUsage -= heap->GetSize(); return S_OK; } @@ -833,14 +833,14 @@ namespace gpgmm::d3d12 { return S_OK; } - RESIDENCY_INFO ResidencyManager::GetInfo() const { + RESIDENCY_STATS ResidencyManager::GetStats() const { // 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 // ExecuteCommandLists(). // Locked heaps are not stored in the residency cache, so usage must be tracked by the // residency manager on Lock/Unlock then added here to get the sum. - RESIDENCY_INFO info = mInfo; + RESIDENCY_STATS info = mStats; for (const auto& entry : mLocalVideoMemorySegment.cache) { if (entry.value()->GetInfo().Status == RESIDENCY_STATUS_CURRENT_RESIDENT) { diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.h b/src/gpgmm/d3d12/ResidencyManagerD3D12.h index 40129e582..62e31abb7 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.h +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.h @@ -60,7 +60,7 @@ namespace gpgmm::d3d12 { HRESULT QueryVideoMemoryInfo(const DXGI_MEMORY_SEGMENT_GROUP& memorySegmentGroup, DXGI_QUERY_VIDEO_MEMORY_INFO* pVideoMemoryInfoOut) override; - RESIDENCY_INFO GetInfo() const override; + RESIDENCY_STATS GetStats() const override; DEFINE_IUNKNOWNIMPL_OVERRIDES() @@ -133,7 +133,7 @@ namespace gpgmm::d3d12 { VideoMemorySegment mLocalVideoMemorySegment; VideoMemorySegment mNonLocalVideoMemorySegment; - RESIDENCY_INFO mInfo = {}; + RESIDENCY_STATS mStats = {}; std::shared_ptr mThreadPool; std::shared_ptr mBudgetNotificationUpdateEvent; diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index dd38f862c..b3ad47170 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -1205,9 +1205,9 @@ namespace gpgmm::d3d12 { // Using committed resources will create a tightly allocated resource allocations. // This means the block and heap size should be equal (modulo driver padding). const uint64_t& allocationSize = resourceHeap->GetSize(); - mInfo.UsedMemoryUsage += allocationSize; - mInfo.UsedMemoryCount++; - mInfo.UsedBlockUsage += allocationSize; + mStats.UsedMemoryUsage += allocationSize; + mStats.UsedMemoryCount++; + mStats.UsedBlockUsage += allocationSize; RESOURCE_ALLOCATION_DESC allocationDesc = {}; allocationDesc.HeapOffset = kInvalidOffset; @@ -1260,9 +1260,9 @@ namespace gpgmm::d3d12 { &resourceHeap)); const uint64_t& allocationSize = resourceInfo.SizeInBytes; - mInfo.UsedMemoryUsage += allocationSize; - mInfo.UsedMemoryCount++; - mInfo.UsedBlockUsage += allocationSize; + mStats.UsedMemoryUsage += allocationSize; + mStats.UsedMemoryCount++; + mStats.UsedBlockUsage += allocationSize; RESOURCE_ALLOCATION_DESC allocationDesc = {}; allocationDesc.HeapOffset = kInvalidSize; @@ -1364,26 +1364,26 @@ namespace gpgmm::d3d12 { return S_OK; } - RESOURCE_ALLOCATOR_INFO ResourceAllocator::GetInfo() const { + RESOURCE_ALLOCATOR_STATS ResourceAllocator::GetStats() const { std::lock_guard lock(mMutex); return GetInfoInternal(); } - RESOURCE_ALLOCATOR_INFO ResourceAllocator::GetInfoInternal() const { + RESOURCE_ALLOCATOR_STATS ResourceAllocator::GetInfoInternal() const { TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceAllocator.GetInfo"); // ResourceAllocator itself could call CreateCommittedResource directly. - RESOURCE_ALLOCATOR_INFO result = mInfo; + RESOURCE_ALLOCATOR_STATS result = mStats; for (uint32_t resourceHeapTypeIndex = 0; resourceHeapTypeIndex < kNumOfResourceHeapTypes; resourceHeapTypeIndex++) { - result += mSmallBufferAllocatorOfType[resourceHeapTypeIndex]->GetInfo(); + result += mSmallBufferAllocatorOfType[resourceHeapTypeIndex]->GetStats(); - result += mMSAADedicatedResourceAllocatorOfType[resourceHeapTypeIndex]->GetInfo(); - result += mMSAAResourceAllocatorOfType[resourceHeapTypeIndex]->GetInfo(); + result += mMSAADedicatedResourceAllocatorOfType[resourceHeapTypeIndex]->GetStats(); + result += mMSAAResourceAllocatorOfType[resourceHeapTypeIndex]->GetStats(); - result += mResourceAllocatorOfType[resourceHeapTypeIndex]->GetInfo(); - result += mDedicatedResourceAllocatorOfType[resourceHeapTypeIndex]->GetInfo(); + result += mResourceAllocatorOfType[resourceHeapTypeIndex]->GetStats(); + result += mDedicatedResourceAllocatorOfType[resourceHeapTypeIndex]->GetStats(); } GPGMM_TRACE_EVENT_METRIC( @@ -1453,9 +1453,9 @@ namespace gpgmm::d3d12 { std::lock_guard lock(mMutex); const uint64_t& allocationSize = allocation->GetSize(); - mInfo.UsedMemoryUsage -= allocationSize; - mInfo.UsedMemoryCount--; - mInfo.UsedBlockUsage -= allocationSize; + mStats.UsedMemoryUsage -= allocationSize; + mStats.UsedMemoryCount--; + mStats.UsedBlockUsage -= allocationSize; SafeRelease(allocation); } diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h index 61ece82d4..ce88c6439 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h @@ -62,7 +62,7 @@ namespace gpgmm::d3d12 { HRESULT CreateResource(ComPtr committedResource, IResourceAllocation** ppResourceAllocationOut) override; uint64_t ReleaseMemory(uint64_t bytesToRelease) override; - RESOURCE_ALLOCATOR_INFO GetInfo() const override; + RESOURCE_ALLOCATOR_STATS GetStats() const override; HRESULT CheckFeatureSupport(ALLOCATOR_FEATURE feature, void* pFeatureSupportData, uint32_t featureSupportDataSize) const override; @@ -138,7 +138,7 @@ namespace gpgmm::d3d12 { // MemoryAllocator interface void DeallocateMemory(std::unique_ptr allocation) override; - RESOURCE_ALLOCATOR_INFO GetInfoInternal() const; + RESOURCE_ALLOCATOR_STATS GetInfoInternal() const; ComPtr mDevice; ComPtr mResidencyManager; diff --git a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp index e78eb3cae..81f731746 100644 --- a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp @@ -94,8 +94,8 @@ namespace gpgmm::d3d12 { " bytes)."; } - mInfo.UsedMemoryUsage += resourceHeapDesc.SizeInBytes; - mInfo.UsedMemoryCount++; + mStats.UsedMemoryUsage += resourceHeapDesc.SizeInBytes; + mStats.UsedMemoryCount++; return std::make_unique(this, resourceHeap, request.SizeInBytes); } @@ -105,8 +105,8 @@ namespace gpgmm::d3d12 { TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceHeapAllocator.DeallocateMemory"); - mInfo.UsedMemoryUsage -= allocation->GetSize(); - mInfo.UsedMemoryCount--; + mStats.UsedMemoryUsage -= allocation->GetSize(); + mStats.UsedMemoryCount--; SafeRelease(allocation); } diff --git a/src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp b/src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp index 40cf90e4e..ef990fe52 100644 --- a/src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp +++ b/src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp @@ -38,10 +38,10 @@ namespace gpgmm::vk { const uint64_t maxDeviceMemoryAllocationCount = mResourceAllocator->GetCaps()->GetMaxDeviceAllocationCount(); - if (mInfo.UsedMemoryCount + 1 >= maxDeviceMemoryAllocationCount) { + if (mStats.UsedMemoryCount + 1 >= maxDeviceMemoryAllocationCount) { DebugEvent("DeviceMemoryAllocator.TryAllocateMemory", EventMessageId::kAllocatorFailed) << "Device exceeded max number of device memory allocations (" + - std::to_string(mInfo.UsedMemoryCount) + " vs " + + std::to_string(mStats.UsedMemoryCount) + " vs " + std::to_string(maxDeviceMemoryAllocationCount) + ")."; return {}; } @@ -61,8 +61,8 @@ namespace gpgmm::vk { return {}; } - mInfo.UsedMemoryUsage += request.SizeInBytes; - mInfo.UsedMemoryCount++; + mStats.UsedMemoryUsage += request.SizeInBytes; + mStats.UsedMemoryCount++; return std::make_unique( this, @@ -79,8 +79,8 @@ namespace gpgmm::vk { mResourceAllocator->GetFunctions().FreeMemory(mResourceAllocator->GetDevice(), deviceMemory, /*allocationCallbacks*/ nullptr); - mInfo.UsedMemoryUsage -= allocation->GetSize(); - mInfo.UsedMemoryCount--; + mStats.UsedMemoryUsage -= allocation->GetSize(); + mStats.UsedMemoryCount--; SafeRelease(allocation); } diff --git a/src/include/gpgmm.h b/src/include/gpgmm.h index c4b63cf84..0d4609a7d 100644 --- a/src/include/gpgmm.h +++ b/src/include/gpgmm.h @@ -56,10 +56,10 @@ namespace gpgmm { virtual void SetPool(IMemoryPool* pool) = 0; }; - /** \struct MemoryAllocatorInfo + /** \struct MemoryAllocatorStats Information about the memory allocator. */ - struct MemoryAllocatorInfo { + struct MemoryAllocatorStats { /** \brief Number of used sub-allocated blocks within the same memory. */ uint32_t UsedBlockCount; @@ -98,7 +98,7 @@ namespace gpgmm { /** \brief Adds or sums together two infos. */ - MemoryAllocatorInfo& operator+=(const MemoryAllocatorInfo& rhs); + MemoryAllocatorStats& operator+=(const MemoryAllocatorStats& rhs); }; /** \enum AllocationMethod diff --git a/src/include/gpgmm_d3d12.h b/src/include/gpgmm_d3d12.h index 234d8fa7f..614ff1c56 100644 --- a/src/include/gpgmm_d3d12.h +++ b/src/include/gpgmm_d3d12.h @@ -439,10 +439,10 @@ namespace gpgmm::d3d12 { uint64_t InitialFenceValue; }; - /** \struct RESIDENCY_INFO + /** \struct RESIDENCY_STATS Additional information about the residency manager. */ - struct RESIDENCY_INFO { + struct RESIDENCY_STATS { /** \brief Amount of memory, in bytes, currently resident. */ uint64_t CurrentMemoryUsage; @@ -521,9 +521,9 @@ namespace gpgmm::d3d12 { /** \brief Return the current residency manager usage. - \return A RESIDENCY_INFO struct. + \return A RESIDENCY_STATS struct. */ - virtual RESIDENCY_INFO GetInfo() const = 0; + virtual RESIDENCY_STATS GetStats() const = 0; }; /** \brief Create residency residency manager to manage video memory. @@ -1091,7 +1091,7 @@ namespace gpgmm::d3d12 { ALLOCATOR_FEATURE_RESOURCE_ALLOCATION_SUPPORT, }; - using RESOURCE_ALLOCATOR_INFO = MemoryAllocatorInfo; + using RESOURCE_ALLOCATOR_STATS = MemoryAllocatorStats; /** \brief ResourceAllocator is a MemoryAllocator that creates ID3D12Resources in a ResourceAllocation. @@ -1179,7 +1179,7 @@ namespace gpgmm::d3d12 { (UsedMemoryUsage + FreeMemoryUsage) * 100%. */ - virtual RESOURCE_ALLOCATOR_INFO GetInfo() const = 0; + virtual RESOURCE_ALLOCATOR_STATS GetStats() const = 0; /** \brief Gets information about the features that are supported by the resource allocator. diff --git a/src/mvi/gpgmm_d3d12_mvi.cpp b/src/mvi/gpgmm_d3d12_mvi.cpp index e9b2563a3..3d0ae3b5f 100644 --- a/src/mvi/gpgmm_d3d12_mvi.cpp +++ b/src/mvi/gpgmm_d3d12_mvi.cpp @@ -226,7 +226,7 @@ namespace gpgmm::d3d12 { return S_OK; } - RESIDENCY_INFO ResidencyManager::GetInfo() const { + RESIDENCY_STATS ResidencyManager::GetStats() const { return {0, 0}; } @@ -402,9 +402,9 @@ namespace gpgmm::d3d12 { &resourceHeap)); const uint64_t& allocationSize = resourceHeap->GetSize(); - mInfo.UsedMemoryUsage += allocationSize; - mInfo.UsedMemoryCount++; - mInfo.UsedBlockUsage += allocationSize; + mStats.UsedMemoryUsage += allocationSize; + mStats.UsedMemoryCount++; + mStats.UsedBlockUsage += allocationSize; RESOURCE_ALLOCATION_DESC allocationDesc = {}; allocationDesc.HeapOffset = kInvalidOffset; @@ -427,8 +427,8 @@ namespace gpgmm::d3d12 { return 0; } - RESOURCE_ALLOCATOR_INFO ResourceAllocator::GetInfo() const { - return mInfo; + RESOURCE_ALLOCATOR_STATS ResourceAllocator::GetStats() const { + return mStats; } HRESULT ResourceAllocator::CheckFeatureSupport(ALLOCATOR_FEATURE feature, @@ -444,9 +444,9 @@ namespace gpgmm::d3d12 { void ResourceAllocator::DeallocateMemory(std::unique_ptr allocation) { const uint64_t& allocationSize = allocation->GetSize(); - mInfo.UsedMemoryUsage -= allocationSize; - mInfo.UsedMemoryCount--; - mInfo.UsedBlockUsage -= allocationSize; + mStats.UsedMemoryUsage -= allocationSize; + mStats.UsedMemoryCount--; + mStats.UsedBlockUsage -= allocationSize; delete allocation->GetMemory(); } diff --git a/src/mvi/gpgmm_d3d12_mvi.h b/src/mvi/gpgmm_d3d12_mvi.h index b89193b1c..48d335768 100644 --- a/src/mvi/gpgmm_d3d12_mvi.h +++ b/src/mvi/gpgmm_d3d12_mvi.h @@ -129,7 +129,7 @@ namespace gpgmm::d3d12 { uint64_t* pCurrentReservationOut = nullptr) override; HRESULT QueryVideoMemoryInfo(const DXGI_MEMORY_SEGMENT_GROUP& memorySegmentGroup, DXGI_QUERY_VIDEO_MEMORY_INFO* pVideoMemoryInfoOut) override; - RESIDENCY_INFO GetInfo() const override; + RESIDENCY_STATS GetStats() const override; // IUnknown interface HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) override; @@ -203,7 +203,7 @@ namespace gpgmm::d3d12 { HRESULT CreateResource(Microsoft::WRL::ComPtr committedResource, IResourceAllocation** ppResourceAllocationOut) override; uint64_t ReleaseMemory(uint64_t bytesToRelease) override; - RESOURCE_ALLOCATOR_INFO GetInfo() const override; + RESOURCE_ALLOCATOR_STATS GetStats() const override; HRESULT CheckFeatureSupport(ALLOCATOR_FEATURE feature, void* pFeatureSupportData, uint32_t featureSupportDataSize) const override; diff --git a/src/mvi/gpgmm_mvi.cpp b/src/mvi/gpgmm_mvi.cpp index 24dba73ff..75669c56c 100644 --- a/src/mvi/gpgmm_mvi.cpp +++ b/src/mvi/gpgmm_mvi.cpp @@ -35,8 +35,8 @@ namespace gpgmm { return 0; } - MemoryAllocatorInfo MemoryAllocator::GetInfo() const { - return mInfo; + MemoryAllocatorStats MemoryAllocator::GetStats() const { + return mStats; } // MemoryAllocation diff --git a/src/mvi/gpgmm_mvi.h b/src/mvi/gpgmm_mvi.h index c90a82d87..fe95ece28 100644 --- a/src/mvi/gpgmm_mvi.h +++ b/src/mvi/gpgmm_mvi.h @@ -39,10 +39,10 @@ namespace gpgmm { public: virtual void DeallocateMemory(std::unique_ptr allocation) = 0; virtual uint64_t ReleaseMemory(uint64_t bytesToRelease); - virtual MemoryAllocatorInfo GetInfo() const; + virtual MemoryAllocatorStats GetStats() const; protected: - MemoryAllocatorInfo mInfo = {}; + MemoryAllocatorStats mStats = {}; }; class MemoryAllocation { diff --git a/src/tests/DummyMemoryAllocator.h b/src/tests/DummyMemoryAllocator.h index 5aa4e35a5..388c55b06 100644 --- a/src/tests/DummyMemoryAllocator.h +++ b/src/tests/DummyMemoryAllocator.h @@ -70,8 +70,8 @@ namespace gpgmm { return {}; } - mInfo.UsedMemoryCount++; - mInfo.UsedMemoryUsage += request.SizeInBytes; + mStats.UsedMemoryCount++; + mStats.UsedMemoryUsage += request.SizeInBytes; return std::make_unique( this, new DummyMemory(request.SizeInBytes, request.Alignment), request.SizeInBytes); @@ -82,8 +82,8 @@ namespace gpgmm { std::lock_guard lock(mMutex); - mInfo.UsedMemoryCount--; - mInfo.UsedMemoryUsage -= allocation->GetSize(); + mStats.UsedMemoryCount--; + mStats.UsedMemoryUsage -= allocation->GetSize(); SafeRelease(allocation); } diff --git a/src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp b/src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp index bfa8d7737..236b746d2 100644 --- a/src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp +++ b/src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp @@ -330,7 +330,7 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith } mReplayedMemoryStats.PeakUsage = - std::max(resourceAllocator->GetInfo().UsedMemoryUsage, + std::max(resourceAllocator->GetStats().UsedMemoryUsage, mReplayedMemoryStats.PeakUsage); } break; diff --git a/src/tests/end2end/D3D12ResidencyManagerTests.cpp b/src/tests/end2end/D3D12ResidencyManagerTests.cpp index 0c641c1c5..2664fd8d4 100644 --- a/src/tests/end2end/D3D12ResidencyManagerTests.cpp +++ b/src/tests/end2end/D3D12ResidencyManagerTests.cpp @@ -175,8 +175,8 @@ TEST_F(D3D12ResidencyManagerTests, CreateResourceHeap) { EXPECT_EQ(resourceHeap->GetInfo().IsLocked, false); // Residency status of resource heap types is always known. - EXPECT_EQ(residencyManager->GetInfo().CurrentMemoryUsage, resourceHeapDesc.SizeInBytes); - EXPECT_EQ(residencyManager->GetInfo().CurrentMemoryCount, 1u); + EXPECT_EQ(residencyManager->GetStats().CurrentMemoryUsage, resourceHeapDesc.SizeInBytes); + EXPECT_EQ(residencyManager->GetStats().CurrentMemoryCount, 1u); ComPtr heap; ASSERT_SUCCEEDED(resourceHeap.As(&heap)); @@ -187,8 +187,8 @@ TEST_F(D3D12ResidencyManagerTests, CreateResourceHeap) { EXPECT_EQ(resourceHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_STATUS_CURRENT_RESIDENT); EXPECT_EQ(resourceHeap->GetInfo().IsLocked, true); - EXPECT_EQ(residencyManager->GetInfo().CurrentMemoryUsage, resourceHeapDesc.SizeInBytes); - EXPECT_EQ(residencyManager->GetInfo().CurrentMemoryCount, 1u); + EXPECT_EQ(residencyManager->GetStats().CurrentMemoryUsage, resourceHeapDesc.SizeInBytes); + EXPECT_EQ(residencyManager->GetStats().CurrentMemoryCount, 1u); ASSERT_SUCCEEDED(residencyManager->UnlockHeap(resourceHeap.Get())); @@ -196,8 +196,8 @@ TEST_F(D3D12ResidencyManagerTests, CreateResourceHeap) { EXPECT_EQ(resourceHeap->GetInfo().IsLocked, false); // Unlocking a heap does not evict it, the memory usage should not change. - EXPECT_EQ(residencyManager->GetInfo().CurrentMemoryUsage, resourceHeapDesc.SizeInBytes); - EXPECT_EQ(residencyManager->GetInfo().CurrentMemoryCount, 1u); + EXPECT_EQ(residencyManager->GetStats().CurrentMemoryUsage, resourceHeapDesc.SizeInBytes); + EXPECT_EQ(residencyManager->GetStats().CurrentMemoryCount, 1u); ASSERT_FAILED(residencyManager->UnlockHeap(resourceHeap.Get())); // Not locked } @@ -239,16 +239,16 @@ TEST_F(D3D12ResidencyManagerTests, CreateDescriptorHeap) { // Residency status of non-resource heap types is unknown, there is no residency usage // yet. - EXPECT_EQ(residencyManager->GetInfo().CurrentMemoryUsage, 0u); - EXPECT_EQ(residencyManager->GetInfo().CurrentMemoryCount, 0u); + EXPECT_EQ(residencyManager->GetStats().CurrentMemoryUsage, 0u); + EXPECT_EQ(residencyManager->GetStats().CurrentMemoryCount, 0u); ASSERT_SUCCEEDED(residencyManager->LockHeap(descriptorHeap.Get())); EXPECT_EQ(descriptorHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_STATUS_CURRENT_RESIDENT); EXPECT_EQ(descriptorHeap->GetInfo().IsLocked, true); - EXPECT_EQ(residencyManager->GetInfo().CurrentMemoryUsage, descriptorHeapDesc.SizeInBytes); - EXPECT_EQ(residencyManager->GetInfo().CurrentMemoryCount, 1u); + EXPECT_EQ(residencyManager->GetStats().CurrentMemoryUsage, descriptorHeapDesc.SizeInBytes); + EXPECT_EQ(residencyManager->GetStats().CurrentMemoryCount, 1u); ASSERT_SUCCEEDED(residencyManager->UnlockHeap(descriptorHeap.Get())); @@ -256,8 +256,8 @@ TEST_F(D3D12ResidencyManagerTests, CreateDescriptorHeap) { EXPECT_EQ(descriptorHeap->GetInfo().IsLocked, false); // Unlocking a heap does not evict it, the memory usage should not change. - EXPECT_EQ(residencyManager->GetInfo().CurrentMemoryUsage, descriptorHeapDesc.SizeInBytes); - EXPECT_EQ(residencyManager->GetInfo().CurrentMemoryCount, 1u); + EXPECT_EQ(residencyManager->GetStats().CurrentMemoryUsage, descriptorHeapDesc.SizeInBytes); + EXPECT_EQ(residencyManager->GetStats().CurrentMemoryCount, 1u); ASSERT_FAILED(residencyManager->UnlockHeap(descriptorHeap.Get())); } @@ -396,7 +396,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudget) { // Keep allocating until we reach the budget. std::vector> allocationsBelowBudget = {}; - while (resourceAllocator->GetInfo().UsedMemoryUsage + kBufferMemorySize <= kDefaultBudget) { + while (resourceAllocator->GetStats().UsedMemoryUsage + kBufferMemorySize <= kDefaultBudget) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( bufferAllocationDesc, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); @@ -413,9 +413,9 @@ TEST_F(D3D12ResidencyManagerTests, OverBudget) { // Allocating the same amount over budget, where older allocations will be evicted. std::vector> allocationsAboveBudget = {}; - const uint64_t currentMemoryUsage = resourceAllocator->GetInfo().UsedMemoryUsage; + const uint64_t currentMemoryUsage = resourceAllocator->GetStats().UsedMemoryUsage; - while (currentMemoryUsage + kMemoryOverBudget > resourceAllocator->GetInfo().UsedMemoryUsage) { + while (currentMemoryUsage + kMemoryOverBudget > resourceAllocator->GetStats().UsedMemoryUsage) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( bufferAllocationDesc, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); @@ -463,7 +463,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetAsync) { // Keep allocating until we reach the budget. Should a budget change occur, we must also // terminate the loop since we cannot guarantee all allocations will be created resident. std::vector> allocations = {}; - while (resourceAllocator->GetInfo().UsedMemoryUsage + kBufferMemorySize < memoryUnderBudget && + while (resourceAllocator->GetStats().UsedMemoryUsage + kBufferMemorySize < memoryUnderBudget && GetBudgetLeft(residencyManager.Get(), bufferMemorySegment) >= kBufferMemorySize) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( @@ -502,7 +502,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetDisablesGrowth) { ALLOCATION_DESC bufferAllocationDesc = {}; bufferAllocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; - while (resourceAllocator->GetInfo().UsedMemoryUsage + kBufferMemorySize <= kDefaultBudget) { + while (resourceAllocator->GetStats().UsedMemoryUsage + kBufferMemorySize <= kDefaultBudget) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( bufferAllocationDesc, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); @@ -542,7 +542,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetWithLockedHeaps) { // Keep allocating until we reach the budget. std::vector> allocationsBelowBudget = {}; - while (resourceAllocator->GetInfo().UsedMemoryUsage + kBufferMemorySize <= kDefaultBudget) { + while (resourceAllocator->GetStats().UsedMemoryUsage + kBufferMemorySize <= kDefaultBudget) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( bufferAllocationDesc, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); @@ -588,7 +588,7 @@ TEST_F(D3D12ResidencyManagerTests, ExecuteCommandListOverBudget) { // Create the first set of heaps below the budget. std::vector> firstSetOfHeaps = {}; - while (resourceAllocator->GetInfo().UsedMemoryUsage + kBufferMemorySize <= kDefaultBudget) { + while (resourceAllocator->GetStats().UsedMemoryUsage + kBufferMemorySize <= kDefaultBudget) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( {}, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); diff --git a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp index a0fe3cfc0..4c6fb9042 100644 --- a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp +++ b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp @@ -32,22 +32,22 @@ static constexpr uint64_t kReleaseAllMemory = std::numeric_limits::max #define GPGMM_GET_VAR_NAME(x) (L#x) -#define EXPECT_SIZE_CACHE_HIT(allocator, statement) \ - do { \ - ASSERT_NE(allocator, nullptr); \ - uint64_t countBefore = allocator->GetInfo().SizeCacheHits; \ - EXPECT_SUCCEEDED(statement); \ - uint64_t countAfter = allocator->GetInfo().SizeCacheHits; \ - EXPECT_GT(countAfter, countBefore); \ +#define EXPECT_SIZE_CACHE_HIT(allocator, statement) \ + do { \ + ASSERT_NE(allocator, nullptr); \ + uint64_t countBefore = allocator->GetStats().SizeCacheHits; \ + EXPECT_SUCCEEDED(statement); \ + uint64_t countAfter = allocator->GetStats().SizeCacheHits; \ + EXPECT_GT(countAfter, countBefore); \ } while (0) -#define EXPECT_SIZE_CACHE_MISS(allocator, statement) \ - do { \ - ASSERT_NE(allocator, nullptr); \ - uint64_t countBefore = allocator->GetInfo().SizeCacheMisses; \ - EXPECT_SUCCEEDED(statement); \ - uint64_t countAfter = allocator->GetInfo().SizeCacheMisses; \ - EXPECT_GT(countAfter, countBefore); \ +#define EXPECT_SIZE_CACHE_MISS(allocator, statement) \ + do { \ + ASSERT_NE(allocator, nullptr); \ + uint64_t countBefore = allocator->GetStats().SizeCacheMisses; \ + EXPECT_SUCCEEDED(statement); \ + uint64_t countAfter = allocator->GetStats().SizeCacheMisses; \ + EXPECT_GT(countAfter, countBefore); \ } while (0) class D3D12ResourceAllocatorTests : public D3D12TestBase, public ::testing::Test { @@ -184,7 +184,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSameHeap) { nullptr, &bufferAllocation)); } - EXPECT_EQ(resourceAllocator->GetInfo().FreeMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(resourceAllocator->GetStats().FreeMemoryUsage, kBufferOf4MBAllocationSize); // Reuse memory for texture in Heap A. { @@ -194,7 +194,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSameHeap) { D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &textureAllocation)); } - EXPECT_EQ(resourceAllocator->GetInfo().FreeMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(resourceAllocator->GetStats().FreeMemoryUsage, kBufferOf4MBAllocationSize); } // Exceeding the max resource heap size should always fail. @@ -219,7 +219,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSeperateHeap) { allocatorDesc.PreferredResourceHeapSize); } - EXPECT_EQ(resourceAllocator->GetInfo().FreeMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(resourceAllocator->GetStats().FreeMemoryUsage, kBufferOf4MBAllocationSize); // Reuse memory for texture in Heap A. { @@ -232,7 +232,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSeperateHeap) { allocatorDesc.PreferredResourceHeapSize); } - EXPECT_EQ(resourceAllocator->GetInfo().FreeMemoryUsage, kBufferOf4MBAllocationSize * 2); + EXPECT_EQ(resourceAllocator->GetStats().FreeMemoryUsage, kBufferOf4MBAllocationSize * 2); } // Exceeding the max resource heap size should always fail. @@ -684,13 +684,13 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferUMA) { resourceAllocator->CreateResource({}, CreateBasicBufferDesc(kBufferOf4MBAllocationSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, nullptr)); - EXPECT_EQ(resourceAllocator->GetInfo().FreeMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(resourceAllocator->GetStats().FreeMemoryUsage, kBufferOf4MBAllocationSize); ASSERT_SUCCEEDED( resourceAllocator->CreateResource({}, CreateBasicBufferDesc(kBufferOf4MBAllocationSize), D3D12_RESOURCE_STATE_COPY_DEST, nullptr, nullptr)); - EXPECT_EQ(resourceAllocator->GetInfo().FreeMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(resourceAllocator->GetStats().FreeMemoryUsage, kBufferOf4MBAllocationSize); ALLOCATION_DESC allocationDesc = {}; allocationDesc.HeapType = D3D12_HEAP_TYPE_READBACK; @@ -699,7 +699,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferUMA) { resourceAllocator->CreateResource(allocationDesc, CreateBasicBufferDesc(kBufferOf4MBAllocationSize), D3D12_RESOURCE_STATE_COPY_DEST, nullptr, nullptr)); - EXPECT_EQ(resourceAllocator->GetInfo().FreeMemoryUsage, kBufferOf4MBAllocationSize * 2); + EXPECT_EQ(resourceAllocator->GetStats().FreeMemoryUsage, kBufferOf4MBAllocationSize * 2); } TEST_F(D3D12ResourceAllocatorTests, CreateBufferDisableCustomHeaps) { @@ -746,7 +746,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferDisableCustomHeaps) { allocationDesc, CreateBasicBufferDesc(kBufferOf4MBAllocationSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, nullptr)); - EXPECT_EQ(resourceAllocator->GetInfo().FreeMemoryUsage, kBufferOf4MBAllocationSize * 2); + EXPECT_EQ(resourceAllocator->GetStats().FreeMemoryUsage, kBufferOf4MBAllocationSize * 2); } } @@ -792,10 +792,10 @@ TEST_F(D3D12ResourceAllocatorTests, CreateMultisampledTexture) { allocation->GetInfo().SizeInBytes, static_cast(D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT))); - EXPECT_EQ(resourceAllocator->GetInfo().UsedMemoryCount, 1u); + EXPECT_EQ(resourceAllocator->GetStats().UsedMemoryCount, 1u); } - EXPECT_EQ(resourceAllocator->GetInfo().UsedMemoryCount, 0u); + EXPECT_EQ(resourceAllocator->GetStats().UsedMemoryCount, 0u); } TEST_F(D3D12ResourceAllocatorTests, CreateBufferImported) { @@ -869,9 +869,9 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAlwaysCommitted) { ASSERT_FAILED(resourceHeap.As(&heap)); // Commited resources must use all the memory allocated. - EXPECT_EQ(resourceAllocator->GetInfo().UsedMemoryUsage, kBufferOf4MBAllocationSize); - EXPECT_EQ(resourceAllocator->GetInfo().UsedBlockUsage, - resourceAllocator->GetInfo().UsedMemoryUsage); + EXPECT_EQ(resourceAllocator->GetStats().UsedMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(resourceAllocator->GetStats().UsedBlockUsage, + resourceAllocator->GetStats().UsedMemoryUsage); } TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverAllocate) { @@ -935,9 +935,9 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { EXPECT_EQ(smallBuffer->GetOffsetFromResource(), 0u); EXPECT_EQ(smallBuffer->GetInfo().Alignment, 4u); // Must re-align. - EXPECT_EQ(resourceAllocator->GetInfo().UsedBlockCount, 1u); - EXPECT_EQ(resourceAllocator->GetInfo().UsedMemoryCount, 1u); - EXPECT_EQ(resourceAllocator->GetInfo().UsedBlockUsage, smallBuffer->GetInfo().SizeInBytes); + EXPECT_EQ(resourceAllocator->GetStats().UsedBlockCount, 1u); + EXPECT_EQ(resourceAllocator->GetStats().UsedMemoryCount, 1u); + EXPECT_EQ(resourceAllocator->GetStats().UsedBlockUsage, smallBuffer->GetInfo().SizeInBytes); } { ALLOCATION_DESC smallBufferWithinDesc = baseAllocationDesc; @@ -953,9 +953,9 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { EXPECT_EQ(smallBuffer->GetOffsetFromResource(), 0u); EXPECT_EQ(smallBuffer->GetInfo().Alignment, 16u); - EXPECT_EQ(resourceAllocator->GetInfo().UsedBlockCount, 1u); - EXPECT_EQ(resourceAllocator->GetInfo().UsedMemoryCount, 1u); - EXPECT_EQ(resourceAllocator->GetInfo().UsedBlockUsage, smallBuffer->GetInfo().SizeInBytes); + EXPECT_EQ(resourceAllocator->GetStats().UsedBlockCount, 1u); + EXPECT_EQ(resourceAllocator->GetStats().UsedMemoryCount, 1u); + EXPECT_EQ(resourceAllocator->GetStats().UsedBlockUsage, smallBuffer->GetInfo().SizeInBytes); } { ALLOCATION_DESC smallBufferWithinDesc = baseAllocationDesc; @@ -971,9 +971,9 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { EXPECT_EQ(smallBuffer->GetOffsetFromResource(), 0u); EXPECT_EQ(smallBuffer->GetInfo().Alignment, 256u); // Re-align - EXPECT_EQ(resourceAllocator->GetInfo().UsedBlockCount, 1u); - EXPECT_EQ(resourceAllocator->GetInfo().UsedMemoryCount, 1u); - EXPECT_EQ(resourceAllocator->GetInfo().UsedBlockUsage, smallBuffer->GetInfo().SizeInBytes); + EXPECT_EQ(resourceAllocator->GetStats().UsedBlockCount, 1u); + EXPECT_EQ(resourceAllocator->GetStats().UsedMemoryCount, 1u); + EXPECT_EQ(resourceAllocator->GetStats().UsedBlockUsage, smallBuffer->GetInfo().SizeInBytes); } { ALLOCATION_DESC smallBufferWithinDesc = baseAllocationDesc; @@ -1113,8 +1113,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithinMany) { EXPECT_EQ(smallBufferC->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); EXPECT_EQ(smallBufferC->GetInfo().SizeInBytes, smallBufferDesc.Width); - EXPECT_EQ(resourceAllocator->GetInfo().UsedBlockCount, 3u); - EXPECT_EQ(resourceAllocator->GetInfo().UsedMemoryCount, 1u); + EXPECT_EQ(resourceAllocator->GetStats().UsedBlockCount, 3u); + EXPECT_EQ(resourceAllocator->GetStats().UsedMemoryCount, 1u); // Should be allocated in sequence, back-to-back. EXPECT_EQ(smallBufferA->GetOffsetFromResource() + smallBufferDesc.Width, @@ -1184,8 +1184,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithinMany) { smallBufferB = nullptr; smallBufferC = nullptr; - EXPECT_EQ(resourceAllocator->GetInfo().UsedBlockCount, 0u); - EXPECT_EQ(resourceAllocator->GetInfo().UsedMemoryCount, 0u); + EXPECT_EQ(resourceAllocator->GetStats().UsedBlockCount, 0u); + EXPECT_EQ(resourceAllocator->GetStats().UsedMemoryCount, 0u); } TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverSubAllocated) { @@ -1329,11 +1329,11 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { EXPECT_EQ(allocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); } - EXPECT_EQ(poolAllocator->GetInfo().FreeMemoryUsage, bufferSize + bufferSize / 2); + EXPECT_EQ(poolAllocator->GetStats().FreeMemoryUsage, bufferSize + bufferSize / 2); EXPECT_EQ(poolAllocator->ReleaseMemory(kReleaseAllMemory), bufferSize + bufferSize / 2); - EXPECT_EQ(poolAllocator->GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(poolAllocator->GetStats().FreeMemoryUsage, 0u); // Create buffer of size A again with it's own resource heap from the empty pool. { @@ -1373,11 +1373,11 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { EXPECT_EQ(allocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); } - EXPECT_EQ(poolAllocator->GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(poolAllocator->GetStats().FreeMemoryUsage, 0u); } -TEST_F(D3D12ResourceAllocatorTests, CreateBufferGetInfo) { - // Calculate info for a single standalone allocation. +TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { + // Calculate stats for a single standalone allocation. { ComPtr resourceAllocator; ASSERT_SUCCEEDED( @@ -1395,9 +1395,9 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferGetInfo) { ASSERT_NE(firstAllocation, nullptr); EXPECT_EQ(firstAllocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); - RESOURCE_ALLOCATOR_INFO info = resourceAllocator->GetInfo(); - EXPECT_EQ(info.UsedMemoryCount, 1u); - EXPECT_EQ(info.UsedMemoryUsage, kBufferOf4MBAllocationSize); + RESOURCE_ALLOCATOR_STATS stats = resourceAllocator->GetStats(); + EXPECT_EQ(stats.UsedMemoryCount, 1u); + EXPECT_EQ(stats.UsedMemoryUsage, kBufferOf4MBAllocationSize); } // Calculate info for two pooled standalone allocations. @@ -1419,9 +1419,9 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferGetInfo) { ASSERT_NE(firstAllocation, nullptr); EXPECT_EQ(firstAllocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); - RESOURCE_ALLOCATOR_INFO info = resourceAllocator->GetInfo(); - EXPECT_EQ(info.UsedMemoryCount, 1u); - EXPECT_EQ(info.UsedMemoryUsage, kBufferOf4MBAllocationSize); + RESOURCE_ALLOCATOR_STATS stats = resourceAllocator->GetStats(); + EXPECT_EQ(stats.UsedMemoryCount, 1u); + EXPECT_EQ(stats.UsedMemoryUsage, kBufferOf4MBAllocationSize); ComPtr secondAllocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( @@ -1430,9 +1430,9 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferGetInfo) { ASSERT_NE(secondAllocation, nullptr); EXPECT_EQ(secondAllocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); - info = resourceAllocator->GetInfo(); - EXPECT_EQ(info.UsedMemoryCount, 2u); - EXPECT_EQ(info.UsedMemoryUsage, kBufferOf4MBAllocationSize * 2); + stats = resourceAllocator->GetStats(); + EXPECT_EQ(stats.UsedMemoryCount, 2u); + EXPECT_EQ(stats.UsedMemoryUsage, kBufferOf4MBAllocationSize * 2); } // Calculate info for two sub-allocations. @@ -1458,11 +1458,11 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferGetInfo) { GPGMM_SKIP_TEST_IF(firstAllocation->GetInfo().Method != gpgmm::AllocationMethod::kSubAllocated); - RESOURCE_ALLOCATOR_INFO info = resourceAllocator->GetInfo(); - EXPECT_EQ(info.UsedMemoryCount, 1u); - EXPECT_GE(info.UsedMemoryUsage, info.UsedBlockUsage); - EXPECT_EQ(info.UsedBlockCount, 1u); - EXPECT_GE(info.UsedBlockUsage, kBufferSize); + RESOURCE_ALLOCATOR_STATS stats = resourceAllocator->GetStats(); + EXPECT_EQ(stats.UsedMemoryCount, 1u); + EXPECT_GE(stats.UsedMemoryUsage, stats.UsedBlockUsage); + EXPECT_EQ(stats.UsedBlockCount, 1u); + EXPECT_GE(stats.UsedBlockUsage, kBufferSize); ComPtr secondAllocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( @@ -1471,14 +1471,14 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferGetInfo) { ASSERT_NE(secondAllocation, nullptr); EXPECT_EQ(secondAllocation->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocated); - info = resourceAllocator->GetInfo(); - EXPECT_GE(info.UsedMemoryCount, 1u); - EXPECT_GE(info.UsedMemoryUsage, info.UsedBlockUsage); - EXPECT_EQ(info.UsedBlockCount, 2u); - EXPECT_GE(info.UsedBlockUsage, kBufferSize * 2); + stats = resourceAllocator->GetStats(); + EXPECT_GE(stats.UsedMemoryCount, 1u); + EXPECT_GE(stats.UsedMemoryUsage, stats.UsedBlockUsage); + EXPECT_EQ(stats.UsedBlockCount, 2u); + EXPECT_GE(stats.UsedBlockUsage, kBufferSize * 2); } - // Calculate info for two sub-allocations within the same resource. + // Calculate stats for two sub-allocations within the same resource. { ComPtr resourceAllocator; ASSERT_SUCCEEDED( @@ -1498,11 +1498,11 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferGetInfo) { ASSERT_NE(firstAllocation, nullptr); EXPECT_EQ(firstAllocation->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); - RESOURCE_ALLOCATOR_INFO info = resourceAllocator->GetInfo(); - EXPECT_EQ(info.UsedMemoryCount, 1u); - EXPECT_EQ(info.UsedMemoryUsage, 64u * 1024u); - EXPECT_EQ(info.UsedBlockCount, 1u); - EXPECT_EQ(info.UsedBlockUsage, kBufferSize); + RESOURCE_ALLOCATOR_STATS stats = resourceAllocator->GetStats(); + EXPECT_EQ(stats.UsedMemoryCount, 1u); + EXPECT_EQ(stats.UsedMemoryUsage, 64u * 1024u); + EXPECT_EQ(stats.UsedBlockCount, 1u); + EXPECT_EQ(stats.UsedBlockUsage, kBufferSize); ComPtr secondAllocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( @@ -1511,11 +1511,11 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferGetInfo) { ASSERT_NE(secondAllocation, nullptr); EXPECT_EQ(secondAllocation->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); - info = resourceAllocator->GetInfo(); - EXPECT_EQ(info.UsedMemoryCount, 1u); - EXPECT_EQ(info.UsedMemoryUsage, 64u * 1024u); - EXPECT_EQ(info.UsedBlockCount, 2u); - EXPECT_EQ(info.UsedBlockUsage, kBufferSize * 2); + stats = resourceAllocator->GetStats(); + EXPECT_EQ(stats.UsedMemoryCount, 1u); + EXPECT_EQ(stats.UsedMemoryUsage, 64u * 1024u); + EXPECT_EQ(stats.UsedBlockCount, 2u); + EXPECT_EQ(stats.UsedBlockUsage, kBufferSize * 2); } } @@ -1677,7 +1677,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferManyThreaded) { thread.join(); } - EXPECT_EQ(resourceAllocator->GetInfo().UsedMemoryUsage, 0u); + EXPECT_EQ(resourceAllocator->GetStats().UsedMemoryUsage, 0u); } // Creates a bunch of buffers concurrently. @@ -1710,7 +1710,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithinManyThreaded) { thread.join(); } - EXPECT_EQ(resourceAllocator->GetInfo().UsedMemoryUsage, 0u); + EXPECT_EQ(resourceAllocator->GetStats().UsedMemoryUsage, 0u); } TEST_F(D3D12ResourceAllocatorTests, CreateBufferCacheSize) { diff --git a/src/tests/unittests/BuddyMemoryAllocatorTests.cpp b/src/tests/unittests/BuddyMemoryAllocatorTests.cpp index 9aa8a9397..80c2f8dca 100644 --- a/src/tests/unittests/BuddyMemoryAllocatorTests.cpp +++ b/src/tests/unittests/BuddyMemoryAllocatorTests.cpp @@ -69,7 +69,7 @@ TEST_F(BuddyMemoryAllocatorTests, SingleHeap) { ASSERT_EQ(allocation1->GetMethod(), AllocationMethod::kSubAllocated); ASSERT_EQ(allocation1->GetSize(), 128u); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); // Cannot allocate when allocator is full. { @@ -79,7 +79,7 @@ TEST_F(BuddyMemoryAllocatorTests, SingleHeap) { } allocator.DeallocateMemory(std::move(allocation1)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 0u); } // Verify that multiple allocation are created in separate heaps. @@ -119,7 +119,7 @@ TEST_F(BuddyMemoryAllocatorTests, MultipleHeaps) { ASSERT_EQ(allocation1->GetMethod(), AllocationMethod::kSubAllocated); // First allocation creates first heap. - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); std::unique_ptr allocation2 = allocator.TryAllocateMemory( CreateBasicRequest(kDefaultMemorySize, kDefaultMemoryAlignment)); @@ -129,15 +129,15 @@ TEST_F(BuddyMemoryAllocatorTests, MultipleHeaps) { ASSERT_EQ(allocation2->GetMethod(), AllocationMethod::kSubAllocated); // Second allocation creates second heap. - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 2u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 2u); ASSERT_NE(allocation1->GetMemory(), allocation2->GetMemory()); // Deallocate both allocations allocator.DeallocateMemory(std::move(allocation1)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); // Released H0 + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); // Released H0 allocator.DeallocateMemory(std::move(allocation2)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); // Released H1 + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 0u); // Released H1 } // Verify multiple sub-allocations can re-use heaps. @@ -165,7 +165,7 @@ TEST_F(BuddyMemoryAllocatorTests, MultipleSplitHeaps) { ASSERT_EQ(allocation1->GetMethod(), AllocationMethod::kSubAllocated); // First sub-allocation creates first heap. - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); std::unique_ptr allocation2 = allocator.TryAllocateMemory(CreateBasicRequest(kDefaultMemorySize / 2, 1)); @@ -175,7 +175,7 @@ TEST_F(BuddyMemoryAllocatorTests, MultipleSplitHeaps) { ASSERT_EQ(allocation2->GetMethod(), AllocationMethod::kSubAllocated); // Second allocation re-uses first heap. - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); ASSERT_EQ(allocation1->GetMemory(), allocation2->GetMemory()); std::unique_ptr allocation3 = @@ -186,19 +186,19 @@ TEST_F(BuddyMemoryAllocatorTests, MultipleSplitHeaps) { ASSERT_EQ(allocation3->GetMethod(), AllocationMethod::kSubAllocated); // Third allocation creates second heap. - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 2u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 2u); ASSERT_NE(allocation1->GetMemory(), allocation3->GetMemory()); // Deallocate all allocations in reverse order. allocator.DeallocateMemory(std::move(allocation1)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 2u); // A2 pins H0. allocator.DeallocateMemory(std::move(allocation2)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); // Released H0 + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); // Released H0 allocator.DeallocateMemory(std::move(allocation3)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); // Released H1 + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 0u); // Released H1 } // Verify resource sub-allocation of various sizes over multiple heaps. @@ -237,7 +237,7 @@ TEST_F(BuddyMemoryAllocatorTests, MultiplSplitHeapsVariableSizes) { ASSERT_EQ(allocation2->GetMethod(), AllocationMethod::kSubAllocated); // A1 and A2 share H0 - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); ASSERT_EQ(allocation1->GetMemory(), allocation2->GetMemory()); std::unique_ptr allocation3 = @@ -249,7 +249,7 @@ TEST_F(BuddyMemoryAllocatorTests, MultiplSplitHeapsVariableSizes) { ASSERT_EQ(allocation3->GetMethod(), AllocationMethod::kSubAllocated); // A3 creates and fully occupies a new heap. - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 2u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 2u); ASSERT_NE(allocation2->GetMemory(), allocation3->GetMemory()); std::unique_ptr allocation4 = @@ -260,7 +260,7 @@ TEST_F(BuddyMemoryAllocatorTests, MultiplSplitHeapsVariableSizes) { ASSERT_EQ(allocation4->GetOffset(), 0u); ASSERT_EQ(allocation4->GetMethod(), AllocationMethod::kSubAllocated); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 3u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 3u); ASSERT_NE(allocation3->GetMemory(), allocation4->GetMemory()); // R5 size forms 64 byte hole after R4. @@ -272,24 +272,24 @@ TEST_F(BuddyMemoryAllocatorTests, MultiplSplitHeapsVariableSizes) { ASSERT_EQ(allocation5->GetOffset(), 0u); ASSERT_EQ(allocation5->GetMethod(), AllocationMethod::kSubAllocated); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 4u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 4u); ASSERT_NE(allocation4->GetMemory(), allocation5->GetMemory()); // Deallocate allocations in staggered order. allocator.DeallocateMemory(std::move(allocation1)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 4u); // A2 pins H0 + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 4u); // A2 pins H0 allocator.DeallocateMemory(std::move(allocation5)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 3u); // Released H3 + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 3u); // Released H3 allocator.DeallocateMemory(std::move(allocation2)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 2u); // Released H0 + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 2u); // Released H0 allocator.DeallocateMemory(std::move(allocation4)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); // Released H2 + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); // Released H2 allocator.DeallocateMemory(std::move(allocation3)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); // Released H1 + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 0u); // Released H1 } // Verify resource sub-allocation of same sizes with various alignments. @@ -318,7 +318,7 @@ TEST_F(BuddyMemoryAllocatorTests, SameSizeVariousAlignment) { ASSERT_EQ(allocation1->GetOffset(), 0u); ASSERT_EQ(allocation1->GetMethod(), AllocationMethod::kSubAllocated); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); std::unique_ptr allocation2 = allocator.TryAllocateMemory(CreateBasicRequest(64, 128)); @@ -328,7 +328,7 @@ TEST_F(BuddyMemoryAllocatorTests, SameSizeVariousAlignment) { ASSERT_EQ(allocation2->GetOffset(), 0u); ASSERT_EQ(allocation2->GetMethod(), AllocationMethod::kSubAllocated); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 2u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 2u); ASSERT_NE(allocation1->GetMemory(), allocation2->GetMemory()); std::unique_ptr allocation3 = @@ -339,7 +339,7 @@ TEST_F(BuddyMemoryAllocatorTests, SameSizeVariousAlignment) { ASSERT_EQ(allocation3->GetOffset(), 0u); ASSERT_EQ(allocation3->GetMethod(), AllocationMethod::kSubAllocated); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 3u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 3u); ASSERT_NE(allocation2->GetMemory(), allocation3->GetMemory()); std::unique_ptr allocation4 = @@ -350,20 +350,20 @@ TEST_F(BuddyMemoryAllocatorTests, SameSizeVariousAlignment) { ASSERT_EQ(allocation4->GetOffset(), 64u); ASSERT_EQ(allocation4->GetMethod(), AllocationMethod::kSubAllocated); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 3u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 3u); ASSERT_EQ(allocation3->GetMemory(), allocation4->GetMemory()); allocator.DeallocateMemory(std::move(allocation1)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 2u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 2u); allocator.DeallocateMemory(std::move(allocation2)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); allocator.DeallocateMemory(std::move(allocation3)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); allocator.DeallocateMemory(std::move(allocation4)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 0u); } // Verify resource sub-allocation of various sizes with same alignments. @@ -393,7 +393,7 @@ TEST_F(BuddyMemoryAllocatorTests, VariousSizeSameAlignment) { ASSERT_EQ(allocation1->GetBlock()->Offset, 0u); ASSERT_EQ(allocation1->GetMethod(), AllocationMethod::kSubAllocated); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); std::unique_ptr allocation2 = allocator.TryAllocateMemory(CreateBasicRequest(64, alignment)); @@ -403,7 +403,7 @@ TEST_F(BuddyMemoryAllocatorTests, VariousSizeSameAlignment) { ASSERT_EQ(allocation2->GetOffset(), 64u); ASSERT_EQ(allocation2->GetMethod(), AllocationMethod::kSubAllocated); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); // Reuses H0 + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); // Reuses H0 ASSERT_EQ(allocation1->GetMemory(), allocation2->GetMemory()); std::unique_ptr allocation3 = @@ -414,7 +414,7 @@ TEST_F(BuddyMemoryAllocatorTests, VariousSizeSameAlignment) { ASSERT_EQ(allocation3->GetOffset(), 0u); ASSERT_EQ(allocation3->GetMethod(), AllocationMethod::kSubAllocated); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 2u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 2u); ASSERT_NE(allocation2->GetMemory(), allocation3->GetMemory()); std::unique_ptr allocation4 = @@ -425,20 +425,20 @@ TEST_F(BuddyMemoryAllocatorTests, VariousSizeSameAlignment) { ASSERT_EQ(allocation4->GetOffset(), 0u); ASSERT_EQ(allocation4->GetMethod(), AllocationMethod::kSubAllocated); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 3u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 3u); ASSERT_NE(allocation3->GetMemory(), allocation4->GetMemory()); allocator.DeallocateMemory(std::move(allocation1)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 3u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 3u); allocator.DeallocateMemory(std::move(allocation2)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 2u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 2u); allocator.DeallocateMemory(std::move(allocation3)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 1u); allocator.DeallocateMemory(std::move(allocation4)); - ASSERT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); + ASSERT_EQ(allocator.GetStats().UsedMemoryCount, 0u); } // Verify allocating a very large resource does not overflow. @@ -479,7 +479,7 @@ TEST_F(BuddyMemoryAllocatorTests, ReuseFreedHeaps) { allocations.push_back(std::move(allocation)); } - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); // Return the allocations to the pool. for (auto& allocation : allocations) { @@ -487,7 +487,7 @@ TEST_F(BuddyMemoryAllocatorTests, ReuseFreedHeaps) { allocator.DeallocateMemory(std::move(allocation)); } - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, kDefaultMemorySize * heaps.size()); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, kDefaultMemorySize * heaps.size()); allocations.clear(); @@ -502,14 +502,14 @@ TEST_F(BuddyMemoryAllocatorTests, ReuseFreedHeaps) { allocations.push_back(std::move(allocation)); } - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); for (auto& allocation : allocations) { ASSERT_NE(allocation, nullptr); allocator.DeallocateMemory(std::move(allocation)); } - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 0u); allocator.ReleaseMemory(kReleaseAllMemory); } @@ -541,7 +541,7 @@ TEST_F(BuddyMemoryAllocatorTests, DestroyHeaps) { allocations.push_back(std::move(allocation)); } - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); // Return the allocations to the pool. for (auto& allocation : allocations) { @@ -549,7 +549,7 @@ TEST_F(BuddyMemoryAllocatorTests, DestroyHeaps) { allocator.DeallocateMemory(std::move(allocation)); } - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, kNumOfHeaps * kDefaultMemorySize); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, kNumOfHeaps * kDefaultMemorySize); allocator.ReleaseMemory(kReleaseAllMemory); } diff --git a/src/tests/unittests/ConditionalMemoryAllocatorTests.cpp b/src/tests/unittests/ConditionalMemoryAllocatorTests.cpp index a8fdb47a8..7d915b802 100644 --- a/src/tests/unittests/ConditionalMemoryAllocatorTests.cpp +++ b/src/tests/unittests/ConditionalMemoryAllocatorTests.cpp @@ -41,7 +41,7 @@ TEST_F(ConditionalMemoryAllocatorTests, Basic) { { std::unique_ptr allocation = alloc.TryAllocateMemory(CreateBasicRequest(4, 1)); - ASSERT_EQ(alloc.GetFirstAllocatorForTesting()->GetInfo().UsedMemoryUsage, 4u); + ASSERT_EQ(alloc.GetFirstAllocatorForTesting()->GetStats().UsedMemoryUsage, 4u); ASSERT_NE(allocation, nullptr); alloc.DeallocateMemory(std::move(allocation)); } @@ -50,7 +50,7 @@ TEST_F(ConditionalMemoryAllocatorTests, Basic) { { std::unique_ptr allocation = alloc.TryAllocateMemory(CreateBasicRequest(16, 1)); - ASSERT_EQ(alloc.GetFirstAllocatorForTesting()->GetInfo().UsedMemoryUsage, 16u); + ASSERT_EQ(alloc.GetFirstAllocatorForTesting()->GetStats().UsedMemoryUsage, 16u); ASSERT_NE(allocation, nullptr); alloc.DeallocateMemory(std::move(allocation)); } @@ -59,7 +59,7 @@ TEST_F(ConditionalMemoryAllocatorTests, Basic) { { std::unique_ptr allocation = alloc.TryAllocateMemory(CreateBasicRequest(24, 1)); - ASSERT_EQ(alloc.GetSecondAllocatorForTesting()->GetInfo().UsedMemoryUsage, 24u); + ASSERT_EQ(alloc.GetSecondAllocatorForTesting()->GetStats().UsedMemoryUsage, 24u); ASSERT_NE(allocation, nullptr); alloc.DeallocateMemory(std::move(allocation)); } @@ -68,7 +68,7 @@ TEST_F(ConditionalMemoryAllocatorTests, Basic) { { std::unique_ptr allocation = alloc.TryAllocateMemory(CreateBasicRequest(4, 1)); - ASSERT_EQ(alloc.GetFirstAllocatorForTesting()->GetInfo().UsedMemoryUsage, 4u); + ASSERT_EQ(alloc.GetFirstAllocatorForTesting()->GetStats().UsedMemoryUsage, 4u); ASSERT_NE(allocation, nullptr); alloc.DeallocateMemory(std::move(allocation)); } @@ -77,7 +77,7 @@ TEST_F(ConditionalMemoryAllocatorTests, Basic) { { std::unique_ptr allocation = alloc.TryAllocateMemory(CreateBasicRequest(24, 1)); - ASSERT_EQ(alloc.GetSecondAllocatorForTesting()->GetInfo().UsedMemoryUsage, 24u); + ASSERT_EQ(alloc.GetSecondAllocatorForTesting()->GetStats().UsedMemoryUsage, 24u); ASSERT_NE(allocation, nullptr); alloc.DeallocateMemory(std::move(allocation)); } diff --git a/src/tests/unittests/MemoryPoolTests.cpp b/src/tests/unittests/MemoryPoolTests.cpp index 039040be3..0e109846a 100644 --- a/src/tests/unittests/MemoryPoolTests.cpp +++ b/src/tests/unittests/MemoryPoolTests.cpp @@ -36,32 +36,32 @@ class LIFOMemoryPoolTests : public MemoryPoolTests {}; TEST_F(LIFOMemoryPoolTests, SingleAllocation) { DummyMemoryAllocator allocator; LIFOMemoryPool pool(kDefaultMemorySize); - EXPECT_EQ(pool.GetInfo().SizeInBytes, 0u); + EXPECT_EQ(pool.GetStats().SizeInBytes, 0u); EXPECT_EQ(pool.ReleasePool(), 0u); - EXPECT_EQ(pool.GetInfo().SizeInBytes, 0u); + EXPECT_EQ(pool.GetStats().SizeInBytes, 0u); pool.ReturnToPool(*allocator.TryAllocateMemory(CreateBasicRequest(kDefaultMemorySize))); - EXPECT_EQ(pool.GetInfo().SizeInBytes, kDefaultMemorySize); + EXPECT_EQ(pool.GetStats().SizeInBytes, kDefaultMemorySize); EXPECT_EQ(pool.GetPoolSize(), 1u); pool.ReturnToPool(pool.AcquireFromPool()); - EXPECT_EQ(pool.GetInfo().SizeInBytes, kDefaultMemorySize); + EXPECT_EQ(pool.GetStats().SizeInBytes, kDefaultMemorySize); EXPECT_EQ(pool.GetPoolSize(), 1u); EXPECT_EQ(pool.ReleasePool(kDefaultMemorySize), kDefaultMemorySize); - EXPECT_EQ(pool.GetInfo().SizeInBytes, 0u); + EXPECT_EQ(pool.GetStats().SizeInBytes, 0u); EXPECT_EQ(pool.GetPoolSize(), 0u); EXPECT_EQ(pool.ReleasePool(), 0u); - EXPECT_EQ(pool.GetInfo().SizeInBytes, 0u); + EXPECT_EQ(pool.GetStats().SizeInBytes, 0u); EXPECT_EQ(pool.GetPoolSize(), 0u); } TEST_F(LIFOMemoryPoolTests, MultipleAllocations) { DummyMemoryAllocator allocator; LIFOMemoryPool pool(kDefaultMemorySize); - EXPECT_EQ(pool.GetInfo().SizeInBytes, 0u); + EXPECT_EQ(pool.GetStats().SizeInBytes, 0u); EXPECT_EQ(pool.GetPoolSize(), 0u); constexpr uint64_t kPoolSize = 64; @@ -69,7 +69,7 @@ TEST_F(LIFOMemoryPoolTests, MultipleAllocations) { pool.ReturnToPool(*allocator.TryAllocateMemory(CreateBasicRequest(kDefaultMemorySize))); } - EXPECT_EQ(pool.GetInfo().SizeInBytes, kDefaultMemorySize * kPoolSize); + EXPECT_EQ(pool.GetStats().SizeInBytes, kDefaultMemorySize * kPoolSize); EXPECT_EQ(pool.GetPoolSize(), kPoolSize); // Release half of the pool. @@ -79,6 +79,6 @@ TEST_F(LIFOMemoryPoolTests, MultipleAllocations) { // Release the other half. EXPECT_EQ(pool.ReleasePool(), kDefaultMemorySize * kPoolSize / 2); - EXPECT_EQ(pool.GetInfo().SizeInBytes, 0u); + EXPECT_EQ(pool.GetStats().SizeInBytes, 0u); EXPECT_EQ(pool.GetPoolSize(), 0u); } diff --git a/src/tests/unittests/PooledMemoryAllocatorTests.cpp b/src/tests/unittests/PooledMemoryAllocatorTests.cpp index 829e087ee..66b689743 100644 --- a/src/tests/unittests/PooledMemoryAllocatorTests.cpp +++ b/src/tests/unittests/PooledMemoryAllocatorTests.cpp @@ -47,13 +47,13 @@ TEST_F(PooledMemoryAllocatorTests, SingleHeap) { ASSERT_NE(allocation, nullptr); EXPECT_EQ(allocation->GetSize(), kDefaultMemorySize); EXPECT_EQ(allocation->GetMethod(), AllocationMethod::kStandalone); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 1u); allocator.DeallocateMemory(std::move(allocation)); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 0u); EXPECT_EQ(allocator.ReleaseMemory(), kDefaultMemorySize); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); } TEST_F(PooledMemoryAllocatorTests, MultipleHeaps) { @@ -70,7 +70,7 @@ TEST_F(PooledMemoryAllocatorTests, MultipleHeaps) { ASSERT_NE(secondAllocation, nullptr); EXPECT_EQ(secondAllocation->GetSize(), kDefaultMemorySize); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 2u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 2u); allocator.DeallocateMemory(std::move(firstAllocation)); allocator.DeallocateMemory(std::move(secondAllocation)); @@ -79,8 +79,8 @@ TEST_F(PooledMemoryAllocatorTests, MultipleHeaps) { EXPECT_EQ(allocator.ReleaseMemory(kDefaultMemorySize), kDefaultMemorySize); EXPECT_EQ(allocator.ReleaseMemory(kDefaultMemorySize), 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 0u); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); } TEST_F(PooledMemoryAllocatorTests, ReuseFreedHeaps) { @@ -95,7 +95,7 @@ TEST_F(PooledMemoryAllocatorTests, ReuseFreedHeaps) { allocator.DeallocateMemory(std::move(allocation)); } - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, kDefaultMemorySize); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, kDefaultMemorySize); { std::unique_ptr allocation = allocator.TryAllocateMemory( @@ -106,7 +106,7 @@ TEST_F(PooledMemoryAllocatorTests, ReuseFreedHeaps) { allocator.DeallocateMemory(std::move(allocation)); } - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, kDefaultMemorySize); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, kDefaultMemorySize); } TEST_F(PooledMemoryAllocatorTests, GetInfo) { @@ -118,18 +118,18 @@ TEST_F(PooledMemoryAllocatorTests, GetInfo) { EXPECT_NE(allocation, nullptr); // Single memory block should be allocated. - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, kDefaultMemorySize); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 1u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, kDefaultMemorySize); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); allocator.DeallocateMemory(std::move(allocation)); // Single memory is made available as free after being released. - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, 0u); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, kDefaultMemorySize); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, kDefaultMemorySize); } diff --git a/src/tests/unittests/SegmentedMemoryAllocatorTests.cpp b/src/tests/unittests/SegmentedMemoryAllocatorTests.cpp index 3d9df3769..1e27f354d 100644 --- a/src/tests/unittests/SegmentedMemoryAllocatorTests.cpp +++ b/src/tests/unittests/SegmentedMemoryAllocatorTests.cpp @@ -195,18 +195,18 @@ TEST(SegmentedMemoryAllocatorTests, GetInfo) { EXPECT_NE(allocation, nullptr); // Single memory block should be allocated. - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, kDefaultMemorySize); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 1u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, kDefaultMemorySize); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); allocator.DeallocateMemory(std::move(allocation)); // Single memory is made available as free after being released. - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, 0u); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, kDefaultMemorySize); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, kDefaultMemorySize); } diff --git a/src/tests/unittests/SlabMemoryAllocatorTests.cpp b/src/tests/unittests/SlabMemoryAllocatorTests.cpp index afb620dff..1eb8e784e 100644 --- a/src/tests/unittests/SlabMemoryAllocatorTests.cpp +++ b/src/tests/unittests/SlabMemoryAllocatorTests.cpp @@ -199,13 +199,13 @@ TEST_F(SlabMemoryAllocatorTests, MultipleSlabs) { allocations.push_back(std::move(allocation)); } - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, kNumOfSlabs); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, kNumOfSlabs); for (auto& allocation : allocations) { allocator.DeallocateMemory(std::move(allocation)); } - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 0u); } // Fill up slabs through pre-allocation (allocation < block < slab size). @@ -226,14 +226,14 @@ TEST_F(SlabMemoryAllocatorTests, MultipleSlabs) { allocations.push_back(std::move(allocation)); } - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 2u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 2u); // Free both slabs. for (auto& allocation : allocations) { allocator.DeallocateMemory(std::move(allocation)); } - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 0u); } // Verify slabs are reused in LIFO. @@ -317,7 +317,7 @@ TEST_F(SlabMemoryAllocatorTests, MultipleSlabs) { allocator.DeallocateMemory(std::move(allocationEInSlabC)); allocator.DeallocateMemory(std::move(allocationFInSlabC)); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, 0u); } } @@ -367,7 +367,7 @@ TEST_F(SlabMemoryAllocatorTests, ReuseSlabs) { allocations.push_back(std::move(allocation)); } - EXPECT_EQ(poolAllocator->GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(poolAllocator->GetStats().FreeMemoryUsage, 0u); // Return the allocations to the pool. for (auto& allocation : allocations) { @@ -375,7 +375,7 @@ TEST_F(SlabMemoryAllocatorTests, ReuseSlabs) { allocator.DeallocateMemory(std::move(allocation)); } - EXPECT_EQ(poolAllocator->GetInfo().FreeMemoryUsage, kDefaultSlabSize * kNumOfSlabs); + EXPECT_EQ(poolAllocator->GetStats().FreeMemoryUsage, kDefaultSlabSize * kNumOfSlabs); poolAllocator->ReleaseMemory(); } @@ -398,20 +398,20 @@ TEST_F(SlabMemoryAllocatorTests, GetInfo) { EXPECT_NE(allocation, nullptr); // Single sub-allocation within a slab should be allocated. - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 1u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, kBlockSize); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, kDefaultSlabSize); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 1u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, kBlockSize); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 1u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, kDefaultSlabSize); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); allocator.DeallocateMemory(std::move(allocation)); // Both the sub-allocation and slab should be released. - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, 0u); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); } // Test slab + pool allocator. @@ -431,19 +431,19 @@ TEST_F(SlabMemoryAllocatorTests, GetInfo) { allocator.TryAllocateMemory(CreateBasicRequest(kBlockSize, 1)); EXPECT_NE(allocation, nullptr); - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 1u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, kBlockSize); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, kDefaultSlabSize); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 1u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, kBlockSize); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 1u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, kDefaultSlabSize); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); allocator.DeallocateMemory(std::move(allocation)); - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, 0u); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, kDefaultSlabSize); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, kDefaultSlabSize); } } @@ -501,7 +501,7 @@ TEST_F(SlabMemoryAllocatorTests, SlabGrowth) { allocator.DeallocateMemory(std::move(allocationAInSlabB)); allocator.DeallocateMemory(std::move(allocationAInSlabA)); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, 0u); } // Start from a kMinSlabSize > kBlockSize. @@ -555,7 +555,7 @@ TEST_F(SlabMemoryAllocatorTests, SlabGrowth) { allocator.DeallocateMemory(std::move(allocationBInSlabA)); allocator.DeallocateMemory(std::move(allocationAInSlabA)); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, 0u); } } @@ -678,7 +678,7 @@ TEST_F(SlabMemoryAllocatorTests, SlabGrowthLimit) { allocator.DeallocateMemory(std::move(allocationAInSlabB)); allocator.DeallocateMemory(std::move(allocationAInSlabA)); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, 0u); } } @@ -806,7 +806,7 @@ TEST_F(SlabCacheAllocatorTests, MultipleSlabsVariableSizes) { allocator.DeallocateMemory(std::move(allocation)); } - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 0u); } TEST_F(SlabCacheAllocatorTests, SingleSlabInBuddy) { @@ -925,20 +925,20 @@ TEST_F(SlabCacheAllocatorTests, GetInfo) { EXPECT_NE(allocation, nullptr); // Single sub-allocation within a slab should be allocated. - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 1u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, kBlockSize); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, kDefaultSlabSize); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 1u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, kBlockSize); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 1u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, kDefaultSlabSize); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); allocator.DeallocateMemory(std::move(allocation)); // Both the sub-allocation and slab should be released. - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, 0u); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); } // Test Slab + pooled allocator. @@ -956,20 +956,20 @@ TEST_F(SlabCacheAllocatorTests, GetInfo) { EXPECT_NE(allocation, nullptr); // Single sub-allocation within a slab should be used. - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 1u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, kBlockSize); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, kDefaultSlabSize); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 1u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, kBlockSize); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 1u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, kDefaultSlabSize); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); allocator.DeallocateMemory(std::move(allocation)); // Only the sub-allocation should be released. - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, 0u); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, kDefaultSlabSize); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, kDefaultSlabSize); } // Test Slab-Buddy allocator. @@ -990,20 +990,20 @@ TEST_F(SlabCacheAllocatorTests, GetInfo) { EXPECT_NE(allocation, nullptr); // Single slab block within buddy memory should be used. - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 1u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, kBlockSize); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 1u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, kDefaultSlabSize); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 1u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, kBlockSize); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 1u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, kDefaultSlabSize); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); allocator.DeallocateMemory(std::move(allocation)); // Both the slab block and buddy memory should be released. - EXPECT_EQ(allocator.GetInfo().UsedBlockCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedBlockUsage, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u); - EXPECT_EQ(allocator.GetInfo().UsedMemoryUsage, 0u); - EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedBlockUsage, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryCount, 0u); + EXPECT_EQ(allocator.GetStats().UsedMemoryUsage, 0u); + EXPECT_EQ(allocator.GetStats().FreeMemoryUsage, 0u); } } @@ -1023,7 +1023,7 @@ TEST_F(SlabCacheAllocatorTests, SlabPrefetch) { } // All but the first slab should be successfully prefetched. - EXPECT_EQ(allocator.GetInfo().PrefetchedMemoryMissesEliminated, kNumOfSlabs - 1); + EXPECT_EQ(allocator.GetStats().PrefetchedMemoryMissesEliminated, kNumOfSlabs - 1); for (auto& allocation : allocations) { allocator.DeallocateMemory(std::move(allocation)); @@ -1047,8 +1047,8 @@ TEST_F(SlabCacheAllocatorTests, SlabPrefetchDisabled) { allocations.push_back(allocator.TryAllocateMemory(alwaysPrefetchRequest)); } - EXPECT_EQ(allocator.GetInfo().PrefetchedMemoryMissesEliminated, 0u); - EXPECT_EQ(allocator.GetInfo().PrefetchedMemoryMisses, 0u); + EXPECT_EQ(allocator.GetStats().PrefetchedMemoryMissesEliminated, 0u); + EXPECT_EQ(allocator.GetStats().PrefetchedMemoryMisses, 0u); for (auto& allocation : allocations) { allocator.DeallocateMemory(std::move(allocation)); @@ -1091,7 +1091,7 @@ TEST_F(SlabCacheAllocatorTests, OutOfMemory) { break; } request.AvailableForAllocation = - (kTotalMemoryAvailable - allocator.GetInfo().UsedMemoryUsage); + (kTotalMemoryAvailable - allocator.GetStats().UsedMemoryUsage); allocations.push_back(std::move(allocation)); }