instrument cache hit rates, fix duration histograms
This commit is contained in:
1 parent
aac2e78970
commit
b08a6ab5ef
7 files changed
+164
-14
No files matched your search
@@ -0,0 +1,45 @@
|
||||
pub struct LruCache<K, V> {
|
||||
hit: &'static str,
|
||||
miss: &'static str,
|
||||
cache: lru::LruCache<K, V>,
|
||||
}
|
||||
|
||||
impl<K: std::hash::Hash + std::cmp::Eq, V> LruCache<K, V> {
|
||||
pub fn new(hit: &'static str, miss: &'static str, cap: usize) -> Self {
|
||||
Self {
|
||||
hit,
|
||||
miss,
|
||||
cache: lru::LruCache::new(cap),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get<'a, Q: ?Sized>(&'a mut self, k: &Q) -> Option<&'a V>
|
||||
where
|
||||
lru::KeyRef<K>: std::borrow::Borrow<Q>,
|
||||
Q: std::hash::Hash + Eq,
|
||||
{
|
||||
let result = self.cache.get(k);
|
||||
metrics::histogram!(
|
||||
if result.is_some() {
|
||||
self.hit
|
||||
} else {
|
||||
self.miss
|
||||
},
|
||||
1.
|
||||
);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> std::ops::Deref for LruCache<K, V> {
|
||||
type Target = lru::LruCache<K, V>;
|
||||
fn deref(&self) -> &lru::LruCache<K, V> {
|
||||
&self.cache
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> std::ops::DerefMut for LruCache<K, V> {
|
||||
fn deref_mut(&mut self) -> &mut lru::LruCache<K, V> {
|
||||
&mut self.cache
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::utilsprites::RenderMetrics;
|
||||
use crate::cache::LruCache;
|
||||
use ::window::bitmaps::atlas::OutOfTextureSpace;
|
||||
use ::window::bitmaps::atlas::{Atlas, Sprite};
|
||||
#[cfg(test)]
|
||||
@@ -11,7 +12,6 @@ use ::window::glium::texture::SrgbTexture2d;
|
||||
use ::window::{Point, Rect};
|
||||
use config::{AllowSquareGlyphOverflow, TextStyle};
|
||||
use euclid::num::Zero;
|
||||
use lru::LruCache;
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Range;
|
||||
use std::rc::Rc;
|
||||
@@ -3830,7 +3830,11 @@ impl GlyphCache<ImageTexture> {
|
||||
Ok(Self {
|
||||
fonts: Rc::clone(fonts),
|
||||
glyph_cache: HashMap::new(),
|
||||
image_cache: LruCache::new(16),
|
||||
image_cache: LruCache::new(
|
||||
"glyph_cache.image_cache.hit.rate",
|
||||
"glyph_cache.image_cache.miss.rate",
|
||||
16,
|
||||
),
|
||||
frame_cache: HashMap::new(),
|
||||
atlas,
|
||||
metrics: metrics.clone(),
|
||||
@@ -3859,7 +3863,11 @@ impl GlyphCache<SrgbTexture2d> {
|
||||
Ok(Self {
|
||||
fonts: Rc::clone(fonts),
|
||||
glyph_cache: HashMap::new(),
|
||||
image_cache: LruCache::new(16),
|
||||
image_cache: LruCache::new(
|
||||
"glyph_cache.image_cache.hit.rate",
|
||||
"glyph_cache.image_cache.miss.rate",
|
||||
16,
|
||||
),
|
||||
frame_cache: HashMap::new(),
|
||||
atlas,
|
||||
metrics: metrics.clone(),
|
||||
@@ -3895,8 +3903,10 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
};
|
||||
|
||||
if let Some(entry) = self.glyph_cache.get(&key as &dyn GlyphKeyTrait) {
|
||||
metrics::histogram!("glyph_cache.glyph_cache.hit.rate", 1.);
|
||||
return Ok(Rc::clone(entry));
|
||||
}
|
||||
metrics::histogram!("glyph_cache.glyph_cache.miss.rate", 1.);
|
||||
|
||||
let glyph = match self.load_glyph(info, style, followed_by_space) {
|
||||
Ok(g) => g,
|
||||
|
||||
@@ -20,6 +20,7 @@ use wezterm_gui_subcommands::*;
|
||||
use wezterm_ssh::*;
|
||||
use wezterm_toast_notification::*;
|
||||
|
||||
mod cache;
|
||||
mod frontend;
|
||||
mod glyphcache;
|
||||
mod markdown;
|
||||
|
||||
@@ -9,18 +9,72 @@ use tabout::{tabulate_output, Alignment, Column};
|
||||
|
||||
static ENABLE_STAT_PRINT: AtomicBool = AtomicBool::new(true);
|
||||
|
||||
struct Inner {
|
||||
histograms: HashMap<Key, Histogram<u64>>,
|
||||
struct Throughput {
|
||||
hist: Histogram<u64>,
|
||||
last: Option<Instant>,
|
||||
count: u64,
|
||||
}
|
||||
|
||||
impl Throughput {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
hist: Histogram::new(2).expect("failed to create histogram"),
|
||||
last: None,
|
||||
count: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn add(&mut self, value: 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());
|
||||
}
|
||||
} else {
|
||||
// Start a new window
|
||||
self.last = Some(Instant::now());
|
||||
};
|
||||
self.count += value;
|
||||
}
|
||||
}
|
||||
|
||||
fn pctile_latency(histogram: &Histogram<u64>, p: f64) -> Duration {
|
||||
Duration::from_nanos(histogram.value_at_percentile(p))
|
||||
}
|
||||
|
||||
struct Inner {
|
||||
histograms: HashMap<Key, Histogram<u64>>,
|
||||
throughput: HashMap<Key, Throughput>,
|
||||
}
|
||||
|
||||
impl Inner {
|
||||
fn run(inner: Arc<Mutex<Inner>>) {
|
||||
let mut last_print = Instant::now();
|
||||
|
||||
let rate_cols = vec![
|
||||
Column {
|
||||
name: "STAT".to_string(),
|
||||
alignment: Alignment::Left,
|
||||
},
|
||||
Column {
|
||||
name: "current".to_string(),
|
||||
alignment: Alignment::Left,
|
||||
},
|
||||
Column {
|
||||
name: "p50".to_string(),
|
||||
alignment: Alignment::Left,
|
||||
},
|
||||
Column {
|
||||
name: "p75".to_string(),
|
||||
alignment: Alignment::Left,
|
||||
},
|
||||
Column {
|
||||
name: "p95".to_string(),
|
||||
alignment: Alignment::Left,
|
||||
},
|
||||
];
|
||||
let cols = vec![
|
||||
Column {
|
||||
name: "STAT".to_string(),
|
||||
@@ -51,8 +105,27 @@ impl Inner {
|
||||
continue;
|
||||
}
|
||||
if last_print.elapsed() >= Duration::from_secs(seconds) {
|
||||
let inner = inner.lock().unwrap();
|
||||
let mut data = vec![];
|
||||
|
||||
let inner = inner.lock().unwrap();
|
||||
for (key, tput) in &inner.throughput {
|
||||
let current = tput.count;
|
||||
let p50 = tput.hist.value_at_percentile(50.);
|
||||
let p75 = tput.hist.value_at_percentile(75.);
|
||||
let p95 = tput.hist.value_at_percentile(95.);
|
||||
data.push(vec![
|
||||
key.to_string(),
|
||||
format!("{:.2?}", current),
|
||||
format!("{:.2?}", p50),
|
||||
format!("{:.2?}", p75),
|
||||
format!("{:.2?}", p95),
|
||||
]);
|
||||
}
|
||||
data.sort_by(|a, b| a[0].cmp(&b[0]));
|
||||
eprintln!();
|
||||
tabulate_output(&rate_cols, &data, &mut std::io::stderr().lock()).ok();
|
||||
|
||||
data.clear();
|
||||
for (key, histogram) in &inner.histograms {
|
||||
if key.to_string().ends_with(".size") {
|
||||
let p50 = histogram.value_at_percentile(50.);
|
||||
@@ -94,6 +167,7 @@ impl Stats {
|
||||
Self {
|
||||
inner: Arc::new(Mutex::new(Inner {
|
||||
histograms: HashMap::new(),
|
||||
throughput: HashMap::new(),
|
||||
})),
|
||||
}
|
||||
}
|
||||
@@ -137,10 +211,24 @@ impl Recorder for Stats {
|
||||
|
||||
fn record_histogram(&self, key: &Key, value: f64) {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
let histogram = inner
|
||||
.histograms
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| Histogram::new(2).expect("failed to crate new Histogram"));
|
||||
histogram.record(value as u64).ok();
|
||||
if key.name().ends_with(".rate") {
|
||||
let tput = inner
|
||||
.throughput
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| Throughput::new());
|
||||
tput.add(value as u64);
|
||||
} else {
|
||||
let value = if key.name().ends_with(".size") {
|
||||
value
|
||||
} else {
|
||||
// Assume seconds; convert to nanoseconds
|
||||
value * 1_000_000_000.0
|
||||
};
|
||||
let histogram = inner
|
||||
.histograms
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| Histogram::new(2).expect("failed to crate new Histogram"));
|
||||
histogram.record(value as u64).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
use super::quad::*;
|
||||
use super::renderstate::*;
|
||||
use super::utilsprites::RenderMetrics;
|
||||
use crate::cache::LruCache;
|
||||
use crate::glium::texture::SrgbTexture2d;
|
||||
use crate::overlay::{
|
||||
confirm_close_pane, confirm_close_tab, confirm_close_window, confirm_quit_program, launcher,
|
||||
@@ -22,7 +23,6 @@ use config::keyassignment::{
|
||||
ClipboardCopyDestination, ClipboardPasteSource, InputMap, KeyAssignment, SpawnCommand,
|
||||
};
|
||||
use config::{configuration, ConfigHandle, WindowCloseConfirmation};
|
||||
use lru::LruCache;
|
||||
use luahelper::impl_lua_conversion;
|
||||
use mlua::FromLua;
|
||||
use mux::domain::{DomainId, DomainState};
|
||||
@@ -479,7 +479,11 @@ impl TermWindow {
|
||||
current_mouse_button: None,
|
||||
last_mouse_click: None,
|
||||
current_highlight: None,
|
||||
shape_cache: RefCell::new(LruCache::new(65536)),
|
||||
shape_cache: RefCell::new(LruCache::new(
|
||||
"shape_cache.hit.rate",
|
||||
"shape_cache.miss.rate",
|
||||
65536,
|
||||
)),
|
||||
last_blink_paint: Instant::now(),
|
||||
last_status_call: Instant::now(),
|
||||
event_states: HashMap::new(),
|
||||
@@ -836,6 +840,7 @@ impl TermWindow {
|
||||
}
|
||||
|
||||
fn mux_pane_output_event(&mut self, pane_id: PaneId) {
|
||||
metrics::histogram!("mux.pane_output_event.rate", 1.);
|
||||
if self.is_pane_visible(pane_id) {
|
||||
if let Some(ref win) = self.window {
|
||||
win.invalidate();
|
||||
|
||||
@@ -131,6 +131,7 @@ impl super::TermWindow {
|
||||
self.call_draw(frame).ok();
|
||||
log::debug!("paint_impl elapsed={:?}", start.elapsed());
|
||||
metrics::histogram!("gui.paint.opengl", start.elapsed());
|
||||
metrics::histogram!("gui.paint.opengl.rate", 1.);
|
||||
self.update_title_post_status();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::ICON_DATA;
|
||||
use std::convert::TryFrom;
|
||||
use anyhow::anyhow;
|
||||
use config::configuration;
|
||||
use config::wezterm_version;
|
||||
@@ -10,6 +9,7 @@ use portable_pty::PtySize;
|
||||
use regex::Regex;
|
||||
use serde::*;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
Reference in new issue
Block a user