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:
1 parent
c589b7c868
commit
dc876b5a5c
13 files changed
+549
-361
No files matched your search
+67
-6
@@ -1,6 +1,6 @@
|
||||
//! Colours and small drawings shared by the sections.
|
||||
|
||||
use eframe::egui::{self, Color32, Pos2, RichText, Sense, Shape, Stroke, Ui};
|
||||
use eframe::egui::{self, Align, Color32, Layout, Pos2, RichText, Sense, Shape, Stroke, Ui};
|
||||
|
||||
/// Served from the cache.
|
||||
pub const CACHE: Color32 = Color32::from_rgb(0x4C, 0xAF, 0x50);
|
||||
@@ -9,7 +9,6 @@ pub const BUILT: Color32 = Color32::from_rgb(0x42, 0xA5, 0xF5);
|
||||
pub const NOT_CACHEABLE: Color32 = Color32::from_rgb(0xFF, 0xA7, 0x26);
|
||||
pub const UNSUPPORTED: Color32 = Color32::from_rgb(0xAB, 0x47, 0xBC);
|
||||
pub const NOT_COMPILE: Color32 = Color32::from_rgb(0x26, 0xA6, 0x9A);
|
||||
pub const ERRORS: Color32 = Color32::from_rgb(0xEF, 0x53, 0x50);
|
||||
|
||||
/// Text colours that mean "good", "worth a look" and "bad", for the theme being drawn.
|
||||
pub fn marks(dark: bool) -> [Color32; 3] {
|
||||
@@ -47,10 +46,16 @@ pub fn section<R>(
|
||||
body: impl FnOnce(&mut Ui) -> R,
|
||||
) -> Option<R> {
|
||||
ui.add_space(8.0);
|
||||
// The body is indented, and then thinks it may run that much further right;
|
||||
// hold it to the width that is left so nothing is pushed off the page.
|
||||
let body_width = ui.available_rect_before_wrap().width() - ui.spacing().indent;
|
||||
egui::CollapsingHeader::new(title.into().strong().size(17.0))
|
||||
.id_salt(id)
|
||||
.default_open(true)
|
||||
.show(ui, body)
|
||||
.show(ui, |ui| {
|
||||
ui.set_max_width(body_width);
|
||||
body(ui)
|
||||
})
|
||||
.body_returned
|
||||
}
|
||||
|
||||
@@ -58,12 +63,16 @@ pub fn section<R>(
|
||||
pub fn banner(ui: &mut Ui, text: impl Into<RichText>, color: Color32) {
|
||||
let mut text: RichText = text.into();
|
||||
text = text.strong();
|
||||
// As wide as there is room, minus a little: text that wraps measures itself a few
|
||||
// pixels wider, and a page that is told to fit exactly that wide grows each time.
|
||||
let width = ui.available_rect_before_wrap().width() - 2.0 * 8.0 - 6.0;
|
||||
egui::Frame::NONE
|
||||
.fill(color.gamma_multiply(0.22))
|
||||
.stroke(Stroke::new(1.0, color))
|
||||
.corner_radius(6.0)
|
||||
.inner_margin(8.0)
|
||||
.show(ui, |ui| {
|
||||
ui.set_min_width(width);
|
||||
ui.add(egui::Label::new(text).wrap());
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
@@ -79,7 +88,7 @@ pub fn swatch(ui: &mut Ui, color: Color32) {
|
||||
/// points break the line, so a gap never looks like a zero. `top` is the value
|
||||
/// drawn at the top of the strip.
|
||||
pub fn sparkline(ui: &mut Ui, height: f32, values: &[Option<f64>], top: f64, color: Color32) {
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(ui.available_width(), height), Sense::hover());
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(ui.available_rect_before_wrap().width(), height), Sense::hover());
|
||||
let painter = ui.painter();
|
||||
painter.hline(
|
||||
rect.x_range(),
|
||||
@@ -117,7 +126,7 @@ pub fn sparkline(ui: &mut Ui, height: f32, values: &[Option<f64>], top: f64, col
|
||||
|
||||
/// A bar filled from the left to `fraction` of its width (0 to 1), always `height` tall.
|
||||
pub fn meter(ui: &mut Ui, height: f32, fraction: f64, fill: Color32) {
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(ui.available_width(), height), Sense::hover());
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(ui.available_rect_before_wrap().width(), height), Sense::hover());
|
||||
let painter = ui.painter();
|
||||
painter.rect_filled(rect, height / 2.0, ui.visuals().extreme_bg_color);
|
||||
let width = (rect.width() * fraction.clamp(0.0, 1.0) as f32).min(rect.width());
|
||||
@@ -133,7 +142,7 @@ pub fn meter(ui: &mut Ui, height: f32, fraction: f64, fill: Color32) {
|
||||
/// One bar split into coloured parts. The parts fill the whole width when
|
||||
/// their counts add up to `total`; a part with no count gets no width.
|
||||
pub fn stacked_bar(ui: &mut Ui, height: f32, parts: &[(&'static str, u64, Color32)], total: u64) {
|
||||
let (rect, response) = ui.allocate_exact_size(egui::vec2(ui.available_width(), height), Sense::hover());
|
||||
let (rect, response) = ui.allocate_exact_size(egui::vec2(ui.available_rect_before_wrap().width(), height), Sense::hover());
|
||||
let painter = ui.painter();
|
||||
painter.rect_filled(rect, 4.0, ui.visuals().extreme_bg_color);
|
||||
let mut x = rect.left();
|
||||
@@ -183,3 +192,55 @@ pub fn log_fraction(ms: f64) -> f64 {
|
||||
let position = (ms.log10() - LOW) / (HIGH - LOW);
|
||||
position.clamp(0.02, 1.0)
|
||||
}
|
||||
|
||||
/// A cell of [`table_row`]: how wide (`f32::INFINITY` for the width that is left),
|
||||
/// which side its content lines up with, and what draws it.
|
||||
pub type Cell<'a> = (f32, egui::Align, Box<dyn FnOnce(&mut Ui) + 'a>);
|
||||
|
||||
/// Text in a cell, cut short if it is too long (or wrapped when `wrap` is set);
|
||||
/// the whole text shows on hover.
|
||||
pub fn text_cell(text: RichText, width: f32, right: bool, wrap: bool) -> Cell<'static> {
|
||||
let hover = text.text().to_owned();
|
||||
let align = if right { egui::Align::Max } else { egui::Align::Min };
|
||||
let draw = Box::new(move |ui: &mut Ui| {
|
||||
let label = egui::Label::new(text);
|
||||
let label = if wrap { label.wrap() } else { label.truncate() };
|
||||
ui.add(label).on_hover_text(hover);
|
||||
});
|
||||
(width, align, draw)
|
||||
}
|
||||
|
||||
/// The width an `f32::INFINITY` cell gets in a row whose other cells are `fixed` wide.
|
||||
pub fn leftover(ui: &Ui, fixed: &[f32]) -> f32 {
|
||||
let all = ui.available_rect_before_wrap().width();
|
||||
(all - fixed.iter().sum::<f32>() - ROW_SPACING * fixed.len() as f32).max(0.0)
|
||||
}
|
||||
|
||||
pub const ROW_SPACING: f32 = 4.0;
|
||||
|
||||
/// One table row: cells of fixed widths from the left, one under another across rows.
|
||||
pub fn table_row(ui: &mut Ui, cells: Vec<Cell<'_>>) {
|
||||
let line = ui.text_style_height(&egui::TextStyle::Body) + 2.0;
|
||||
let total = ui.available_rect_before_wrap().width();
|
||||
let fixed: f32 = cells
|
||||
.iter()
|
||||
.filter(|(width, _, _)| width.is_finite())
|
||||
.map(|(width, _, _)| *width)
|
||||
.sum();
|
||||
let rest = (total - fixed - ROW_SPACING * cells.len() as f32).max(0.0);
|
||||
ui.allocate_ui_with_layout(
|
||||
egui::vec2(total, line),
|
||||
Layout::left_to_right(Align::Center),
|
||||
|ui| {
|
||||
ui.spacing_mut().item_spacing.x = ROW_SPACING;
|
||||
for (width, align, draw) in cells {
|
||||
let width = if width.is_finite() { width } else { rest };
|
||||
let layout = match align {
|
||||
Align::Max => Layout::right_to_left(Align::Center),
|
||||
_ => Layout::left_to_right(Align::Center),
|
||||
};
|
||||
ui.allocate_ui_with_layout(egui::vec2(width, line), layout, |ui| draw(ui));
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user