summaryrefslogtreecommitdiff
path: root/client/src/interfaces/profiler.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-01-18 01:21:46 +0100
committermetamuffin <metamuffin@disroot.org>2025-01-18 01:21:46 +0100
commit0f120ca3eee991566cda704be13b0b1e41dc8d66 (patch)
treecfcf3006a73960f80bc8a9abaeb58c6e7ac1b26d /client/src/interfaces/profiler.rs
parent6703f1c56605ca7dca8f7fe87b79badb764bd461 (diff)
downloadweareserver-0f120ca3eee991566cda704be13b0b1e41dc8d66.tar
weareserver-0f120ca3eee991566cda704be13b0b1e41dc8d66.tar.bz2
weareserver-0f120ca3eee991566cda704be13b0b1e41dc8d66.tar.zst
more profiler things
Diffstat (limited to 'client/src/interfaces/profiler.rs')
-rw-r--r--client/src/interfaces/profiler.rs50
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
+ }
+}