mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 21:32:13 +03:00
instrument executor spawn delay
This commit is contained in:
parent
bc24399f06
commit
d8701dc771
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -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)",
|
||||
|
@ -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"
|
||||
|
@ -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<SpawnQueue> = Arc::new(SpawnQueue::new().expect("failed to create SpawnQueue"));
|
||||
}
|
||||
|
||||
struct InstrumentedSpawnFunc {
|
||||
func: SpawnFunc,
|
||||
at: Instant,
|
||||
}
|
||||
|
||||
pub(crate) struct SpawnQueue {
|
||||
spawned_funcs: Mutex<VecDeque<SpawnFunc>>,
|
||||
spawned_funcs_low_pri: Mutex<VecDeque<SpawnFunc>>,
|
||||
spawned_funcs: Mutex<VecDeque<InstrumentedSpawnFunc>>,
|
||||
spawned_funcs_low_pri: Mutex<VecDeque<InstrumentedSpawnFunc>>,
|
||||
|
||||
#[cfg(windows)]
|
||||
pub event_handle: EventHandle,
|
||||
@ -48,13 +54,21 @@ impl SpawnQueue {
|
||||
// returned function
|
||||
fn pop_func(&self) -> Option<SpawnFunc> {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user