Skip to content

Commit 35f6cd0

Browse files
Add option to log allocations to std out
Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent 205e2e1 commit 35f6cd0

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed

opencl/test/unit_test/os_interface/linux/file_logger_linux_tests.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,59 @@ TEST(FileLogger, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) {
6363
}
6464
}
6565

66+
TEST(FileLogger, givenLogAllocationStdoutWhenLogAllocationThenLogToStdoutInsteadOfFileAndDoNotCreateFile) {
67+
std::string testFile = "testfile";
68+
DebugVariables flags;
69+
flags.LogAllocationMemoryPool.set(true);
70+
flags.LogAllocationStdout.set(true);
71+
FullyEnabledFileLogger fileLogger(testFile, flags);
72+
73+
// Log file not created
74+
bool logFileCreated = fileExists(fileLogger.getLogFileName());
75+
EXPECT_FALSE(logFileCreated);
76+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
77+
executionEnvironment->prepareRootDeviceEnvironments(1);
78+
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
79+
80+
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::System64KBPages);
81+
82+
allocation.setCpuPtrAndGpuAddress(&allocation, 0x12345);
83+
84+
MockBufferObject bo(&drm);
85+
bo.handle = 4;
86+
87+
allocation.bufferObjects[0] = &bo;
88+
89+
testing::internal::CaptureStdout();
90+
fileLogger.logAllocation(&allocation);
91+
std::string output = testing::internal::GetCapturedStdout();
92+
93+
std::thread::id thisThread = std::this_thread::get_id();
94+
95+
std::stringstream threadIDCheck;
96+
threadIDCheck << " ThreadID: " << thisThread;
97+
98+
std::stringstream memoryPoolCheck;
99+
memoryPoolCheck << " MemoryPool: " << allocation.getMemoryPool();
100+
101+
std::stringstream gpuAddressCheck;
102+
gpuAddressCheck << " GPU address: 0x" << std::hex << allocation.getGpuAddress();
103+
104+
std::stringstream rootDeviceIndexCheck;
105+
rootDeviceIndexCheck << " Root device index: " << allocation.getRootDeviceIndex();
106+
107+
EXPECT_TRUE(output.find(threadIDCheck.str()) != std::string::npos);
108+
EXPECT_TRUE(output.find(memoryPoolCheck.str()) != std::string::npos);
109+
EXPECT_TRUE(output.find(gpuAddressCheck.str()) != std::string::npos);
110+
EXPECT_TRUE(output.find(rootDeviceIndexCheck.str()) != std::string::npos);
111+
EXPECT_TRUE(output.find("AllocationType: BUFFER") != std::string::npos);
112+
EXPECT_TRUE(output.find("Handle: 4") != std::string::npos);
113+
EXPECT_TRUE(output.find("\n") != std::string::npos);
114+
115+
logFileCreated = fileExists(fileLogger.getLogFileName());
116+
EXPECT_FALSE(logFileCreated);
117+
}
118+
66119
TEST(FileLogger, GivenDrmAllocationWithoutBOThenNoHandleLogged) {
67120
std::string testFile = "testfile";
68121
DebugVariables flags;

opencl/test/unit_test/test_files/igdrcl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ AllowUnrestrictedSize = 0
329329
DoNotFreeResources = 0
330330
OverrideGmmResourceUsageField = -1
331331
LogAllocationType = 0
332+
LogAllocationStdout = 0
332333
ProgramPipeControlPriorToNonPipelinedStateCommand = -1
333334
ProgramWalkerPartitionSelfCleanup = -1
334335
WparidRegisterProgramming = -1

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ DECLARE_DEBUG_VARIABLE(bool, LogTaskCounts, false, "Enables logging taskCounts a
196196
DECLARE_DEBUG_VARIABLE(bool, LogAlignedAllocations, false, "Logs alignedMalloc and alignedFree allocations")
197197
DECLARE_DEBUG_VARIABLE(bool, LogAllocationMemoryPool, false, "Logs memory pool for allocations")
198198
DECLARE_DEBUG_VARIABLE(bool, LogAllocationType, false, "Logs allocation type to sdout")
199+
DECLARE_DEBUG_VARIABLE(bool, LogAllocationStdout, false, "Log allocations to std out instead of file")
199200
DECLARE_DEBUG_VARIABLE(bool, LogMemoryObject, false, "Logs memory object ptrs, sizes and operations")
200201
DECLARE_DEBUG_VARIABLE(bool, LogWaitingForCompletion, false, "Logs waiting for completion")
201202
DECLARE_DEBUG_VARIABLE(bool, ResidencyDebugEnable, false, "enables debug messages and checks for Residency Model")

shared/source/utilities/logger.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ FileLogger<DebugLevel>::FileLogger(std::string filename, const DebugVariables &f
2929
logApiCalls = flags.LogApiCalls.get();
3030
logAllocationMemoryPool = flags.LogAllocationMemoryPool.get();
3131
logAllocationType = flags.LogAllocationType.get();
32+
logAllocationStdout = flags.LogAllocationStdout.get();
3233
}
3334

3435
template <DebugFunctionalityLevel DebugLevel>
@@ -84,14 +85,10 @@ void FileLogger<DebugLevel>::logAllocation(GraphicsAllocation const *graphicsAll
8485
printDebugString(true, stdout, "Created Graphics Allocation of type %s\n", getAllocationTypeString(graphicsAllocation));
8586
}
8687

87-
if (false == enabled()) {
88-
return;
89-
}
90-
88+
std::stringstream ss;
9189
if (logAllocationMemoryPool || logAllocationType) {
9290
std::thread::id thisThread = std::this_thread::get_id();
9391

94-
std::stringstream ss;
9592
ss << " ThreadID: " << thisThread;
9693
ss << " AllocationType: " << getAllocationTypeString(graphicsAllocation);
9794
ss << " MemoryPool: " << graphicsAllocation->getMemoryPool();
@@ -100,9 +97,19 @@ void FileLogger<DebugLevel>::logAllocation(GraphicsAllocation const *graphicsAll
10097

10198
ss << graphicsAllocation->getAllocationInfoString();
10299
ss << std::endl;
100+
}
101+
auto str = ss.str();
103102

104-
auto str = ss.str();
103+
if (logAllocationStdout) {
104+
printf("%s", str.c_str());
105+
return;
106+
}
105107

108+
if (false == enabled()) {
109+
return;
110+
}
111+
112+
if (logAllocationMemoryPool || logAllocationType) {
106113
writeToFile(logFileName, str.c_str(), str.size(), std::ios::app);
107114
}
108115
}

shared/source/utilities/logger.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class FileLogger {
142142
bool logApiCalls = false;
143143
bool logAllocationMemoryPool = false;
144144
bool logAllocationType = false;
145+
bool logAllocationStdout = false;
145146

146147
// Required for variadic template with 0 args passed
147148
void printInputs(std::stringstream &ss) {}

0 commit comments

Comments
 (0)