Improve allocation type logging.

- allow to do this in release builds.
- allow to capture thise on stdout.

Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
This commit is contained in:
Michal Mrozek 2021-08-18 11:48:14 +00:00 committed by Compute-Runtime-Automation
parent d8a98acafd
commit b5d5784b81
5 changed files with 25 additions and 15 deletions

View File

@ -35,6 +35,7 @@ FileLogger<DebugLevel>::FileLogger(std::string filename, const DebugVariables &f
dumpKernelArgsEnabled = flags.DumpKernelArgs.get(); dumpKernelArgsEnabled = flags.DumpKernelArgs.get();
logApiCalls = flags.LogApiCalls.get(); logApiCalls = flags.LogApiCalls.get();
logAllocationMemoryPool = flags.LogAllocationMemoryPool.get(); logAllocationMemoryPool = flags.LogAllocationMemoryPool.get();
logAllocationType = flags.LogAllocationType.get();
} }
template <DebugFunctionalityLevel DebugLevel> template <DebugFunctionalityLevel DebugLevel>
@ -86,6 +87,10 @@ void FileLogger<DebugLevel>::logApiCall(const char *function, bool enter, int32_
template <DebugFunctionalityLevel DebugLevel> template <DebugFunctionalityLevel DebugLevel>
void FileLogger<DebugLevel>::logAllocation(GraphicsAllocation const *graphicsAllocation) { void FileLogger<DebugLevel>::logAllocation(GraphicsAllocation const *graphicsAllocation) {
if (logAllocationType) {
printDebugString(true, stdout, "Created Graphics Allocation of type %s\n", getAllocationTypeString(graphicsAllocation));
}
if (false == enabled()) { if (false == enabled()) {
return; return;
} }
@ -244,12 +249,7 @@ void FileLogger<DebugLevel>::dumpKernelArgs(const MultiDispatchInfo *multiDispat
} }
} }
template <DebugFunctionalityLevel DebugLevel> const char *getAllocationTypeString(GraphicsAllocation const *graphicsAllocation) {
const char *FileLogger<DebugLevel>::getAllocationTypeString(GraphicsAllocation const *graphicsAllocation) {
if (false == enabled()) {
return nullptr;
}
auto type = graphicsAllocation->getAllocationType(); auto type = graphicsAllocation->getAllocationType();
switch (type) { switch (type) {

View File

@ -20,6 +20,8 @@ namespace NEO {
class Kernel; class Kernel;
struct MultiDispatchInfo; struct MultiDispatchInfo;
const char *getAllocationTypeString(GraphicsAllocation const *graphicsAllocation);
template <DebugFunctionalityLevel DebugLevel> template <DebugFunctionalityLevel DebugLevel>
class FileLogger { class FileLogger {
public: public:
@ -137,7 +139,6 @@ class FileLogger {
logFileName = filename; logFileName = filename;
} }
const char *getAllocationTypeString(GraphicsAllocation const *graphicsAllocation);
bool peekLogApiCalls() { return logApiCalls; } bool peekLogApiCalls() { return logApiCalls; }
protected: protected:
@ -147,6 +148,7 @@ class FileLogger {
bool dumpKernelArgsEnabled = false; bool dumpKernelArgsEnabled = false;
bool logApiCalls = false; bool logApiCalls = false;
bool logAllocationMemoryPool = false; bool logAllocationMemoryPool = false;
bool logAllocationType = false;
// Required for variadic template with 0 args passed // Required for variadic template with 0 args passed
void printInputs(std::stringstream &ss) {} void printInputs(std::stringstream &ss) {}

View File

@ -320,3 +320,4 @@ SkipFlushingEventsOnGetStatusCalls = 0
AllowUnrestrictedSize = 0 AllowUnrestrictedSize = 0
DoNotFreeResources = 0 DoNotFreeResources = 0
OverrideGmmResourceUsageField = -1 OverrideGmmResourceUsageField = -1
LogAllocationType = 0

View File

@ -906,7 +906,7 @@ TEST_P(AllocationTypeLogging, givenGraphicsAllocationTypeWhenConvertingToStringT
GraphicsAllocation graphicsAllocation(0, input.type, nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); 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); EXPECT_STREQ(result, input.str);
} }
@ -922,7 +922,7 @@ TEST(AllocationTypeLoggingSingle, givenGraphicsAllocationTypeWhenConvertingToStr
GraphicsAllocation graphicsAllocation(0, static_cast<GraphicsAllocation::AllocationType>(999), nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull); GraphicsAllocation graphicsAllocation(0, static_cast<GraphicsAllocation::AllocationType>(999), nullptr, 0ull, 0ull, 0, MemoryPool::MemoryNull);
auto result = fileLogger.getAllocationTypeString(&graphicsAllocation); auto result = getAllocationTypeString(&graphicsAllocation);
EXPECT_STREQ(result, "ILLEGAL_VALUE"); EXPECT_STREQ(result, "ILLEGAL_VALUE");
} }
@ -937,20 +937,26 @@ TEST(AllocationTypeLoggingSingle, givenAllocationTypeWhenConvertingToStringThenS
for (uint32_t i = 0; i < static_cast<uint32_t>(GraphicsAllocation::AllocationType::COUNT); i++) { for (uint32_t i = 0; i < static_cast<uint32_t>(GraphicsAllocation::AllocationType::COUNT); i++) {
graphicsAllocation.setAllocationType(static_cast<GraphicsAllocation::AllocationType>(i)); graphicsAllocation.setAllocationType(static_cast<GraphicsAllocation::AllocationType>(i));
auto result = fileLogger.getAllocationTypeString(&graphicsAllocation); auto result = getAllocationTypeString(&graphicsAllocation);
EXPECT_STRNE(result, "ILLEGAL_VALUE"); EXPECT_STRNE(result, "ILLEGAL_VALUE");
} }
} }
TEST(AllocationTypeLoggingSingle, givenDisabledDebugFunctionalityWhenGettingGraphicsAllocationTypeThenNullptrReturned) { TEST(AllocationTypeLoggingSingle, givenDebugVariableToCaptureAllocationTypeWhenFunctionIsCalledThenProperAllocationTypeIsPrinted) {
std::string testFile = "testfile"; std::string testFile = "testfile";
DebugVariables flags; 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());
} }

View File

@ -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, LogTaskCounts, false, "Enables logging taskCounts and taskLevels to file")
DECLARE_DEBUG_VARIABLE(bool, LogAlignedAllocations, false, "Logs alignedMalloc and alignedFree allocations") 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, 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, LogMemoryObject, false, "Logs memory object ptrs, sizes and operations")
DECLARE_DEBUG_VARIABLE(bool, LogWaitingForCompletion, false, "Logs waiting for completion") DECLARE_DEBUG_VARIABLE(bool, LogWaitingForCompletion, false, "Logs waiting for completion")
DECLARE_DEBUG_VARIABLE(bool, ResidencyDebugEnable, false, "enables debug messages and checks for Residency Model") DECLARE_DEBUG_VARIABLE(bool, ResidencyDebugEnable, false, "enables debug messages and checks for Residency Model")