From 609738252022f89a8aae68ee8a34503cb19578df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Fri, 1 Mar 2024 22:04:46 +0100 Subject: [PATCH] Introduce `skip_next_timing` in `iced_debug` This is useful to avoid infinite recursion when implementing a `sentinel` client that can inspect itself. --- debug/src/lib.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/debug/src/lib.rs b/debug/src/lib.rs index d04a7ac2..cabe4440 100644 --- a/debug/src/lib.rs +++ b/debug/src/lib.rs @@ -46,6 +46,10 @@ pub fn time(window: window::Id, name: impl AsRef) -> Timer { internal::time(window, name) } +pub fn skip_next_timing() { + internal::skip_next_timing(); +} + #[cfg(feature = "enable")] mod internal { use crate::core::time::{Instant, SystemTime}; @@ -100,6 +104,10 @@ mod internal { timer(timing::Stage::Custom(window, name.as_ref().to_owned())) } + pub fn skip_next_timing() { + lock().skip_next_timing = true; + } + fn timer(stage: timing::Stage) -> Timer { Timer { stage, @@ -117,7 +125,14 @@ mod internal { impl Timer { pub fn finish(self) { - lock().sentinel.report_timing(Timing { + let mut debug = lock(); + + if debug.skip_next_timing { + debug.skip_next_timing = false; + return; + } + + debug.sentinel.report_timing(Timing { stage: self.stage, start: self.start_system_time, duration: self.start.elapsed(), @@ -129,6 +144,7 @@ mod internal { struct Debug { sentinel: Client, last_palette: Option, + skip_next_timing: bool, } fn lock() -> MutexGuard<'static, Debug> { @@ -136,6 +152,7 @@ mod internal { Mutex::new(Debug { sentinel: client::connect(), last_palette: None, + skip_next_timing: false, }) }); @@ -182,6 +199,8 @@ mod internal { Timer } + pub fn skip_next_timing() {} + #[derive(Debug)] pub struct Timer;