diff --git a/opencl/source/utilities/logger.cpp b/opencl/source/utilities/logger.cpp index 60699cae4c..5be4cb2d03 100644 --- a/opencl/source/utilities/logger.cpp +++ b/opencl/source/utilities/logger.cpp @@ -35,6 +35,7 @@ FileLogger::FileLogger(std::string filename, const DebugVariables &f dumpKernelArgsEnabled = flags.DumpKernelArgs.get(); logApiCalls = flags.LogApiCalls.get(); logAllocationMemoryPool = flags.LogAllocationMemoryPool.get(); + logAllocationType = flags.LogAllocationType.get(); } template @@ -86,6 +87,10 @@ void FileLogger::logApiCall(const char *function, bool enter, int32_ template void FileLogger::logAllocation(GraphicsAllocation const *graphicsAllocation) { + if (logAllocationType) { + printDebugString(true, stdout, "Created Graphics Allocation of type %s\n", getAllocationTypeString(graphicsAllocation)); + } + if (false == enabled()) { return; } @@ -244,12 +249,7 @@ void FileLogger::dumpKernelArgs(const MultiDispatchInfo *multiDispat } } -template -const char *FileLogger::getAllocationTypeString(GraphicsAllocation const *graphicsAllocation) { - if (false == enabled()) { - return nullptr; - } - +const char *getAllocationTypeString(GraphicsAllocation const *graphicsAllocation) { auto type = graphicsAllocation->getAllocationType(); switch (type) { diff --git a/opencl/source/utilities/logger.h b/opencl/source/utilities/logger.h index 0ecac16377..bd428edbf5 100644 --- a/opencl/source/utilities/logger.h +++ b/opencl/source/utilities/logger.h @@ -20,6 +20,8 @@ namespace NEO { class Kernel; struct MultiDispatchInfo; +const char *getAllocationTypeString(GraphicsAllocation const *graphicsAllocation); + template class FileLogger { public: @@ -137,7 +139,6 @@ class FileLogger { logFileName = filename; } - const char *getAllocationTypeString(GraphicsAllocation const *graphicsAllocation); bool peekLogApiCalls() { return logApiCalls; } protected: @@ -147,6 +148,7 @@ class FileLogger { bool dumpKernelArgsEnabled = false; bool logApiCalls = false; bool logAllocationMemoryPool = false; + bool logAllocationType = false; // Required for variadic template with 0 args passed void printInputs(std::stringstream &ss) {} diff --git a/opencl/test/unit_test/test_files/igdrcl.config b/opencl/test/unit_test/test_files/igdrcl.config index 28ec8d841f..c8679eb12b 100644 --- a/opencl/test/unit_test/test_files/igdrcl.config +++ b/opencl/test/unit_test/test_files/igdrcl.config @@ -320,3 +320,4 @@ SkipFlushingEventsOnGetStatusCalls = 0 AllowUnrestrictedSize = 0 DoNotFreeResources = 0 OverrideGmmResourceUsageField = -1 +LogAllocationType = 0 diff --git a/opencl/test/unit_test/utilities/file_logger_tests.cpp b/opencl/test/unit_test/utilities/file_logger_tests.cpp index 5dc73089f3..bbefab651c 100644 --- a/opencl/test/unit_test/utilities/file_logger_tests.cpp +++ b/opencl/test/unit_test/utilities/file_logger_tests.cpp @@ -906,7 +906,7 @@ TEST_P(AllocationTypeLogging, givenGraphicsAllocationTypeWhenConvertingToStringT GraphicsAllocation graphicsAllocation(0, input.type, nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); - auto result = fileLogger.getAllocationTypeString(&graphicsAllocation); + auto result = getAllocationTypeString(&graphicsAllocation); EXPECT_STREQ(result, input.str); } @@ -922,7 +922,7 @@ TEST(AllocationTypeLoggingSingle, givenGraphicsAllocationTypeWhenConvertingToStr GraphicsAllocation graphicsAllocation(0, static_cast(999), nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); - auto result = fileLogger.getAllocationTypeString(&graphicsAllocation); + auto result = getAllocationTypeString(&graphicsAllocation); EXPECT_STREQ(result, "ILLEGAL_VALUE"); } @@ -937,20 +937,26 @@ TEST(AllocationTypeLoggingSingle, givenAllocationTypeWhenConvertingToStringThenS for (uint32_t i = 0; i < static_cast(GraphicsAllocation::AllocationType::COUNT); i++) { graphicsAllocation.setAllocationType(static_cast(i)); - auto result = fileLogger.getAllocationTypeString(&graphicsAllocation); + auto result = getAllocationTypeString(&graphicsAllocation); EXPECT_STRNE(result, "ILLEGAL_VALUE"); } } -TEST(AllocationTypeLoggingSingle, givenDisabledDebugFunctionalityWhenGettingGraphicsAllocationTypeThenNullptrReturned) { +TEST(AllocationTypeLoggingSingle, givenDebugVariableToCaptureAllocationTypeWhenFunctionIsCalledThenProperAllocationTypeIsPrinted) { std::string testFile = "testfile"; DebugVariables flags; - FullyDisabledFileLogger fileLogger(testFile, flags); + flags.LogAllocationType.set(1); - GraphicsAllocation graphicsAllocation(0, GraphicsAllocation::AllocationType::BUFFER, nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); + FullyEnabledFileLogger fileLogger(testFile, flags); - auto result = fileLogger.getAllocationTypeString(&graphicsAllocation); + GraphicsAllocation graphicsAllocation(0, GraphicsAllocation::AllocationType::COMMAND_BUFFER, nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); - EXPECT_STREQ(result, nullptr); + 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()); } diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index f4ba78b226..f31c2bfac5 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -172,6 +172,7 @@ DECLARE_DEBUG_VARIABLE(bool, LogPatchTokens, false, "Enables logging patch token DECLARE_DEBUG_VARIABLE(bool, LogTaskCounts, false, "Enables logging taskCounts and taskLevels to file") DECLARE_DEBUG_VARIABLE(bool, LogAlignedAllocations, false, "Logs alignedMalloc and alignedFree allocations") DECLARE_DEBUG_VARIABLE(bool, LogAllocationMemoryPool, false, "Logs memory pool for allocations") +DECLARE_DEBUG_VARIABLE(bool, LogAllocationType, false, "Logs allocation type to sdout") DECLARE_DEBUG_VARIABLE(bool, LogMemoryObject, false, "Logs memory object ptrs, sizes and operations") DECLARE_DEBUG_VARIABLE(bool, LogWaitingForCompletion, false, "Logs waiting for completion") DECLARE_DEBUG_VARIABLE(bool, ResidencyDebugEnable, false, "enables debug messages and checks for Residency Model")