Dashboard page for sccache-dash (crates/ui)
An eframe/egui page compiled to WebAssembly with trunk. It draws the one View the server sends: controls on top, three big figures, six cards, and the collapsible sections Problems, Where compiles went, Over time, Speed, Extras and Raw counters. The range, refresh interval and theme are remembered between visits with eframe storage. mise.toml names trunk 0.22.2 as the build tool.
This commit is contained in:
1 parent
a8e7bd66cf
commit
b80749ebb5
16 files changed
+2242
No files matched your search
@@ -0,0 +1,64 @@
|
||||
//! Speed: how long a cache fetch, a cache write and a build take on average.
|
||||
|
||||
use eframe::egui::{self, Layout, RichText, Ui};
|
||||
use sccache_dash_api::View;
|
||||
|
||||
use crate::fmt;
|
||||
use crate::style;
|
||||
|
||||
pub fn section(ui: &mut Ui, view: &View) {
|
||||
let timing = view.timing;
|
||||
style::section(ui, "speed", "Speed", |ui| {
|
||||
let rows = [
|
||||
("Cache fetch (a hit)", timing.avg_hit_read_ms, style::CACHE),
|
||||
("Cache write", timing.avg_cache_write_ms, style::BUILT),
|
||||
("Build (compile)", timing.avg_compile_ms, egui::Color32::GRAY),
|
||||
];
|
||||
let label_width = if ui.available_width() < 480.0 {
|
||||
124.0
|
||||
} else {
|
||||
170.0
|
||||
};
|
||||
for (label, ms, color) in rows {
|
||||
ui.horizontal(|ui| {
|
||||
cell(ui, label_width, Layout::left_to_right(egui::Align::Center), |ui| {
|
||||
ui.add(egui::Label::new(label).truncate());
|
||||
});
|
||||
let text = ms.map_or("—".into(), |ms| fmt::duration(ms / 1000.0));
|
||||
cell(ui, 72.0, Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.label(RichText::new(text).strong());
|
||||
});
|
||||
style::meter(ui, 12.0, ms.map_or(0.0, style::log_fraction), color);
|
||||
});
|
||||
}
|
||||
let hit = timing.avg_hit_read_ms;
|
||||
let write = timing.avg_cache_write_ms;
|
||||
let build = timing.avg_compile_ms;
|
||||
let sentence = if let Some(times) = faster(build, hit) {
|
||||
format!("A cache hit is about {}x faster than building.", times)
|
||||
} else if let Some(times) = faster(build, write) {
|
||||
format!("Writing to the cache is about {times}x faster than building.")
|
||||
} else {
|
||||
"There are no timings to compare in this range.".to_owned()
|
||||
};
|
||||
ui.label(sentence);
|
||||
ui.label(
|
||||
RichText::new("The bars use a log scale, so a fraction of a millisecond and several \
|
||||
seconds are both visible.")
|
||||
.small()
|
||||
.weak(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// `faster` is about how many times shorter than `slower`, when both are known and positive.
|
||||
fn faster(slower: Option<f64>, faster: Option<f64>) -> Option<String> {
|
||||
let (slower, faster) = (slower?, faster?);
|
||||
(slower > 0.0 && faster > 0.0).then(|| fmt::round_number(slower / faster))
|
||||
}
|
||||
|
||||
/// Draw with a fixed width, so the bars all start at the same place.
|
||||
fn cell(ui: &mut Ui, width: f32, layout: Layout, contents: impl FnOnce(&mut Ui)) {
|
||||
let height = ui.text_style_height(&egui::TextStyle::Body);
|
||||
ui.allocate_ui_with_layout(egui::vec2(width, height), layout, contents);
|
||||
}
|
||||
Reference in new issue
Block a user