diff --git a/application/application.cpp b/application/application.cpp index 563cba5c1..117e6573a 100644 --- a/application/application.cpp +++ b/application/application.cpp @@ -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(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(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)}) { diff --git a/utilities/Globals.cpp b/utilities/Globals.cpp index a4d5f6669..d95911cf0 100644 --- a/utilities/Globals.cpp +++ b/utilities/Globals.cpp @@ -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 ); diff --git a/utilities/Globals.h b/utilities/Globals.h index 3364c49a0..1fb4bd290 100644 --- a/utilities/Globals.h +++ b/utilities/Globals.h @@ -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