diff --git a/src/gpgmm/common/Utils.h b/src/gpgmm/common/Utils.h index f51d6d420..565458dc4 100644 --- a/src/gpgmm/common/Utils.h +++ b/src/gpgmm/common/Utils.h @@ -50,6 +50,11 @@ namespace gpgmm { return output.str(); } + template + std::string ToString(T object, Args... args) { + return ToString(object) + ToString(args...); + } + } // namespace gpgmm #endif // GPGMM_COMMON_UTILS_H_ diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index 3b49ce318..22277a7c8 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -31,6 +31,22 @@ namespace gpgmm { namespace d3d12 { static constexpr uint32_t kDefaultEvictLimit = 50ll * 1024ll * 1024ll; // 50MB static constexpr float kDefaultVideoMemoryBudget = 0.95f; // 95% + namespace { + const char* GetMemorySegmentGroupName(const DXGI_MEMORY_SEGMENT_GROUP& memorySegmentGroup) { + switch (memorySegmentGroup) { + case DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL: + return "NonLocal"; + case DXGI_MEMORY_SEGMENT_GROUP_LOCAL: + return "Local"; + default: + UNREACHABLE(); + return ""; + } + } + } // namespace + + GPGMM_UNUSED_FUNC(GetMemorySegmentGroupName); + // static HRESULT ResidencyManager::CreateResidencyManager(ComPtr device, ComPtr adapter, @@ -273,11 +289,17 @@ namespace gpgmm { namespace d3d12 { mVideoMemoryBudget); } - TRACE_COUNTER1(TraceEventCategory::Default, "GPU memory budget (MB)", - videoMemoryInfo->Budget / 1e6); - - TRACE_COUNTER1(TraceEventCategory::Default, "GPU memory usage (MB)", - videoMemoryInfo->CurrentUsage / 1e6); + TRACE_COUNTER1( + TraceEventCategory::Default, + ToString("GPU memory (", GetMemorySegmentGroupName(memorySegmentGroup), ") budget (MB)") + .c_str(), + videoMemoryInfo->Budget / 1e6); + + TRACE_COUNTER1( + TraceEventCategory::Default, + ToString("GPU memory (", GetMemorySegmentGroupName(memorySegmentGroup), ") usage (MB)") + .c_str(), + videoMemoryInfo->CurrentUsage / 1e6); return S_OK; } diff --git a/src/tests/BUILD.gn b/src/tests/BUILD.gn index d59ba5b4c..e89c853c5 100644 --- a/src/tests/BUILD.gn +++ b/src/tests/BUILD.gn @@ -117,6 +117,7 @@ test("gpgmm_unittests") { "unittests/SegmentedMemoryAllocatorTests.cpp", "unittests/SlabBlockAllocatorTests.cpp", "unittests/SlabMemoryAllocatorTests.cpp", + "unittests/UtilsTest.cpp", ] # When building inside Chromium, use their gtest main function because it is diff --git a/src/tests/unittests/UtilsTest.cpp b/src/tests/unittests/UtilsTest.cpp new file mode 100644 index 000000000..84c71ea79 --- /dev/null +++ b/src/tests/unittests/UtilsTest.cpp @@ -0,0 +1,23 @@ +// Copyright 2021 The GPGMM Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include "gpgmm/common/Utils.h" + +using namespace gpgmm; + +TEST(UtilsTest, ConcatString) { + EXPECT_TRUE(ToString("This ", "is ", "a ", "sentance") == std::string("This is a sentance")); +}