refactor: improve logging of allocations

add capability to measure total amount of allocated memory
Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
This commit is contained in:
Michal Mrozek
2024-09-11 20:46:36 +00:00
committed by Compute-Runtime-Automation
parent d18d58d4f7
commit da59b88122
8 changed files with 64 additions and 35 deletions

View File

@@ -27,6 +27,7 @@ TEST(FileLogger, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) {
EXPECT_FALSE(logFileCreated);
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->initializeMemoryManager();
MockDrmAllocation allocation(0u, AllocationType::buffer, MemoryPool::system64KBPages);
auto gmmHelper = executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper();
@@ -46,7 +47,7 @@ TEST(FileLogger, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) {
allocation.bufferObjects[0] = &bo;
fileLogger.logAllocation(&allocation);
fileLogger.logAllocation(&allocation, executionEnvironment->memoryManager.get());
std::thread::id thisThread = std::this_thread::get_id();
@@ -54,13 +55,19 @@ TEST(FileLogger, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) {
threadIDCheck << " ThreadID: " << thisThread;
std::stringstream memoryPoolCheck;
memoryPoolCheck << " MemoryPool: " << getMemoryPoolString(&allocation);
memoryPoolCheck << " Pool: " << getMemoryPoolString(&allocation);
std::stringstream gpuAddressCheck;
gpuAddressCheck << " GPU address: 0x" << std::hex << allocation.getGpuAddress();
gpuAddressCheck << " GPU VA: 0x" << std::hex << allocation.getGpuAddress();
std::stringstream rootDeviceIndexCheck;
rootDeviceIndexCheck << " Root device index: " << allocation.getRootDeviceIndex();
rootDeviceIndexCheck << " Root index: " << allocation.getRootDeviceIndex();
std::stringstream totalSystemMemoryCheck;
totalSystemMemoryCheck << "Total sys mem allocated: " << executionEnvironment->memoryManager->getUsedSystemMemorySize();
std::stringstream totalLocalMemoryCheck;
totalLocalMemoryCheck << "Total lmem allocated: " << executionEnvironment->memoryManager->getUsedLocalMemorySize(0);
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
@@ -68,8 +75,10 @@ TEST(FileLogger, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) {
EXPECT_TRUE(str.find(memoryPoolCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find(gpuAddressCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find(rootDeviceIndexCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find("AllocationType: BUFFER") != std::string::npos);
EXPECT_TRUE(str.find("Type: BUFFER") != std::string::npos);
EXPECT_TRUE(str.find("Handle: 4") != std::string::npos);
EXPECT_TRUE(str.find(totalSystemMemoryCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find(totalLocalMemoryCheck.str()) != std::string::npos);
}
}
@@ -105,7 +114,7 @@ TEST(FileLogger, givenLogAllocationStdoutWhenLogAllocationThenLogToStdoutInstead
allocation.bufferObjects[0] = &bo;
testing::internal::CaptureStdout();
fileLogger.logAllocation(&allocation);
fileLogger.logAllocation(&allocation, nullptr);
std::string output = testing::internal::GetCapturedStdout();
std::thread::id thisThread = std::this_thread::get_id();
@@ -114,19 +123,19 @@ TEST(FileLogger, givenLogAllocationStdoutWhenLogAllocationThenLogToStdoutInstead
threadIDCheck << " ThreadID: " << thisThread;
std::stringstream memoryPoolCheck;
memoryPoolCheck << " MemoryPool: " << getMemoryPoolString(&allocation);
memoryPoolCheck << " Pool: " << getMemoryPoolString(&allocation);
std::stringstream gpuAddressCheck;
gpuAddressCheck << " GPU address: 0x" << std::hex << allocation.getGpuAddress();
gpuAddressCheck << " GPU VA: 0x" << std::hex << allocation.getGpuAddress();
std::stringstream rootDeviceIndexCheck;
rootDeviceIndexCheck << " Root device index: " << allocation.getRootDeviceIndex();
rootDeviceIndexCheck << " Root index: " << allocation.getRootDeviceIndex();
EXPECT_TRUE(output.find(threadIDCheck.str()) != std::string::npos);
EXPECT_TRUE(output.find(memoryPoolCheck.str()) != std::string::npos);
EXPECT_TRUE(output.find(gpuAddressCheck.str()) != std::string::npos);
EXPECT_TRUE(output.find(rootDeviceIndexCheck.str()) != std::string::npos);
EXPECT_TRUE(output.find("AllocationType: BUFFER") != std::string::npos);
EXPECT_TRUE(output.find("Type: BUFFER") != std::string::npos);
EXPECT_TRUE(output.find("Handle: 4") != std::string::npos);
EXPECT_TRUE(output.find("\n") != std::string::npos);
@@ -152,20 +161,20 @@ TEST(FileLogger, GivenDrmAllocationWithoutBOThenNoHandleLogged) {
allocation.getDefaultGmm()->resourceParams.Usage = GMM_RESOURCE_USAGE_TYPE_ENUM::GMM_RESOURCE_USAGE_OCL_BUFFER;
allocation.getDefaultGmm()->resourceParams.Flags.Info.Cacheable = true;
fileLogger.logAllocation(&allocation);
fileLogger.logAllocation(&allocation, nullptr);
std::thread::id thisThread = std::this_thread::get_id();
std::stringstream threadIDCheck;
threadIDCheck << " ThreadID: " << thisThread;
std::stringstream memoryPoolCheck;
memoryPoolCheck << " MemoryPool: " << getMemoryPoolString(&allocation);
memoryPoolCheck << " Pool: " << getMemoryPoolString(&allocation);
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
EXPECT_TRUE(str.find(threadIDCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find(memoryPoolCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find("AllocationType: BUFFER") != std::string::npos);
EXPECT_TRUE(str.find("Type: BUFFER") != std::string::npos);
EXPECT_FALSE(str.find("Handle: 4") != std::string::npos);
}
}
@@ -181,7 +190,7 @@ TEST(FileLogger, GivenLogAllocationMemoryPoolFlagSetFalseThenAllocationIsNotLogg
EXPECT_FALSE(logFileCreated);
MockDrmAllocation allocation(0u, AllocationType::buffer, MemoryPool::system64KBPages);
fileLogger.logAllocation(&allocation);
fileLogger.logAllocation(&allocation, nullptr);
std::thread::id thisThread = std::this_thread::get_id();
@@ -189,12 +198,12 @@ TEST(FileLogger, GivenLogAllocationMemoryPoolFlagSetFalseThenAllocationIsNotLogg
threadIDCheck << " ThreadID: " << thisThread;
std::stringstream memoryPoolCheck;
memoryPoolCheck << " MemoryPool: " << getMemoryPoolString(&allocation);
memoryPoolCheck << " Pool: " << getMemoryPoolString(&allocation);
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
EXPECT_FALSE(str.find(threadIDCheck.str()) != std::string::npos);
EXPECT_FALSE(str.find(memoryPoolCheck.str()) != std::string::npos);
EXPECT_FALSE(str.find("AllocationType: BUFFER") != std::string::npos);
EXPECT_FALSE(str.find("Type: BUFFER") != std::string::npos);
}
}

View File

@@ -26,6 +26,9 @@ TEST_F(FileLoggerTests, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) {
// Log file not created
bool logFileCreated = fileExists(fileLogger.getLogFileName());
EXPECT_FALSE(logFileCreated);
auto executionEnvironment = std::unique_ptr<ExecutionEnvironment>(MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u));
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
executionEnvironment->initializeMemoryManager();
MockWddmAllocation allocation(getGmmHelper());
allocation.handle = 4;
@@ -35,7 +38,7 @@ TEST_F(FileLoggerTests, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) {
allocation.setGpuAddress(0x12345);
allocation.size = 777u;
fileLogger.logAllocation(&allocation);
fileLogger.logAllocation(&allocation, executionEnvironment->memoryManager.get());
std::thread::id thisThread = std::this_thread::get_id();
@@ -43,13 +46,19 @@ TEST_F(FileLoggerTests, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) {
threadIDCheck << " ThreadID: " << thisThread;
std::stringstream memoryPoolCheck;
memoryPoolCheck << " MemoryPool: " << getMemoryPoolString(&allocation);
memoryPoolCheck << " Pool: " << getMemoryPoolString(&allocation);
std::stringstream gpuAddressCheck;
gpuAddressCheck << " GPU address: 0x" << std::hex << allocation.getGpuAddress();
gpuAddressCheck << " GPU VA: 0x" << std::hex << allocation.getGpuAddress();
std::stringstream rootDeviceIndexCheck;
rootDeviceIndexCheck << " Root device index: " << allocation.getRootDeviceIndex();
rootDeviceIndexCheck << " Root index: " << allocation.getRootDeviceIndex();
std::stringstream totalSystemMemoryCheck;
totalSystemMemoryCheck << "Total sys mem allocated: " << executionEnvironment->memoryManager->getUsedSystemMemorySize();
std::stringstream totalLocalMemoryCheck;
totalLocalMemoryCheck << "Total lmem allocated: " << executionEnvironment->memoryManager->getUsedLocalMemorySize(0);
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
@@ -58,8 +67,10 @@ TEST_F(FileLoggerTests, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) {
EXPECT_TRUE(str.find(memoryPoolCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find(gpuAddressCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find(rootDeviceIndexCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find("AllocationType: BUFFER") != std::string::npos);
EXPECT_TRUE(str.find("Type: BUFFER") != std::string::npos);
EXPECT_TRUE(str.find("Size: 777") != std::string::npos);
EXPECT_TRUE(str.find(totalSystemMemoryCheck.str()) != std::string::npos);
EXPECT_TRUE(str.find(totalLocalMemoryCheck.str()) != std::string::npos);
}
}
@@ -75,13 +86,14 @@ TEST_F(FileLoggerTests, GivenLogAllocationMemoryPoolFlagSetFalseThenAllocationIs
auto executionEnvironment = std::unique_ptr<ExecutionEnvironment>(MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u));
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
MockWddmAllocation allocation(executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper());
allocation.handle = 4;
allocation.setAllocationType(AllocationType::buffer);
allocation.memoryPool = MemoryPool::system64KBPages;
allocation.getDefaultGmm()->resourceParams.Flags.Info.NonLocalOnly = 0;
fileLogger.logAllocation(&allocation);
fileLogger.logAllocation(&allocation, nullptr);
std::thread::id thisThread = std::this_thread::get_id();

View File

@@ -535,7 +535,7 @@ TEST(AllocationTypeLoggingSingle, givenDebugVariableToCaptureAllocationTypeWhenF
GraphicsAllocation graphicsAllocation(0, 1u /*num gmms*/, AllocationType::commandBuffer, nullptr, 0, 0, MemoryPool::memoryNull, MemoryManager::maxOsContextCount, 0llu);
testing::internal::CaptureStdout();
fileLogger.logAllocation(&graphicsAllocation);
fileLogger.logAllocation(&graphicsAllocation, nullptr);
std::string output = testing::internal::GetCapturedStdout();
std::string expectedOutput = "Created Graphics Allocation of type COMMAND_BUFFER\n";
@@ -557,7 +557,7 @@ TEST(AllocationTypeLoggingSingle, givenLogAllocationTypeWhenLoggingAllocationThe
EXPECT_FALSE(logFileCreated);
testing::internal::CaptureStdout();
fileLogger.logAllocation(&graphicsAllocation);
fileLogger.logAllocation(&graphicsAllocation, nullptr);
std::string output = testing::internal::GetCapturedStdout();
std::string expectedOutput = "Created Graphics Allocation of type COMMAND_BUFFER\n";
@@ -566,7 +566,7 @@ TEST(AllocationTypeLoggingSingle, givenLogAllocationTypeWhenLoggingAllocationThe
if (fileLogger.wasFileCreated(fileLogger.getLogFileName())) {
auto str = fileLogger.getFileString(fileLogger.getLogFileName());
EXPECT_TRUE(str.find("AllocationType: ") != std::string::npos);
EXPECT_TRUE(str.find("Type: ") != std::string::npos);
} else {
EXPECT_FALSE(true);
}