Skip to content

Commit 787c74c

Browse files
Do not make dynamic allocations in hot calls.
std::stringstream does memory allocation even though it is not used. Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
1 parent 5ba6f4a commit 787c74c

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

shared/source/utilities/logger.cpp

+13-14
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ void FileLogger<DebugLevel>::logAllocation(GraphicsAllocation const *graphicsAll
8585
printDebugString(true, stdout, "Created Graphics Allocation of type %s\n", getAllocationTypeString(graphicsAllocation));
8686
}
8787

88-
std::stringstream ss;
88+
if (false == enabled()) {
89+
return;
90+
}
91+
8992
if (logAllocationMemoryPool || logAllocationType) {
93+
std::stringstream ss;
9094
std::thread::id thisThread = std::this_thread::get_id();
9195

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

98102
ss << graphicsAllocation->getAllocationInfoString();
99103
ss << std::endl;
100-
}
101-
auto str = ss.str();
102-
103-
if (logAllocationStdout) {
104-
printf("%s", str.c_str());
105-
return;
106-
}
107-
108-
if (false == enabled()) {
109-
return;
110-
}
104+
auto str = ss.str();
105+
if (logAllocationStdout) {
106+
printf("%s", str.c_str());
107+
return;
108+
}
111109

112-
if (logAllocationMemoryPool || logAllocationType) {
113-
writeToFile(logFileName, str.c_str(), str.size(), std::ios::app);
110+
if (logAllocationMemoryPool || logAllocationType) {
111+
writeToFile(logFileName, str.c_str(), str.size(), std::ios::app);
112+
}
114113
}
115114
}
116115

0 commit comments

Comments
 (0)