driver: diagnostics: track the actual number of frames stepped

this allows fps-related diagnostics to be meaningful after
serialization / restarts.
This commit is contained in:
2022-08-11 18:29:58 -07:00
parent e85d38d415
commit 6f1e1557b3

View File

@@ -29,6 +29,7 @@ pub struct Driver<S> {
}
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<S: AbstractSim + Clone + Default + Send + 'static> Driver<S> {
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<S: AbstractSim + Clone + Default + Send + 'static> Driver<S> {
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())),