From c5cd236b7380c3689792934aeaecd2942713fa67 Mon Sep 17 00:00:00 2001 From: Bingus Date: Tue, 29 Nov 2022 19:50:58 -0800 Subject: Initial profiling support for Iced. --- glutin/src/application.rs | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'glutin/src') diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 3e9d11f9..21051f16 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -17,6 +17,9 @@ use iced_winit::{Clipboard, Command, Debug, Proxy, Settings}; use glutin::window::Window; use std::mem::ManuallyDrop; +#[cfg(feature = "trace")] +use iced_profiling::{info_span, instrument::Instrument}; + /// Runs an [`Application`] with an executor, compositor, and the provided /// settings. pub fn run( @@ -35,9 +38,15 @@ where use glutin::platform::run_return::EventLoopExtRunReturn; use glutin::ContextBuilder; + #[cfg(feature = "trace")] + let _guard = iced_profiling::init(); + let mut debug = Debug::new(); debug.startup_started(); + #[cfg(feature = "trace")] + let _ = info_span!("Application::Glutin", "RUN").entered(); + let mut event_loop = EventLoopBuilder::with_user_event().build(); let proxy = event_loop.create_proxy(); @@ -124,18 +133,26 @@ where let (mut sender, receiver) = mpsc::unbounded(); - let mut instance = Box::pin(run_instance::( - application, - compositor, - renderer, - runtime, - proxy, - debug, - receiver, - context, - init_command, - settings.exit_on_close_request, - )); + let mut instance = Box::pin({ + let run_instance = run_instance::( + application, + compositor, + renderer, + runtime, + proxy, + debug, + receiver, + context, + init_command, + settings.exit_on_close_request, + ); + + #[cfg(feature = "trace")] + let run_instance = + run_instance.instrument(info_span!("Application", "LOOP")); + + run_instance + }); let mut context = task::Context::from_waker(task::noop_waker_ref()); @@ -333,6 +350,9 @@ async fn run_instance( messages.push(message); } event::Event::RedrawRequested(_) => { + #[cfg(feature = "trace")] + let _ = info_span!("Application", "FRAME").entered(); + debug.render_started(); #[allow(unsafe_code)] -- cgit From 4b6d3797d43acb1d78a292a7ec712a0be7c8f6a2 Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Tue, 20 Dec 2022 20:41:09 -0800 Subject: Restructured everything to make profiling a feature of iced_winit. --- glutin/src/application.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'glutin/src') diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 21051f16..1464bb2d 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -17,8 +17,8 @@ use iced_winit::{Clipboard, Command, Debug, Proxy, Settings}; use glutin::window::Window; use std::mem::ManuallyDrop; -#[cfg(feature = "trace")] -use iced_profiling::{info_span, instrument::Instrument}; +#[cfg(feature = "tracing")] +use tracing::{info_span, instrument::Instrument}; /// Runs an [`Application`] with an executor, compositor, and the provided /// settings. @@ -39,12 +39,12 @@ where use glutin::ContextBuilder; #[cfg(feature = "trace")] - let _guard = iced_profiling::init(); + let _guard = iced_winit::Profiler::init(); let mut debug = Debug::new(); debug.startup_started(); - #[cfg(feature = "trace")] + #[cfg(feature = "tracing")] let _ = info_span!("Application::Glutin", "RUN").entered(); let mut event_loop = EventLoopBuilder::with_user_event().build(); @@ -147,7 +147,7 @@ where settings.exit_on_close_request, ); - #[cfg(feature = "trace")] + #[cfg(feature = "tracing")] let run_instance = run_instance.instrument(info_span!("Application", "LOOP")); @@ -350,7 +350,7 @@ async fn run_instance( messages.push(message); } event::Event::RedrawRequested(_) => { - #[cfg(feature = "trace")] + #[cfg(feature = "tracing")] let _ = info_span!("Application", "FRAME").entered(); debug.render_started(); -- cgit