Skip to content

Commit 59cae1b

Browse files
fix: improve LogAllocationStdout to print CPU VA
Related-To: NEO-16500 Signed-off-by: Narendra Bagria <narendra.bagria@intel.com>
1 parent 8b33955 commit 59cae1b

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

shared/source/utilities/logger_neo_only.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Intel Corporation
2+
* Copyright (C) 2024-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -36,6 +36,11 @@ void logAllocation(FileLogger<level> &logger, GraphicsAllocation const *graphics
3636
ss << " Pool: " << getMemoryPoolString(graphicsAllocation);
3737
ss << " Root index: " << graphicsAllocation->getRootDeviceIndex();
3838
ss << " Size: " << graphicsAllocation->getUnderlyingBufferSize();
39+
if (graphicsAllocation->getUnderlyingBuffer() != nullptr) {
40+
ss << " CPU VA: 0x" << std::hex << reinterpret_cast<uintptr_t>(graphicsAllocation->getUnderlyingBuffer()) << " - 0x" << std::hex << reinterpret_cast<uintptr_t>(graphicsAllocation->getUnderlyingBuffer()) + graphicsAllocation->getUnderlyingBufferSize() - 1;
41+
} else {
42+
ss << " CPU VA: NULL";
43+
}
3944
ss << " GPU VA: 0x" << std::hex << graphicsAllocation->getGpuAddress() << " - 0x" << std::hex << graphicsAllocation->getGpuAddress() + graphicsAllocation->getUnderlyingBufferSize() - 1;
4045

4146
ss << graphicsAllocation->getAllocationInfoString();

shared/test/unit_test/utilities/logger_tests.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,3 +596,44 @@ TEST(MemoryPoolLogging, givenGraphicsMemoryPoolWhenConvertingToStringThenCorrect
596596
EXPECT_STREQ(result, str);
597597
}
598598
}
599+
600+
TEST(CpuGpuVaLogging, givenAllocationWithCpuVaWhenLoggingAllocationThenCpuVaRangeIsLoggedToFile) {
601+
std::string testFile = "testfile";
602+
DebugVariables flags;
603+
flags.LogAllocationType.set(1);
604+
605+
FullyEnabledFileLogger fileLogger(testFile, flags);
606+
607+
char buffer[4096];
608+
GraphicsAllocation graphicsAllocation(0, 1u /*num gmms*/, AllocationType::buffer, buffer, reinterpret_cast<uint64_t>(buffer), 0, MemoryPool::system4KBPages, MemoryManager::maxOsContextCount, sizeof(buffer));
609+
610+
logAllocation(fileLogger, &graphicsAllocation, nullptr);
611+
612+
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
613+
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
614+
EXPECT_TRUE(str.find("CPU VA: 0x") != std::string::npos);
615+
EXPECT_FALSE(str.find("CPU VA: NULL") != std::string::npos);
616+
EXPECT_TRUE(str.find(" - 0x") != std::string::npos);
617+
} else {
618+
EXPECT_FALSE(true);
619+
}
620+
}
621+
622+
TEST(CpuGpuVaLogging, givenAllocationWithoutCpuVaWhenLoggingAllocationThenNullIsLoggedToFile) {
623+
std::string testFile = "testfile";
624+
DebugVariables flags;
625+
flags.LogAllocationType.set(1);
626+
627+
FullyEnabledFileLogger fileLogger(testFile, flags);
628+
629+
GraphicsAllocation graphicsAllocation(0, 1u /*num gmms*/, AllocationType::buffer, nullptr, 0x1000, 0, MemoryPool::localMemory, MemoryManager::maxOsContextCount, 4096);
630+
631+
logAllocation(fileLogger, &graphicsAllocation, nullptr);
632+
633+
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
634+
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
635+
EXPECT_TRUE(str.find("CPU VA: NULL") != std::string::npos);
636+
} else {
637+
EXPECT_FALSE(true);
638+
}
639+
}

0 commit comments

Comments
 (0)