Skip to content

Commit

Permalink
Do not make dynamic allocations in hot calls.
Browse files Browse the repository at this point in the history
std::stringstream does memory allocation even though it is not used.

Signed-off-by: Michal Mrozek <[email protected]>
  • Loading branch information
MichalMrozek authored and Compute-Runtime-Automation committed Apr 1, 2022
1 parent 5ba6f4a commit 787c74c
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions shared/source/utilities/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ void FileLogger<DebugLevel>::logAllocation(GraphicsAllocation const *graphicsAll
printDebugString(true, stdout, "Created Graphics Allocation of type %s\n", getAllocationTypeString(graphicsAllocation));
}

std::stringstream ss;
if (false == enabled()) {
return;
}

if (logAllocationMemoryPool || logAllocationType) {
std::stringstream ss;
std::thread::id thisThread = std::this_thread::get_id();

ss << " ThreadID: " << thisThread;
Expand All @@ -97,20 +101,15 @@ void FileLogger<DebugLevel>::logAllocation(GraphicsAllocation const *graphicsAll

ss << graphicsAllocation->getAllocationInfoString();
ss << std::endl;
}
auto str = ss.str();

if (logAllocationStdout) {
printf("%s", str.c_str());
return;
}

if (false == enabled()) {
return;
}
auto str = ss.str();
if (logAllocationStdout) {
printf("%s", str.c_str());
return;
}

if (logAllocationMemoryPool || logAllocationType) {
writeToFile(logFileName, str.c_str(), str.size(), std::ios::app);
if (logAllocationMemoryPool || logAllocationType) {
writeToFile(logFileName, str.c_str(), str.size(), std::ios::app);
}
}
}

Expand Down

0 comments on commit 787c74c

Please sign in to comment.