diff --git a/editor/Cargo.toml b/editor/Cargo.toml index fbbc268..df33df7 100644 --- a/editor/Cargo.toml +++ b/editor/Cargo.toml @@ -9,3 +9,5 @@ egui = "0.17.0" egui-winit = "0.17.0" egui_wgpu_backend = "0.17.0" pollster = "0.2" +puffin = "^0.13" +puffin_egui = "0.14.0" diff --git a/editor/src/main.rs b/editor/src/main.rs index acbdcef..0dec69c 100644 --- a/editor/src/main.rs +++ b/editor/src/main.rs @@ -96,10 +96,15 @@ impl Application { Err(wgpu::SurfaceError::Lost) => self.on_resize(self.size), Err(e) => panic!("Surface error: {:?}", e), Ok(surface_texture) => { - let raw_input = self.egui_state.take_egui_input(&self.window); - let output = self.egui_ctx.run(raw_input, |ctx| { - self.ui.run(ctx); - }); + puffin::GlobalProfiler::lock().new_frame(); + + let output = { + puffin::profile_scope!("Draw egui"); + let raw_input = self.egui_state.take_egui_input(&self.window); + self.egui_ctx.run(raw_input, |ctx| self.ui.run(ctx)) + }; + + puffin::profile_scope!("Render egui"); self.egui_state.handle_platform_output( &self.window, diff --git a/editor/src/ui.rs b/editor/src/ui.rs index c8029ec..69dcde7 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -65,7 +65,10 @@ impl UserInterface { ui.menu_button("View", |ui| { ui.checkbox(&mut self.developer_mode, "Developer mode"); - ui.checkbox(&mut self.show_profiler, "Show profiler"); + + if ui.checkbox(&mut self.show_profiler, "Profiler").changed() { + puffin_egui::puffin::set_scopes_on(self.show_profiler); + } }); ui.menu_button("Help", |ui| { @@ -81,6 +84,10 @@ impl UserInterface { ui.heading("Hello world!"); }); + if self.show_profiler { + self.show_profiler = puffin_egui::profiler_window(ctx); + } + if self.show_about { egui::Window::new("About") .open(&mut self.show_about)