From 98a39aade93666db4f0ad1a10b12d925d6c61ef1 Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Sun, 1 Aug 2021 10:05:43 +0100 Subject: [PATCH] Profiling - fix frame_time measurement When the `sync_after_draw` feature was on it was possible for the profiler's frame_time measurement to be incorrect. This fixes this problem by storing the raw measured time for use by the profiler. --- main/main.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 8edec36e0fc..38e342279f1 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2056,17 +2056,20 @@ bool Main::iteration() { iterating++; + // ticks may become modified later on, and we want to store the raw measured + // value for profiling. + uint64_t raw_ticks_at_start = OS::get_singleton()->get_ticks_usec(); + #ifdef TOOLS_ENABLED - uint64_t ticks = OS::get_singleton()->get_ticks_usec(); + uint64_t ticks = raw_ticks_at_start; #else // we can either sync the delta from here, or later in the iteration - uint64_t ticks_at_start = OS::get_singleton()->get_ticks_usec(); - uint64_t ticks_difference = ticks_at_start - frame_delta_sync_time; + uint64_t ticks_difference = raw_ticks_at_start - frame_delta_sync_time; // if we are syncing at start or if frame_delta_sync_time is being initialized // or a large gap has happened between the last delta_sync_time and now if (!delta_sync_after_draw || (ticks_difference > 100000)) { - frame_delta_sync_time = ticks_at_start; + frame_delta_sync_time = raw_ticks_at_start; } uint64_t ticks = frame_delta_sync_time; #endif @@ -2165,9 +2168,10 @@ bool Main::iteration() { } #endif + // profiler timing information idle_process_ticks = OS::get_singleton()->get_ticks_usec() - idle_begin; idle_process_max = MAX(idle_process_ticks, idle_process_max); - uint64_t frame_time = OS::get_singleton()->get_ticks_usec() - ticks; + uint64_t frame_time = OS::get_singleton()->get_ticks_usec() - raw_ticks_at_start; for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptServer::get_language(i)->frame();