18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 09:36:48 +01:00

feat(debug): debug.perflog writes the times of the renderer to perf.txt while the game runs

debug.perflog <seconds> in eu07.ini, 0 (off) by default. Once the scenery is loaded, every so many seconds the tables of the
debug panel of the renderer (info_times(): its times on the CPU and the GPU by the pass; info_stats(): its counts) are appended
to perf.txt in the working folder of the game, beside the log, each headed with the number of frames since the last write, the
longest of them and how many took over 25 and over 50 ms, which the averages of the tables don't show. The file is emptied at the
first write of a run. Parsed in ConfigParseDebug() and written to the log with the other settings.

Off, nothing changes. It showed the stutter of the TreeGenX trees (the sky occlusion gathering them on the main thread) and a
stall while the memory of a 16 GB card filled up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
miloszunio
2026-11-29 10:58:14 +01:00
parent b7f2186a19
commit 460ee1780d
3 changed files with 44 additions and 0 deletions
+36
View File
@@ -102,6 +102,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 << std::format("==== {:.1f} s\n", Timer::GetTime()) << GfxRenderer->info_times() << "\n" << GfxRenderer->info_stats() << "\n";
}
} // namespace
#ifdef _WIN32
@@ -825,6 +860,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)})
{
+7
View File
@@ -1485,6 +1485,12 @@ bool global_settings::ConfigParseDebug(cParser& Parser, const std::string& token
return true;
}
if (token == "debug.perflog")
{
ParseOne(Parser, debug_perflog);
return true;
}
if (token == "debuglog")
{
std::string value;
@@ -2512,6 +2518,7 @@ global_settings::export_as_text( std::ostream &Output ) const {
export_as_text( Output, "physics.pipewake", physics_pipewake );
export_as_text( Output, "performance.multithreading", performance_multithreading );
export_as_text( Output, "debug.memorystats", debug_memorystats );
export_as_text( Output, "debug.perflog", debug_perflog );
export_as_text( Output, "debuglog", iWriteLogEnabled );
export_as_text( Output, "multiplelogs", MultipleLogs );
export_as_text( Output, "crashdump.full", crashdump_full );
+1
View File
@@ -151,6 +151,7 @@ struct global_settings {
bool physics_roadlod{ false }; // road vehicles far from the camera go by one step of the physics in a frame, see vehicle_table::update()
float physics_pipewake{ 0.f }; // bar: air flowing along a pipe wakes the physics of a vehicle when it changes its pressure by more than this. 0: any flow does
bool performance_multithreading{ true }; // work split over the logical cores of the machine (worker_pool), as many as each job is worth
float debug_perflog{ 0.f }; // every so many seconds the times and the counts of the renderer (its debug panel) go to perf.txt beside the log; 0: never
bool debug_memorystats{ false }; // the memory of the parts of the program in the debug panel, with new and delete counted (start_heap_counting()). slows the loading down
bool bnewAirCouplers{ true };
float fMoveLight{ 0.f }; // numer dnia w roku albo -1