Skip to content

Commit cdc130e

Browse files
authored
Merge pull request #23 from TECHNICANGEL/perf-optimize-logging-6945768175472539227
⚡ Optimize console I/O in main loop using AsyncLogger
2 parents 5310bbc + 51a2ca3 commit cdc130e

2 files changed

Lines changed: 17 additions & 38 deletions

File tree

benchmark_snprintf.cpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/main.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ class RacingEngine {
251251
} else {
252252
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
253253
}
254-
std::cout << "\n[CURSOR] " << (engine->cursorLocked ? "LOCKED (Camera Active)" : "UNLOCKED (Camera Paused)") << "\n";
254+
255+
std::string status = engine->cursorLocked ? "LOCKED (Camera Active)" : "UNLOCKED (Camera Paused)";
256+
engine->logger.log("\n[CURSOR] " + status + "\n");
255257
}
256258
if (key == GLFW_KEY_TAB && action == GLFW_RELEASE) {
257259
engine->tabKeyPressed = false;
@@ -261,7 +263,9 @@ class RacingEngine {
261263
if (key == GLFW_KEY_D && action == GLFW_PRESS && !engine->denoiserKeyPressed) {
262264
engine->denoiserKeyPressed = true;
263265
engine->denoiserEnabled = !engine->denoiserEnabled;
264-
std::cout << "\n[DENOISER] " << (engine->denoiserEnabled ? "ENABLED" : "DISABLED") << "\n";
266+
267+
std::string status = engine->denoiserEnabled ? "ENABLED" : "DISABLED";
268+
engine->logger.log("\n[DENOISER] " + status + "\n");
265269
}
266270
if (key == GLFW_KEY_D && action == GLFW_RELEASE) {
267271
engine->denoiserKeyPressed = false;
@@ -866,11 +870,13 @@ class RacingEngine {
866870

867871
// Extra verbose debug every 500 frames
868872
if (frameCount % 500 == 0 && frameCount > 0) {
869-
std::cout << "\n[DEBUG Frame " << frameCount << "] "
870-
<< "GPU Memory OK | "
871-
<< "Sync objects valid | "
872-
<< "currentFrame=" << currentFrame
873-
<< std::endl;
873+
std::stringstream ss;
874+
ss << "\n[DEBUG Frame " << frameCount << "] "
875+
<< "GPU Memory OK | "
876+
<< "Sync objects valid | "
877+
<< "currentFrame=" << currentFrame
878+
<< "\n";
879+
logger.log(ss.str());
874880
}
875881
#endif
876882
frameCount++;
@@ -919,7 +925,7 @@ class RacingEngine {
919925
rayTracing.copyStagingToAccumulation(device, graphicsQueue, WIDTH, HEIGHT);
920926

921927
#if ENABLE_RENDER_LOOP_LOGGING
922-
std::cout << "\n[DENOISER] Frame denoised with Tensor Cores!\n";
928+
logger.log("\n[DENOISER] Frame denoised with Tensor Cores!\n");
923929
#endif
924930
}
925931
}
@@ -928,8 +934,9 @@ class RacingEngine {
928934
void printDebugStep(const char* step, uint32_t frame, int stepNum) {
929935
#if ENABLE_RENDER_LOOP_LOGGING
930936
if (VERBOSE_DEBUG || (frame - lastDebugPrintFrame >= DEBUG_PRINT_INTERVAL && stepNum == 0)) {
931-
std::cout << "[F" << frame << "] " << step << std::endl;
932-
std::cout.flush();
937+
std::stringstream ss;
938+
ss << "[F" << frame << "] " << step << "\n";
939+
logger.log(ss.str());
933940
if (stepNum == 0) lastDebugPrintFrame = frame;
934941
}
935942
#endif

0 commit comments

Comments
 (0)