From 2e0c03923ca08184d520c190927a01e314dea2d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 16 Apr 2025 18:17:14 +0200 Subject: [PATCH] Add custom timing support for `comet` --- beacon/src/lib.rs | 7 +++---- beacon/src/span.rs | 9 +++------ debug/src/lib.rs | 18 +++++++++++++----- src/advanced.rs | 2 -- src/lib.rs | 5 +++++ 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/beacon/src/lib.rs b/beacon/src/lib.rs index b96bf754..76df883a 100644 --- a/beacon/src/lib.rs +++ b/beacon/src/lib.rs @@ -206,10 +206,9 @@ pub fn run() -> impl Stream { span::Stage::Present(window) => { Span::Present { window } } - span::Stage::Custom( - window, - name, - ) => Span::Custom { window, name }, + span::Stage::Custom(name) => { + Span::Custom { name } + } }; let _ = output diff --git a/beacon/src/span.rs b/beacon/src/span.rs index 8d163a2f..d35f7b54 100644 --- a/beacon/src/span.rs +++ b/beacon/src/span.rs @@ -33,7 +33,6 @@ pub enum Span { window: window::Id, }, Custom { - window: window::Id, name: String, }, } @@ -70,9 +69,7 @@ impl Span { Span::Prepare { primitive, .. } => Stage::Prepare(*primitive), Span::Render { primitive, .. } => Stage::Render(*primitive), Span::Present { window } => Stage::Present(*window), - Span::Custom { window, name } => { - Stage::Custom(*window, name.clone()) - } + Span::Custom { name, .. } => Stage::Custom(name.clone()), } } } @@ -90,7 +87,7 @@ pub enum Stage { Present(window::Id), Prepare(Primitive), Render(Primitive), - Custom(window::Id, String), + Custom(String), } impl std::fmt::Display for Stage { @@ -105,7 +102,7 @@ impl std::fmt::Display for Stage { Stage::Prepare(_) => "Prepare", Stage::Render(_) => "Render", Stage::Present(_) => "Present", - Stage::Custom(_, name) => name, + Stage::Custom(name) => name, }) } } diff --git a/debug/src/lib.rs b/debug/src/lib.rs index 6036222b..f3335c70 100644 --- a/debug/src/lib.rs +++ b/debug/src/lib.rs @@ -72,8 +72,16 @@ pub fn present(window: window::Id) -> Span { internal::present(window) } -pub fn time(window: window::Id, name: impl AsRef) -> Span { - internal::time(window, name) +pub fn time(name: impl Into) -> Span { + internal::time(name) +} + +pub fn time_with(name: impl Into, f: impl FnOnce() -> T) -> T { + let span = time(name); + let result = f(); + span.finish(); + + result } pub fn skip_next_timing() { @@ -201,8 +209,8 @@ mod internal { span(span::Stage::Present(window)) } - pub fn time(window: window::Id, name: impl AsRef) -> Span { - span(span::Stage::Custom(window, name.as_ref().to_owned())) + pub fn time(name: impl Into) -> Span { + span(span::Stage::Custom(name.into())) } pub fn skip_next_timing() { @@ -312,7 +320,7 @@ mod internal { Span } - pub fn time(_window: window::Id, _name: impl AsRef) -> Span { + pub fn time(_name: impl Into) -> Span { Span } diff --git a/src/advanced.rs b/src/advanced.rs index 5a2ac990..fa11c1df 100644 --- a/src/advanced.rs +++ b/src/advanced.rs @@ -24,6 +24,4 @@ pub use crate::core::svg; pub use crate::core::text::{self, Text}; pub use crate::renderer::graphics; -pub use iced_debug as debug; - pub use widget::Widget; diff --git a/src/lib.rs b/src/lib.rs index 980e6564..b98dc4b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -533,6 +533,11 @@ pub use Length::{Fill, FillPortion, Shrink}; pub use alignment::Horizontal::{Left, Right}; pub use alignment::Vertical::{Bottom, Top}; +pub mod debug { + //! Debug your applications. + pub use iced_debug::{Span, skip_next_timing, time, time_with}; +} + pub mod task { //! Create runtime tasks. pub use crate::runtime::task::{Handle, Task};