From 6f1e1557b33d8c51a48f44694ebd11b3c1031ecd Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 11 Aug 2022 18:29:58 -0700 Subject: [PATCH] driver: diagnostics: track the actual number of frames stepped this allows fps-related diagnostics to be meaningful after serialization / restarts. --- crates/coremem/src/driver.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/coremem/src/driver.rs b/crates/coremem/src/driver.rs index 738b0cb..8560e6b 100644 --- a/crates/coremem/src/driver.rs +++ b/crates/coremem/src/driver.rs @@ -29,6 +29,7 @@ pub struct Driver { } struct Diagnostics { + frames_completed: u64, time_spent_stepping: Duration, time_spent_on_stimuli: Duration, time_spent_prepping_render: Duration, @@ -41,6 +42,7 @@ struct Diagnostics { impl Diagnostics { fn new() -> Self { Self { + frames_completed: 0, time_spent_stepping: Default::default(), time_spent_on_stimuli: Default::default(), time_spent_prepping_render: Default::default(), @@ -196,6 +198,7 @@ impl Driver { trace!("step begin"); let start_time = Instant::now(); self.state.step_multiple(can_step, &self.stimuli); + self.diag.frames_completed += can_step as u64; self.diag.time_spent_stepping += start_time.elapsed(); trace!("step end"); if self.diag.last_diag_time.elapsed().as_secs_f64() >= 5.0 { @@ -208,7 +211,7 @@ impl Driver { let render_prep_time = self.diag.time_spent_prepping_render.as_secs_f64(); let block_time = self.diag.time_spent_blocked_on_render.as_secs_f64(); let overall_time = self.diag.start_time.elapsed().as_secs_f64(); - let fps = (self.state.step_no() as f64) / overall_time; + let fps = (self.diag.frames_completed as f64) / overall_time; let sim_time = self.state.time() as f64; let percent_complete = match self.sim_end_time { Some(t) => format!("[{:.1}%] ", 100.0 * self.state.time() / *t.to_seconds(self.timestep())),