summaryrefslogtreecommitdiffstats
path: root/winit
diff options
context:
space:
mode:
authorLibravatar Bingus <shankern@protonmail.com>2022-11-29 19:50:58 -0800
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-01-09 18:52:38 +0100
commitc5cd236b7380c3689792934aeaecd2942713fa67 (patch)
treec27a0e6ecfdec7936791ee70e07ce19c713095cd /winit
parentba20ac8e49aedfa9d822d71784587d0635cec4f8 (diff)
downloadiced-c5cd236b7380c3689792934aeaecd2942713fa67.tar.gz
iced-c5cd236b7380c3689792934aeaecd2942713fa67.tar.bz2
iced-c5cd236b7380c3689792934aeaecd2942713fa67.zip
Initial profiling support for Iced.
Diffstat (limited to 'winit')
-rw-r--r--winit/Cargo.toml6
-rw-r--r--winit/src/application.rs62
2 files changed, 56 insertions, 12 deletions
diff --git a/winit/Cargo.toml b/winit/Cargo.toml
index ebbadb12..22b40f70 100644
--- a/winit/Cargo.toml
+++ b/winit/Cargo.toml
@@ -11,6 +11,7 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"]
categories = ["gui"]
[features]
+trace = ["iced_profiling"]
debug = ["iced_native/debug"]
system = ["sysinfo"]
application = []
@@ -37,6 +38,11 @@ path = "../graphics"
version = "0.5"
path = "../futures"
+[dependencies.iced_profiling]
+version = "0.1.0"
+path = "../profiling"
+optional = true
+
[target.'cfg(target_os = "windows")'.dependencies.winapi]
version = "0.3.6"
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 1973fdce..fc73db89 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -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(