Skip to content

Commit

Permalink
fps_metrics: don't erase elements until after 10min uptime
Browse files Browse the repository at this point in the history
  • Loading branch information
flightlessmango committed Jan 19, 2024
1 parent d4a66cc commit 3cee6f1
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/fps_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t, float>& 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<uint64_t, float>& entry) {
return entry.first < ten_minutes_ago;
}
),
fps_stats.end()
);
}
}

void update_thread(){
{
Expand Down

0 comments on commit 3cee6f1

Please sign in to comment.