Print frame times for glium and wasm excluding painting
This commit is contained in:
parent
1e685d1cb0
commit
89823ab617
3 changed files with 33 additions and 7 deletions
|
@ -226,6 +226,7 @@ impl Painter {
|
||||||
target.finish().unwrap();
|
target.finish().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(never)] // Easier profiling
|
||||||
fn paint_batch(
|
fn paint_batch(
|
||||||
&mut self,
|
&mut self,
|
||||||
target: &mut Frame,
|
target: &mut Frame,
|
||||||
|
|
|
@ -43,6 +43,8 @@ fn main() {
|
||||||
|
|
||||||
let mut frame_start = Instant::now();
|
let mut frame_start = Instant::now();
|
||||||
|
|
||||||
|
let mut frame_times = std::collections::VecDeque::new();
|
||||||
|
|
||||||
let mut example_app = ExampleApp::default();
|
let mut example_app = ExampleApp::default();
|
||||||
|
|
||||||
while running {
|
while running {
|
||||||
|
@ -73,6 +75,19 @@ fn main() {
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mean_frame_time = if frame_times.is_empty() {
|
||||||
|
0.0
|
||||||
|
} else {
|
||||||
|
frame_times.iter().sum::<f64>() / (frame_times.len() as f64)
|
||||||
|
};
|
||||||
|
region.add(
|
||||||
|
label!(
|
||||||
|
"Frame time: {:.1} ms (excludes painting)",
|
||||||
|
1e3 * mean_frame_time
|
||||||
|
)
|
||||||
|
.text_style(TextStyle::Monospace),
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: Make it even simpler to show a window
|
// TODO: Make it even simpler to show a window
|
||||||
|
|
||||||
Window::new("Examples")
|
Window::new("Examples")
|
||||||
|
@ -90,6 +105,12 @@ fn main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
let (output, paint_batches) = emigui.end_frame();
|
let (output, paint_batches) = emigui.end_frame();
|
||||||
|
|
||||||
|
frame_times.push_back((Instant::now() - emigui_start).as_secs_f64());
|
||||||
|
while frame_times.len() > 30 {
|
||||||
|
frame_times.pop_front();
|
||||||
|
}
|
||||||
|
|
||||||
painter.paint_batches(&display, paint_batches, emigui.texture());
|
painter.paint_batches(&display, paint_batches, emigui.texture());
|
||||||
|
|
||||||
let cursor = match output.cursor_icon {
|
let cursor = match output.cursor_icon {
|
||||||
|
|
|
@ -73,7 +73,10 @@ impl State {
|
||||||
self.frame_times.iter().sum::<f64>() / (self.frame_times.len() as f64)
|
self.frame_times.iter().sum::<f64>() / (self.frame_times.len() as f64)
|
||||||
};
|
};
|
||||||
region.add(
|
region.add(
|
||||||
label!("Total CPU usage: {:.1} ms", 1e3 * mean_frame_time)
|
label!(
|
||||||
|
"Frame time: {:.1} ms (excludes painting)",
|
||||||
|
1e3 * mean_frame_time
|
||||||
|
)
|
||||||
.text_style(TextStyle::Monospace),
|
.text_style(TextStyle::Monospace),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -95,6 +98,12 @@ impl State {
|
||||||
|
|
||||||
let bg_color = srgba(0, 0, 0, 0); // Use background css color.
|
let bg_color = srgba(0, 0, 0, 0); // Use background css color.
|
||||||
let (output, batches) = self.emigui.end_frame();
|
let (output, batches) = self.emigui.end_frame();
|
||||||
|
|
||||||
|
self.frame_times.push_back(now_sec() - everything_start);
|
||||||
|
while self.frame_times.len() > 30 {
|
||||||
|
self.frame_times.pop_front();
|
||||||
|
}
|
||||||
|
|
||||||
self.webgl_painter.paint_batches(
|
self.webgl_painter.paint_batches(
|
||||||
bg_color,
|
bg_color,
|
||||||
batches,
|
batches,
|
||||||
|
@ -102,11 +111,6 @@ impl State {
|
||||||
pixels_per_point,
|
pixels_per_point,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.frame_times.push_back(now_sec() - everything_start);
|
|
||||||
while self.frame_times.len() > 30 {
|
|
||||||
self.frame_times.pop_front();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue