18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 00:45:29 +01:00

Merge pull request #550 from miloszunio/feat/debug-perflog

feat(debug): debug.perflog writes the times of the renderer to perf.txt while the game runs
This commit is contained in:
2026-11-29 17:36:21 +00:00
committed by GitHub
3 changed files with 44 additions and 0 deletions
+36
View File
@@ -103,6 +103,41 @@ void end_timer_period()
timer_period_set = false;
#endif
}
// debug.perflog: every so many seconds the tables of the debug panel of the renderer, its times on the cpu and the gpu by the pass
// and its counts of the draws, appended to perf.txt beside the log (emptied at the first write of the run), to tell what slows the
// frame down while the game runs
void write_performance_log()
{
if ((Global.debug_perflog <= 0.f) || (GfxRenderer == nullptr) || (false == simulation::is_ready))
return;
// the frames between two writes: the longest and how many took long, which the averages of the tables don't show
static auto last{std::chrono::steady_clock::now()};
static auto next{last + std::chrono::seconds(5)};
static bool started{false};
static double longest{0.0};
static int slow{0};
static int stalled{0};
static int frames{0};
auto const now{std::chrono::steady_clock::now()};
auto const frame{std::chrono::duration<double, std::milli>(now - last).count()};
last = now;
longest = std::max(longest, frame);
slow += (frame > 25.0 ? 1 : 0);
stalled += (frame > 50.0 ? 1 : 0);
++frames;
if (now < next)
return;
next = now + std::chrono::milliseconds(static_cast<long long>(Global.debug_perflog * 1000.f));
std::ofstream out{"perf.txt", started ? std::ios::app : std::ios::trunc};
started = true;
out << std::format("==== {:.1f} s, {} frames, the longest {:.1f} ms, {} over 25 ms, {} over 50 ms\n", Timer::GetTime(), frames, longest, slow, stalled);
longest = 0.0;
slow = 0;
stalled = 0;
frames = 0;
out << GfxRenderer->info_times() << "\n" << GfxRenderer->info_stats() << "\n";
}
} // namespace
#ifdef _WIN32
@@ -826,6 +861,7 @@ int eu07_application::run()
m_network->update();
Timer::subsystem.mainloop_total.stop();
write_performance_log();
// fpslimit: wait for the next frame's slot (eu07/maszyna#416)
if (auto const nextframe{framepacer.next_frame(frame_pacer::clock::now(), Global.minframetime)})
{