diff options
Diffstat (limited to 'client/src/interfaces/profiler.rs')
-rw-r--r-- | client/src/interfaces/profiler.rs | 50 |
1 files changed, 48 insertions, 2 deletions
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 <https://www.gnu.org/licenses/>. */ 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<InterfaceData>, @@ -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 + } +} |