From 3cee6f15ded1b086333738e2388eb1d10dce9ba6 Mon Sep 17 00:00:00 2001 From: flightlessmango Date: Fri, 19 Jan 2024 19:56:39 +0100 Subject: [PATCH] fps_metrics: don't erase elements until after 10min uptime --- src/fps_metrics.h | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/fps_metrics.h b/src/fps_metrics.h index 3d011a20..0cab909d 100644 --- a/src/fps_metrics.h +++ b/src/fps_metrics.h @@ -106,17 +106,24 @@ class fpsMetrics { void update(uint64_t now, double fps){ fps_stats.push_back({now, fps}); - // Calculate the cut-off nanotime (10 minutes ago) - uint64_t ten_minutes_ns = 600000000000ULL; // 10 minutes in nanoseconds - uint64_t cutoff_time_ns = os_time_get_nano() - ten_minutes_ns; - - // Removing elements older than 10 minutes - fps_stats.erase(std::remove_if(fps_stats.begin(), fps_stats.end(), - [cutoff_time_ns](const std::pair& p) { - return p.first < cutoff_time_ns; - }), - fps_stats.end()); - }; + uint64_t ten_minute_duration = 600000000000ULL; // 10 minutes in nanoseconds + + // Check if the system's uptime is less than 10 minutes + if (now >= ten_minute_duration) { + uint64_t ten_minutes_ago = now - ten_minute_duration; + + fps_stats.erase( + std::remove_if( + fps_stats.begin(), + fps_stats.end(), + [ten_minutes_ago](const std::pair& entry) { + return entry.first < ten_minutes_ago; + } + ), + fps_stats.end() + ); + } + } void update_thread(){ {