diff --git a/Cargo.lock b/Cargo.lock index 85c36a676..541d4313c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2884,6 +2884,7 @@ dependencies = [ "line_drawing 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "metrics 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", "mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/window/Cargo.toml b/window/Cargo.toml index 665a405dd..bb25b339c 100644 --- a/window/Cargo.toml +++ b/window/Cargo.toml @@ -23,6 +23,7 @@ lazy_static = "1.3" libloading = { version = "0.5", optional=true } line_drawing = "0.8" log = "0.4" +metrics = { version="0.12", features=["std"]} palette = "0.4" promise = { path = "../promise" } resize = "0.3" diff --git a/window/src/spawn.rs b/window/src/spawn.rs index 90edb4397..9edee141e 100644 --- a/window/src/spawn.rs +++ b/window/src/spawn.rs @@ -5,6 +5,7 @@ use core_foundation::runloop::*; use promise::{BasicExecutor, SpawnFunc}; use std::collections::VecDeque; use std::sync::{Arc, Mutex}; +use std::time::Instant; #[cfg(all(unix, not(target_os = "macos")))] use { filedescriptor::{FileDescriptor, Pipe}, @@ -17,9 +18,14 @@ lazy_static::lazy_static! { pub(crate) static ref SPAWN_QUEUE: Arc = Arc::new(SpawnQueue::new().expect("failed to create SpawnQueue")); } +struct InstrumentedSpawnFunc { + func: SpawnFunc, + at: Instant, +} + pub(crate) struct SpawnQueue { - spawned_funcs: Mutex>, - spawned_funcs_low_pri: Mutex>, + spawned_funcs: Mutex>, + spawned_funcs_low_pri: Mutex>, #[cfg(windows)] pub event_handle: EventHandle, @@ -48,13 +54,21 @@ impl SpawnQueue { // returned function fn pop_func(&self) -> Option { if let Some(func) = self.spawned_funcs.lock().unwrap().pop_front() { - Some(func) + metrics::value!("executor.spawn_delay", func.at.elapsed()); + Some(func.func) + } else if let Some(func) = self.spawned_funcs_low_pri.lock().unwrap().pop_front() { + metrics::value!("executor.spawn_delay.low_pri", func.at.elapsed()); + Some(func.func) } else { - self.spawned_funcs_low_pri.lock().unwrap().pop_front() + None } } fn queue_func(&self, f: SpawnFunc, high_pri: bool) { + let f = InstrumentedSpawnFunc { + func: f, + at: Instant::now(), + }; if high_pri { self.spawned_funcs.lock().unwrap() } else {