driver: abstract the step diagnostics measurements

This commit is contained in:
2022-08-11 18:41:41 -07:00
parent a413a4d391
commit f7b72a72be

View File

@@ -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<F: FnOnce()>(&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<S: AbstractSim> Driver<S> {
@@ -214,10 +222,9 @@ impl<S: AbstractSim + Clone + Default + Send + 'static> Driver<S> {
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.