diff options
Diffstat (limited to 'winit/src/application.rs')
-rw-r--r-- | winit/src/application.rs | 83 |
1 files changed, 65 insertions, 18 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs index 0f9b562e..74c73815 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -1,4 +1,6 @@ //! Create interactive, native cross-platform applications. +#[cfg(feature = "trace")] +mod profiler; mod state; pub use state::State; @@ -24,6 +26,11 @@ pub use iced_native::application::{Appearance, StyleSheet}; use std::mem::ManuallyDrop; +#[cfg(feature = "trace")] +pub use profiler::Profiler; +#[cfg(feature = "trace")] +use tracing::{info_span, instrument::Instrument}; + /// An interactive, native cross-platform application. /// /// This trait is the main entrypoint of Iced. Once implemented, you can run @@ -111,9 +118,15 @@ where use futures::Future; use winit::event_loop::EventLoopBuilder; + #[cfg(feature = "trace")] + let _guard = Profiler::init(); + let mut debug = Debug::new(); debug.startup_started(); + #[cfg(feature = "trace")] + let _ = info_span!("Application", "RUN").entered(); + let event_loop = EventLoopBuilder::with_user_event().build(); let proxy = event_loop.create_proxy(); @@ -175,18 +188,26 @@ where let (mut sender, receiver) = mpsc::unbounded(); - let mut instance = Box::pin(run_instance::<A, E, C>( - application, - compositor, - renderer, - runtime, - proxy, - debug, - receiver, - init_command, - window, - settings.exit_on_close_request, - )); + let mut instance = Box::pin({ + let run_instance = run_instance::<A, E, C>( + application, + compositor, + renderer, + runtime, + proxy, + debug, + receiver, + init_command, + window, + 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()); @@ -391,6 +412,9 @@ async fn run_instance<A, E, C>( messages.push(message); } event::Event::RedrawRequested(_) => { + #[cfg(feature = "trace")] + let _ = info_span!("Application", "FRAME").entered(); + let physical_size = state.physical_size(); if physical_size.width == 0 || physical_size.height == 0 { @@ -529,12 +553,24 @@ pub fn build_user_interface<'a, A: Application>( where <A::Renderer as crate::Renderer>::Theme: StyleSheet, { + #[cfg(feature = "trace")] + let view_span = info_span!("Application", "VIEW").entered(); + debug.view_started(); let view = application.view(); + + #[cfg(feature = "trace")] + let _ = view_span.exit(); debug.view_finished(); + #[cfg(feature = "trace")] + let layout_span = info_span!("Application", "LAYOUT").entered(); + debug.layout_started(); let user_interface = UserInterface::build(view, size, cache, renderer); + + #[cfg(feature = "trace")] + let _ = layout_span.exit(); debug.layout_finished(); user_interface @@ -559,10 +595,16 @@ pub fn update<A: Application, E: Executor>( <A::Renderer as crate::Renderer>::Theme: StyleSheet, { for message in messages.drain(..) { + #[cfg(feature = "trace")] + let update_span = info_span!("Application", "UPDATE").entered(); + debug.log_message(&message); debug.update_started(); let command = runtime.enter(|| application.update(message)); + + #[cfg(feature = "trace")] + let _ = update_span.exit(); debug.update_finished(); run_command( @@ -657,12 +699,6 @@ pub fn run_command<A, E>( mode, )); } - window::Action::ToggleMaximize => { - window.set_maximized(!window.is_maximized()) - } - window::Action::ToggleDecorations => { - window.set_decorations(!window.is_decorated()) - } window::Action::FetchMode(tag) => { let mode = if window.is_visible().unwrap_or(true) { conversion::mode(window.fullscreen()) @@ -674,6 +710,17 @@ pub fn run_command<A, E>( .send_event(tag(mode)) .expect("Send message to event loop"); } + window::Action::ToggleMaximize => { + window.set_maximized(!window.is_maximized()) + } + window::Action::ToggleDecorations => { + window.set_decorations(!window.is_decorated()) + } + window::Action::RequestUserAttention(user_attention) => window + .request_user_attention( + user_attention.map(conversion::user_attention), + ), + window::Action::GainFocus => window.focus_window(), }, command::Action::System(action) => match action { system::Action::QueryInformation(_tag) => { |