[PERF] Host Debug Overlay Isolation

This commit is contained in:
2026-04-10 14:10:20 +01:00
parent b8d33c9e02
commit 58a5f9a3a6
18 changed files with 1315 additions and 123 deletions
@@ -9,6 +9,9 @@ pub struct HostStats {
pub current_fps: f64,
pub audio_load_accum_us: u64,
pub audio_load_samples: u64,
recent_host_cpu_us: [u64; 5],
recent_host_cpu_count: usize,
recent_host_cpu_cursor: usize,
}
impl Default for HostStats {
@@ -25,6 +28,9 @@ impl HostStats {
current_fps: 0.0,
audio_load_accum_us: 0,
audio_load_samples: 0,
recent_host_cpu_us: [0; 5],
recent_host_cpu_count: 0,
recent_host_cpu_cursor: 0,
}
}
@@ -37,6 +43,21 @@ impl HostStats {
self.audio_load_samples += 1;
}
pub fn record_host_cpu_time(&mut self, us: u64) {
self.recent_host_cpu_us[self.recent_host_cpu_cursor] = us;
self.recent_host_cpu_cursor = (self.recent_host_cpu_cursor + 1) % self.recent_host_cpu_us.len();
self.recent_host_cpu_count = self.recent_host_cpu_count.saturating_add(1).min(self.recent_host_cpu_us.len());
}
pub fn average_host_cpu_ms(&self) -> f64 {
if self.recent_host_cpu_count == 0 {
0.0
} else {
let sum: u64 = self.recent_host_cpu_us.iter().take(self.recent_host_cpu_count).sum();
(sum as f64 / self.recent_host_cpu_count as f64) / 1000.0
}
}
pub fn update(
&mut self,
now: Instant,
@@ -51,8 +72,7 @@ impl HostStats {
if let Some(window) = window {
// Fixed comparison always against 60Hz, keep even when doing CPU stress tests
let frame_budget_us = 16666.0;
let cpu_load_core =
(firmware.os.last_frame_cpu_time_us as f64 / frame_budget_us) * 100.0;
let cpu_load_core = (self.average_host_cpu_ms() * 1000.0 / frame_budget_us) * 100.0;
let cpu_load_audio = if self.audio_load_samples > 0 {
(self.audio_load_accum_us as f64 / stats_elapsed.as_micros() as f64) * 100.0