From 566243ade559105be3ff553e8a772c9a0c81bfb9 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 10 Jul 2021 20:53:10 -0700 Subject: [PATCH] mux: add some metrics around reading from ptys --- Cargo.lock | 1 + mux/Cargo.toml | 1 + mux/src/lib.rs | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9de12f317..73f5934c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2499,6 +2499,7 @@ dependencies = [ "libc", "log", "luahelper", + "metrics", "portable-pty", "promise", "rangeset", diff --git a/mux/Cargo.toml b/mux/Cargo.toml index cad5567ff..b001297ac 100644 --- a/mux/Cargo.toml +++ b/mux/Cargo.toml @@ -19,6 +19,7 @@ lazy_static = "1.4" libc = "0.2" log = "0.4" luahelper = { path = "../luahelper" } +metrics = { version="0.16", features=["std"]} portable-pty = { path = "../pty", features = ["serde_support"]} promise = { path = "../promise" } rangeset = { path = "../rangeset" } diff --git a/mux/src/lib.rs b/mux/src/lib.rs index e3a7067e3..d103596c5 100644 --- a/mux/src/lib.rs +++ b/mux/src/lib.rs @@ -5,6 +5,7 @@ use anyhow::{anyhow, Error}; use config::{configuration, ExitBehavior}; use domain::{Domain, DomainId}; use log::error; +use metrics::histogram; use portable_pty::ExitStatus; use std::cell::{Ref, RefCell, RefMut}; use std::collections::HashMap; @@ -13,9 +14,8 @@ use std::io::Read; use std::rc::Rc; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::{Arc, Condvar, Mutex}; -use std::time::Duration; - use std::thread; +use std::time::{Duration, Instant}; use termwiz::escape::Action; use thiserror::*; @@ -66,12 +66,18 @@ pub struct Mux { /// It blocks until the mux has finished consuming the data, which provides /// some back-pressure so that eg: ctrl-c can remain responsive. fn send_actions_to_mux(pane_id: PaneId, dead: &Arc, actions: Vec) { + let start = Instant::now(); promise::spawn::block_on(promise::spawn::spawn_into_main_thread({ let dead = Arc::clone(&dead); async move { let mux = Mux::get().unwrap(); if let Some(pane) = mux.get_pane(pane_id) { + let start = Instant::now(); pane.perform_actions(actions); + histogram!( + "send_actions_to_mux.perform_actions.latency", + start.elapsed() + ); mux.notify(MuxNotification::PaneOutput(pane_id)); } else { // Something else removed the pane from @@ -81,6 +87,8 @@ fn send_actions_to_mux(pane_id: PaneId, dead: &Arc, actions: Vec, mut reader: Box { + histogram!("read_from_pane_pty.bytes.rate", size as f64); state.write(&buf[..size]); } }