1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 22:42:48 +03:00

improve some of our counters/stats

This commit is contained in:
Wez Furlong 2022-01-10 17:51:59 -07:00
parent aa648797ae
commit 0d18a40d60
3 changed files with 47 additions and 5 deletions

View File

@ -328,6 +328,7 @@ macro_rules! pdu {
let (data, is_compressed) = serialize(s)?; let (data, is_compressed) = serialize(s)?;
let encoded_size = encode_raw($vers, serial, &data, is_compressed, w)?; let encoded_size = encode_raw($vers, serial, &data, is_compressed, w)?;
metrics::histogram!("pdu.size", encoded_size as f64, "pdu" => stringify!($name)); metrics::histogram!("pdu.size", encoded_size as f64, "pdu" => stringify!($name));
metrics::histogram!("pdu.size.rate", encoded_size as f64, "pdu" => stringify!($name));
Ok(()) Ok(())
} }
,)* ,)*
@ -342,6 +343,7 @@ macro_rules! pdu {
let (data, is_compressed) = serialize(s)?; let (data, is_compressed) = serialize(s)?;
let encoded_size = encode_raw_async($vers, serial, &data, is_compressed, w).await?; let encoded_size = encode_raw_async($vers, serial, &data, is_compressed, w).await?;
metrics::histogram!("pdu.size", encoded_size as f64, "pdu" => stringify!($name)); metrics::histogram!("pdu.size", encoded_size as f64, "pdu" => stringify!($name));
metrics::histogram!("pdu.size.rate", encoded_size as f64, "pdu" => stringify!($name));
Ok(()) Ok(())
} }
,)* ,)*
@ -354,6 +356,7 @@ macro_rules! pdu {
$( $(
$vers => { $vers => {
metrics::histogram!("pdu.size", decoded.data.len() as f64, "pdu" => stringify!($name)); metrics::histogram!("pdu.size", decoded.data.len() as f64, "pdu" => stringify!($name));
metrics::histogram!("pdu.size.rate", decoded.data.len() as f64, "pdu" => stringify!($name));
Ok(DecodedPdu { Ok(DecodedPdu {
serial: decoded.serial, serial: decoded.serial,
pdu: Pdu::$name(deserialize(decoded.data.as_slice(), decoded.is_compressed)?) pdu: Pdu::$name(deserialize(decoded.data.as_slice(), decoded.is_compressed)?)
@ -362,6 +365,7 @@ macro_rules! pdu {
,)* ,)*
_ => { _ => {
metrics::histogram!("pdu.size", decoded.data.len() as f64, "pdu" => "??"); metrics::histogram!("pdu.size", decoded.data.len() as f64, "pdu" => "??");
metrics::histogram!("pdu.size.rate", decoded.data.len() as f64, "pdu" => "??");
Ok(DecodedPdu { Ok(DecodedPdu {
serial: decoded.serial, serial: decoded.serial,
pdu: Pdu::Invalid{ident:decoded.ident} pdu: Pdu::Invalid{ident:decoded.ident}

View File

@ -68,6 +68,7 @@ macro_rules! rpc {
let result = self.send_pdu(Pdu::$request_type(pdu)).await; let result = self.send_pdu(Pdu::$request_type(pdu)).await;
let elapsed = start.elapsed(); let elapsed = start.elapsed();
metrics::histogram!("rpc", elapsed, "method" => stringify!($method_name)); metrics::histogram!("rpc", elapsed, "method" => stringify!($method_name));
metrics::counter!("rpc.count", 1, "method" => stringify!($method_name));
match result { match result {
Ok(Pdu::$response_type(res)) => Ok(res), Ok(Pdu::$response_type(res)) => Ok(res),
Ok(_) => bail!("unexpected response {:?}", result), Ok(_) => bail!("unexpected response {:?}", result),
@ -86,6 +87,7 @@ macro_rules! rpc {
let result = self.send_pdu(Pdu::$request_type($request_type{})).await; let result = self.send_pdu(Pdu::$request_type($request_type{})).await;
let elapsed = start.elapsed(); let elapsed = start.elapsed();
metrics::histogram!("rpc", elapsed, "method" => stringify!($method_name)); metrics::histogram!("rpc", elapsed, "method" => stringify!($method_name));
metrics::counter!("rpc.count", 1, "method" => stringify!($method_name));
match result { match result {
Ok(Pdu::$response_type(res)) => Ok(res), Ok(Pdu::$response_type(res)) => Ok(res),
Ok(_) => bail!("unexpected response {:?}", result), Ok(_) => bail!("unexpected response {:?}", result),

View File

@ -38,6 +38,18 @@ impl Throughput {
}; };
self.count += value; self.count += value;
} }
fn current(&mut self) -> u64 {
if let Some(ref last) = self.last {
let elapsed = last.elapsed();
if elapsed > Duration::from_secs(1) {
self.hist.record(self.count).ok();
self.count = 0;
self.last = Some(Instant::now());
}
}
self.count
}
} }
fn pctile_latency(histogram: &Histogram<u64>, p: f64) -> Duration { fn pctile_latency(histogram: &Histogram<u64>, p: f64) -> Duration {
@ -47,6 +59,7 @@ fn pctile_latency(histogram: &Histogram<u64>, p: f64) -> Duration {
struct Inner { struct Inner {
histograms: HashMap<Key, Histogram<u64>>, histograms: HashMap<Key, Histogram<u64>>,
throughput: HashMap<Key, Throughput>, throughput: HashMap<Key, Throughput>,
counters: HashMap<Key, u64>,
} }
impl Inner { impl Inner {
@ -93,9 +106,20 @@ impl Inner {
alignment: Alignment::Left, alignment: Alignment::Left,
}, },
]; ];
let count_cols = vec![
Column {
name: "STAT".to_string(),
alignment: Alignment::Left,
},
Column {
name: "COUNT".to_string(),
alignment: Alignment::Left,
},
];
loop { loop {
std::thread::sleep(Duration::from_secs(10)); std::thread::sleep(Duration::from_secs(1));
if !ENABLE_STAT_PRINT.load(Ordering::Acquire) { if !ENABLE_STAT_PRINT.load(Ordering::Acquire) {
break; break;
} }
@ -107,9 +131,9 @@ impl Inner {
if last_print.elapsed() >= Duration::from_secs(seconds) { if last_print.elapsed() >= Duration::from_secs(seconds) {
let mut data = vec![]; let mut data = vec![];
let inner = inner.lock().unwrap(); let mut inner = inner.lock().unwrap();
for (key, tput) in &inner.throughput { for (key, tput) in &mut inner.throughput {
let current = tput.count; let current = tput.current();
let p50 = tput.hist.value_at_percentile(50.); let p50 = tput.hist.value_at_percentile(50.);
let p75 = tput.hist.value_at_percentile(75.); let p75 = tput.hist.value_at_percentile(75.);
let p95 = tput.hist.value_at_percentile(95.); let p95 = tput.hist.value_at_percentile(95.);
@ -152,6 +176,15 @@ impl Inner {
data.sort_by(|a, b| a[0].cmp(&b[0])); data.sort_by(|a, b| a[0].cmp(&b[0]));
eprintln!(); eprintln!();
tabulate_output(&cols, &data, &mut std::io::stderr().lock()).ok(); tabulate_output(&cols, &data, &mut std::io::stderr().lock()).ok();
data.clear();
for (key, count) in &inner.counters {
data.push(vec![key.to_string(), count.to_string()]);
}
data.sort_by(|a, b| a[0].cmp(&b[0]));
eprintln!();
tabulate_output(&count_cols, &data, &mut std::io::stderr().lock()).ok();
last_print = Instant::now(); last_print = Instant::now();
} }
} }
@ -168,6 +201,7 @@ impl Stats {
inner: Arc::new(Mutex::new(Inner { inner: Arc::new(Mutex::new(Inner {
histograms: HashMap::new(), histograms: HashMap::new(),
throughput: HashMap::new(), throughput: HashMap::new(),
counters: HashMap::new(),
})), })),
} }
} }
@ -202,7 +236,9 @@ impl Recorder for Stats {
} }
fn increment_counter(&self, key: &Key, value: u64) { fn increment_counter(&self, key: &Key, value: u64) {
log::trace!("counter '{}' -> {}", key, value); let mut inner = self.inner.lock().unwrap();
let counter = inner.counters.entry(key.clone()).or_insert_with(|| 0);
*counter = *counter + value;
} }
fn update_gauge(&self, key: &Key, value: GaugeValue) { fn update_gauge(&self, key: &Key, value: GaugeValue) {