Compare commits

..
11 Commits
Author SHA1 Message Date
swaitsandClaude Opus 5.5 3a2bcefd38 Redesign the page as an instrument panel: hairline panels, amber hero band, counter strip, two-column grid
Dark charcoal with one amber accent, a derived light theme, the problems list (click to open) inside the hero, raw counters collapsed by default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 09:14:58 -07:00
swaitsandClaude Fable 5.2 06abc4de80 Speed panel: say the time is for one crate's compile, not a whole build
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-28 18:47:40 -07:00
swaitsandClaude Fable 5.2 e3b56cb213 Never start sccache unless asked; compact reasons panel
A server started from the dashboard has the dashboard's environment, not
the builds'. It came up with the 10 GB default beside a 250 GB cache and
sccache trimmed the cache. Starting is now opt-in
(SCCACHE_DASH_START_SCCACHE=1) and the README says why.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-28 18:32:20 -07:00
swaitsandClaude Fable 5.2 c2b07734c6 Merge compact reasons panel: one line per reason, click to open
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-28 18:26:16 -07:00
swaitsandClaude Sonnet 5.5 30643390a7 Reasons: one line each, click to open; stack the small panels beside tall reasons
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 18:23:28 -07:00
swaitsandClaude Fable 5.2 0759cbaa25 just shots: screenshots of the whole page at the 3, 2 and 1 column widths
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-28 18:08:13 -07:00
swaitsandClaude Fable 5.2 29e5103648 Merge scroll fix: a row scrolled above the window ends at its own bottom
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-28 18:02:52 -07:00
swaitsandClaude Sonnet 5.5 9630b96c1b Fix the page growing while scrolled: close panel rows at their own bottom
end_row folded the panels' bottoms from 0.0, so a row whose bottom was above
the top of the window (negative screen y while scrolled) was closed at y=0.
Everything after it was placed from there, the scroll content grew by the
scroll offset, and the scroll bar kept shrinking at the bottom. The lowest
bottom is now a plain function in fmt with a native test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 18:02:00 -07:00
swaitsandClaude Fable 5.2 f08f4655e4 Shorten the low-hit-rate warning; the fix lives in the reasons panel
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-28 17:51:30 -07:00
swaitsandClaude Fable 5.2 a8c69567b4 Merge hit-rate advice: what each not-cacheable reason means and what to change
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-28 17:46:17 -07:00
swaitsandClaude Sonnet 5.5 0f4df265a5 Say what each not-cacheable reason means and what to change; explain a low Rust hit rate
Each reason now carries a plain name, meaning, action and a fixable flag (checked
against sccache 0.18.0), shown with its count in the reasons panel, fixable first.
The low-hit-rate problem names the fixable loss and the Rust hash-key inputs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 17:45:38 -07:00
21 changed files with 1114 additions and 405 deletions

No files matched your search

+8 -2
View File
@@ -74,8 +74,14 @@ reading ever is a baseline and counts for nothing.
## Notes on sccache
When no sccache server is running, sccache-dash starts one (`sccache --start-server`); if that
fails it shows "not running" with the error and tries again a minute later.
sccache-dash never starts or stops sccache's server by itself. When none is running it shows
"not running"; sccache starts its own server on your next build, with your build's settings.
To have sccache-dash start the server when none is running, set `SCCACHE_DASH_START_SCCACHE=1`
in its environment. Be careful with this: a server started that way gets sccache-dash's
environment, not your build's. If your cache size or folder is set only in your build's
environment, the server comes up with sccache's defaults, and sccache deletes cache entries
until the cache fits the 10 GB default.
While sccache-dash runs, sccache's server stays up: being asked for its stats every 10 seconds
keeps it from shutting itself down after 10 idle minutes.
+19 -2
View File
@@ -78,8 +78,9 @@ pub struct View {
pub build_times: Vec<BuildTimes>,
/// Sorted by hits + misses, largest first.
pub languages: Vec<Language>,
/// Why compiles were not cacheable, largest first, e.g. ("crate-type", 562).
pub not_cached: Vec<(String, u64)>,
/// Why compiles were not cacheable: reasons you can fix first, then expected ones,
/// each largest first.
pub not_cached: Vec<NotCached>,
/// Oldest first, evenly spaced, at most 120.
pub buckets: Vec<Bucket>,
/// Most serious first. Empty means no problems.
@@ -92,6 +93,22 @@ pub struct View {
pub summary_markdown: String,
}
/// One reason sccache gave for not caching a compile, with what to do about it.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct NotCached {
/// Exactly as sccache words it, e.g. "crate-type".
pub reason: String,
pub count: u64,
/// A plain name, e.g. "Incremental compilation is on".
pub name: String,
/// One sentence on what the reason means.
pub meaning: String,
/// What to change, or why nothing needs changing.
pub action: String,
/// True when a setting you control would make these compiles cacheable.
pub fixable: bool,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum Status {
/// Compiles arrived in the last five minutes.
+289
View File
@@ -0,0 +1,289 @@
//! What each "not cacheable" reason means and what to do about it.
//!
//! Every statement here was checked against the sccache 0.18.0 source (the file and line
//! of the code that produces each reason is beside its entry) and, where a command is
//! named, by running it. A reason that is not listed is shown as sccache words it, with
//! "sccache does not say more": we do not guess.
use sccache_dash_api::NotCached;
/// What we know about one reason.
pub struct Advice {
pub name: String,
pub meaning: String,
pub action: String,
pub fixable: bool,
}
fn entry(name: &str, meaning: &str, action: &str, fixable: bool) -> Advice {
Advice {
name: name.to_owned(),
meaning: meaning.to_owned(),
action: action.to_owned(),
fixable,
}
}
/// The advice for `reason`, exactly as sccache's "Non-cacheable reasons" prints it.
pub fn advise(reason: &str) -> Advice {
let expected = |name: &str, meaning: &str, why: &str| {
entry(name, meaning, &format!("Nothing to do, this is expected. {why}"), false)
};
match reason {
// rust.rs:1208 `("incremental", _) => cannot_cache!("incremental")`
"incremental" => entry(
"Incremental compilation is on",
"rustc was told to compile incrementally (-C incremental=...), and sccache 0.18.0 never caches those compiles; its own note says rustc in incremental mode is likely to be faster than fetching from the cache.",
"To cache them, turn incremental off: set CARGO_INCREMENTAL=0 in the environment, or incremental = false under [profile.dev] in Cargo.toml, or incremental = false under [build] in ~/.cargo/config.toml. The trade-off: incremental makes rebuilds of your own crates faster, while the cache helps clean builds and dependency builds.",
true,
),
// rust.rs:1187 and rust.rs:1298: only lib, rlib and staticlib are cached.
"crate-type" => expected(
"Programs and libraries that get linked",
"sccache only caches the crate types lib, rlib and staticlib. Anything else (bin, which includes build scripts and test programs, plus proc-macro, dylib and cdylib), or a call with no crate type, is not cached because rustc runs the system linker and sccache cannot know all of the linker's inputs.",
"Cargo builds each of these in every project, and they cannot be cached.",
),
// rust.rs:1026 `flag!("-", TooHardFlag)`, gcc.rs:190
"-" => expected(
"Source read from standard input",
"The compiler was given a bare - (read the source from standard input), which sccache does not cache.",
"Cargo makes one such call per run to ask rustc about the target it builds for.",
),
// rust.rs:1062 `take_arg!("-o", ..., TooHardPath)`; rust.rs doc: "We don't support `-o file`"
"-o" => entry(
"rustc called with -o",
"rustc was given -o <file>, which sccache 0.18.0 does not cache; it needs --out-dir (cargo passes that for normal builds).",
"Nothing to change in sccache. The tool that called rustc directly would have to use --out-dir instead.",
false,
),
// rust.rs:1280 req!(input) (macro at 1269-1276). Seen in the log as CannotCache(missing input): ["-vV"].
"missing input" => expected(
"rustc call with no source file",
"A rustc call had no source file on its command line, so there was nothing to cache.",
"Cargo starts every run with `rustc -vV` to read the compiler's version, and that is counted here.",
),
// rust.rs:1282 req!(output_dir)
"missing output_dir" => expected(
"rustc call without --out-dir",
"A rustc call had no --out-dir, which sccache requires.",
"It comes from the tool that called rustc; cargo's normal builds pass --out-dir.",
),
// rust.rs:1283 req!(emit)
"missing emit" => expected(
"rustc call without --emit",
"A rustc call had no --emit, which sccache requires.",
"It comes from the tool that called rustc; cargo's normal builds pass --emit.",
),
// rust.rs:1284 req!(crate_name)
"missing crate_name" => expected(
"rustc call without --crate-name",
"A rustc call had no --crate-name, which sccache requires.",
"It comes from the tool that called rustc; cargo's normal builds pass --crate-name.",
),
// rust.rs:1173
"more than one --emit" => expected(
"rustc call with --emit given twice",
"rustc was given --emit more than once, which sccache does not handle.",
"It comes from the tool that called rustc.",
),
// rust.rs:1303 ALLOWED_EMIT = link, metadata, dep-info
"unsupported --emit" => expected(
"rustc asked for extra output",
"rustc was asked to emit something other than link, metadata and dep-info (for example asm or llvm-ir), which sccache does not cache.",
"Those outputs were asked for on purpose.",
),
// rust.rs:1198
"extra-filename" => expected(
"-C extra-filename without a value",
"rustc was given -C extra-filename with no value, which sccache cannot use.",
"It comes from the tool that called rustc.",
),
// rust.rs:1232 ArgTarget::Unsure, rust.rs:955-980
"target unsure" => entry(
"Ambiguous --target",
"The --target value is a plain name, but a file with that name plus .json exists, so sccache cannot tell whether a built-in target or your target file is meant.",
"Pass the target file by its path ending in .json (--target path/to/target.json); sccache then hashes the file's contents.",
true,
),
// rust.rs:1048 `take_arg!("--sysroot", ..., TooHardPath)`
"--sysroot" => entry(
"rustc given --sysroot",
"rustc was given --sysroot, which sccache 0.18.0 does not cache.",
"If it comes from RUSTFLAGS or build.rustflags and you do not need a custom sysroot, remove it.",
true,
),
// rust.rs:1248, gcc.rs:666, msvc.rs:791
"multiple input files" => entry(
"Several source files in one compiler call",
"One compiler call named more than one source file, and sccache caches only one source file per call.",
"If your build passes several files to one compiler call, change it to compile one file per call.",
true,
),
// gcc.rs:362 and diab.rs:206
"@" => expected(
"Option value starting with @",
"An option's value began with @: an @file that sccache could not read or expand, or one attached straight to an option. sccache gives up on both.",
"It comes from how the build passes its flags.",
),
// gcc.rs:466
"-x" => entry(
"Unknown language after -x",
"The call said -x <language> with a language sccache does not know.",
"Use a language sccache knows (c, c++, objective-c, objective-c++, assembler, assembler-with-cpp, cu, cuda, hip, or a header kind) or drop -x.",
true,
),
// gcc.rs:472
"multiple different -arch, and SCCACHE_CACHE_MULTIARCH not set" => entry(
"Several -arch values in one call",
"The call had more than one different -arch, and sccache only caches that when SCCACHE_CACHE_MULTIARCH is set.",
"Set SCCACHE_CACHE_MULTIARCH=1 in the environment sccache's server starts with.",
true,
),
// gcc.rs:674, msvc.rs:802
"no input file" => expected(
"C/C++ call with no source file",
"The compiler call had no source file, so there was nothing to cache.",
"It comes from the tool that called the compiler.",
),
// gcc.rs:688, msvc.rs:799
"unknown source language" => entry(
"Source file type not recognised",
"sccache could not tell the language from the file's extension and the call had no -x.",
"Give the file a standard extension, or add -x c or -x c++ to the call.",
true,
),
// gcc.rs:414
"unknown module output format" => expected(
"Unknown clang module output option",
"A clang module-output option had a value sccache does not understand.",
"Only clang modules builds do this.",
),
// gcc.rs:593-604
"Can't handle complex arguments through clang"
| "Can't handle Raw arguments with -Xclang"
| "Can't handle UnknownFlag arguments with -Xclang" => expected(
"Complicated -Xclang options",
"The call passes options through -Xclang that sccache cannot follow.",
"Remove the -Xclang options if you do not need them.",
),
// msvc.rs:610, msvc.rs:911, msvc.rs:831
"output to nul" | "shared pdb" | "invalid input file" => expected(
"Visual C++ call sccache cannot cache",
"The Visual C++ call writes its output to nul, uses a program database file shared by every compile in the folder (-Zi or -ZI without -Fd), or has an input path with no file name; sccache caches none of these.",
"These come from the call's own options.",
),
// gcc.rs:201-214 TooHardFlag: preprocess-only and dependency-only calls
"-E" | "-M" | "-MM" | "-P" => expected(
"Preprocess-only or dependency-only call",
"The call only preprocesses the source or only writes dependency rules (-E, -M, -MM, -P), so it produces no object file; sccache lists these options as too hard to cache.",
"Your build tool runs these calls on purpose.",
),
// gcc.rs:352, rust.rs:1147, msvc.rs:590
"argument parse" => entry(
"A compiler option sccache could not read",
"sccache could not parse one of the compiler's arguments.",
"sccache does not say more in its counters; run the server with SCCACHE_LOG=debug to see the call.",
false,
),
// gcc.rs:375, clang.rs:192-295, msvc.rs:593: the reason is the option's own name.
other if other.starts_with('-') && other.len() > 1 => entry(
&format!("Option {other} is never cached"),
&format!(
"The compiler call contains {other}, which sccache's option table lists as too hard to cache, so every call with it runs uncached."
),
"If you do not need the option, remove it from the build's flags.",
true,
),
other => entry(
other,
"sccache does not say more.",
"",
false,
),
}
}
/// Dress counted reasons with their advice: fixable ones first, then expected ones, each
/// largest first.
pub fn describe(reasons: &[(String, u64)]) -> Vec<NotCached> {
let mut out: Vec<NotCached> = reasons
.iter()
.map(|(reason, count)| {
let a = advise(reason);
NotCached {
reason: reason.clone(),
count: *count,
name: a.name,
meaning: a.meaning,
action: a.action,
fixable: a.fixable,
}
})
.collect();
out.sort_by(|a, b| {
b.fixable
.cmp(&a.fixable)
.then_with(|| b.count.cmp(&a.count))
.then_with(|| a.reason.cmp(&b.reason))
});
out
}
/// How many compiles were lost to reasons that can be fixed, and the biggest of them.
pub fn fixable_loss(reasons: &[NotCached]) -> Option<(u64, &NotCached)> {
let top = reasons.iter().filter(|r| r.fixable).max_by_key(|r| r.count)?;
Some((reasons.iter().filter(|r| r.fixable).map(|r| r.count).sum(), top))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn incremental_says_how_to_turn_it_off_and_what_it_costs() {
let a = advise("incremental");
assert!(a.fixable);
assert!(a.action.contains("CARGO_INCREMENTAL=0"));
assert!(a.action.contains("[profile.dev]"));
assert!(a.action.contains("[build]"));
assert!(a.action.contains("trade-off"));
}
#[test]
fn crate_type_is_expected_and_names_what_is_cached() {
let a = advise("crate-type");
assert!(!a.fixable);
assert!(a.action.starts_with("Nothing to do"));
assert!(a.meaning.contains("lib, rlib and staticlib"));
}
#[test]
fn an_unknown_reason_is_shown_as_it_came() {
let a = advise("something new in 0.19");
assert_eq!(a.name, "something new in 0.19");
assert_eq!(a.meaning, "sccache does not say more.");
assert!(!a.fixable);
}
#[test]
fn an_option_name_is_a_fixable_reason_but_the_known_dashes_are_not() {
assert!(advise("-fplugin").fixable);
assert!(!advise("-").fixable);
assert!(!advise("-o").fixable);
}
#[test]
fn fixable_reasons_come_first_then_the_biggest() {
let out = describe(&[
("crate-type".to_owned(), 1548),
("-".to_owned(), 156),
("incremental".to_owned(), 1642),
("multiple input files".to_owned(), 63),
]);
let order: Vec<&str> = out.iter().map(|r| r.reason.as_str()).collect();
assert_eq!(order, ["incremental", "multiple input files", "crate-type", "-"]);
let (lost, top) = fixable_loss(&out).unwrap();
assert_eq!((lost, top.reason.as_str()), (1705, "incremental"));
assert!(fixable_loss(&out[2..]).is_none());
}
}
+12 -2
View File
@@ -34,10 +34,16 @@ pub struct Config {
pub sccache: OsString,
/// The SQLite file the history is saved in.
pub history: PathBuf,
/// Whether to start sccache's server when none is listening. Off unless asked for: a
/// server started from here has this program's environment, not the builds', so it can
/// come up with another cache size or folder, and sccache trims the cache to the size
/// it is started with.
pub start_sccache: bool,
}
impl Config {
/// `SCCACHE_DASH_SCCACHE` names the sccache command (`sccache` when unset); the history
/// `SCCACHE_DASH_SCCACHE` names the sccache command (`sccache` when unset);
/// `SCCACHE_DASH_START_SCCACHE=1` lets it start sccache's server; the history
/// lives in `$XDG_DATA_HOME/sccache-dash/history.db`.
pub fn from_env() -> Result<Config, String> {
let sccache = std::env::var_os("SCCACHE_DASH_SCCACHE").unwrap_or_else(|| "sccache".into());
@@ -46,6 +52,7 @@ impl Config {
Ok(Config {
sccache,
history: dir.join("sccache-dash").join("history.db"),
start_sccache: std::env::var_os("SCCACHE_DASH_START_SCCACHE").is_some_and(|v| v == "1"),
})
}
}
@@ -299,9 +306,12 @@ impl Task {
}
}
/// Starts sccache's server when none is listening, at most once a minute. `Err` says why
/// Starts sccache's server when none is listening and that was asked for, at most once a minute. `Err` says why
/// there is none, including when an earlier attempt is still being waited out.
fn start_server(&mut self, app: &App, now: i64) -> Result<(), String> {
if !app.cfg.start_sccache {
return Err("no sccache server is running; your next build starts it".to_owned());
}
if let Some(when) = self.started_at {
if now - when < START_EVERY {
return Err(self
+1
View File
@@ -1,6 +1,7 @@
//! The server half of sccache-dash: it asks sccache for its counters, keeps their history and
//! serves the page that draws them.
pub mod advice;
pub mod app;
pub mod history;
pub mod http;
+61 -14
View File
@@ -2,11 +2,12 @@
//! after every poll and kept; a request never waits for the database.
use sccache_dash_api::{
Bucket, BuildTimes, Language, Problem, Range, Server, Severity, Status, TimeSaved, Timing, View,
Bucket, BuildTimes, Language, NotCached, Problem, Range, Server, Severity, Status, TimeSaved, Timing, View,
};
use sccache_dash_stats::{LanguageHits, Observation, Resampled, Saved};
use serde_json::Value;
use crate::advice;
use crate::app::State;
use crate::history::{BucketLangs, BucketRow, History, Row};
use crate::pretty;
@@ -433,6 +434,34 @@ fn buckets(chart: Chart<'_>, now: i64, builds: &Builds, hit_read: f64, live: boo
out
}
/// What a low hit rate means and what to try. Everything said about why a Rust compile misses
/// is what sccache 0.18.0's hash key for Rust (src/compiler/rust.rs, `generate_hash_key`) is
/// made of, and was checked by building the same crate twice, in two directories, through a
/// throwaway server.
fn low_hit_rate_detail(name: &str, hits: u64, n: u64, reasons: &[NotCached]) -> String {
let mut text = format!(
"Only {}% of {} {name} compiles came from the cache.",
pretty::pct(hits as f64 / n as f64),
pretty::thousands(n)
);
if let Some((lost, top)) = advice::fixable_loss(reasons) {
text.push_str(&format!(
" Another {} were skipped for reasons you can fix, mostly \"{}\" ({}): see \"Why compiles were not cacheable\".",
pretty::thousands(lost),
top.name,
pretty::thousands(top.count),
));
}
if name == "Rust" {
text.push_str(
" A Rust compile misses when the folder it is built in, the compiler version, the flags or a CARGO_* variable differ from last time, so the same crate built in two folders (two git worktrees, or a different CARGO_TARGET_DIR variable) is built twice.",
);
} else {
text.push_str(" sccache's counters do not say why a compile missed.");
}
text
}
fn problems(c: &Counters, server: &Server) -> Vec<Problem> {
let t = &c.totals;
let (mut errors, mut warnings) = (Vec::new(), Vec::new());
@@ -492,15 +521,12 @@ fn problems(c: &Counters, server: &Server) -> Vec<Problem> {
.map(|(name, v)| (name, v[0], v[0] + v[1]))
.collect();
low.sort_by(|a, b| (a.1 * b.2).cmp(&(b.1 * a.2)).then_with(|| a.0.cmp(b.0)));
let reasons = advice::describe(&c.not_cached);
for (name, hits, n) in low {
warnings.push(problem(
Severity::Warning,
format!("{name} hit rate {}%", pretty::pct(hits as f64 / n as f64)),
format!(
"Only {}% of {} {name} compiles came from the cache, so most were rebuilt; a different toolchain, compiler flags or environment makes sccache miss, so compare those between two builds.",
pretty::pct(hits as f64 / n as f64),
pretty::thousands(n)
),
low_hit_rate_detail(name, hits, n, &reasons),
));
}
if let (Some(size), Some(max)) = (server.cache_size, server.max_cache_size) {
@@ -678,8 +704,7 @@ fn compute(
.cmp(&(a.hits + a.misses))
.then_with(|| a.name.cmp(&b.name))
});
let mut not_cached = counters.not_cached.clone();
not_cached.sort_by(|a, b| b.1.cmp(&a.1).then_with(|| a.0.cmp(&b.0)));
let not_cached = advice::describe(&counters.not_cached);
let mut view = View {
range: Some(range),
@@ -1052,11 +1077,15 @@ mod tests {
errors: 0
}
);
let order: Vec<&str> = v.not_cached.iter().map(|r| r.reason.as_str()).collect();
assert_eq!(
v.not_cached[0],
("crate-type".to_owned(), 621),
"largest reason first"
order,
["incremental", "multiple input files", "crate-type", "-o", "-", "missing input", "missing emit"],
"reasons you can fix first, then the expected ones, each largest first"
);
assert_eq!((v.not_cached[0].count, v.not_cached[0].fixable), (105, true));
assert_eq!(v.not_cached[2].count, 621);
assert!(!v.not_cached[2].fixable);
assert_eq!(v.raw, serde_json::from_str::<Value>(LIVE).unwrap());
}
@@ -1450,7 +1479,24 @@ mod tests {
);
assert!(rate(vec![("Rust", [4, 46, 0])]).problems[0]
.detail
.starts_with("Only 8% of 50 Rust compiles came from the cache, so most were rebuilt;"));
.starts_with("Only 8% of 50 Rust compiles came from the cache."));
let detail = seen(
|s| {
s.counters.langs = vec![("Rust".to_owned(), [4, 46, 0])];
s.counters.not_cached = vec![("incremental".to_owned(), 30), ("crate-type".to_owned(), 90)];
},
"0.18.0",
)
.problems[0]
.detail
.clone();
assert!(
detail.contains("Another 30 were skipped for reasons you can fix")
&& detail.contains("\"Incremental compilation is on\" (30)")
&& detail.contains("the folder it is built in")
&& !detail.contains("Programs and libraries"),
"{detail}"
);
assert!(
rate(vec![("Rust", [19, 30, 0])]).problems.is_empty(),
"49 compiles is too few to say"
@@ -1545,8 +1591,9 @@ mod tests {
assert!(
all.problems
.iter()
.all(|p| p.detail.split(". ").count() == 1 && p.detail.ends_with('.')),
"each detail is one sentence: {:?}",
.all(|p| p.detail.ends_with('.')
&& (p.title.contains("hit rate") || p.detail.split(". ").count() == 1)),
"each detail is one sentence, except the hit-rate one that says what to change: {:?}",
all.problems
);
}
+25
View File
@@ -91,6 +91,7 @@ esac
Config {
sccache: self.script.clone().into(),
history: self.history.clone(),
start_sccache: true,
}
}
}
@@ -444,6 +445,30 @@ fn old_rows_are_deleted_at_startup() {
);
}
#[test]
fn a_missing_sccache_server_is_left_alone_unless_starting_was_asked_for() {
let fake = Fake::new();
fake.down();
let app = App::with_probe(
Config {
start_sccache: false,
..fake.config()
},
fake.probe(),
);
let mut task = Task::memory();
task.poll(&app, NOW);
task.poll(&app, NOW + 120);
let calls = fake.calls();
assert!(!calls.iter().any(|c| c == "--start-server"), "{calls:?}");
assert!(app
.lock()
.error
.as_deref()
.is_some_and(|e| e.contains("your next build starts it")));
}
#[test]
fn a_missing_sccache_server_is_started_once_then_read() {
let fake = Fake::new();
+185 -171
View File
@@ -5,6 +5,7 @@ use std::time::Duration;
use eframe::egui;
use sccache_dash_api::{Range, View};
use crate::disclosure;
use crate::fmt;
use crate::theme;
use crate::{cards, extras, net, overtime, problems, raw, speed, style, where_went};
@@ -249,35 +250,48 @@ fn theme_labels() -> [&'static str; 3] {
ThemeChoice::ALL.map(|theme| theme.name())
}
/// The wordmark at the left of the top bar.
fn wordmark(ui: &mut egui::Ui) {
ui.add(egui::Label::new(
egui::RichText::new("sccache dash")
.font(theme::number_font(15.0))
.color(theme::ui(ui).text),
));
}
fn wordmark_width(ui: &egui::Ui) -> f32 {
style::text_width(ui, "sccache dash", theme::number_font(15.0))
}
/// About how wide the row of actions is, from the width of its labels.
fn actions_width(ui: &egui::Ui) -> f32 {
let medium = theme::medium(theme::px::BODY);
let label = |text: &str| style::text_width(ui, text, medium.clone()) + 22.0;
let gaps = theme::space::PANEL_GAP;
label(&fmt::refresh_label(30)) + label("Refresh")
let label = |text: &str| style::text_width(ui, text, medium.clone()) + 18.0;
let gaps = theme::space::TOOL_GAP;
label(&fmt::refresh_label(30)) + 20.0 + label("Refresh")
+ theme_labels().iter().map(|text| style::text_width(ui, text, medium.clone()) + 2.0 * theme::space::CONTROL_PAD).sum::<f32>()
+ label("Copy summary") + label("Export JSON") + label("Zero stats")
+ theme::space::TOOLBAR_NOTE_WIDTH
+ gaps * 7.0
}
/// The row of controls that stays at the top of the page: the range as one
/// segmented control at the left; the actions at the right, on their own lines
/// where there is no room beside the range.
/// The slim bar at the top of the page: the wordmark and the range at the left; the
/// actions at the right, on their own line where there is no room beside the range.
fn controls(dashboard: &mut Dashboard, ui: &mut egui::Ui) {
let ctx = ui.ctx().clone();
let now = Dashboard::now(&ctx);
let gap = theme::space::PANEL_GAP;
let gap = theme::space::TOOL_GAP;
let margin = theme::space::PAGE_MARGIN;
ui.add_space(margin);
let vertical = 10.0;
ui.add_space(vertical);
let width = ui.available_rect_before_wrap().width() - 2.0 * margin;
let medium = theme::medium(theme::px::BODY);
let range_width: f32 = Range::ALL
.iter()
.map(|range| style::text_width(ui, range.code(), medium.clone()) + 2.0 * theme::space::CONTROL_PAD)
.sum();
let beside = width >= theme::layout::TOOLBAR_TWO_LINES_BELOW;
let one_line = beside && range_width + gap + actions_width(ui) <= width;
let left_width = wordmark_width(ui) + 2.0 * theme::space::PANEL_GAP + range_width;
let one_line = left_width + gap + actions_width(ui) <= width;
let phone = width + 2.0 * theme::space::PAGE_MARGIN < theme::layout::TWO_COLUMNS_FROM;
let labels: Vec<&str> = Range::ALL.iter().map(|range| range.code()).collect();
@@ -285,6 +299,8 @@ fn controls(dashboard: &mut Dashboard, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = gap;
ui.add_space(margin);
wordmark(ui);
ui.add_space(theme::space::PANEL_GAP - gap);
if let Some(index) = style::segmented(ui, "range", &labels, chosen) {
if index != chosen {
dashboard.range = Range::ALL[index];
@@ -293,7 +309,7 @@ fn controls(dashboard: &mut Dashboard, ui: &mut egui::Ui) {
}
}
if one_line {
ui.add_space((ui.available_width() - actions_width(ui)).max(0.0));
ui.add_space((ui.available_width() - actions_width(ui) - margin).max(0.0));
ui.allocate_ui_with_layout(
egui::vec2(actions_width(ui), theme::layout::TOOLBAR_HEIGHT),
egui::Layout::left_to_right(egui::Align::Center),
@@ -303,8 +319,8 @@ fn controls(dashboard: &mut Dashboard, ui: &mut egui::Ui) {
});
if !one_line {
let height = theme::layout::TOOLBAR_HEIGHT;
ui.add_space(margin);
let room = ui.available_rect_before_wrap().width();
ui.add_space(gap);
let room = ui.available_rect_before_wrap().width() - 2.0 * margin;
let group_width = if phone { room } else { actions_width(ui).min(room) };
// On a phone the actions wrap at the left; on a narrower window they sit
// on a second line, at the right.
@@ -313,20 +329,30 @@ fn controls(dashboard: &mut Dashboard, ui: &mut egui::Ui) {
} else {
egui::Layout::right_to_left(egui::Align::Center)
};
ui.allocate_ui_with_layout(egui::vec2(room, height), layout, |ui| {
if !phone {
ui.allocate_ui_with_layout(
egui::vec2(group_width, height),
egui::Layout::left_to_right(egui::Align::Center),
|ui| actions(dashboard, ui, &ctx, now, gap),
);
} else {
ui.spacing_mut().item_spacing = egui::vec2(gap, gap);
actions(dashboard, ui, &ctx, now, gap);
}
ui.horizontal(|ui| {
ui.add_space(margin);
ui.allocate_ui_with_layout(egui::vec2(room, height), layout, |ui| {
if !phone {
ui.allocate_ui_with_layout(
egui::vec2(group_width, height),
egui::Layout::left_to_right(egui::Align::Center),
|ui| actions(dashboard, ui, &ctx, now, gap),
);
} else {
ui.spacing_mut().item_spacing = egui::vec2(gap, gap);
actions(dashboard, ui, &ctx, now, gap);
}
});
});
}
ui.add_space(gap - theme::space::LINE);
ui.add_space(vertical);
let rule = ui.available_rect_before_wrap();
ui.painter().hline(
rule.x_range(),
rule.top() + 0.5,
egui::Stroke::new(1.0, theme::ctx(&ctx).border),
);
ui.add_space(1.0);
}
/// Refresh, theme, Copy summary, Export JSON, Zero stats, and the message slot.
@@ -460,7 +486,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.
let width = ui.available_rect_before_wrap().width();
let height = theme::layout::HEADLINE_HEIGHT + theme::space::PANEL_GAP + theme::layout::CARD_HEIGHT * 2.0;
let height = theme::layout::HEADLINE_HEIGHT + theme::space::PANEL_GAP + theme::layout::STRIP_ROW_HEIGHT * 2.0;
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, height), egui::Sense::hover());
let mut place = ui.new_child(
egui::UiBuilder::new()
@@ -481,7 +507,7 @@ fn lost_contact(ctx: &egui::Context, error: &str, from: i64, page_width: f32) {
egui::Area::new(egui::Id::unique("lost-contact"))
.anchor(
egui::Align2::RIGHT_TOP,
egui::vec2(-theme::space::PAGE_MARGIN, theme::layout::TOOLBAR_HEIGHT + 2.0 * theme::space::PAGE_MARGIN),
egui::vec2(-theme::space::PAGE_MARGIN, theme::layout::TOOLBAR_HEIGHT + 3.0 * theme::space::PAGE_MARGIN),
)
.order(egui::Order::Foreground)
.show(ctx, |ui| {
@@ -490,9 +516,9 @@ fn lost_contact(ctx: &egui::Context, error: &str, from: i64, page_width: f32) {
.fill(p.panel)
.stroke(egui::Stroke::new(1.0, p.bad))
.corner_radius(theme::space::PANEL_RADIUS)
.inner_margin(theme::space::PANEL_PADDING)
.inner_margin(theme::space::PANEL_PAD_Y)
.show(ui, |ui| {
ui.set_max_width(width - 2.0 * theme::space::PANEL_PADDING);
ui.set_max_width(width - 2.0 * theme::space::PANEL_PAD_Y);
ui.add(
egui::Label::new(
theme::strong(format!(
@@ -528,16 +554,6 @@ fn table_height(fixed: f32, rows: usize) -> f32 {
fixed + rows as f32 * theme::space::ROW
}
/// How tall the row of "Where compiles went", "By language" and "Problems" is:
/// enough for the tallest of the three, and never less than the usual height.
fn triptych_height(view: &View) -> f32 {
use theme::layout as l;
l::TRIPTYCH_HEIGHT
.max(l::WHERE_FIXED_HEIGHT)
.max(table_height(l::LANGUAGES_FIXED_HEIGHT, view.languages.len()))
.max(problems_height(view))
}
/// How tall "Speed" is.
fn speed_height(view: &View) -> f32 {
use theme::layout as l;
@@ -549,33 +565,9 @@ fn speed_height(view: &View) -> f32 {
table_height(l::SPEED_FIXED_HEIGHT, 0) + with_histograms as f32 * l::HISTOGRAM_HEIGHT
}
fn problems_height(view: &View) -> f32 {
use theme::layout as l;
if view.problems.is_empty() {
88.0
} else {
table_height(l::PROBLEMS_FIXED_HEIGHT, 0) + view.problems.len() as f32 * l::PROBLEM_HEIGHT
}
}
/// How tall the row of "Over time" is when "Speed" and "Why compiles were not
/// cacheable" are stacked beside it: the taller of the two sides.
fn charts_height(view: &View) -> f32 {
use theme::layout as l;
let stacked = speed_height(view)
+ theme::space::PANEL_GAP
+ where_went::reasons_height(view.not_cached.len());
l::CHARTS_HEIGHT.max(stacked)
}
/// How tall each chart of "Over time" is in a row `height` tall: the usual
/// height, plus the room a taller row leaves.
fn chart_height(height: f32) -> f32 {
let extra = (height - theme::layout::CHARTS_HEIGHT).max(0.0);
theme::drawing::CHART_HEIGHT + (extra / 2.0 - 2.0 * theme::space::LINE).max(0.0)
}
/// The whole page below the controls: a grid of panels.
/// The whole page below the controls: a grid of panels. Two columns of panels
/// from the medium width up, one below it; the counter strip is six across,
/// three across, or two.
fn page(ui: &mut egui::Ui, view: &View, asked: Range, hidden_languages: &mut Vec<String>) {
let p = theme::ui(ui);
use theme::layout as l;
@@ -588,7 +580,7 @@ fn page(ui: &mut egui::Ui, view: &View, asked: Range, hidden_languages: &mut Vec
headline(ui, view, asked);
// Six cards in one row on a wide screen; three in the two-column layout; two on a phone.
// Six counters in one row on a wide screen; three in the medium layout; two on a phone.
let per_row = match columns {
3 => 6,
2 => 3,
@@ -596,71 +588,56 @@ fn page(ui: &mut egui::Ui, view: &View, asked: Range, hidden_languages: &mut Vec
};
cards::row(ui, view, per_row);
match columns {
3 => {
let [a, b, c] = row(ui, triptych_height(view), &[1, 1, 1]).try_into().expect("three panels");
let (_, a) = style::panel(ui, a, "Where compiles went", |ui| where_went::section(ui, view));
let (_, b) = style::panel(ui, b, "By language", |ui| where_went::languages(ui, view));
let (_, c) = style::panel(ui, c, "Problems", |ui| problems::section(ui, view));
close_row(ui, &[a, b, c]);
if columns >= 2 {
let half = style::span_width(ui, 2, 1);
let languages_h = table_height(l::LANGUAGES_FIXED_HEIGHT, view.languages.len() + 1);
let [a, b] = row(ui, l::WHERE_FIXED_HEIGHT.max(languages_h), &[1, 1]).try_into().expect("two panels");
let (_, a) = style::panel(ui, a, "Where compiles went", |ui| where_went::section(ui, view));
let (_, b) = style::panel(ui, b, "By language", |ui| where_went::languages(ui, view));
close_row(ui, &[a, b]);
// "Over time" over two columns; "Speed" and the reasons stacked in the third, together as tall.
let height = charts_height(view);
let [wide, side] = row(ui, height, &[2, 1]).try_into().expect("two panels");
let speed = speed_height(view);
let speed_rect = egui::Rect::from_min_max(side.min, egui::pos2(side.right(), side.top() + speed));
let reasons_rect = egui::Rect::from_min_max(egui::pos2(side.left(), side.top() + speed + gap), side.max);
let (_, wide) = style::panel(ui, wide, "Over time", |ui| {
overtime::section(ui, view, hidden_languages, chart_height(height))
});
let (_, speed) = style::panel(ui, speed_rect, "Speed", |ui| speed::section(ui, view));
let (_, reasons) = style::panel(ui, reasons_rect, "Why compiles were not cacheable", |ui| {
where_went::reasons(ui, view)
});
close_row(ui, &[wide, speed, reasons]);
}
2 => {
let reasons = where_went::reasons_height(view.not_cached.len());
let height = l::TRIPTYCH_HEIGHT.max(l::WHERE_FIXED_HEIGHT).max(reasons);
let [a, b] = row(ui, height, &[1, 1]).try_into().expect("two panels");
let (_, a) = style::panel(ui, a, "Where compiles went", |ui| where_went::section(ui, view));
let (_, b) = style::panel(ui, b, "Why compiles were not cacheable", |ui| where_went::reasons(ui, view));
close_row(ui, &[a, b]);
let height = l::TRIPTYCH_HEIGHT
.max(table_height(l::LANGUAGES_FIXED_HEIGHT, view.languages.len()))
.max(problems_height(view));
let [a, b] = row(ui, height, &[1, 1]).try_into().expect("two panels");
let (_, a) = style::panel(ui, a, "By language", |ui| where_went::languages(ui, view));
let (_, b) = style::panel(ui, b, "Problems", |ui| problems::section(ui, view));
close_row(ui, &[a, b]);
let [a] = row(ui, l::CHARTS_HEIGHT, &[2]).try_into().expect("one panel");
let (_, a) = style::panel(ui, a, "Over time", |ui| {
overtime::section(ui, view, hidden_languages, theme::drawing::CHART_HEIGHT)
});
close_row(ui, &[a]);
single(ui, "Speed", |ui| speed::section(ui, view));
}
_ => {
// One column: the phone's order, each panel as tall as what it holds.
single(ui, "Problems", |ui| problems::section(ui, view));
single(ui, "Where compiles went", |ui| where_went::section(ui, view));
single(ui, "Why compiles were not cacheable", |ui| where_went::reasons(ui, view));
single(ui, "By language", |ui| where_went::languages(ui, view));
single(ui, "Over time", |ui| {
overtime::section(ui, view, hidden_languages, theme::drawing::CHART_HEIGHT)
});
single(ui, "Speed", |ui| speed::section(ui, view));
}
overtime::filter(ui, view, hidden_languages);
ui.add_space(theme::space::ITEM);
let hidden: &[String] = hidden_languages;
let [a, b] = row(ui, l::CHART_PANEL_HEIGHT, &[1, 1]).try_into().expect("two panels");
let (_, a) = style::panel(ui, a, "Hit rate over time", |ui| {
overtime::hit_rate_panel(ui, view, hidden, theme::drawing::CHART_HEIGHT)
});
let (_, b) = style::panel(ui, b, "Compiles over time", |ui| {
overtime::volume_panel(ui, view, hidden, theme::drawing::CHART_HEIGHT)
});
close_row(ui, &[a, b]);
let height = speed_height(view).max(where_went::reasons_height(ui, view, half));
let [a, b] = row(ui, height, &[1, 1]).try_into().expect("two panels");
let (_, a) = style::panel(ui, a, "Speed", |ui| speed::section(ui, view));
let (_, b) = style::panel(ui, b, "Why compiles were not cacheable", |ui| where_went::reasons(ui, view));
close_row(ui, &[a, b]);
} else {
// One column: each panel as tall as what it holds.
single(ui, "Where compiles went", |ui| where_went::section(ui, view));
single(ui, "By language", |ui| where_went::languages(ui, view));
overtime::filter(ui, view, hidden_languages);
ui.add_space(theme::space::ITEM);
let hidden: &[String] = hidden_languages;
single(ui, "Hit rate over time", |ui| {
overtime::hit_rate_panel(ui, view, hidden, theme::drawing::CHART_HEIGHT)
});
single(ui, "Compiles over time", |ui| {
overtime::volume_panel(ui, view, hidden, theme::drawing::CHART_HEIGHT)
});
single(ui, "Speed", |ui| speed::section(ui, view));
single(ui, "Why compiles were not cacheable", |ui| where_went::reasons(ui, view));
}
extras(ui, view);
let open = ui
.ctx()
.data_mut(|data| data.get_temp::<bool>(egui::Id::unique("raw-counters-open")))
.unwrap_or(true);
let full = style::span_width(ui, columns, columns);
let [rect] = row(ui, raw::height(view, full, open), &[columns]).try_into().expect("one panel");
.data_mut(|data| data.get_temp::<bool>(egui::Id::new("raw-counters-open")))
.unwrap_or(false);
let full = style::span_width(ui, 1, 1);
let [rect] = row(ui, raw::height(view, full, open), &[1]).try_into().expect("one panel");
let taken = raw::section(ui, view, rect);
close_row(ui, &[taken]);
ui.add_space(theme::space::PAGE_MARGIN);
@@ -671,12 +648,12 @@ fn extras(ui: &mut egui::Ui, view: &View) {
if view.extras.is_empty() {
return;
}
let columns = theme::columns(ui.available_rect_before_wrap().width());
let columns = theme::columns(ui.available_rect_before_wrap().width()).min(2);
let per_row = columns.min(view.extras.len()).max(1);
for line in view.extras.chunks(per_row) {
let spans: Vec<usize> = line.iter().map(|_| 1).collect();
let height = theme::space::ROW * (line.iter().map(|extra| extra.rows.len()).max().unwrap_or(0) + 1) as f32
+ theme::space::PANEL_PADDING * 2.0 + theme::space::UNDER_TITLE + 12.0;
+ theme::space::PANEL_PAD_Y * 2.0 + theme::space::UNDER_TITLE + 12.0;
let cells = style::cells(ui, height, &spans);
let mut taken = Vec::with_capacity(cells.len());
for (rect, extra) in cells.iter().zip(line) {
@@ -701,9 +678,18 @@ struct Figure<'a> {
small2: String,
/// A trend line and the value it is drawn against.
trend: Option<(&'a [Option<f64>], f64)>,
/// Instead of a trend line and small print: the problems list.
problems: Option<&'a View>,
hover: Option<String>,
}
/// The line the figure's number sits on: every figure's number has this much room, so all
/// the captions below start at the same height whatever size the number is drawn at.
const VALUE_ROW: f32 = theme::px::HEADLINE * 1.25;
/// The room the storage line (meter and text) is given under the figures; a phone has a second text line.
const STORAGE_LINE: f32 = 30.0;
impl Figure<'_> {
/// Draw in a column `width` wide and always the same height.
fn draw(self, ui: &mut egui::Ui, width: f32) {
@@ -714,14 +700,29 @@ impl Figure<'_> {
|ui| {
ui.set_width(width);
ui.spacing_mut().item_spacing = egui::vec2(gap, gap);
let value = egui::Label::new(
egui::RichText::new(&self.value)
.font(theme::number_font(self.size))
.color(self.color),
)
.truncate();
ui.add(value.sense(egui::Sense::hover())).on_hover_text(&self.value);
ui.add(egui::Label::new(theme::small(ui, self.caption.clone())).truncate());
// Shrink a long figure to the column instead of cutting it.
let natural = style::text_width(ui, &self.value, theme::number_font(self.size));
let size = if natural > width { (self.size * width / natural).max(20.0) } else { self.size };
ui.allocate_ui_with_layout(
egui::vec2(width, VALUE_ROW),
egui::Layout::left_to_right(egui::Align::Max),
|ui| {
let value = egui::Label::new(
egui::RichText::new(&self.value)
.font(theme::number_font(size))
.color(self.color),
)
.truncate();
ui.add(value.sense(egui::Sense::hover())).on_hover_text(&self.value);
},
);
ui.add(egui::Label::new(theme::title(ui, self.caption.clone())).truncate());
ui.add_space(gap * 2.0);
if let Some(view) = self.problems {
let room = ui.available_height();
problems::hero_list(ui, view, room);
return;
}
match self.trend {
Some((values, top)) => style::sparkline(ui, theme::drawing::SPARKLINE, values, top, self.color),
None => ui.add_space(theme::drawing::SPARKLINE + gap),
@@ -755,12 +756,6 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range) {
let saved_top = saved.iter().flatten().fold(0.0_f64, |top, seconds| top.max(*seconds));
let problems = view.problems.len();
let worst = view.problems.first();
let problem_color = match worst.map(|problem| problem.severity) {
Some(sccache_dash_api::Severity::Error) => p.bad,
Some(sccache_dash_api::Severity::Warning) => p.warn,
None => p.text,
};
let counts = format!(
"{} compiles · {} from cache · {} built",
@@ -771,10 +766,15 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range) {
let title_text = theme::title(ui, range.label()).text().to_owned();
let counts_text = counts.clone();
let width = ui.available_rect_before_wrap().width();
let rect = egui::Rect::from_min_size(
ui.cursor().min,
egui::vec2(width, theme::layout::HEADLINE_HEIGHT),
);
// Side by side where there is room; one under another on a phone.
let side_by_side = width >= 600.0;
let spacing = theme::space::PANEL_GAP;
let height = if side_by_side {
theme::layout::HEADLINE_HEIGHT
} else {
theme::layout::HEADLINE_HEIGHT + 2.0 * (theme::layout::FIGURE_HEIGHT + spacing) + STORAGE_LINE / 2.0
};
let rect = egui::Rect::from_min_size(ui.cursor().min, egui::vec2(width, height));
let (_, taken) = style::panel_titled(
ui,
rect,
@@ -788,20 +788,19 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range) {
},
|ui| {
let width = ui.available_rect_before_wrap().width();
let spacing = theme::space::PANEL_GAP;
// Side by side where there is room; one under another on a phone.
let side_by_side = width >= 600.0;
let columns = if side_by_side { 3.0 } else { 1.0 };
let column = (width - spacing * (columns - 1.0)) / columns;
ui.add_space(theme::space::ITEM);
let draw = |ui: &mut egui::Ui, figure: Figure<'_>| figure.draw(ui, column);
// Timeouts, cache errors and forced recaches are inside the built count, as sccache counts them.
let first = Figure {
value: fmt::percent(totals.hit_rate()),
size: theme::px::HEADLINE,
color: theme::hit_rate_color(totals.hit_rate(), p),
color: p.hero,
caption: "from cache".into(),
small: format!("{} of all compiler calls", fmt::percent(totals.hit_rate_of_all())),
trend: Some((&rates, 1.0)),
problems: None,
hover: None,
small2: String::new(),
};
@@ -838,46 +837,51 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range) {
let second = Figure {
value,
size,
color: p.text,
color: p.hero,
caption: "saved (rough)".into(),
small,
small2,
trend: Some((&saved, saved_top)),
problems: None,
hover: Some(view.time_saved.note.clone()),
};
let third = Figure {
value: if problems == 1 {
"1 problem".into()
} else if problems == 0 {
"No problems".into()
} else {
format!("{} problems", fmt::count(problems as u64))
},
size: theme::px::CARD_NUMBER,
color: problem_color,
caption: worst
.map(|problem| problem.title.clone())
.unwrap_or_else(|| "Nothing needs attention".into()),
value: fmt::count(problems as u64),
size: theme::px::HEADLINE,
color: if problems > 0 { p.bad } else { p.text },
caption: if problems == 1 { "problem".into() } else { "problems".into() },
small: String::new(),
small2: String::new(),
trend: None,
problems: Some(view),
hover: None,
};
let top = ui.cursor().top();
let left = ui.cursor().left();
if side_by_side {
ui.horizontal(|ui| {
ui.horizontal_top(|ui| {
ui.spacing_mut().item_spacing.x = spacing;
draw(ui, first);
draw(ui, second);
draw(ui, third);
});
// A hairline in the middle of each gutter between figures.
let y = top..=top + theme::layout::FIGURE_HEIGHT;
for index in 1..3 {
let x = left + index as f32 * column + (index as f32 - 0.5) * spacing;
ui.painter().vline(x.round() + 0.5, y.clone(), egui::Stroke::new(1.0, p.grid));
}
} else {
draw(ui, first);
ui.add_space(spacing);
draw(ui, second);
ui.add_space(spacing);
draw(ui, third);
}
ui.add_space(theme::space::ITEM);
style::rule(ui);
ui.add_space(theme::space::PANEL_GAP);
ui.add_space(theme::space::ITEM + 2.0);
let server = &view.server;
let mut parts = Vec::new();
@@ -885,7 +889,7 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range) {
// sccache words it `Local disk: "/home/me/.cache/sccache"`; the kind is enough here.
let kind = location.split(':').next().unwrap_or(location);
let kind = if kind.eq_ignore_ascii_case("LOCAL DISK") {
"local disk".to_owned()
"Local disk".to_owned()
} else {
kind.to_owned()
};
@@ -905,15 +909,25 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range) {
}
.to_owned(),
);
let line = format!("Cache: {}", parts.join(" · "));
let response = ui.add(egui::Label::new(theme::small(ui, line)).wrap());
if let Some(location) = &server.cache_location {
response.on_hover_text(location.clone());
}
let line = parts.join(" · ");
// The meter first, then the text under it, in a box of fixed height.
let lines = if side_by_side { 1.0 } else { 2.0 };
let text_height = STORAGE_LINE / 2.0 * lines;
if let (Some(size), Some(max)) = (server.cache_size, server.max_cache_size) {
let full = if max > 0 { size as f64 / max as f64 } else { 0.0 };
let color = if full >= theme::state::CACHE_FULL { p.bad } else { p.from_cache };
let color = if full >= theme::state::CACHE_FULL { p.bad } else { p.hero };
style::meter(ui, theme::drawing::USAGE_BAR, full, color);
ui.add_space(theme::space::ITEM);
}
let response = ui
.allocate_ui_with_layout(
egui::vec2(width, text_height),
egui::Layout::top_down(egui::Align::Min),
|ui| ui.add(egui::Label::new(theme::small(ui, line)).wrap()),
)
.inner;
if let Some(location) = &server.cache_location {
response.on_hover_text(location.clone());
}
},
);
+15 -8
View File
@@ -1,4 +1,4 @@
//! The six stat cards under the headline: all the same size, tops in a line.
//! The six counters under the headline: one quiet strip, all cells the same size, tops in a line.
use eframe::egui::{self, Color32, Pos2, Rect, RichText};
@@ -77,25 +77,32 @@ pub fn row(ui: &mut egui::Ui, view: &View, per_row: usize) {
let left = ui.cursor().left();
let mut top = ui.cursor().top();
let width = ui.available_rect_before_wrap().width();
let card_width = (width - theme::space::PANEL_GAP * (per_row - 1) as f32) / per_row as f32;
for line in cards.chunks(per_row) {
let mut x = left;
for card in line {
let cell_width = width / per_row as f32;
let height = theme::layout::STRIP_ROW_HEIGHT;
let rule = egui::Stroke::new(1.0, p.border);
ui.painter().hline(left..=left + width, top + 0.5, rule);
for (line_index, line) in cards.chunks(per_row).enumerate() {
if line_index > 0 {
ui.painter().hline(left..=left + width, top + 0.5, egui::Stroke::new(1.0, p.grid));
}
for (index, card) in line.iter().enumerate() {
let change = change(card.count, card.previous, range, card.good_when_up, p);
style::card(
ui,
Rect::from_min_size(Pos2::new(x, top), egui::vec2(card_width, theme::layout::CARD_HEIGHT)),
Rect::from_min_size(Pos2::new(left + index as f32 * cell_width, top), egui::vec2(cell_width, height)),
index == 0,
card.title,
&fmt::count(card.count),
&card.detail,
change,
card.color.unwrap_or(p.text),
);
x += card_width + theme::space::PANEL_GAP;
}
top += theme::layout::CARD_HEIGHT + theme::space::PANEL_GAP;
top += height;
}
ui.painter().hline(left..=left + width, top - 0.5, rule);
ui.add_space(top - ui.cursor().top());
ui.add_space(theme::space::PANEL_GAP);
}
struct Card {
+88
View File
@@ -0,0 +1,88 @@
//! The arithmetic of a list of lines that open: which start open, how tall the
//! list is, and whether stacking panels beside it wastes less room. No drawing
//! here, so it is tested natively.
/// A line that opens to show a text beneath it, laid out for a width.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Entry {
/// The line itself.
pub row: f32,
pub open: bool,
/// The first paragraph's height; used only when open.
pub meaning: f32,
/// The second paragraph's height, `None` when there is none; used only when open.
pub action: Option<f32>,
}
/// Whether a line is open: what was clicked, else open when `fixable`.
pub fn is_open(stored: Option<bool>, fixable: bool) -> bool {
stored.unwrap_or(fixable)
}
/// How tall one line is: `gap` between its parts, `pad` under the open text.
pub fn entry_height(entry: &Entry, gap: f32, pad: f32) -> f32 {
if !entry.open {
return entry.row;
}
let action = entry.action.map_or(0.0, |height| gap + height);
entry.row + gap + entry.meaning + action + pad
}
/// How tall the whole list is: its lines and a hairline `separator` tall between them.
pub fn list_height(entries: &[Entry], gap: f32, pad: f32, separator: f32) -> f32 {
let lines: f32 = entries.iter().map(|entry| entry_height(entry, gap, pad)).sum();
lines + entries.len().saturating_sub(1) as f32 * separator
}
/// Whether to stack the panels (`stacked` tall in all) beside a panel `beside` tall rather
/// than put the one `single` panel there: yes when that leaves less empty room.
pub fn stack_beside(single: f32, stacked: f32, beside: f32) -> bool {
(stacked - beside).abs() < (single - beside).abs()
}
#[cfg(test)]
mod tests {
use super::*;
fn entry(open: bool) -> Entry {
Entry { row: 28.0, open, meaning: 45.0, action: Some(30.0) }
}
#[test]
fn only_fixable_lines_start_open() {
assert!(is_open(None, true));
assert!(!is_open(None, false));
}
#[test]
fn a_click_wins_over_the_default() {
assert!(!is_open(Some(false), true));
assert!(is_open(Some(true), false));
}
#[test]
fn a_closed_line_is_one_row_and_an_open_one_adds_its_text() {
assert_eq!(entry_height(&entry(false), 3.0, 8.0), 28.0);
assert_eq!(entry_height(&entry(true), 3.0, 8.0), 28.0 + 3.0 + 45.0 + 3.0 + 30.0 + 8.0);
let no_action = Entry { action: None, ..entry(true) };
assert_eq!(entry_height(&no_action, 3.0, 8.0), 28.0 + 3.0 + 45.0 + 8.0);
}
#[test]
fn a_list_is_its_lines_and_the_hairlines_between() {
let list = [entry(true), entry(false), entry(false)];
assert_eq!(list_height(&list, 3.0, 8.0, 1.0), 117.0 + 28.0 + 28.0 + 2.0);
assert_eq!(list_height(&[], 3.0, 8.0, 1.0), 0.0);
assert_eq!(list_height(&[entry(false)], 3.0, 8.0, 1.0), 28.0);
}
#[test]
fn stacking_is_chosen_only_when_it_fills_the_room_better() {
// Everything closed: the lone panel (244) is close to the list (300); three stacked (500) are not.
assert!(!stack_beside(244.0, 500.0, 300.0));
// Two open: the list (520) is nearer the stack.
assert!(stack_beside(244.0, 500.0, 520.0));
// A tie keeps the simple layout.
assert!(!stack_beside(200.0, 400.0, 300.0));
}
}
+16
View File
@@ -9,6 +9,13 @@ pub fn previous_label(range: Range) -> String {
format!("previous {}", label.strip_prefix("last ").unwrap_or(label))
}
/// The lowest edge of a row of panels: the largest of their `bottoms`, or
/// `empty` when there are none. The bottoms are screen positions, so they are
/// negative while the row is scrolled above the top of the window.
pub fn lowest(bottoms: impl IntoIterator<Item = f32>, empty: f32) -> f32 {
bottoms.into_iter().reduce(f32::max).unwrap_or(empty)
}
/// 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> {
@@ -229,6 +236,15 @@ pub fn hidden_after_all<'a>(ticked: bool, languages: impl Iterator<Item = &'a st
mod tests {
use super::*;
#[test]
fn a_row_scrolled_above_the_window_still_ends_at_its_own_bottom() {
// Rows closed by their lowest panel: the same answer wherever the page is scrolled.
assert_eq!(lowest([260.0, 300.0, 280.0], 0.0), 300.0);
assert_eq!(lowest([-340.0, -300.0, -320.0], 0.0), -300.0);
assert_eq!(lowest([-17250.0, -17210.5], 0.0), -17210.5);
assert_eq!(lowest([], 42.0), 42.0);
}
#[test]
fn counts_have_thousands_separators() {
assert_eq!(count(0), "0");
+4 -2
View File
@@ -1,6 +1,7 @@
//! The sccache-dash dashboard page. `trunk` compiles this to WebAssembly and
//! the sccache-dash server serves it at http://127.0.0.1:8226.
pub mod disclosure;
pub mod fmt;
// Drawing needs eframe, which is only built for the browser so far; the rest
@@ -114,7 +115,7 @@ mod tests {
{ "name": "Rust", "hits": 229, "misses": 3256, "errors": 0 },
{ "name": "C/C++", "hits": 2082, "misses": 0, "errors": 0 }
],
"not_cached": [["crate-type", 621], ["incremental", 105]],
"not_cached": [{"reason": "crate-type", "count": 621, "name": "Programs and libraries that get linked", "meaning": "m", "action": "a", "fixable": false}, {"reason": "incremental", "count": 105, "name": "n", "meaning": "m", "action": "a", "fixable": true}],
"buckets": [
{ "start": 1764290000, "hits": 10, "misses": 5, "other": 1, "errors": 0, "saved_seconds": 60.0,
"languages": [["Rust", 10, 5]], "reset": false, "gap": false },
@@ -140,7 +141,8 @@ mod tests {
assert_eq!(view.time_saved.interval_90, Some((9700.0, 12600.0)));
assert_eq!(view.build_times[0].bins[1].compiles, 980);
assert_eq!(view.build_times[1].compiles, 0);
assert_eq!(view.not_cached[0], ("crate-type".to_owned(), 621));
assert_eq!((view.not_cached[0].reason.as_str(), view.not_cached[0].count), ("crate-type", 621));
assert!(view.not_cached[1].fixable);
assert_eq!(view.buckets[1].gap, true);
assert_eq!(view.extras[0].rows[0].1, "2");
}
+14 -14
View File
@@ -18,25 +18,25 @@ pub fn hit_rate(hits: u64, misses: u64) -> Option<f64> {
(hits + misses > 0).then(|| hits as f64 / (hits + misses) as f64)
}
pub fn section(ui: &mut Ui, view: &View, hidden: &mut Vec<String>, chart_height: f32) {
let p = theme::ui(ui);
filter(ui, view, hidden);
let tz = fmt::local_offset() as f64;
fn axes_of(view: &View, dark: bool) -> Axes {
let step = bucket_step(&view.buckets, view.range);
let axes = Axes {
Axes {
window: range_window(view, step),
step,
tz,
dark: p.dark,
};
tz: fmt::local_offset() as f64,
dark,
}
}
ui.add_space(theme::space::BETWEEN_PARTS);
part_title(ui, "Hit rate");
/// The body of the "Hit rate over time" panel.
pub fn hit_rate_panel(ui: &mut Ui, view: &View, hidden: &[String], chart_height: f32) {
let axes = axes_of(view, theme::ui(ui).dark);
hit_rate_chart(ui, view, hidden, axes, chart_height);
}
ui.add_space(theme::space::BETWEEN_PARTS);
part_title(ui, "Compiles");
/// The body of the "Compiles over time" panel.
pub fn volume_panel(ui: &mut Ui, view: &View, hidden: &[String], chart_height: f32) {
let axes = axes_of(view, theme::ui(ui).dark);
volume_chart(ui, view, hidden, axes, chart_height);
}
@@ -46,7 +46,7 @@ pub fn part_title(ui: &mut Ui, text: &str) {
}
/// Checkboxes that narrow both charts to some languages.
fn filter(ui: &mut Ui, view: &View, hidden: &mut Vec<String>) {
pub fn filter(ui: &mut Ui, view: &View, hidden: &mut Vec<String>) {
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing.x = theme::space::PANEL_GAP;
let mut all = hidden.is_empty();
+66 -30
View File
@@ -1,41 +1,77 @@
//! Problems: what is wrong, most serious first. A dot for how serious, the
//! title, and the detail in small print.
//! Problems: what is wrong, most serious first, as the list under the hero's problem
//! count. Each problem is a line (a square for how serious, its title, a chevron); clicking
//! it shows the full explanation under it, as the reasons list does. The list scrolls inside
//! a fixed height, so a longer list or an open explanation never moves the page.
use eframe::egui::{self, Ui};
use eframe::egui::{self, Sense, Ui};
use sccache_dash_api::{Severity, View};
use crate::style;
use crate::theme;
use crate::where_went::chevron;
pub fn section(ui: &mut Ui, view: &View) {
const ROW: f32 = 22.0;
const GAP: f32 = 8.0;
const CHEVRON: f32 = 8.0;
fn open_id(title: &str) -> egui::Id {
egui::Id::new(("problem-open", title))
}
/// The problems of `view` in a list `height` tall.
pub fn hero_list(ui: &mut Ui, view: &View, height: f32) {
let p = theme::ui(ui);
if view.problems.is_empty() {
// Nothing to alarm: a calm dot in the good colour and the words.
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = theme::space::ITEM + 2.0;
style::dot(ui, p.good);
ui.label(theme::body("No problems"));
});
ui.add(egui::Label::new(theme::small(ui, "Nothing needs attention.")).wrap());
ui.add(egui::Label::new(theme::small(ui, "Nothing needs attention.")).truncate());
return;
}
for (index, problem) in view.problems.iter().enumerate() {
if index > 0 {
ui.add_space(theme::space::BETWEEN_PARTS);
}
let color = match problem.severity {
Severity::Error => p.bad,
Severity::Warning => p.warn,
};
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = theme::space::ITEM + 2.0;
style::dot(ui, color);
ui.add(
egui::Label::new(
theme::strong(problem.title.clone()).color(color),
),
);
egui::ScrollArea::vertical()
.id_salt("hero-problems")
.max_height(height)
.auto_shrink([false, false])
.show(ui, |ui| {
ui.spacing_mut().item_spacing.y = 0.0;
let width = ui.available_width();
let indent = theme::drawing::SEVERITY_DOT + GAP;
for problem in &view.problems {
let id = open_id(&problem.title);
let open = ui.ctx().data(|data| data.get_temp::<bool>(id)).unwrap_or(false);
let (row, response) = ui.allocate_exact_size(egui::vec2(width, ROW), Sense::click());
let response = response.on_hover_cursor(egui::CursorIcon::PointingHand);
response.widget_info(|| {
egui::WidgetInfo::labeled(egui::WidgetType::Button, true, problem.title.as_str())
});
if response.clicked() {
ui.ctx().data_mut(|data| data.insert_temp(id, !open));
ui.ctx().request_repaint();
}
if response.hovered() {
ui.painter().rect_filled(row, theme::space::CONTROL_RADIUS, p.hover);
}
let color = match problem.severity {
Severity::Error => p.bad,
Severity::Warning => p.warn,
};
let side = theme::drawing::SEVERITY_DOT;
ui.painter().rect_filled(
egui::Rect::from_center_size(egui::pos2(row.left() + side / 2.0, row.center().y), egui::vec2(side, side)),
0.0,
color,
);
let chevron_x = row.right() - CHEVRON;
chevron(ui.painter(), egui::pos2(chevron_x + CHEVRON / 2.0, row.center().y), open, p.muted);
let title = crate::style::galley(ui, theme::body(problem.title.clone()), false, f32::INFINITY);
let room = (chevron_x - GAP - row.left() - indent).max(10.0);
let place = egui::Rect::from_min_size(egui::pos2(row.left() + indent, row.top()), egui::vec2(room, ROW));
ui.painter().with_clip_rect(place).galley(
egui::pos2(place.left(), row.center().y - title.size().y / 2.0),
title,
p.text,
);
if open {
let detail = crate::style::galley(ui, theme::small(ui, problem.detail.clone()), true, width - indent);
let (place, _) = ui.allocate_exact_size(egui::vec2(width, detail.size().y + 6.0), Sense::hover());
ui.painter().galley(egui::pos2(place.left() + indent, place.top()), detail, p.muted);
}
}
});
ui.add(egui::Label::new(theme::small(ui, problem.detail.clone())).wrap());
}
}
+5 -5
View File
@@ -1,6 +1,6 @@
//! Raw counters: the sccache stats exactly as the server read them, as compact
//! key/value lines that flow in columns. The panel opens and closes; it starts
//! open.
//! closed, as one line.
use std::cell::Cell;
@@ -44,7 +44,7 @@ fn columns(inner: f32) -> usize {
/// How tall the panel is when it is `width` wide: its title and, when open,
/// its lines.
pub fn height(view: &View, width: f32, open: bool) -> f32 {
let title = theme::space::ROW + theme::space::UNDER_TITLE + 2.0 * (theme::space::PANEL_PADDING + 1.0);
let title = theme::space::ROW + theme::space::UNDER_TITLE + 2.0 * theme::space::PANEL_PAD_Y;
if !open {
return title - theme::space::UNDER_TITLE + theme::space::LINE;
}
@@ -54,14 +54,14 @@ pub fn height(view: &View, width: f32, open: bool) -> f32 {
leaves(&view.raw, String::new(), &mut out);
lines = out.len();
}
let inner = width - 2.0 * (theme::space::PANEL_PADDING + 1.0);
let inner = width - 2.0 * theme::space::PANEL_PADDING;
title + lines.div_ceil(columns(inner)) as f32 * theme::space::ROW
}
/// The panel at `rect`; its title opens and closes it. Returns the rect it took.
pub fn section(ui: &mut Ui, view: &View, rect: Rect) -> Rect {
let id = egui::Id::unique("raw-counters-open");
let open = Cell::new(ui.ctx().data_mut(|data| data.get_temp::<bool>(id)).unwrap_or(true));
let id = egui::Id::new("raw-counters-open");
let open = Cell::new(ui.ctx().data_mut(|data| data.get_temp::<bool>(id)).unwrap_or(false));
let (_, taken) = style::panel_titled(
ui,
rect,
+8 -8
View File
@@ -19,8 +19,8 @@ pub fn section(ui: &mut Ui, view: &View) {
let timing = view.timing;
let rows = [
("Cache fetch (a hit)", timing.avg_hit_read_ms, p.from_cache),
("Cache write", timing.avg_cache_write_ms, p.built),
("Build (compile)", timing.avg_compile_ms, p.muted),
("Cache write", timing.avg_cache_write_ms, p.muted),
("Compile one crate", timing.avg_compile_ms, p.built),
];
for (label, ms, color) in rows {
ui.horizontal(|ui| {
@@ -60,14 +60,14 @@ pub fn section(ui: &mut Ui, view: &View) {
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 {times}x faster than building.")
format!("A cache hit is about {times}x faster than compiling the crate.")
} else if let Some(times) = faster(build, write) {
format!("Writing to the cache is about {times}x faster than building.")
format!("Writing to the cache is about {times}x faster than compiling the crate.")
} else {
"There are no timings to compare in this range.".to_owned()
};
ui.add_space(theme::space::ITEM);
ui.add(egui::Label::new(theme::strong(sentence)).wrap());
ui.add(egui::Label::new(theme::strong(sentence).color(p.hero)).wrap());
ui.add(
egui::Label::new(
theme::small(
@@ -87,7 +87,7 @@ fn faster(slower: Option<f64>, faster: Option<f64>) -> Option<String> {
(slower > 0.0 && faster > 0.0).then(|| fmt::round_number(slower / faster))
}
/// "How long builds take, by language": one histogram per language, all on the
/// "How long one crate takes to compile": one histogram per language, all on the
/// same log scale of build time, with the mean, median and p90 marked.
fn build_times(ui: &mut Ui, view: &View) {
let p = theme::ui(ui);
@@ -100,7 +100,7 @@ fn build_times(ui: &mut Ui, view: &View) {
return;
}
ui.add_space(theme::space::BETWEEN_PARTS);
crate::overtime::part_title(ui, "How long builds take, by language");
crate::overtime::part_title(ui, "How long one crate takes to compile");
// One shared axis, from a quarter step before the fastest bin to a quarter step after the slowest.
let (mut low, mut high) = (f64::MAX, 0.0_f64);
@@ -118,7 +118,7 @@ fn build_times(ui: &mut Ui, view: &View) {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = theme::space::ITEM;
ui.add(egui::Label::new(theme::strong(times.language.clone())).truncate());
ui.add(egui::Label::new(theme::small(ui, format!("{} builds", fmt::count(times.compiles)))).truncate());
ui.add(egui::Label::new(theme::small(ui, format!("{} compiles", fmt::count(times.compiles)))).truncate());
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.spacing_mut().item_spacing.x = theme::space::ITEM;
for (name, value, color) in [
+34 -49
View File
@@ -71,7 +71,7 @@ pub fn cells(ui: &Ui, height: f32, spans: &[usize]) -> Vec<Rect> {
/// Close a row of panels drawn at `rects`: the cursor moves below the tallest.
pub fn end_row(ui: &mut Ui, rects: &[Rect]) {
let bottom = rects.iter().map(|rect| rect.bottom()).fold(0.0, f32::max);
let bottom = crate::fmt::lowest(rects.iter().map(|rect| rect.bottom()), ui.cursor().top());
let left = rects.first().map_or(ui.cursor().left(), |rect| rect.left());
ui.allocate_rect(
Rect::from_min_max(Pos2::new(left, ui.cursor().top()), Pos2::new(ui.cursor().right(), bottom)),
@@ -92,7 +92,7 @@ pub fn rule(ui: &mut Ui) {
// ---- Panels and cards ----
/// A panel with a title, at `rect`: panel colour, a 1 px border, 8 px corners.
/// A panel with a title, at `rect`: no fill and no box, a hairline across its top.
/// It comes out at least as tall as `rect`; the rect it took is returned second.
pub fn panel<R>(ui: &mut Ui, rect: Rect, title: &str, body: impl FnOnce(&mut Ui) -> R) -> (R, Rect) {
let text = theme::title(ui, title).text().to_owned();
@@ -114,29 +114,20 @@ pub fn panel_titled<R>(
body: impl FnOnce(&mut Ui) -> R,
) -> (R, Rect) {
let p = p(ui);
let pad = space::PANEL_PADDING + 1.0;
let pad = egui::vec2(space::PANEL_PADDING, space::PANEL_PAD_Y);
let mut inner = ui.new_child(
egui::UiBuilder::new()
.max_rect(rect.shrink(pad))
.max_rect(rect.shrink2(pad))
.layout(Layout::top_down(Align::Min)),
);
inner.set_width((rect.width() - 2.0 * pad).max(0.0));
inner.set_min_height((rect.height() - 2.0 * pad).max(0.0));
inner.set_width((rect.width() - 2.0 * pad.x).max(0.0));
inner.set_min_height((rect.height() - 2.0 * pad.y).max(0.0));
inner.spacing_mut().item_spacing = egui::vec2(space::ITEM, space::LINE);
// A placeholder goes under the content now and is filled with the panel once
// its height is known, so a body that needs more room still sits on it.
let background = ui.painter().add(Shape::Noop);
title(&mut inner);
inner.add_space(space::UNDER_TITLE);
let value = body(&mut inner);
let taken = inner.min_rect().expand(pad);
ui.painter().set(
background,
Shape::Vec(vec![
Shape::rect_filled(taken, space::PANEL_RADIUS, p.panel),
Shape::rect_stroke(taken, space::PANEL_RADIUS, Stroke::new(1.0, p.border), StrokeKind::Inside),
]),
);
let taken = inner.min_rect().expand2(pad);
ui.painter().hline(taken.x_range(), taken.top() + 0.5, Stroke::new(1.0, p.border));
(value, taken)
}
@@ -204,25 +195,22 @@ pub fn toggling_title(ui: &mut Ui, title: &str, open: &mut bool) -> bool {
*open
}
/// One stat card: a small upper-case label, the number in mono, one line of
/// small print and the change against the period before. Exactly `rect`.
pub fn card(ui: &mut Ui, rect: Rect, label: &str, number: &str, detail: &str, change: RichText, color: Color32) {
/// One cell of the counter strip: a small upper-case label, the number in mono, one line of
/// small print and the change against the period before. Exactly `rect`; a hairline stands at
/// its left unless it is the first of its row.
pub fn card(ui: &mut Ui, rect: Rect, first: bool, label: &str, number: &str, detail: &str, change: RichText, color: Color32) {
let p = p(ui);
ui.allocate_rect(rect, Sense::hover());
let painter = ui.painter();
painter.rect(
rect,
space::PANEL_RADIUS,
p.panel,
Stroke::new(1.0, p.border),
StrokeKind::Inside,
let inset = if first { 0.0 } else { 16.0 };
if !first {
ui.painter().vline(rect.left() + 0.5, rect.y_range().shrink(10.0), Stroke::new(1.0, p.grid));
}
let inner_rect = Rect::from_min_max(
Pos2::new(rect.left() + inset, rect.top() + 10.0),
Pos2::new(rect.right() - 8.0, rect.bottom() - 6.0),
);
let mut inner = ui.new_child(
egui::UiBuilder::new()
.max_rect(rect.shrink(space::CARD_PADDING + 1.0))
.layout(Layout::top_down(Align::Min)),
);
inner.set_width(rect.width() - 2.0 * (space::CARD_PADDING + 1.0));
let mut inner = ui.new_child(egui::UiBuilder::new().max_rect(inner_rect).layout(Layout::top_down(Align::Min)));
inner.set_width(inner_rect.width());
inner.spacing_mut().item_spacing = egui::vec2(space::ITEM, 1.0);
inner.add(egui::Label::new(theme::title(ui, label)).truncate());
inner.add(
@@ -353,8 +341,11 @@ pub fn table(ui: &mut Ui, head: &[&str], rows: &[Vec<Cell>]) {
}
// The label column takes the slack, and gives first when the table is too
// wide (after a bar column, which can shrink to a stub).
// The table reaches `pad` past both edges, so the first column's text and the last
// column's numbers line up with the panel's own edges.
let width_cells = width + 2.0 * pad;
let whole: f32 = natural.iter().sum();
let slack = width - whole;
let slack = width_cells - whole;
if slack >= 0.0 {
natural[0] += slack;
} else {
@@ -378,7 +369,7 @@ pub fn table(ui: &mut Ui, head: &[&str], rows: &[Vec<Cell>]) {
}
let lefts: Vec<f32> = natural
.iter()
.scan(ui.cursor().left(), |left, size| {
.scan(ui.cursor().left() - pad, |left, size| {
let at = *left;
*left += size;
Some(at)
@@ -441,7 +432,7 @@ pub fn table(ui: &mut Ui, head: &[&str], rows: &[Vec<Cell>]) {
Pos2::new(place.left() + pad + side / 2.0, place.center().y),
egui::vec2(side, side),
);
ui.painter().rect_filled(square, 2.0, *color);
ui.painter().rect_filled(square, 0.0, *color);
let (galley, text) = &line[column];
if let Some(galley) = galley {
let text_place = Rect::from_min_max(
@@ -476,12 +467,12 @@ pub fn meter(ui: &mut Ui, height: f32, fraction: f64, fill: Color32) {
pub fn fill_bar(ui: &mut Ui, rect: Rect, fraction: f64, fill: Color32) {
let p = p(ui);
let painter = ui.painter();
painter.rect_filled(rect, rect.height() / 2.0, p.track);
painter.rect_filled(rect, 0.0, p.track);
let width = rect.width() * fraction.clamp(0.0, 1.0) as f32;
if width > 0.5 {
painter.rect_filled(
Rect::from_min_max(rect.min, Pos2::new(rect.left() + width, rect.bottom())),
rect.height() / 2.0,
0.0,
fill,
);
}
@@ -498,14 +489,14 @@ pub fn stacked_bar(ui: &mut Ui, parts: &[(&'static str, u64, Color32)], total: u
Sense::hover(),
);
let painter = ui.painter();
painter.rect_filled(rect, 3.0, p.track);
painter.rect_filled(rect, 0.0, p.track);
let mut x = rect.left();
let mut tip = String::new();
for (name, part, color) in parts {
let width = if total > 0 { rect.width() * *part as f64 as f32 / total as f32 } else { 0.0 };
if width > 0.0 {
let part_rect = Rect::from_min_max(Pos2::new(x, rect.top()), Pos2::new(x + width, rect.bottom()));
painter.rect_filled(part_rect, 3.0, *color);
painter.rect_filled(part_rect, 0.0, *color);
x += width;
tip.push_str(&format!(
"{name}: {} ({})\n",
@@ -523,24 +514,18 @@ pub fn stacked_bar(ui: &mut Ui, parts: &[(&'static str, u64, Color32)], total: u
pub fn hit_bar(ui: &mut Ui, rect: Rect, hits: u64, misses: u64) {
let p = p(ui);
let painter = ui.painter();
painter.rect_filled(rect, rect.height() / 2.0, p.track);
painter.rect_filled(rect, 0.0, p.track);
let total = hits + misses;
if total > 0 {
let hit_width = rect.width() * hits as f32 / total as f32;
painter.rect_filled(
Rect::from_min_max(rect.min, Pos2::new(rect.left() + hit_width, rect.bottom())),
rect.height() / 2.0,
0.0,
p.from_cache,
);
}
}
pub fn dot(ui: &mut Ui, color: Color32) {
let side = theme::drawing::SEVERITY_DOT;
let (rect, _) = ui.allocate_exact_size(egui::vec2(side, side), Sense::hover());
ui.painter().circle_filled(rect.center(), side / 2.0, color);
}
/// A trend line one point per bucket, drawn in a strip `height` tall. `None`
/// points break the line, so a gap never looks like a zero. `top` is the value
/// drawn at the top of the strip.
@@ -635,7 +620,7 @@ pub fn key(ui: &mut Ui, mark: Mark) {
/// The key to a chart, drawn under it so it never sits on the data.
pub fn legend(ui: &mut Ui, entries: Vec<(Mark, String)>) {
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing.x = space::PANEL_GAP + 2.0;
ui.spacing_mut().item_spacing.x = 14.0;
for (mark, text) in entries {
key(ui, mark);
let response = ui.add(egui::Label::new(theme::small(ui, text.clone())).truncate());
+81 -79
View File
@@ -44,6 +44,8 @@ pub struct Palette {
pub accent: Color32,
/// Text on the accent: what a selected control says.
pub on_accent: Color32,
/// Amber as text and lines: the hero figures and key lines (darker in the light theme to pass contrast).
pub hero: Color32,
/// The tint over time nothing was recorded in.
pub unrecorded: Color32,
/// The line of the mean, the median and the p90 on a build-time histogram.
@@ -54,54 +56,56 @@ pub struct Palette {
pub const DARK: Palette = Palette {
dark: true,
page: rgb(0x0e1116),
panel: rgb(0x161a22),
border: rgb(0x232936),
text: rgb(0xe6e9ef),
muted: rgb(0x8a93a5),
grid: rgb(0x1f2530),
track: rgb(0x0b0e13),
hover: rgb(0x1f2530),
good: rgb(0x3fb950),
warn: rgb(0xd29922),
bad: rgb(0xf85149),
from_cache: rgb(0x4cc38a),
page: rgb(0x0f0f10),
panel: rgb(0x161617),
border: rgb(0x2a2a2c),
text: rgb(0xe8e6e1),
muted: rgb(0x8f8d87),
grid: rgb(0x1f1f21),
track: rgb(0x1b1b1d),
hover: rgb(0x1f1f21),
good: rgb(0x3ecf8e),
warn: rgb(0xffb000),
bad: rgb(0xff5f56),
from_cache: rgb(0x3ecf8e),
built: rgb(0x5b8def),
not_cacheable: rgb(0x8a93a5),
unsupported: rgb(0xb08cf0),
not_compile: rgb(0x4fb3bf),
accent: rgb(0x5b8def),
on_accent: rgb(0xffffff),
not_cacheable: rgb(0x8a8a8f),
unsupported: rgb(0x5f5f64),
not_compile: rgb(0x424246),
accent: rgb(0xffb000),
on_accent: rgb(0x0f0f10),
hero: rgb(0xffb000),
unrecorded: Color32::from_rgba_premultiplied(14, 14, 14, 14),
mean: rgb(0xe6e9ef),
median: rgb(0xb08cf0),
p90: rgb(0x4fb3bf),
mean: rgb(0xe8e6e1),
median: rgb(0xffb000),
p90: rgb(0x8a8a8f),
};
pub const LIGHT: Palette = Palette {
dark: false,
page: rgb(0xf5f6f8),
panel: rgb(0xffffff),
border: rgb(0xdfe3ea),
text: rgb(0x1b2029),
muted: rgb(0x5d6675),
grid: rgb(0xeceff4),
track: rgb(0xeef0f4),
hover: rgb(0xf0f2f6),
good: rgb(0x1a7f37),
warn: rgb(0x9a6700),
bad: rgb(0xcf222e),
from_cache: rgb(0x2a9150),
built: rgb(0x3a6fd8),
not_cacheable: rgb(0x6b7484),
unsupported: rgb(0x7c5cd6),
not_compile: rgb(0x1f8a9b),
accent: rgb(0x3a6fd8),
on_accent: rgb(0xffffff),
unrecorded: Color32::from_rgba_premultiplied(0, 0, 0, 18),
mean: rgb(0x1b2029),
median: rgb(0x7c5cd6),
p90: rgb(0x1f8a9b),
page: rgb(0xf6f3ec),
panel: rgb(0xfffdf8),
border: rgb(0xd5cfc1),
text: rgb(0x1d1b17),
muted: rgb(0x6a655b),
grid: rgb(0xe6e1d6),
track: rgb(0xebe6da),
hover: rgb(0xe9e4d8),
good: rgb(0x1a8f5a),
warn: rgb(0xb87400),
bad: rgb(0xc62f26),
from_cache: rgb(0x1f9d63),
built: rgb(0x2f63d0),
not_cacheable: rgb(0x7a766c),
unsupported: rgb(0xa39f94),
not_compile: rgb(0xc2beb2),
accent: rgb(0xffb000),
on_accent: rgb(0x1d1b17),
hero: rgb(0x8a5600),
unrecorded: Color32::from_rgba_premultiplied(0, 0, 0, 16),
mean: rgb(0x1d1b17),
median: rgb(0x8a5600),
p90: rgb(0x7a766c),
};
/// The palette of the theme being drawn.
@@ -138,20 +142,24 @@ pub mod px {
/// Small print.
pub const SMALL: f32 = 11.0;
/// The number on a stat card.
pub const CARD_NUMBER: f32 = 24.0;
pub const CARD_NUMBER: f32 = 22.0;
/// The three figures of the headline panel.
pub const HEADLINE: f32 = 40.0;
pub const HEADLINE: f32 = 56.0;
}
/// Space in pixels.
pub mod space {
pub const PAGE_MARGIN: f32 = 16.0;
/// Between panels, and between cards.
pub const PANEL_GAP: f32 = 12.0;
pub const PANEL_PADDING: f32 = 16.0;
pub const CARD_PADDING: f32 = 12.0;
pub const PANEL_RADIUS: f32 = 8.0;
pub const CONTROL_RADIUS: f32 = 6.0;
pub const PANEL_GAP: f32 = 24.0;
/// Between the controls of the top bar.
pub const TOOL_GAP: f32 = 8.0;
/// Panels have no side padding: their content lines up with the hairline above it.
pub const PANEL_PADDING: f32 = 0.0;
/// Room between a panel's top hairline and its title, and under its content.
pub const PANEL_PAD_Y: f32 = 12.0;
pub const PANEL_RADIUS: f32 = 0.0;
pub const CONTROL_RADIUS: f32 = 2.0;
/// Between items that follow each other in a panel.
pub const ITEM: f32 = 8.0;
/// Between lines of one paragraph.
@@ -162,8 +170,8 @@ pub mod space {
pub const CELL_PAD: f32 = 8.0;
/// The narrowest the label column of a table gets before its text is cut.
pub const LABEL_MIN: f32 = 72.0;
pub const CONTROL_HEIGHT: f32 = 28.0;
pub const CONTROL_PAD: f32 = 10.0;
pub const CONTROL_HEIGHT: f32 = 24.0;
pub const CONTROL_PAD: f32 = 9.0;
pub const TITLE_SPACING: f32 = 0.8;
pub const TOOLBAR_NOTE_WIDTH: f32 = 150.0;
/// Between a raw counter's key and its value.
@@ -180,49 +188,42 @@ pub mod layout {
pub const THREE_COLUMNS_FROM: f32 = 1100.0;
/// From this width it has two; below it, one.
pub const TWO_COLUMNS_FROM: f32 = 700.0;
/// Below this width the toolbar's actions go on a second line.
pub const TOOLBAR_TWO_LINES_BELOW: f32 = 1240.0;
/// How many columns of key/value lines the raw counters run in, per page column.
pub const RAW_LINE_WIDTH: f32 = 400.0;
pub const TOOLBAR_HEIGHT: f32 = 28.0;
pub const HEADLINE_HEIGHT: f32 = 216.0;
/// A headline figure: the number, its caption, the trend line and two lines of small print.
pub const FIGURE_HEIGHT: f32 = 124.0;
pub const CARD_HEIGHT: f32 = 104.0;
/// The row of "Where compiles went", "By language" and "Problems". It grows
/// only when the tables have more rows than this height holds.
pub const TRIPTYCH_HEIGHT: f32 = 232.0;
/// The row of "Over time" and "Speed".
pub const CHARTS_HEIGHT: f32 = 516.0;
pub const TOOLBAR_HEIGHT: f32 = 24.0;
/// The hero band on a wide page: caption row, one row of figures and the storage line.
pub const HEADLINE_HEIGHT: f32 = 296.0;
/// A hero figure: the number, its caption, the trend line and two lines of small print.
pub const FIGURE_HEIGHT: f32 = 176.0;
/// One row of the counter strip.
pub const STRIP_ROW_HEIGHT: f32 = 92.0;
/// "Where compiles went": its bar, legend and the "of the built" line.
pub const WHERE_FIXED_HEIGHT: f32 = 244.0;
/// "Why compiles were not cacheable" needs this much beside its rows.
pub const REASONS_FIXED_HEIGHT: f32 = 90.0;
pub const WHERE_FIXED_HEIGHT: f32 = 212.0;
/// "Why compiles were not cacheable" needs this much beside its reasons: padding, title and the room under it.
pub const REASONS_FIXED_HEIGHT: f32 = 56.0;
/// From this panel width the "By language" table has room for its hit-rate bars.
pub const LANGUAGE_BARS_FROM: f32 = 380.0;
/// "By language" needs this much beside its rows.
pub const LANGUAGES_FIXED_HEIGHT: f32 = 60.0;
pub const LANGUAGES_FIXED_HEIGHT: f32 = 50.0;
/// "Speed" needs this much beside its histograms.
pub const SPEED_FIXED_HEIGHT: f32 = 250.0;
/// "Problems" needs this much beside its problems.
pub const PROBLEMS_FIXED_HEIGHT: f32 = 60.0;
/// "Problems" needs this much per problem.
pub const PROBLEM_HEIGHT: f32 = 62.0;
pub const SPEED_FIXED_HEIGHT: f32 = 240.0;
/// "Speed" needs this much per language with a histogram.
pub const HISTOGRAM_HEIGHT: f32 = 85.0;
/// A panel of one time chart: padding, title, plot and legend.
pub const CHART_PANEL_HEIGHT: f32 = 306.0;
}
/// Drawings inside panels, in pixels.
pub mod drawing {
pub const CHART_HEIGHT: f32 = 170.0;
pub const CHART_HEIGHT: f32 = 240.0;
/// The trend line under a headline figure.
pub const SPARKLINE: f32 = 28.0;
pub const SPARKLINE: f32 = 36.0;
pub const BUILD_HISTOGRAM: f32 = 44.0;
pub const BUILD_AXIS: f32 = 14.0;
pub const STACKED_BAR: f32 = 22.0;
pub const SPEED_BAR: f32 = 10.0;
pub const USAGE_BAR: f32 = 6.0;
pub const USAGE_BAR: f32 = 4.0;
pub const HIT_BAR: f32 = 72.0;
pub const HIT_BAR_HEIGHT: f32 = 6.0;
pub const LEGEND_SWATCH: f32 = 10.0;
@@ -371,10 +372,10 @@ fn visuals(p: &Palette) -> egui::Visuals {
expansion: 0.0,
};
visuals.widgets.noninteractive = control(p.track, p.border, p.muted);
visuals.widgets.inactive = control(p.track, p.border, p.text);
visuals.widgets.hovered = control(p.hover, p.accent, p.text);
visuals.widgets.inactive = control(Color32::TRANSPARENT, p.border, p.text);
visuals.widgets.hovered = control(p.hover, p.muted, p.text);
visuals.widgets.active = control(tint(p.accent, 0.25), p.accent, p.text);
visuals.widgets.open = control(p.hover, p.accent, p.text);
visuals.widgets.open = control(p.hover, p.muted, p.text);
visuals
}
@@ -384,7 +385,8 @@ pub fn install(ctx: &egui::Context) {
ctx.all_styles_mut(|style| {
style.text_styles = text_styles();
style.spacing.item_spacing = egui::vec2(space::ITEM, space::LINE);
style.spacing.button_padding = egui::vec2(10.0, 4.0);
style.spacing.button_padding = egui::vec2(8.0, 2.0);
style.spacing.interact_size.y = space::CONTROL_HEIGHT;
style.spacing.indent = 12.0;
style.visuals = visuals(of(style.visuals.dark_mode));
});
+155 -19
View File
@@ -2,9 +2,13 @@
//! shares; what happened inside the built share; and why some could not be
//! cached. How each language fared is its own panel ([`languages`]).
use eframe::egui::{self, Color32, Ui};
use sccache_dash_api::View;
use std::sync::Arc;
use eframe::egui::{self, Color32, Sense, Stroke, Ui};
use eframe::epaint::text::Galley;
use sccache_dash_api::{NotCached, View};
use crate::disclosure;
use crate::fmt;
use crate::style::{self, Cell};
use crate::theme;
@@ -54,30 +58,162 @@ pub fn section(ui: &mut Ui, view: &View) {
));
}
/// "Why compiles were not cacheable": the reasons table, one row per reason.
/// One reason laid out for a width: its line, and the two small paragraphs when it is open.
struct Block {
name: Arc<Galley>,
count: Arc<Galley>,
share: Arc<Galley>,
/// `None` while the reason is closed.
meaning: Option<Arc<Galley>>,
/// `None` when closed, or when sccache gives nothing to do.
action: Option<Arc<Galley>>,
/// The line: at least a control tall, taller when the name wraps.
row: f32,
open: bool,
}
impl Block {
fn entry(&self) -> disclosure::Entry {
disclosure::Entry {
row: self.row,
open: self.open,
meaning: self.meaning.as_ref().map_or(0.0, |g| g.size().y),
action: self.action.as_ref().map(|g| g.size().y),
}
}
}
/// How far the name is from the numbers, and from the dot.
const NAME_GAP: f32 = 8.0;
/// The side of the chevron's triangle box.
const CHEVRON: f32 = 8.0;
/// The hairline between two lines.
const SEPARATOR: f32 = 1.0;
/// Where a reason remembers whether it is open.
fn open_id(reason: &str) -> egui::Id {
egui::Id::new(("reason-open", reason))
}
fn is_open(ctx: &egui::Context, reason: &NotCached) -> bool {
let stored = ctx.data(|data| data.get_temp::<bool>(open_id(&reason.reason)));
disclosure::is_open(stored, reason.fixable)
}
/// Lay every reason out in `width`; counts and shares line up in columns, the name takes the rest.
fn blocks(ui: &Ui, view: &View, width: f32) -> Vec<Block> {
let number = |text: String| style::galley(ui, theme::number(text), false, f32::INFINITY);
let numbers: Vec<(Arc<Galley>, Arc<Galley>)> = view
.not_cached
.iter()
.map(|r| (number(fmt::count(r.count)), number(fmt::share(r.count, view.totals.not_cacheable))))
.collect();
let widest = |pick: fn(&(Arc<Galley>, Arc<Galley>)) -> &Arc<Galley>| {
numbers.iter().map(|n| pick(n).size().x).fold(0.0, f32::max)
};
let (count_width, share_width) = (widest(|n| &n.0), widest(|n| &n.1));
let indent = theme::drawing::SEVERITY_DOT + NAME_GAP;
let name_width = (width - indent - count_width - share_width - CHEVRON - 3.0 * NAME_GAP).max(40.0);
view.not_cached
.iter()
.zip(numbers)
.map(|(r, (count, share))| {
let name = style::galley(ui, theme::body(r.name.clone()), true, name_width);
let open = is_open(ui.ctx(), r);
let small = |text: &str| style::galley(ui, theme::small(ui, text), true, width - indent);
Block {
row: theme::space::CONTROL_HEIGHT.max(name.size().y + 2.0 * theme::space::ITEM),
name,
count,
share,
meaning: open.then(|| small(&r.meaning)),
action: (open && !r.action.is_empty()).then(|| small(&r.action)),
open,
}
})
.collect()
}
/// A triangle in the muted colour: pointing right when closed, down when open.
pub(crate) fn chevron(painter: &egui::Painter, center: egui::Pos2, open: bool, color: Color32) {
let h = CHEVRON / 2.0;
let points = if open {
vec![center + egui::vec2(-h, -h / 2.0), center + egui::vec2(h, -h / 2.0), center + egui::vec2(0.0, h / 2.0 + 1.0)]
} else {
vec![center + egui::vec2(-h / 2.0, -h), center + egui::vec2(-h / 2.0, h), center + egui::vec2(h / 2.0 + 1.0, 0.0)]
};
painter.add(egui::Shape::convex_polygon(points, color, Stroke::NONE));
}
/// "Why compiles were not cacheable": one line per reason, each with a dot (the warning
/// colour when a setting would fix it, the muted one when it is expected), its plain name,
/// its count and share, and a chevron. Clicking the line shows, in small print under it,
/// what it means and what to do; the reasons a setting would fix start open.
pub fn reasons(ui: &mut Ui, view: &View) {
if view.not_cached.is_empty() {
ui.label(theme::small(ui, "Every compile could be cached in this range."));
return;
}
let rows: Vec<Vec<Cell>> = view
.not_cached
.iter()
.map(|(reason, count)| {
vec![
Cell::Text(theme::body(reason.clone())),
Cell::Text(theme::number(fmt::count(*count))),
Cell::Text(theme::number(fmt::share(*count, view.totals.not_cacheable))),
]
})
.collect();
style::table(ui, &["Reason", "Compiles", "Share"], &rows);
let p = theme::ui(ui);
let width = ui.available_width();
let blocks = blocks(ui, view, width);
let indent = theme::drawing::SEVERITY_DOT + NAME_GAP;
// Every height is added by hand, so the list is as tall as `reasons_height` says.
ui.spacing_mut().item_spacing.y = 0.0;
for (index, (reason, block)) in view.not_cached.iter().zip(&blocks).enumerate() {
if index > 0 {
let (gap, _) = ui.allocate_exact_size(egui::vec2(width, SEPARATOR), Sense::hover());
ui.painter().rect_filled(gap, 0.0, p.grid);
}
let (row, response) = ui.allocate_exact_size(egui::vec2(width, block.row), Sense::click());
let response = response.on_hover_cursor(egui::CursorIcon::PointingHand);
response.widget_info(|| {
egui::WidgetInfo::labeled(egui::WidgetType::Button, true, reason.name.as_str())
});
if response.clicked() {
ui.ctx().data_mut(|data| data.insert_temp(open_id(&reason.reason), !block.open));
ui.ctx().request_repaint();
}
let painter = ui.painter();
if response.hovered() || response.has_focus() {
painter.rect_filled(row, theme::space::CONTROL_RADIUS, p.hover);
}
if response.has_focus() {
painter.rect_stroke(row, theme::space::CONTROL_RADIUS, Stroke::new(1.0, p.muted), egui::StrokeKind::Inside);
}
let side = theme::drawing::SEVERITY_DOT;
let dot = if reason.fixable { p.warn } else { p.not_cacheable };
let name_top = row.top() + (block.row - block.name.size().y) / 2.0;
painter.rect_filled(egui::Rect::from_center_size(egui::pos2(row.left() + side / 2.0, row.center().y), egui::vec2(side, side)), 0.0, dot);
painter.galley(egui::pos2(row.left() + indent, name_top), block.name.clone(), p.text);
let chevron_left = row.right() - CHEVRON;
chevron(painter, egui::pos2(chevron_left + CHEVRON / 2.0, row.center().y), block.open, p.muted);
let share_left = chevron_left - NAME_GAP - block.share.size().x;
let at = |galley: &Arc<Galley>, left: f32| {
egui::pos2(left, row.top() + (block.row - galley.size().y) / 2.0)
};
painter.galley(at(&block.share, share_left), block.share.clone(), p.text);
let count_left = share_left - NAME_GAP - block.count.size().x;
painter.galley(at(&block.count, count_left), block.count.clone(), p.text);
let mut opened = false;
for galley in block.meaning.iter().chain(block.action.as_ref()) {
ui.add_space(theme::space::LINE);
let (place, _) = ui.allocate_exact_size(egui::vec2(width, galley.size().y), Sense::hover());
ui.painter().galley(egui::pos2(place.left() + indent, place.top()), galley.clone(), p.muted);
opened = true;
}
if opened {
ui.add_space(theme::space::ITEM);
}
}
}
/// How tall "Why compiles were not cacheable" is with `rows` reasons.
pub fn reasons_height(rows: usize) -> f32 {
let rows = rows.max(1);
theme::layout::REASONS_FIXED_HEIGHT + rows as f32 * theme::space::ROW
/// How tall "Why compiles were not cacheable" is in a panel `panel_width` wide.
pub fn reasons_height(ui: &Ui, view: &View, panel_width: f32) -> f32 {
let inner = panel_width - 2.0 * theme::space::PANEL_PADDING;
let entries: Vec<_> = blocks(ui, view, inner).iter().map(Block::entry).collect();
let list = disclosure::list_height(&entries, theme::space::LINE, theme::space::ITEM, SEPARATOR);
theme::layout::REASONS_FIXED_HEIGHT + list.max(theme::space::ROW)
}
/// "By language": one row per language, with hits, misses, errors, the hit rate
+4
View File
@@ -8,3 +8,7 @@ test:
run:
cargo run -p sccache-dash
# Screenshots of the whole page at the 3, 2 and 1 column widths; read them before merging a page change.
shots url="http://127.0.0.1:8226/" out="target/shots":
prlimit --core=1:1 -- node scripts/shots.js {{url}} {{out}}
+24
View File
@@ -0,0 +1,24 @@
// Screenshots of the whole page at each layout width (3, 2 and 1 column), read
// before any page change is merged. Usage: just shots [url] [out-dir]
const path = require('path');
const { execSync } = require('child_process');
const root = execSync('mise where npm:playwright 2>/dev/null || mise where playwright', { encoding: 'utf8' }).trim();
const { chromium } = require(path.join(root, 'node_modules/playwright'));
const [, , url = 'http://127.0.0.1:8226/', out = 'target/shots'] = process.argv;
(async () => {
require('fs').mkdirSync(out, { recursive: true });
const browser = await chromium.launch({
args: ['--use-gl=angle', '--use-angle=swiftshader', '--enable-unsafe-swiftshader', '--ignore-gpu-blocklist'],
});
for (const [width, height] of [[1400, 2600], [900, 3600], [390, 5600]]) {
// The page scrolls inside its canvas, so a tall window shows all of it.
const page = await browser.newPage({ viewport: { width, height }, colorScheme: 'dark' });
await page.goto(url);
await page.waitForTimeout(5000);
const file = path.join(out, `page-${width}.png`);
await page.screenshot({ path: file });
console.log(file);
await page.close();
}
await browser.close();
})().catch((error) => { console.error(error); process.exit(1); });