Merge page polish: full-range charts, even cards, aligned tables

This commit is contained in:
swaits committed 2026-11-28 12:49:48 -07:00
commit 72fcf8f976
6 files changed
+367 -179

No files matched your search

+77 -29
View File
@@ -180,6 +180,14 @@ impl eframe::App for Dashboard {
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) { fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
controls(self, ui); controls(self, ui);
if let (Some(view), Some(error)) = (&self.view, &self.error) {
lost_contact(
ui.ctx(),
error,
view.generated_at,
ui.available_rect_before_wrap().width(),
);
}
egui::CentralPanel::default().show(ui, |ui| { egui::CentralPanel::default().show(ui, |ui| {
egui::ScrollArea::vertical() egui::ScrollArea::vertical()
.auto_shrink([false; 2]) .auto_shrink([false; 2])
@@ -188,15 +196,12 @@ impl eframe::App for Dashboard {
let Self { let Self {
range, range,
view, view,
error,
hidden_languages, hidden_languages,
.. ..
} = self; } = self;
match view { match view {
None => waiting(ui, error.as_deref(), self.refresh_secs), None => waiting(ui, self.error.as_deref(), self.refresh_secs),
Some(view) => { Some(view) => page(ui, view, *range, hidden_languages),
page(ui, view, *range, error.as_deref(), hidden_languages)
}
} }
}); });
}); });
@@ -397,23 +402,39 @@ fn waiting(ui: &mut egui::Ui, error: Option<&str>, refresh_secs: u64) {
} }
/// The whole page below the controls. /// The whole page below the controls.
fn page( /// A notice that the server can't be reached, shown over the page rather than
ui: &mut egui::Ui, /// in it, so what is already on screen keeps its place and height.
view: &View, fn lost_contact(ctx: &egui::Context, error: &str, from: i64, page_width: f32) {
asked: Range, let [_, _, bad] = style::marks(ctx.theme() == egui::Theme::Dark);
error: Option<&str>, let when = fmt::moment_text(from + fmt::local_offset());
hidden_languages: &mut Vec<String>, egui::Area::new(egui::Id::unique("lost-contact"))
) { .anchor(egui::Align2::RIGHT_TOP, egui::vec2(-8.0, 52.0))
.order(egui::Order::Foreground)
.show(ctx, |ui| {
let width = (page_width - 16.0).min(440.0);
egui::Frame::NONE
.fill(bad.gamma_multiply(0.25))
.stroke(egui::Stroke::new(1.0, bad))
.corner_radius(6.0)
.inner_margin(8.0)
.show(ui, |ui| {
ui.set_max_width(width);
ui.add(
egui::Label::new(
egui::RichText::new(format!(
"Can't reach the server: {error}. These figures are from {when}."
))
.strong(),
)
.wrap(),
);
});
});
}
fn page(ui: &mut egui::Ui, view: &View, asked: Range, hidden_languages: &mut Vec<String>) {
let dark = ui.visuals().dark_mode; let dark = ui.visuals().dark_mode;
let [_, _, bad] = style::marks(dark); let [_, _, bad] = style::marks(dark);
if let Some(error) = error {
let from = fmt::moment_text(view.generated_at + fmt::local_offset());
style::banner(
ui,
format!("Lost contact with the server: {error}. These figures are from {from}."),
bad,
);
}
if let Some(error) = &view.server.error { if let Some(error) = &view.server.error {
style::banner(ui, format!("sccache is not working: {error}"), bad); style::banner(ui, format!("sccache is not working: {error}"), bad);
} }
@@ -432,6 +453,8 @@ fn page(
/// One of the three big figures. /// One of the three big figures.
struct Figure<'a> { struct Figure<'a> {
value: String, value: String,
/// How big the figure is written: 30 for numbers, less for words.
size: f32,
color: egui::Color32, color: egui::Color32,
caption: String, caption: String,
/// Smaller print under the figure. /// Smaller print under the figure.
@@ -453,7 +476,9 @@ impl Figure<'_> {
|ui| { |ui| {
ui.set_width(width); ui.set_width(width);
ui.add( ui.add(
egui::Label::new(egui::RichText::new(&self.value).size(30.0).color(self.color)) egui::Label::new(
egui::RichText::new(&self.value).size(self.size).color(self.color),
)
.truncate(), .truncate(),
); );
ui.add(egui::Label::new(egui::RichText::new(&self.caption).small()).truncate()); ui.add(egui::Label::new(egui::RichText::new(&self.caption).small()).truncate());
@@ -510,6 +535,7 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range, dark: bool) {
ui.horizontal_wrapped(|ui| { ui.horizontal_wrapped(|ui| {
Figure { Figure {
value: fmt::percent(totals.hit_rate()), value: fmt::percent(totals.hit_rate()),
size: 30.0,
color: style::hit_rate_color(totals.hit_rate(), dark), color: style::hit_rate_color(totals.hit_rate(), dark),
caption: "from cache".into(), caption: "from cache".into(),
small: format!("{} of all compiler calls", fmt::percent(totals.hit_rate_of_all())), small: format!("{} of all compiler calls", fmt::percent(totals.hit_rate_of_all())),
@@ -518,22 +544,43 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range, dark: bool) {
small2: String::new(), small2: String::new(),
} }
.draw(ui, column); .draw(ui, column);
// A saving is never written in milliseconds; and when no language's build time is
// known yet, the figure says so instead of showing nothing.
let seconds = view.time_saved.seconds;
let left_out = view.time_saved.hits_left_out; let left_out = view.time_saved.hits_left_out;
// The 90% range goes first; the hits left out are the line under it. let left_out_line = if left_out > 0 {
format!("{} hits left out of this figure", fmt::count(left_out))
} else {
"every hit counted".to_owned()
};
let interval = view let interval = view
.time_saved .time_saved
.interval_90 .interval_90
.map(|(low, high)| format!("{} – {} (90% range)", fmt::duration(low), fmt::duration(high))); .map(|(low, high)| format!("{} – {} (90% range)", fmt::duration(low), fmt::duration(high)));
let (value, size, small, small2) = if seconds >= 1.0 {
(format!("~{}", fmt::duration(seconds)), 30.0, interval.unwrap_or_default(), left_out_line)
} else if seconds > 0.0 {
("~under 1 s".to_owned(), 30.0, interval.unwrap_or_default(), left_out_line)
} else if left_out > 0 {
(
"not enough data yet".to_owned(),
22.0,
String::new(),
format!(
"{} hits not counted: no build time known yet for their language",
fmt::count(left_out)
),
)
} else {
("nothing saved yet".to_owned(), 22.0, String::new(), String::new())
};
Figure { Figure {
value: format!("~{}", fmt::duration(view.time_saved.seconds)), value,
size,
color: text_color, color: text_color,
caption: "saved (rough)".into(), caption: "saved (rough)".into(),
small: interval.unwrap_or_default(), small,
small2: if left_out > 0 { small2,
format!("{} hits left out of this figure", fmt::count(left_out))
} else {
"every hit counted".into()
},
trend: Some((&saved, saved_top)), trend: Some((&saved, saved_top)),
hover: Some(view.time_saved.note.clone()), hover: Some(view.time_saved.note.clone()),
} }
@@ -546,6 +593,7 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range, dark: bool) {
} else { } else {
format!("{} problems", fmt::count(problems as u64)) format!("{} problems", fmt::count(problems as u64))
}, },
size: 30.0,
color: problem_color, color: problem_color,
caption: worst caption: worst
.map(|problem| problem.title.clone()) .map(|problem| problem.title.clone())
+32 -24
View File
@@ -1,13 +1,14 @@
//! The six compact cards under the headline. //! The six compact cards under the headline: all the same size, tops in a line.
use eframe::egui::{self, Color32, RichText, Ui}; use eframe::egui::{self, Color32, RichText, Sense, StrokeKind, Ui};
use sccache_dash_api::{Range, View}; use sccache_dash_api::{Range, View};
use crate::fmt; use crate::fmt;
use crate::style; use crate::style;
/// Every card is this tall, whatever it has to say. /// Every card is exactly this tall and as wide as its share of the row.
const HEIGHT: f32 = 78.0; const HEIGHT: f32 = 78.0;
const MARGIN: f32 = 8.0;
pub fn row(ui: &mut Ui, view: &View, dark: bool) { pub fn row(ui: &mut Ui, view: &View, dark: bool) {
let totals = &view.totals; let totals = &view.totals;
@@ -98,28 +99,35 @@ struct Card {
} }
impl Card { impl Card {
/// A box of exactly `width` by `HEIGHT`, so every card lines up whatever it says.
fn draw(self, ui: &mut Ui, width: f32, range: Range, [good, bad]: [Color32; 2]) { fn draw(self, ui: &mut Ui, width: f32, range: Range, [good, bad]: [Color32; 2]) {
let margin = 8.0; let (rect, _) = ui.allocate_exact_size(egui::vec2(width, HEIGHT), Sense::hover());
// Laid out from the top down inside exactly `width`, whatever row it sits in. let visuals = ui.visuals();
ui.allocate_ui_with_layout(egui::vec2(width, HEIGHT), egui::Layout::top_down(egui::Align::Min), |ui| { ui.painter().rect(
egui::Frame::group(ui.style()) rect,
.inner_margin(margin) 6.0,
.show(ui, |ui| { visuals.faint_bg_color,
ui.set_width(ui.available_rect_before_wrap().width() - 2.0); visuals.widgets.noninteractive.bg_stroke,
ui.set_min_height(HEIGHT - 2.0 * margin); StrokeKind::Inside,
ui.add(egui::Label::new(RichText::new(self.title).small()).truncate()); );
let color = self.color.unwrap_or_else(|| ui.visuals().text_color()); let mut card = ui.new_child(
ui.add(egui::Label::new(RichText::new(fmt::count(self.count)).size(20.0).color(color)).truncate()); egui::UiBuilder::new()
let detail = ui.add( .max_rect(rect.shrink(MARGIN))
egui::Label::new(RichText::new(&self.detail).small().weak()).truncate(), .layout(egui::Layout::top_down(egui::Align::Min)),
); );
if !self.detail.is_empty() { card.add(egui::Label::new(RichText::new(self.title).small()).truncate());
detail.on_hover_text(self.detail.clone()); let color = self.color.unwrap_or_else(|| card.visuals().text_color());
} card.add(
let (change, color) = change(self.count, self.previous, range, self.good_when_up, [good, bad]); egui::Label::new(RichText::new(fmt::count(self.count)).size(20.0).color(color)).truncate(),
ui.add(egui::Label::new(RichText::new(change).small().color(color)).truncate()); );
}); let detail = card.add(
}); egui::Label::new(RichText::new(&self.detail).small().weak()).truncate(),
);
if !self.detail.is_empty() {
detail.on_hover_text(self.detail.clone());
}
let (change, color) = change(self.count, self.previous, range, self.good_when_up, [good, bad]);
card.add(egui::Label::new(RichText::new(change).small().color(color)).truncate());
} }
} }
+1 -6
View File
@@ -15,16 +15,11 @@ pub fn section(ui: &mut Ui, view: &View) {
ui.add_space(6.0); ui.add_space(6.0);
} }
ui.label(RichText::new(&extra.title).strong()); ui.label(RichText::new(&extra.title).strong());
let label_width = if ui.available_rect_before_wrap().width() < 480.0 {
104.0
} else {
160.0
};
for (label, value) in &extra.rows { for (label, value) in &extra.rows {
style::table_row( style::table_row(
ui, ui,
vec![ vec![
style::text_cell(RichText::new(label.as_str()).strong(), label_width, false, false), style::text_cell(RichText::new(label.as_str()).strong(), 0.3, false, false),
style::text_cell(RichText::new(value.as_str()), f32::INFINITY, false, true), style::text_cell(RichText::new(value.as_str()), f32::INFINITY, false, true),
], ],
); );
+143 -78
View File
@@ -1,9 +1,11 @@
//! Over time: hit rate and compile volume per bucket, with a language filter. //! Over time: hit rate and compile volume per bucket, with a language filter.
//! Both charts always show the whole selected range; time nothing was recorded
//! in is shaded and labelled once.
use eframe::egui::{self, Color32, RichText, Stroke, Ui}; use eframe::egui::{self, Color32, RichText, Stroke, Ui};
use egui_plot::{ use egui_plot::{
Bar, BarChart, CoordinatesFormatter, Corner, GridInput, GridMark, Legend, Line, LineStyle, Bar, BarChart, CoordinatesFormatter, Corner, GridInput, GridMark, Line, LineStyle, Plot,
Plot, PlotBounds, PlotPoint, PlotPoints, PlotResponse, PlotUi, Span, VLine, PlotBounds, PlotPoint, PlotPoints, PlotResponse, PlotUi, Span, VLine,
}; };
use sccache_dash_api::{Bucket, Range, View}; use sccache_dash_api::{Bucket, Range, View};
@@ -21,41 +23,24 @@ pub fn section(ui: &mut Ui, view: &View, hidden: &mut Vec<String>, dark: bool) {
style::section(ui, "overtime", "Over time", |ui| { style::section(ui, "overtime", "Over time", |ui| {
filter(ui, view, hidden); filter(ui, view, hidden);
let tz = fmt::local_offset(); let tz = fmt::local_offset() as f64;
let step = bucket_step(&view.buckets, view.range); let step = bucket_step(&view.buckets, view.range);
let window = view let axes = Axes {
.buckets window: range_window(view, step),
.iter() step,
.filter(|bucket| !bucket.gap) tz,
.map(|bucket| (bucket.start + tz) as f64) dark,
.fold(None::<(f64, f64)>, |window, start| { };
Some(match window {
Some((first, last)) => (first.min(start), last.max(start)),
None => (start, start),
})
});
let axes = Axes { window, step, tz };
ui.label(RichText::new("Hit rate").strong()); ui.label(RichText::new("Hit rate").strong());
hit_rate_chart(ui, view, hidden, axes, dark); hit_rate_chart(ui, view, hidden, axes);
ui.add_space(6.0); ui.add_space(6.0);
ui.label(RichText::new("Compiles").strong()); ui.label(RichText::new("Compiles").strong());
volume_chart(ui, view, hidden, axes, dark); volume_chart(ui, view, hidden, axes);
}); });
} }
/// What both charts share: the time window, the bucket width and the time zone.
#[derive(Clone, Copy)]
struct Axes {
/// First and last bucket start shown, if any bucket was recorded.
window: Option<(f64, f64)>,
/// Seconds per bucket.
step: f64,
/// Seconds to add to a Unix time to get local clock time.
tz: i64,
}
/// Checkboxes that narrow both charts to some languages. /// Checkboxes that narrow both charts to some languages.
fn filter(ui: &mut Ui, view: &View, hidden: &mut Vec<String>) { fn filter(ui: &mut Ui, view: &View, hidden: &mut Vec<String>) {
ui.horizontal_wrapped(|ui| { ui.horizontal_wrapped(|ui| {
@@ -108,26 +93,72 @@ fn bucket_step(buckets: &[Bucket], range: Option<Range>) -> f64 {
} }
} }
/// A chart with a time axis: clock times as ticks and a readout of where the /// The whole selected range as Unix seconds (start, end): a fixed-length range
/// pointer is. It can't be zoomed or dragged, so the wheel and a finger keep /// runs back from now by its length, whatever the buckets cover; "since reset"
/// scrolling the page; that also means it can fit its data afresh every frame, /// runs from the first bucket to the last one's end.
/// so new buckets are never cut off. fn range_window(view: &View, step: f64) -> (f64, f64) {
let now = view.generated_at as f64;
let (first, last) = match (view.buckets.first(), view.buckets.last()) {
(Some(first), Some(last)) => (first.start as f64, last.start as f64 + step),
_ => (now - step, now),
};
match view.range {
Some(Range::Hour) => (now - 3_600.0, now),
Some(Range::Day) => (now - 86_400.0, now),
Some(Range::Week) => (now - 604_800.0, now),
Some(Range::Month) => (now - 2_592_000.0, now),
_ => (first, last.max(first + step)),
}
}
/// The stretches of the window no recorded bucket covers.
fn unrecorded(buckets: &[Bucket], window: (f64, f64), step: f64) -> Vec<(f64, f64)> {
let mut stretches = Vec::new();
let mut cursor = window.0;
for bucket in buckets.iter().filter(|bucket| !bucket.gap) {
let (from, to) = (bucket.start as f64, bucket.start as f64 + step);
if from > cursor {
stretches.push((cursor, from));
}
cursor = cursor.max(to);
}
if cursor < window.1 {
stretches.push((cursor, window.1));
}
stretches
}
/// What both charts share.
#[derive(Clone, Copy)]
struct Axes {
/// Start and end of the range in Unix seconds.
window: (f64, f64),
/// Seconds per bucket.
step: f64,
/// Seconds to add to a Unix time to get local clock time.
tz: f64,
dark: bool,
}
/// A chart with a time axis over the whole range: clock times as ticks and a
/// readout of where the pointer is. It can't be zoomed or dragged, so the wheel
/// and a finger keep scrolling the page; that also means it can fit its data
/// afresh every frame, so new buckets are never cut off.
fn time_plot<'a>( fn time_plot<'a>(
name: &'static str, name: &'static str,
axes: Axes, axes: Axes,
readout: impl Fn(&PlotPoint) -> String + 'a, readout: impl Fn(&PlotPoint) -> String + 'a,
) -> Plot<'a> { ) -> Plot<'a> {
let (first, last) = axes.window.unwrap_or((0.0, axes.step)); let (first, last) = (axes.window.0 + axes.tz, axes.window.1 + axes.tz);
let step = axes.step; let tick = fmt::tick_step(last - first);
let tick = fmt::tick_step(last - first + 2.0 * step); Plot::new(name)
let plot = Plot::new(name)
.height(CHART_HEIGHT) .height(CHART_HEIGHT)
.allow_scroll(false) .allow_scroll(false)
.allow_drag(false) .allow_drag(false)
.allow_zoom(false) .allow_zoom(false)
.allow_boxed_zoom(false) .allow_boxed_zoom(false)
.include_x(first - step) // Exactly the range, edge to edge, with no air either side.
.include_x(last + step) .default_x_bounds(first, last)
.x_grid_spacer(move |input: GridInput| ticks(input.bounds.0, input.bounds.1, tick)) .x_grid_spacer(move |input: GridInput| ticks(input.bounds.0, input.bounds.1, tick))
.x_axis_formatter(move |mark: GridMark, _range| { .x_axis_formatter(move |mark: GridMark, _range| {
fmt::tick_label(mark.value.round() as i64, tick) fmt::tick_label(mark.value.round() as i64, tick)
@@ -135,8 +166,8 @@ fn time_plot<'a>(
.coordinates_formatter( .coordinates_formatter(
Corner::LeftTop, Corner::LeftTop,
CoordinatesFormatter::new(move |point: &PlotPoint, _bounds: &PlotBounds| readout(point)), CoordinatesFormatter::new(move |point: &PlotPoint, _bounds: &PlotBounds| readout(point)),
); )
plot.reset() .reset()
} }
fn ticks(from: f64, to: f64, tick: i64) -> Vec<GridMark> { fn ticks(from: f64, to: f64, tick: i64) -> Vec<GridMark> {
@@ -154,31 +185,53 @@ fn ticks(from: f64, to: f64, tick: i64) -> Vec<GridMark> {
marks marks
} }
/// Resets as dashed lines and gaps as grey bands, so a gap never reads as zero. /// The shade for time nothing was recorded in.
fn marks(plot: &mut PlotUi<'_>, buckets: &[Bucket], step: f64, dark: bool, tz: i64) { fn shade(dark: bool) -> Color32 {
let warn = style::marks(dark)[1]; if dark {
let shade = if dark { Color32::WHITE.gamma_multiply(0.14)
Color32::WHITE.gamma_multiply(0.08)
} else { } else {
Color32::BLACK.gamma_multiply(0.08) Color32::BLACK.gamma_multiply(0.12)
}; }
}
/// Resets as dashed lines, and everything unrecorded as one grey band per stretch.
fn marks(plot: &mut PlotUi<'_>, buckets: &[Bucket], axes: Axes) {
let warn = style::marks(axes.dark)[1];
for bucket in buckets { for bucket in buckets {
let start = (bucket.start + tz) as f64;
if bucket.reset { if bucket.reset {
plot.vline( plot.vline(
VLine::new("Reset", start) VLine::new("Reset", bucket.start as f64 + axes.tz)
.stroke(Stroke::new(1.5, warn)) .stroke(Stroke::new(1.5, warn))
.style(LineStyle::Dashed { length: 12.0 }), .style(LineStyle::Dashed { length: 12.0 }),
); );
} }
if bucket.gap {
plot.span(
Span::new("Not recorded", start..=start + step)
.fill(shade)
.border_width(0.0),
);
}
} }
for (from, to) in unrecorded(buckets, axes.window, axes.step) {
plot.span(
Span::new("Not recorded", (from + axes.tz)..=(to + axes.tz))
.fill(shade(axes.dark))
.border_width(0.0),
);
}
}
/// Whether there is anything to mark: a reset, or time nothing was recorded in.
fn marked(buckets: &[Bucket], axes: Axes) -> (bool, bool) {
let any_reset = buckets.iter().any(|bucket| bucket.reset);
let any_gap = !unrecorded(buckets, axes.window, axes.step).is_empty();
(any_reset, any_gap)
}
/// The key to a chart, drawn under it so it never sits on the data.
fn legend(ui: &mut Ui, entries: Vec<(style::Mark, &'static str)>) {
ui.add_space(4.0);
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing.x = 14.0;
for (mark, text) in entries {
style::key(ui, mark);
ui.label(RichText::new(text).small().weak());
}
});
} }
fn overlay(ui: &mut Ui, chart: &PlotResponse<()>, text: &str) { fn overlay(ui: &mut Ui, chart: &PlotResponse<()>, text: &str) {
@@ -206,21 +259,17 @@ fn split(bucket: &Bucket, hidden: &[String]) -> (u64, u64) {
} }
} }
fn hit_rate_chart( fn hit_rate_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes) {
ui: &mut Ui,
view: &View,
hidden: &[String],
axes: Axes,
dark: bool,
) {
let (step, tz) = (axes.step, axes.tz);
// One line per stretch of buckets that have a hit rate. // One line per stretch of buckets that have a hit rate.
let mut runs: Vec<Vec<PlotPoint>> = Vec::new(); let mut runs: Vec<Vec<PlotPoint>> = Vec::new();
let mut run: Vec<PlotPoint> = Vec::new(); let mut run: Vec<PlotPoint> = Vec::new();
for bucket in view.buckets.iter().filter(|bucket| !bucket.gap) { for bucket in view.buckets.iter().filter(|bucket| !bucket.gap) {
let (hits, misses) = split(bucket, hidden); let (hits, misses) = split(bucket, hidden);
match hit_rate(hits, misses) { match hit_rate(hits, misses) {
Some(rate) => run.push(PlotPoint::new((bucket.start + tz) as f64, rate * 100.0)), Some(rate) => run.push(PlotPoint::new(
bucket.start as f64 + axes.tz,
rate * 100.0,
)),
None if !run.is_empty() => runs.push(std::mem::take(&mut run)), None if !run.is_empty() => runs.push(std::mem::take(&mut run)),
None => {} None => {}
} }
@@ -246,7 +295,7 @@ fn hit_rate_chart(
}) })
.y_axis_formatter(|mark: GridMark, _| format!("{:.0}%", mark.value)); .y_axis_formatter(|mark: GridMark, _| format!("{:.0}%", mark.value));
let chart = plot.show(ui, |plot| { let chart = plot.show(ui, |plot| {
marks(plot, &view.buckets, step, dark, tz); marks(plot, &view.buckets, axes);
for points in &runs { for points in &runs {
plot.line( plot.line(
Line::new("Hit rate", PlotPoints::Owned(points.clone())) Line::new("Hit rate", PlotPoints::Owned(points.clone()))
@@ -258,16 +307,18 @@ fn hit_rate_chart(
if runs.is_empty() { if runs.is_empty() {
overlay(ui, &chart, "No cacheable compiles in this range"); overlay(ui, &chart, "No cacheable compiles in this range");
} }
let (any_reset, any_gap) = marked(&view.buckets, axes);
let mut entries = vec![(style::Mark::Line(style::CACHE), "Hit rate")];
if any_reset {
entries.push((style::Mark::Dashed(style::marks(axes.dark)[1]), "Reset"));
}
if any_gap {
entries.push((style::Mark::Band(axes.dark), "Not recorded"));
}
legend(ui, entries);
} }
fn volume_chart( fn volume_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes) {
ui: &mut Ui,
view: &View,
hidden: &[String],
axes: Axes,
dark: bool,
) {
let (step, tz) = (axes.step, axes.tz);
// The tallest stack of one bucket, with a little air above it. // The tallest stack of one bucket, with a little air above it.
let top = view let top = view
.buckets .buckets
@@ -283,15 +334,14 @@ fn volume_chart(
axes, axes,
|point| fmt::moment_text(point.x.round() as i64), |point| fmt::moment_text(point.x.round() as i64),
) )
.legend(Legend::default().position(Corner::RightTop))
.default_y_bounds(0.0, top) .default_y_bounds(0.0, top)
.y_axis_formatter(|mark: GridMark, _| fmt::count(mark.value.max(0.0).round() as u64)); .y_axis_formatter(|mark: GridMark, _| fmt::count(mark.value.max(0.0).round() as u64));
let width = step * 0.8; let width = axes.step * 0.8;
let (mut from_cache, mut built, mut other) = (vec![], vec![], vec![]); let (mut from_cache, mut built, mut other) = (vec![], vec![], vec![]);
let mut any = false; let mut any = false;
for bucket in view.buckets.iter().filter(|bucket| !bucket.gap) { for bucket in view.buckets.iter().filter(|bucket| !bucket.gap) {
let x = (bucket.start + tz) as f64; let x = bucket.start as f64 + axes.tz;
let (hits, misses) = split(bucket, hidden); let (hits, misses) = split(bucket, hidden);
for (bars, count) in [ for (bars, count) in [
(&mut from_cache, hits), (&mut from_cache, hits),
@@ -306,7 +356,7 @@ fn volume_chart(
} }
let chart = plot.show(ui, |plot| { let chart = plot.show(ui, |plot| {
marks(plot, &view.buckets, step, dark, tz); marks(plot, &view.buckets, axes);
let from_cache = BarChart::new("From cache", from_cache) let from_cache = BarChart::new("From cache", from_cache)
.width(width) .width(width)
.color(style::CACHE); .color(style::CACHE);
@@ -327,4 +377,19 @@ fn volume_chart(
if !any { if !any {
overlay(ui, &chart, "Nothing recorded in this range"); overlay(ui, &chart, "Nothing recorded in this range");
} }
let (any_reset, any_gap) = marked(&view.buckets, axes);
let mut entries = vec![
(style::Mark::Fill(style::CACHE), "From cache"),
(style::Mark::Fill(style::BUILT), "Built"),
];
if hidden.is_empty() {
entries.push((style::Mark::Fill(style::NOT_CACHEABLE), "Not cacheable and other"));
}
if any_reset {
entries.push((style::Mark::Dashed(style::marks(axes.dark)[1]), "Reset"));
}
if any_gap {
entries.push((style::Mark::Band(axes.dark), "Not recorded"));
}
legend(ui, entries);
} }
+88 -27
View File
@@ -128,7 +128,14 @@ pub fn sparkline(ui: &mut Ui, height: f32, values: &[Option<f64>], top: f64, col
pub fn meter(ui: &mut Ui, height: f32, fraction: f64, fill: Color32) { pub fn meter(ui: &mut Ui, height: f32, fraction: f64, fill: Color32) {
let (rect, _) = ui.allocate_exact_size(egui::vec2(ui.available_rect_before_wrap().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(); let painter = ui.painter();
painter.rect_filled(rect, height / 2.0, ui.visuals().extreme_bg_color); // An outline, so the empty track can be seen when the bar is nearly empty.
painter.rect(
rect,
height / 2.0,
ui.visuals().extreme_bg_color,
ui.visuals().widgets.noninteractive.bg_stroke,
egui::StrokeKind::Inside,
);
let width = (rect.width() * fraction.clamp(0.0, 1.0) as f32).min(rect.width()); let width = (rect.width() * fraction.clamp(0.0, 1.0) as f32).min(rect.width());
if width > 0.5 { if width > 0.5 {
painter.rect_filled( painter.rect_filled(
@@ -193,13 +200,14 @@ pub fn log_fraction(ms: f64) -> f64 {
position.clamp(0.02, 1.0) position.clamp(0.02, 1.0)
} }
/// A cell of [`table_row`]: how wide (`f32::INFINITY` for the width that is left), /// A cell of [`table_row`]: its width as a share of the row (0 to 1), or
/// which side its content lines up with, and what draws it. /// `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>); 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); /// Text in a cell, cut short if it is too long (or wrapped when `wrap` is set);
/// the whole text shows on hover. /// the whole text shows on hover.
pub fn text_cell(text: RichText, width: f32, right: bool, wrap: bool) -> Cell<'static> { pub fn text_cell(text: RichText, share: f32, right: bool, wrap: bool) -> Cell<'static> {
let hover = text.text().to_owned(); let hover = text.text().to_owned();
let align = if right { egui::Align::Max } else { egui::Align::Min }; let align = if right { egui::Align::Max } else { egui::Align::Min };
let draw = Box::new(move |ui: &mut Ui| { let draw = Box::new(move |ui: &mut Ui| {
@@ -207,40 +215,93 @@ pub fn text_cell(text: RichText, width: f32, right: bool, wrap: bool) -> Cell<'s
let label = if wrap { label.wrap() } else { label.truncate() }; let label = if wrap { label.wrap() } else { label.truncate() };
ui.add(label).on_hover_text(hover); ui.add(label).on_hover_text(hover);
}); });
(width, align, draw) (share, align, draw)
} }
/// The width an `f32::INFINITY` cell gets in a row whose other cells are `fixed` wide. /// The width an `f32::INFINITY` cell gets in a row whose other cells take `fixed` of the row.
pub fn leftover(ui: &Ui, fixed: &[f32]) -> f32 { pub fn leftover(ui: &Ui, fixed: f32, cells: usize) -> f32 {
let all = ui.available_rect_before_wrap().width(); let all = ui.available_rect_before_wrap().width();
(all - fixed.iter().sum::<f32>() - ROW_SPACING * fixed.len() as f32).max(0.0) (all * (1.0 - fixed) - ROW_SPACING * cells as f32).max(0.0)
} }
pub const ROW_SPACING: f32 = 4.0; pub const ROW_SPACING: f32 = 4.0;
/// One table row: cells of fixed widths from the left, one under another across rows. /// One table row. Each cell sits at a fixed share of the row's width, so the
/// columns line up across rows whatever the numbers are.
pub fn table_row(ui: &mut Ui, cells: Vec<Cell<'_>>) { pub fn table_row(ui: &mut Ui, cells: Vec<Cell<'_>>) {
let line = ui.text_style_height(&egui::TextStyle::Body) + 2.0; let line = ui.text_style_height(&egui::TextStyle::Body) + 2.0;
let total = ui.available_rect_before_wrap().width(); let total = ui.available_rect_before_wrap().width();
let fixed: f32 = cells let fixed: f32 = cells
.iter() .iter()
.filter(|(width, _, _)| width.is_finite()) .filter(|(share, _, _)| share.is_finite())
.map(|(width, _, _)| *width) .map(|(share, _, _)| *share)
.sum(); .sum::<f32>()
let rest = (total - fixed - ROW_SPACING * cells.len() as f32).max(0.0); .min(1.0);
ui.allocate_ui_with_layout( let rest = (total * (1.0 - fixed) - ROW_SPACING * cells.len() as f32).max(0.0);
egui::vec2(total, line), // The row is one exact rectangle, and every cell gets its own place in it.
Layout::left_to_right(Align::Center), let (rect, _) = ui.allocate_exact_size(egui::vec2(total, line), Sense::hover());
|ui| { let mut row = ui.new_child(
ui.spacing_mut().item_spacing.x = ROW_SPACING; egui::UiBuilder::new()
for (width, align, draw) in cells { .max_rect(rect)
let width = if width.is_finite() { width } else { rest }; .layout(Layout::left_to_right(Align::Center)),
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));
}
},
); );
let mut left = rect.left();
for (share, align, draw) in cells {
let width = if share.is_finite() { total * share } else { rest };
let cell = egui::Rect::from_min_max(
egui::pos2(left, rect.top()),
egui::pos2(left + width, rect.bottom()),
);
let layout = match align {
Align::Max => Layout::right_to_left(Align::Center),
_ => Layout::left_to_right(Align::Center),
};
let mut cell = row.new_child(egui::UiBuilder::new().max_rect(cell).layout(layout));
draw(&mut cell);
left += width + ROW_SPACING;
}
}
/// What an entry of a chart's key stands for.
pub enum Mark {
/// A bar.
Fill(Color32),
/// A line.
Line(Color32),
/// A dashed line: a reset.
Dashed(Color32),
/// Time nothing was recorded in.
Band(bool),
}
/// The swatch for one entry of a chart's key.
pub fn key(ui: &mut Ui, mark: Mark) {
let (rect, _) = ui.allocate_exact_size(egui::vec2(16.0, 10.0), Sense::hover());
let painter = ui.painter();
let left = egui::pos2(rect.left(), rect.center().y);
let right = egui::pos2(rect.right(), rect.center().y);
match mark {
Mark::Fill(color) => {
painter.rect_filled(rect.shrink(1.0), 2.0, color);
}
Mark::Line(color) => {
painter.add(Shape::line(vec![left, right], Stroke::new(2.0, color)));
}
Mark::Dashed(color) => {
painter.add(Shape::dashed_line(
&[left, right],
Stroke::new(1.5, color),
4.0,
3.0,
));
}
Mark::Band(dark) => {
let color = if dark {
Color32::WHITE.gamma_multiply(0.14)
} else {
Color32::BLACK.gamma_multiply(0.12)
};
painter.rect_filled(rect.shrink(1.0), 2.0, color);
}
}
} }
+26 -15
View File
@@ -48,15 +48,26 @@ pub fn section(ui: &mut Ui, view: &View, _dark: bool) {
if !view.not_cached.is_empty() { if !view.not_cached.is_empty() {
ui.add_space(6.0); ui.add_space(6.0);
ui.label(RichText::new("Why compiles could not be cached").strong()); ui.label(RichText::new("Why compiles could not be cached").strong());
let heading = |text: &'static str, share: f32, right: bool| {
style::text_cell(RichText::new(text).small().weak(), share, right, false)
};
style::table_row(
ui,
vec![
heading("Reason", f32::INFINITY, false),
heading("Compiles", 0.16, true),
heading("Share", 0.12, true),
],
);
for (reason, count) in &view.not_cached { for (reason, count) in &view.not_cached {
style::table_row( style::table_row(
ui, ui,
vec![ vec![
style::text_cell(RichText::new(reason.as_str()), f32::INFINITY, false, false), style::text_cell(RichText::new(reason.as_str()), f32::INFINITY, false, false),
style::text_cell(RichText::new(fmt::count(*count)), 72.0, true, false), style::text_cell(RichText::new(fmt::count(*count)), 0.16, true, false),
style::text_cell( style::text_cell(
RichText::new(fmt::share(*count, totals.not_cacheable)), RichText::new(fmt::share(*count, totals.not_cacheable)),
56.0, 0.12,
true, true,
false, false,
), ),
@@ -73,28 +84,28 @@ pub fn section(ui: &mut Ui, view: &View, _dark: bool) {
}); });
} }
/// Column shares for the language table: name, hits, misses, errors, hit rate.
/// The bar takes what is left, so the columns line up at every width.
const LANGUAGE_COLUMNS: [f32; 5] = [0.2, 0.16, 0.16, 0.13, 0.12];
/// One row per language: hits, misses, errors, hit rate and a small bar. /// One row per language: hits, misses, errors, hit rate and a small bar.
fn languages(ui: &mut Ui, view: &View) { fn languages(ui: &mut Ui, view: &View) {
let dark = ui.visuals().dark_mode; let dark = ui.visuals().dark_mode;
let text_color = ui.visuals().text_color(); let text_color = ui.visuals().text_color();
let [_, _, bad] = style::marks(dark); let [_, _, bad] = style::marks(dark);
// Narrower cells on a phone, so the whole row fits. let [name, hits, misses, errors, rate] = LANGUAGE_COLUMNS;
let (name, hits, misses, errors, rate) = if ui.available_rect_before_wrap().width() < 480.0 { let bar = style::leftover(ui, LANGUAGE_COLUMNS.iter().sum(), 6) - style::ROW_SPACING;
(68.0, 56.0, 64.0, 52.0, 48.0) let heading = |text: &'static str, share: f32, right: bool| {
} else { style::text_cell(RichText::new(text).small().weak(), share, right, false)
(130.0, 80.0, 80.0, 72.0, 76.0)
}; };
let widths = [name, hits, misses, errors, rate];
let bar = (style::leftover(ui, &widths) - style::ROW_SPACING).max(0.0);
let weak = |text: &'static str, width| style::text_cell(RichText::new(text).small().weak(), width, true, false);
style::table_row( style::table_row(
ui, ui,
vec![ vec![
style::text_cell(RichText::new("").small(), name, false, false), heading("", name, false),
weak("Hits", hits), heading("Hits", hits, true),
weak("Misses", misses), heading("Misses", misses, true),
weak("Errors", errors), heading("Errors", errors, true),
weak("Hit rate", rate), heading("Hit rate", rate, true),
(f32::INFINITY, egui::Align::Min, Box::new(|_ui| {})), (f32::INFINITY, egui::Align::Min, Box::new(|_ui| {})),
], ],
); );