Initial profiling support for Iced.

This commit is contained in:
Bingus 2022-11-29 19:50:58 -08:00 committed by Héctor Ramón Jiménez
parent ba20ac8e49
commit c5cd236b73
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
20 changed files with 357 additions and 35 deletions

View file

@ -24,6 +24,9 @@ pub use iced_native::application::{Appearance, StyleSheet};
use std::mem::ManuallyDrop;
#[cfg(feature = "trace")]
use iced_profiling::{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 +114,15 @@ where
use futures::Future;
use winit::event_loop::EventLoopBuilder;
#[cfg(feature = "trace")]
let _guard = iced_profiling::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 +184,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 +408,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 +549,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 +591,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(