Improve allocation logging

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2021-08-23 15:44:47 +00:00
committed by Compute-Runtime-Automation
parent 2a577c6466
commit ed5771f132
2 changed files with 32 additions and 2 deletions

View File

@ -95,7 +95,7 @@ void FileLogger<DebugLevel>::logAllocation(GraphicsAllocation const *graphicsAll
return;
}
if (logAllocationMemoryPool) {
if (logAllocationMemoryPool || logAllocationType) {
std::thread::id thisThread = std::this_thread::get_id();
std::stringstream ss;
@ -103,7 +103,8 @@ void FileLogger<DebugLevel>::logAllocation(GraphicsAllocation const *graphicsAll
ss << " AllocationType: " << getAllocationTypeString(graphicsAllocation);
ss << " MemoryPool: " << graphicsAllocation->getMemoryPool();
ss << " Root device index: " << graphicsAllocation->getRootDeviceIndex();
ss << " GPU address: 0x" << std::hex << graphicsAllocation->getGpuAddress();
ss << " GPU address: 0x" << std::hex << graphicsAllocation->getGpuAddress() << " - 0x" << std::hex << graphicsAllocation->getGpuAddress() + graphicsAllocation->getUnderlyingBufferSize() - 1;
ss << graphicsAllocation->getAllocationInfoString();
ss << std::endl;

View File

@ -960,3 +960,32 @@ TEST(AllocationTypeLoggingSingle, givenDebugVariableToCaptureAllocationTypeWhenF
EXPECT_STREQ(output.c_str(), expectedOutput.c_str());
}
TEST(AllocationTypeLoggingSingle, givenLogAllocationTypeWhenLoggingAllocationThenTypeIsLoggedToFile) {
std::string testFile = "testfile";
DebugVariables flags;
flags.LogAllocationType.set(1);
FullyEnabledFileLogger fileLogger(testFile, flags);
GraphicsAllocation graphicsAllocation(0, GraphicsAllocation::AllocationType::COMMAND_BUFFER, nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull);
// Log file not created
bool logFileCreated = fileExists(fileLogger.getLogFileName());
EXPECT_FALSE(logFileCreated);
testing::internal::CaptureStdout();
fileLogger.logAllocation(&graphicsAllocation);
std::string output = testing::internal::GetCapturedStdout();
std::string expectedOutput = "Created Graphics Allocation of type COMMAND_BUFFER\n";
EXPECT_STREQ(output.c_str(), expectedOutput.c_str());
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
EXPECT_TRUE(str.find("AllocationType: ") != std::string::npos);
} else {
EXPECT_FALSE(true);
}
}