From f7b72a72be84ccae97527a087d3823e44521c8f1 Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 11 Aug 2022 18:41:41 -0700 Subject: [PATCH] driver: abstract the `step` diagnostics measurements --- crates/coremem/src/driver.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/coremem/src/driver.rs b/crates/coremem/src/driver.rs index ad90481..62535ee 100644 --- a/crates/coremem/src/driver.rs +++ b/crates/coremem/src/driver.rs @@ -51,6 +51,7 @@ impl Diagnostics { start_time: Instant::now(), } } + fn format(&self) -> String { let step_time = self.time_spent_stepping.as_secs_f64(); let stim_time = self.time_spent_on_stimuli.as_secs_f64(); @@ -69,6 +70,13 @@ impl Diagnostics { overall_time - step_time - stim_time - block_time - render_prep_time, ) } + + fn instrument_step(&mut self, frames: u64, f: F) { + let start_time = Instant::now(); + f(); + self.time_spent_stepping += start_time.elapsed(); + self.frames_completed += frames as u64; + } } impl Driver { @@ -214,10 +222,9 @@ impl Driver { can_step += 1; } 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(); + self.diag.instrument_step(can_step as u64, || { + self.state.step_multiple(can_step, &self.stimuli); + }); trace!("step end"); if self.last_diag_time.elapsed().as_secs_f64() >= 5.0 { // TODO: make this a method on the Diagnostics.