1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 21:32:13 +03:00

mux: add some metrics around reading from ptys

This commit is contained in:
Wez Furlong 2021-07-10 20:53:10 -07:00
parent 77c5acaaf5
commit 566243ade5
3 changed files with 15 additions and 2 deletions

1
Cargo.lock generated
View File

@ -2499,6 +2499,7 @@ dependencies = [
"libc", "libc",
"log", "log",
"luahelper", "luahelper",
"metrics",
"portable-pty", "portable-pty",
"promise", "promise",
"rangeset", "rangeset",

View File

@ -19,6 +19,7 @@ lazy_static = "1.4"
libc = "0.2" libc = "0.2"
log = "0.4" log = "0.4"
luahelper = { path = "../luahelper" } luahelper = { path = "../luahelper" }
metrics = { version="0.16", features=["std"]}
portable-pty = { path = "../pty", features = ["serde_support"]} portable-pty = { path = "../pty", features = ["serde_support"]}
promise = { path = "../promise" } promise = { path = "../promise" }
rangeset = { path = "../rangeset" } rangeset = { path = "../rangeset" }

View File

@ -5,6 +5,7 @@ use anyhow::{anyhow, Error};
use config::{configuration, ExitBehavior}; use config::{configuration, ExitBehavior};
use domain::{Domain, DomainId}; use domain::{Domain, DomainId};
use log::error; use log::error;
use metrics::histogram;
use portable_pty::ExitStatus; use portable_pty::ExitStatus;
use std::cell::{Ref, RefCell, RefMut}; use std::cell::{Ref, RefCell, RefMut};
use std::collections::HashMap; use std::collections::HashMap;
@ -13,9 +14,8 @@ use std::io::Read;
use std::rc::Rc; use std::rc::Rc;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::{Arc, Condvar, Mutex}; use std::sync::{Arc, Condvar, Mutex};
use std::time::Duration;
use std::thread; use std::thread;
use std::time::{Duration, Instant};
use termwiz::escape::Action; use termwiz::escape::Action;
use thiserror::*; use thiserror::*;
@ -66,12 +66,18 @@ pub struct Mux {
/// It blocks until the mux has finished consuming the data, which provides /// It blocks until the mux has finished consuming the data, which provides
/// some back-pressure so that eg: ctrl-c can remain responsive. /// some back-pressure so that eg: ctrl-c can remain responsive.
fn send_actions_to_mux(pane_id: PaneId, dead: &Arc<AtomicBool>, actions: Vec<Action>) { fn send_actions_to_mux(pane_id: PaneId, dead: &Arc<AtomicBool>, actions: Vec<Action>) {
let start = Instant::now();
promise::spawn::block_on(promise::spawn::spawn_into_main_thread({ promise::spawn::block_on(promise::spawn::spawn_into_main_thread({
let dead = Arc::clone(&dead); let dead = Arc::clone(&dead);
async move { async move {
let mux = Mux::get().unwrap(); let mux = Mux::get().unwrap();
if let Some(pane) = mux.get_pane(pane_id) { if let Some(pane) = mux.get_pane(pane_id) {
let start = Instant::now();
pane.perform_actions(actions); pane.perform_actions(actions);
histogram!(
"send_actions_to_mux.perform_actions.latency",
start.elapsed()
);
mux.notify(MuxNotification::PaneOutput(pane_id)); mux.notify(MuxNotification::PaneOutput(pane_id));
} else { } else {
// Something else removed the pane from // Something else removed the pane from
@ -81,6 +87,8 @@ fn send_actions_to_mux(pane_id: PaneId, dead: &Arc<AtomicBool>, actions: Vec<Act
} }
} }
})); }));
histogram!("send_actions_to_mux.latency", start.elapsed());
histogram!("send_actions_to_mux.rate", 1.);
} }
struct BufState { struct BufState {
@ -91,8 +99,10 @@ struct BufState {
impl BufState { impl BufState {
fn write(&self, buf: &[u8]) { fn write(&self, buf: &[u8]) {
let start = Instant::now();
let mut queue = self.queue.lock().unwrap(); let mut queue = self.queue.lock().unwrap();
queue.extend(buf); queue.extend(buf);
histogram!("read_from_pane_pty.BufState.extend", start.elapsed());
self.cond.notify_one(); self.cond.notify_one();
} }
} }
@ -179,6 +189,7 @@ fn read_from_pane_pty(pane_id: PaneId, banner: Option<String>, mut reader: Box<d
break; break;
} }
Ok(size) => { Ok(size) => {
histogram!("read_from_pane_pty.bytes.rate", size as f64);
state.write(&buf[..size]); state.write(&buf[..size]);
} }
} }