Added tracing to multi_window applications
This commit is contained in:
parent
f78ccd9af9
commit
790fa3e7a0
7 changed files with 94 additions and 36 deletions
|
|
@ -11,7 +11,7 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"]
|
||||||
categories = ["gui"]
|
categories = ["gui"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
trace = ["iced_winit/trace"]
|
trace = ["iced_winit/trace", "tracing"]
|
||||||
debug = ["iced_winit/debug"]
|
debug = ["iced_winit/debug"]
|
||||||
system = ["iced_winit/system"]
|
system = ["iced_winit/system"]
|
||||||
multi_window = ["iced_winit/multi_window"]
|
multi_window = ["iced_winit/multi_window"]
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ use std::ffi::CString;
|
||||||
use std::mem::ManuallyDrop;
|
use std::mem::ManuallyDrop;
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
|
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "trace")]
|
||||||
use tracing::{info_span, instrument::Instrument};
|
use tracing::{info_span, instrument::Instrument};
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
|
@ -62,7 +62,7 @@ where
|
||||||
let mut debug = Debug::new();
|
let mut debug = Debug::new();
|
||||||
debug.startup_started();
|
debug.startup_started();
|
||||||
|
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "trace")]
|
||||||
let _ = info_span!("Application::Glutin", "RUN").entered();
|
let _ = info_span!("Application::Glutin", "RUN").entered();
|
||||||
|
|
||||||
let mut event_loop = EventLoopBuilder::with_user_event().build();
|
let mut event_loop = EventLoopBuilder::with_user_event().build();
|
||||||
|
|
@ -298,7 +298,7 @@ where
|
||||||
settings.exit_on_close_request,
|
settings.exit_on_close_request,
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "trace")]
|
||||||
let run_instance =
|
let run_instance =
|
||||||
run_instance.instrument(info_span!("Application", "LOOP"));
|
run_instance.instrument(info_span!("Application", "LOOP"));
|
||||||
|
|
||||||
|
|
@ -509,7 +509,7 @@ async fn run_instance<A, E, C>(
|
||||||
messages.push(message);
|
messages.push(message);
|
||||||
}
|
}
|
||||||
event::Event::RedrawRequested(_) => {
|
event::Event::RedrawRequested(_) => {
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "trace")]
|
||||||
let _ = info_span!("Application", "FRAME").entered();
|
let _ = info_span!("Application", "FRAME").entered();
|
||||||
|
|
||||||
debug.render_started();
|
debug.render_started();
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,9 @@ use std::ffi::CString;
|
||||||
use std::mem::ManuallyDrop;
|
use std::mem::ManuallyDrop;
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
|
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
|
use tracing::{info_span, instrument::Instrument};
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
const ONE: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(1) };
|
const ONE: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(1) };
|
||||||
|
|
||||||
|
|
@ -52,9 +55,15 @@ where
|
||||||
use winit::event_loop::EventLoopBuilder;
|
use winit::event_loop::EventLoopBuilder;
|
||||||
use winit::platform::run_return::EventLoopExtRunReturn;
|
use winit::platform::run_return::EventLoopExtRunReturn;
|
||||||
|
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let _guard = iced_winit::Profiler::init();
|
||||||
|
|
||||||
let mut debug = Debug::new();
|
let mut debug = Debug::new();
|
||||||
debug.startup_started();
|
debug.startup_started();
|
||||||
|
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
|
let _ = info_span!("Application::Glutin", "RUN").entered();
|
||||||
|
|
||||||
let mut event_loop = EventLoopBuilder::with_user_event().build();
|
let mut event_loop = EventLoopBuilder::with_user_event().build();
|
||||||
let proxy = event_loop.create_proxy();
|
let proxy = event_loop.create_proxy();
|
||||||
|
|
||||||
|
|
@ -267,21 +276,29 @@ where
|
||||||
|
|
||||||
let (mut sender, receiver) = mpsc::unbounded();
|
let (mut sender, receiver) = mpsc::unbounded();
|
||||||
|
|
||||||
let mut instance = Box::pin(run_instance::<A, E, C>(
|
let mut instance = Box::pin({
|
||||||
application,
|
let run_instance = run_instance::<A, E, C>(
|
||||||
compositor,
|
application,
|
||||||
renderer,
|
compositor,
|
||||||
runtime,
|
renderer,
|
||||||
proxy,
|
runtime,
|
||||||
debug,
|
proxy,
|
||||||
receiver,
|
debug,
|
||||||
display,
|
receiver,
|
||||||
windows,
|
display,
|
||||||
configuration,
|
windows,
|
||||||
context,
|
configuration,
|
||||||
init_command,
|
context,
|
||||||
settings.exit_on_close_request,
|
init_command,
|
||||||
));
|
settings.exit_on_close_request,
|
||||||
|
);
|
||||||
|
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
|
let run_instance =
|
||||||
|
run_instance.instrument(info_span!("Application", "LOOP"));
|
||||||
|
|
||||||
|
run_instance
|
||||||
|
});
|
||||||
|
|
||||||
let mut context = task::Context::from_waker(task::noop_waker_ref());
|
let mut context = task::Context::from_waker(task::noop_waker_ref());
|
||||||
|
|
||||||
|
|
@ -619,6 +636,9 @@ async fn run_instance<A, E, C>(
|
||||||
Event::NewWindow { .. } => unreachable!(),
|
Event::NewWindow { .. } => unreachable!(),
|
||||||
},
|
},
|
||||||
event::Event::RedrawRequested(id) => {
|
event::Event::RedrawRequested(id) => {
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
|
let _ = info_span!("Application", "FRAME").entered();
|
||||||
|
|
||||||
let state = window_ids
|
let state = window_ids
|
||||||
.get(&id)
|
.get(&id)
|
||||||
.and_then(|id| states.get_mut(id))
|
.and_then(|id| states.get_mut(id))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
//! Create interactive, native cross-platform applications.
|
//! Create interactive, native cross-platform applications.
|
||||||
#[cfg(feature = "trace")]
|
|
||||||
mod profiler;
|
|
||||||
mod state;
|
mod state;
|
||||||
|
|
||||||
pub use state::State;
|
pub use state::State;
|
||||||
|
|
@ -27,7 +25,7 @@ pub use iced_native::application::{Appearance, StyleSheet};
|
||||||
use std::mem::ManuallyDrop;
|
use std::mem::ManuallyDrop;
|
||||||
|
|
||||||
#[cfg(feature = "trace")]
|
#[cfg(feature = "trace")]
|
||||||
pub use profiler::Profiler;
|
pub use crate::Profiler;
|
||||||
#[cfg(feature = "trace")]
|
#[cfg(feature = "trace")]
|
||||||
use tracing::{info_span, instrument::Instrument};
|
use tracing::{info_span, instrument::Instrument};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,11 +51,13 @@ pub mod system;
|
||||||
mod error;
|
mod error;
|
||||||
mod icon;
|
mod icon;
|
||||||
mod proxy;
|
mod proxy;
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
mod profiler;
|
||||||
|
|
||||||
#[cfg(feature = "application")]
|
#[cfg(feature = "application")]
|
||||||
pub use application::Application;
|
pub use application::Application;
|
||||||
#[cfg(feature = "trace")]
|
#[cfg(feature = "trace")]
|
||||||
pub use application::Profiler;
|
pub use profiler::Profiler;
|
||||||
pub use clipboard::Clipboard;
|
pub use clipboard::Clipboard;
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
pub use icon::Icon;
|
pub use icon::Icon;
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,11 @@ use iced_native::window::Action;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::mem::ManuallyDrop;
|
use std::mem::ManuallyDrop;
|
||||||
|
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
pub use crate::Profiler;
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
use tracing::{info_span, instrument::Instrument};
|
||||||
|
|
||||||
/// TODO(derezzedex)
|
/// TODO(derezzedex)
|
||||||
// This is the an wrapper around the `Application::Message` associate type
|
// This is the an wrapper around the `Application::Message` associate type
|
||||||
// to allows the `shell` to create internal messages, while still having
|
// to allows the `shell` to create internal messages, while still having
|
||||||
|
|
@ -172,9 +177,15 @@ where
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use winit::event_loop::EventLoopBuilder;
|
use winit::event_loop::EventLoopBuilder;
|
||||||
|
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let _guard = Profiler::init();
|
||||||
|
|
||||||
let mut debug = Debug::new();
|
let mut debug = Debug::new();
|
||||||
debug.startup_started();
|
debug.startup_started();
|
||||||
|
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let _ = info_span!("Application", "RUN").entered();
|
||||||
|
|
||||||
let event_loop = EventLoopBuilder::with_user_event().build();
|
let event_loop = EventLoopBuilder::with_user_event().build();
|
||||||
let proxy = event_loop.create_proxy();
|
let proxy = event_loop.create_proxy();
|
||||||
|
|
||||||
|
|
@ -227,18 +238,26 @@ where
|
||||||
|
|
||||||
let (mut sender, receiver) = mpsc::unbounded();
|
let (mut sender, receiver) = mpsc::unbounded();
|
||||||
|
|
||||||
let mut instance = Box::pin(run_instance::<A, E, C>(
|
let mut instance = Box::pin({
|
||||||
application,
|
let run_instance = run_instance::<A, E, C>(
|
||||||
compositor,
|
application,
|
||||||
renderer,
|
compositor,
|
||||||
runtime,
|
renderer,
|
||||||
proxy,
|
runtime,
|
||||||
debug,
|
proxy,
|
||||||
receiver,
|
debug,
|
||||||
init_command,
|
receiver,
|
||||||
windows,
|
init_command,
|
||||||
settings.exit_on_close_request,
|
windows,
|
||||||
));
|
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());
|
let mut context = task::Context::from_waker(task::noop_waker_ref());
|
||||||
|
|
||||||
|
|
@ -604,6 +623,9 @@ async fn run_instance<A, E, C>(
|
||||||
Event::NewWindow { .. } => unreachable!(),
|
Event::NewWindow { .. } => unreachable!(),
|
||||||
},
|
},
|
||||||
event::Event::RedrawRequested(id) => {
|
event::Event::RedrawRequested(id) => {
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let _ = info_span!("Application", "FRAME").entered();
|
||||||
|
|
||||||
let state = window_ids
|
let state = window_ids
|
||||||
.get(&id)
|
.get(&id)
|
||||||
.and_then(|id| states.get_mut(id))
|
.and_then(|id| states.get_mut(id))
|
||||||
|
|
@ -788,12 +810,22 @@ pub fn build_user_interface<'a, A: Application>(
|
||||||
where
|
where
|
||||||
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
|
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let view_span = info_span!("Application", "VIEW").entered();
|
||||||
|
|
||||||
debug.view_started();
|
debug.view_started();
|
||||||
let view = application.view(id);
|
let view = application.view(id);
|
||||||
|
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let _ = view_span.exit();
|
||||||
debug.view_finished();
|
debug.view_finished();
|
||||||
|
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let layout_span = info_span!("Application", "LAYOUT").entered();
|
||||||
debug.layout_started();
|
debug.layout_started();
|
||||||
let user_interface = UserInterface::build(view, size, cache, renderer);
|
let user_interface = UserInterface::build(view, size, cache, renderer);
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let _ = layout_span.exit();
|
||||||
debug.layout_finished();
|
debug.layout_finished();
|
||||||
|
|
||||||
user_interface
|
user_interface
|
||||||
|
|
@ -817,10 +849,15 @@ pub fn update<A: Application, E: Executor>(
|
||||||
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
|
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
for message in messages.drain(..) {
|
for message in messages.drain(..) {
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let update_span = info_span!("Application", "UPDATE").entered();
|
||||||
|
|
||||||
debug.log_message(&message);
|
debug.log_message(&message);
|
||||||
|
|
||||||
debug.update_started();
|
debug.update_started();
|
||||||
let command = runtime.enter(|| application.update(message));
|
let command = runtime.enter(|| application.update(message));
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let _ = update_span.exit();
|
||||||
debug.update_finished();
|
debug.update_finished();
|
||||||
|
|
||||||
run_command(
|
run_command(
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ pub struct Profiler {
|
||||||
impl Profiler {
|
impl Profiler {
|
||||||
/// Initializes the [`Profiler`].
|
/// Initializes the [`Profiler`].
|
||||||
pub fn init() -> Self {
|
pub fn init() -> Self {
|
||||||
|
log::info!("Capturing trace..");
|
||||||
// Registry stores the spans & generates unique span IDs
|
// Registry stores the spans & generates unique span IDs
|
||||||
let subscriber = Registry::default();
|
let subscriber = Registry::default();
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue