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

+37 -41
View File
@@ -2,50 +2,36 @@
use sccache_dash_api::Range;
/// The code the server uses for a range, as in `/api/view?range=24h`.
pub fn range_code(range: Range) -> &'static str {
match range {
Range::Hour => "1h",
Range::Day => "24h",
Range::Week => "7d",
Range::Month => "30d",
Range::SinceReset => "reset",
}
/// How a comparison with the period before is worded, from the range's own
/// label: "previous 24 hours".
pub fn previous_label(range: Range) -> String {
let label = range.label();
format!("previous {}", label.strip_prefix("last ").unwrap_or(label))
}
/// The range a remembered code names.
pub fn range_from_code(code: &str) -> Option<Range> {
[
Range::Hour,
Range::Day,
Range::Week,
Range::Month,
Range::SinceReset,
]
.into_iter()
.find(|range| range_code(*range) == code)
}
/// The heading over the figures: "LAST 24 HOURS".
pub fn range_title(range: Range) -> &'static str {
match range {
Range::Hour => "LAST HOUR",
Range::Day => "LAST 24 HOURS",
Range::Week => "LAST 7 DAYS",
Range::Month => "LAST 30 DAYS",
Range::SinceReset => "SINCE RESET",
/// Whole-number percentages of `parts` that add up to exactly 100, giving the
/// leftovers of rounding to the largest shares. All zero when nothing is counted.
pub fn shares(parts: &[u64]) -> Vec<u64> {
let total: u64 = parts.iter().sum();
if total == 0 {
return vec![0; parts.len()];
}
}
/// How a comparison with the period before is worded: "previous 24h".
pub fn previous_label(range: Range) -> &'static str {
match range {
Range::Hour => "previous hour",
Range::Day => "previous 24h",
Range::Week => "previous 7d",
Range::Month => "previous 30d",
Range::SinceReset => "the period before",
let exact: Vec<f64> = parts
.iter()
.map(|part| 100.0 * *part as f64 / total as f64)
.collect();
let mut whole: Vec<u64> = exact.iter().map(|value| value.floor() as u64).collect();
let mut left = 100 - whole.iter().sum::<u64>();
let mut by_fraction: Vec<usize> = (0..parts.len()).collect();
by_fraction.sort_by(|a, b| exact[*b].fract().total_cmp(&exact[*a].fract()));
for index in by_fraction {
if left == 0 {
break;
}
whole[index] += 1;
left -= 1;
}
whole
}
/// How the refresh control names an interval: "Every 10 s", or "Off".
@@ -64,7 +50,7 @@ pub fn count(n: u64) -> String {
let mut out = String::with_capacity(digits.len() + digits.len() / 3);
out.push_str(&digits[..first]);
for (index, digit) in digits[first..].chars().enumerate() {
if index > 0 && index % 3 == 0 {
if index % 3 == 0 {
out.push(',');
}
out.push(digit);
@@ -281,4 +267,14 @@ mod tests {
assert_eq!(tick_label(43_200, 600), "12:00");
assert_eq!(tick_label(86_400, 600), "Jan 2");
}
#[test]
fn shares_add_up_to_one_hundred() {
assert_eq!(shares(&[50, 33, 17]), [50, 33, 17]);
assert_eq!(shares(&[1, 1, 1]), [34, 33, 33]);
assert_eq!(shares(&[7351, 0, 0, 0, 0]), [100, 0, 0, 0, 0]);
assert_eq!(shares(&[0, 0]), [0, 0]);
let parts = [3254, 3256, 829, 14, 13];
assert_eq!(shares(&parts).iter().sum::<u64>(), 100);
}
}