Dashboard page: fit the page, five shares, build-time histograms

- Built is the miss count, as sccache counts timeouts, cache errors and
  forced recaches inside it. The bar under the headline has five shares
  that add up to every compiler call and always to 100%; what happened
  inside the built share is one line under the bar.
- The time saved shows its 90% range in small print under the figure.
- Speed gains "How long builds take, by language": one fixed-height
  histogram per language on a shared log scale of build time, with the
  mean, median and p90 marked.
- The api crate's Range helpers replace the page's own copies.
- Drawing is built only for the browser, so the tests (and the rest of
  the crate) build anywhere without eframe's native backends.
- Tables are drawn row by row; egui's Grid lost its rows when a cell
  held more than a plain widget. Fold-away bodies are held to the width
  of the page, and the charts fit their data every frame.
- mise.toml takes trunk 0.22.2 as a release binary; building it from
  source took over half an hour.
This commit is contained in:
swaits committed 2026-11-28 12:10:01 -07:00
1 parent c589b7c868
commit dc876b5a5c
13 files changed
+549 -361

No files matched your search

+22 -150
View File
@@ -8,15 +8,6 @@ use sccache_dash_api::{Range, View};
use crate::fmt;
use crate::{cards, extras, net, overtime, problems, raw, speed, style, where_went};
/// The ranges, in the order the buttons show them.
const RANGES: [Range; 5] = [
Range::Hour,
Range::Day,
Range::Week,
Range::Month,
Range::SinceReset,
];
/// Refresh intervals offered, in seconds; zero means off.
const REFRESH_CHOICES: [u64; 4] = [0, 5, 10, 30];
@@ -69,8 +60,6 @@ pub struct Dashboard {
sent_at: Option<f64>,
/// Languages unticked in the "Over time" filter.
hidden_languages: Vec<String>,
/// Set when the charts should forget their zoom and fit the data again.
refit_charts: bool,
/// Whether the "Zero stats" question is open.
asking_zero: bool,
/// A short message for the controls row, and the page time it goes away.
@@ -91,7 +80,6 @@ impl Dashboard {
error: None,
sent_at: None,
hidden_languages: Vec::new(),
refit_charts: false,
asking_zero: false,
note: None,
settings_changed: false,
@@ -202,13 +190,12 @@ impl eframe::App for Dashboard {
view,
error,
hidden_languages,
refit_charts,
..
} = self;
match view {
None => waiting(ui, error.as_deref(), self.refresh_secs),
Some(view) => {
page(ui, view, *range, error.as_deref(), hidden_languages, refit_charts)
page(ui, view, *range, error.as_deref(), hidden_languages)
}
}
});
@@ -252,17 +239,16 @@ fn controls(dashboard: &mut Dashboard, ui: &mut egui::Ui) {
egui::Panel::top("controls").show(ui, |ui| {
ui.add_space(6.0);
ui.horizontal_wrapped(|ui| {
for range in RANGES {
for range in Range::ALL {
if ui
.add(egui::Button::selectable(
dashboard.range == range,
fmt::range_code(range),
range.code(),
))
.clicked()
{
dashboard.range = range;
dashboard.settings_changed = true;
dashboard.refit_charts = true;
dashboard.send(&ctx, Ask::View);
}
}
@@ -399,7 +385,7 @@ fn waiting(ui: &mut egui::Ui, error: Option<&str>, refresh_secs: u64) {
};
// The same height the headline and cards take, so the page doesn't jump when they arrive.
ui.allocate_ui_with_layout(
egui::vec2(ui.available_width(), 250.0),
egui::vec2(ui.available_rect_before_wrap().width(), 250.0),
egui::Layout::centered_and_justified(egui::Direction::TopDown),
|ui| {
ui.vertical(|ui| {
@@ -417,7 +403,6 @@ fn page(
asked: Range,
error: Option<&str>,
hidden_languages: &mut Vec<String>,
refit_charts: &mut bool,
) {
let dark = ui.visuals().dark_mode;
let [_, _, bad] = style::marks(dark);
@@ -437,7 +422,7 @@ fn page(
cards::row(ui, view, dark);
problems::section(ui, view, dark);
where_went::section(ui, view, dark);
overtime::section(ui, view, hidden_languages, refit_charts, dark);
overtime::section(ui, view, hidden_languages, dark);
speed::section(ui, view);
extras::section(ui, view);
raw::section(ui, view);
@@ -451,6 +436,8 @@ struct Figure<'a> {
caption: String,
/// Smaller print under the figure.
small: String,
/// A second line of smaller print, kept so the block's height never changes.
small2: String,
/// A trend line and the value it is drawn against.
trend: Option<(&'a [Option<f64>], f64)>,
hover: Option<String>,
@@ -475,6 +462,7 @@ impl Figure<'_> {
None => ui.add_space(TREND_HEIGHT + gap),
}
ui.add(egui::Label::new(egui::RichText::new(&self.small).small().weak()).truncate());
ui.add(egui::Label::new(egui::RichText::new(&self.small2).small().weak()).truncate());
},
);
if let Some(hover) = self.hover {
@@ -484,7 +472,7 @@ impl Figure<'_> {
}
const TREND_HEIGHT: f32 = 22.0;
const FIGURE_HEIGHT: f32 = 104.0;
const FIGURE_HEIGHT: f32 = 120.0;
/// The big numbers, what they mean, and where the cache lives.
fn headline(ui: &mut egui::Ui, view: &View, asked: Range, dark: bool) {
@@ -512,9 +500,9 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range, dark: bool) {
None => text_color,
};
ui.label(egui::RichText::new(fmt::range_title(range)).strong());
ui.label(egui::RichText::new(range.label().to_uppercase()).strong());
let width = ui.available_width();
let width = ui.available_rect_before_wrap().width();
let spacing = ui.spacing().item_spacing.x;
// Side by side where there is room; one under another on a phone.
let columns = if width >= 600.0 { 3.0 } else { 1.0 };
@@ -527,14 +515,21 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range, dark: bool) {
small: format!("{} of all compiler calls", fmt::percent(totals.hit_rate_of_all())),
trend: Some((&rates, 1.0)),
hover: None,
small2: String::new(),
}
.draw(ui, column);
let left_out = view.time_saved.hits_left_out;
// The 90% range goes first; the hits left out are the line under it.
let interval = view
.time_saved
.interval_90
.map(|(low, high)| format!("{} – {} (90% range)", fmt::duration(low), fmt::duration(high)));
Figure {
value: format!("~{}", fmt::duration(view.time_saved.seconds)),
color: text_color,
caption: "saved (rough)".into(),
small: if left_out > 0 {
small: interval.unwrap_or_default(),
small2: if left_out > 0 {
format!("{} hits left out of this figure", fmt::count(left_out))
} else {
"every hit counted".into()
@@ -556,13 +551,15 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range, dark: bool) {
.map(|problem| problem.title.clone())
.unwrap_or_else(|| "Nothing needs attention".into()),
small: String::new(),
small2: String::new(),
trend: None,
hover: None,
}
.draw(ui, column);
});
let built = totals.executed.saturating_sub(totals.hits);
// Timeouts, cache errors and forced recaches are inside the built count, as sccache counts them.
let built = totals.misses;
ui.add(egui::Label::new(format!(
"{} compiles · {} from cache · {} built",
fmt::count(totals.requests),
@@ -607,128 +604,3 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range, dark: bool) {
style::meter(ui, 6.0, full, color);
}
}
#[cfg(test)]
mod tests {
use super::*;
/// A view with something in every part of the page.
const SAMPLE: &str = r#"{
"range": "24h",
"generated_at": 1764300000,
"server": {
"status": "Running",
"version": "0.18.0",
"client_version": "0.18.0",
"cache_location": "Local disk: \"/home/me/.cache/sccache\"",
"cache_size": 10726353131,
"max_cache_size": 10737418240,
"error": null
},
"totals": {
"requests": 5610, "executed": 5610, "hits": 2815, "misses": 2795,
"not_cacheable": 0, "unsupported_compiler": 0, "not_compile": 0,
"timeouts": 3, "read_errors": 2, "write_errors": 1, "other_errors": 0,
"compile_fails": 12, "forced_recaches": 4, "cache_writes": 2795
},
"previous": {
"requests": 5000, "executed": 5000, "hits": 2000, "misses": 3000,
"not_cacheable": 0, "unsupported_compiler": 0, "not_compile": 0,
"timeouts": 0, "read_errors": 0, "write_errors": 0, "other_errors": 0,
"compile_fails": 9, "forced_recaches": 0, "cache_writes": 3000
},
"timing": { "avg_hit_read_ms": 0.72, "avg_cache_write_ms": 310.0, "avg_compile_ms": 8050.0 },
"time_saved": { "seconds": 11100.0, "hits_left_out": 7, "note": "Low on purpose." },
"languages": [
{ "name": "Rust", "hits": 229, "misses": 3256, "errors": 0 },
{ "name": "C/C++", "hits": 2082, "misses": 0, "errors": 0 }
],
"not_cached": [["crate-type", 621], ["incremental", 105]],
"buckets": [
{ "start": 1764290000, "hits": 10, "misses": 5, "other": 1, "errors": 0, "saved_seconds": 60.0,
"languages": [["Rust", 10, 5]], "reset": false, "gap": false },
{ "start": 1764290600, "hits": 0, "misses": 0, "other": 0, "errors": 0, "saved_seconds": 0.0,
"languages": [], "reset": false, "gap": true },
{ "start": 1764291200, "hits": 4, "misses": 4, "other": 0, "errors": 0, "saved_seconds": 30.0,
"languages": [["C/C++", 4, 4]], "reset": true, "gap": false }
],
"problems": [
{ "severity": "Warning", "title": "Rust hit rate 8%", "detail": "Most Rust compiles miss." }
],
"extras": [ { "title": "Multi-level cache", "rows": [["Levels", "2"]] } ],
"raw": { "stats": { "compile_requests": 5610 }, "version": "0.18.0" },
"summary_markdown": "**Cache:** 50%"
}"#;
fn sample() -> View {
serde_json::from_str(SAMPLE).expect("the sample is a View")
}
#[test]
fn a_view_deserialises() {
let view = sample();
assert_eq!(view.range, Some(Range::Day));
assert_eq!(view.totals.hit_rate(), Some(0.5));
assert_eq!(view.server.version.as_deref(), Some("0.18.0"));
assert_eq!(view.not_cached[0], ("crate-type".to_owned(), 621));
assert_eq!(view.buckets[1].gap, true);
assert_eq!(view.extras[0].rows[0].1, "2");
}
#[test]
fn an_empty_view_deserialises() {
let view: View = serde_json::from_str(
r#"{"range": null, "generated_at": 0, "server": {"status": "NotRunning"},
"totals": {}, "previous": null, "timing": {}, "time_saved": {"seconds": 0.0, "hits_left_out": 0, "note": ""},
"languages": [], "not_cached": [], "buckets": [], "problems": [], "extras": [],
"raw": null, "summary_markdown": ""}"#,
)
.expect("an empty view is still a View");
assert_eq!(view.totals.hit_rate(), None);
assert!(view.raw.is_null());
}
/// Run the page once without a window and fail if drawing it panics.
fn draw(view: Option<&View>) {
let ctx = egui::Context::default();
ctx.set_fonts(egui::FontDefinitions::default());
let mut hidden = Vec::new();
let mut refit = true;
// An area stands in for the window's own `Ui`.
let _ = ctx.run(egui::RawInput::default(), |ctx| {
egui::Area::new(egui::Id::unique("test-page"))
.show(ctx, |ui| {
ui.set_max_width(800.0);
egui::ScrollArea::vertical()
.auto_shrink([false; 2])
.show(ui, |ui| match view {
None => waiting(ui, Some("connection refused"), 10),
Some(view) => page(ui, view, Range::Day, None, &mut hidden, &mut refit),
});
})
});
}
#[test]
fn the_page_draws_a_full_view() {
let view = sample();
draw(Some(&view));
}
#[test]
fn the_page_draws_a_view_with_nothing_in_it() {
let view: View = serde_json::from_value(serde_json::json!({
"range": "reset", "generated_at": 1, "server": {"status": "Idle"},
"totals": {}, "previous": null, "timing": {}, "time_saved": {},
"languages": [], "not_cached": [], "buckets": [], "problems": [], "extras": [],
"raw": null, "summary_markdown": ""
}))
.expect("an empty view is still a View");
draw(Some(&view));
}
#[test]
fn the_page_draws_while_waiting() {
draw(None);
}
}