mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
Much more accurate cpu_usage timing (#3913)
`frame.info.cpu_usage` now includes time for tessellation and rendering, but excludes vsync and context switching.
This commit is contained in:
@@ -179,8 +179,6 @@ impl AppRunner {
|
||||
///
|
||||
/// The result can be painted later with a call to [`Self::run_and_paint`] or [`Self::paint`].
|
||||
pub fn logic(&mut self) {
|
||||
let frame_start = now_sec();
|
||||
|
||||
super::resize_canvas_to_screen_size(self.canvas_id(), self.web_options.max_size_points);
|
||||
let canvas_size = super::canvas_size_in_points(self.canvas_id());
|
||||
let raw_input = self.input.new_frame(canvas_size);
|
||||
@@ -211,8 +209,6 @@ impl AppRunner {
|
||||
self.handle_platform_output(platform_output);
|
||||
self.textures_delta.append(textures_delta);
|
||||
self.clipped_primitives = Some(self.egui_ctx.tessellate(shapes, pixels_per_point));
|
||||
|
||||
self.frame.info.cpu_usage = Some((now_sec() - frame_start) as f32);
|
||||
}
|
||||
|
||||
/// Paint the results of the last call to [`Self::logic`].
|
||||
@@ -232,6 +228,10 @@ impl AppRunner {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn report_frame_time(&mut self, cpu_usage_seconds: f32) {
|
||||
self.frame.info.cpu_usage = Some(cpu_usage_seconds);
|
||||
}
|
||||
|
||||
fn handle_platform_output(&mut self, platform_output: egui::PlatformOutput) {
|
||||
#[cfg(feature = "web_screen_reader")]
|
||||
if self.egui_ctx.options(|o| o.screen_reader) {
|
||||
|
||||
@@ -30,11 +30,16 @@ fn paint_if_needed(runner: &mut AppRunner) {
|
||||
// running the logic, as the logic could cause it to be set again.
|
||||
runner.needs_repaint.clear();
|
||||
|
||||
let mut stopwatch = crate::stopwatch::Stopwatch::new();
|
||||
stopwatch.start();
|
||||
|
||||
// Run user code…
|
||||
runner.logic();
|
||||
|
||||
// …and paint the result.
|
||||
runner.paint();
|
||||
|
||||
runner.report_frame_time(stopwatch.total_time_sec());
|
||||
}
|
||||
}
|
||||
runner.auto_save_if_needed();
|
||||
|
||||
Reference in New Issue
Block a user