[frame_stats] Key binding to clear min/max frame time; address review comments

This commit is contained in:
Arman Uguray 2023-03-16 00:30:51 -07:00
parent 1ac4a4f1a8
commit 306aeab6df
3 changed files with 14 additions and 9 deletions

View file

@ -19,4 +19,5 @@ $ cargo run -p with_winit --release -- [SVG FILES]
- Arrow keys switch between SVG images in the current set.
- Space resets the position and zoom of the image.
- S toggles the frame statistics layer
- C resets the min/max frame time tracked by statistics
- Escape exits the program.

View file

@ -99,7 +99,7 @@ fn run(
let mut simple_text = SimpleText::new();
let mut images = ImageCache::new();
let mut stats = stats::Stats::new();
let mut stats_toggle = true;
let mut stats_shown = true;
let start = Instant::now();
let mut touch_state = multi_touch::TouchState::new();
@ -146,7 +146,10 @@ fn run(
transform = Affine::IDENTITY;
}
Some(VirtualKeyCode::S) => {
stats_toggle = !stats_toggle;
stats_shown = !stats_shown;
}
Some(VirtualKeyCode::C) => {
stats.clear_min_and_max();
}
Some(VirtualKeyCode::Escape) => {
*control_flow = ControlFlow::Exit;
@ -304,7 +307,7 @@ fn run(
transform = transform * Affine::scale(scale_factor);
}
builder.append(&fragment, Some(transform));
if stats_toggle {
if stats_shown {
snapshot.draw_layer(
&mut builder,
&mut scene_params.text,

View file

@ -168,6 +168,11 @@ impl Stats {
}
}
pub fn clear_min_and_max(&mut self) {
self.min = u64::MAX;
self.max = u64::MIN;
}
pub fn add_sample(&mut self, sample: Sample) {
let oldest = if self.count < SLIDING_WINDOW_SIZE {
self.count += 1;
@ -181,11 +186,7 @@ impl Stats {
if let Some(oldest) = oldest {
self.sum -= oldest;
}
if micros < self.min {
self.min = micros;
}
if micros > self.max {
self.max = micros;
}
self.min = self.min.min(micros);
self.max = self.max.max(micros);
}
}