From 0f120ca3eee991566cda704be13b0b1e41dc8d66 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 18 Jan 2025 01:21:46 +0100 Subject: more profiler things --- client/src/interfaces/profiler.rs | 50 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'client/src/interfaces/profiler.rs') diff --git a/client/src/interfaces/profiler.rs b/client/src/interfaces/profiler.rs index 5c8737b..85b5858 100644 --- a/client/src/interfaces/profiler.rs +++ b/client/src/interfaces/profiler.rs @@ -15,8 +15,8 @@ along with this program. If not, see . */ use super::InterfaceData; -use egui::Widget; -use std::sync::Arc; +use egui::{Grid, Widget}; +use std::{sync::Arc, time::Instant}; pub struct Profiler { pub idata: Arc, @@ -28,6 +28,52 @@ impl Widget for &mut Profiler { ui.add(&*self.idata.scene_prepare); ui.heading("Download"); ui.add(&*self.idata.downloader); + ui.heading("Render"); + ui.add(&*self.idata.render_timing.lock().unwrap()); ui.response() } } + +pub struct TimingProfiler { + last_cp: Instant, + cur_cp: &'static str, + checkpoints: Vec<(&'static str, f32)>, +} + +impl Default for TimingProfiler { + fn default() -> Self { + Self { + last_cp: Instant::now(), + checkpoints: Default::default(), + cur_cp: "none", + } + } +} +impl TimingProfiler { + pub fn begin(&mut self, name: &'static str) { + self.checkpoints.clear(); + self.last_cp = Instant::now(); + self.cur_cp = name; + } + pub fn checkpoint(&mut self, name: &'static str) { + let now = Instant::now(); + let dur = (now - self.last_cp).as_secs_f32(); + self.last_cp = now; + self.checkpoints.push((self.cur_cp, dur)); + self.cur_cp = name; + } +} +impl Widget for &TimingProfiler { + fn ui(self, ui: &mut egui::Ui) -> egui::Response { + Grid::new("tp") + .num_columns(2) + .show(ui, |ui| { + for (name, dur) in &self.checkpoints { + ui.label(*name); + ui.label(format!("{:.02}ms", dur * 1000.)); + ui.end_row(); + } + }) + .response + } +} -- cgit v1.2.3-70-g09d2