Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f08f4655e4 | ||
|
|
a8c69567b4 | ||
|
|
0f4df265a5 |
No files matched your search
+19
-2
@@ -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.
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
+22
-12
@@ -530,12 +530,12 @@ fn table_height(fixed: f32, rows: usize) -> f32 {
|
||||
|
||||
/// 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 {
|
||||
fn triptych_height(ui: &egui::Ui, view: &View, panel_width: f32) -> 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))
|
||||
.max(problems_height(ui, view, panel_width))
|
||||
}
|
||||
|
||||
/// How tall "Speed" is.
|
||||
@@ -549,22 +549,30 @@ 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 {
|
||||
/// How tall "Problems" is in a panel `panel_width` wide: each problem's title, and its detail
|
||||
/// wrapped to the panel.
|
||||
fn problems_height(ui: &egui::Ui, view: &View, panel_width: f32) -> 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
|
||||
return 88.0;
|
||||
}
|
||||
let inner = panel_width - 2.0 * (theme::space::PANEL_PADDING + 1.0);
|
||||
let details: f32 = view
|
||||
.problems
|
||||
.iter()
|
||||
.map(|problem| style::galley(ui, theme::small(ui, problem.detail.clone()), true, inner).size().y + 21.0)
|
||||
.sum();
|
||||
let gaps = (view.problems.len() - 1) as f32 * (theme::space::BETWEEN_PARTS + theme::space::LINE);
|
||||
l::PROBLEMS_FIXED_HEIGHT + details + gaps
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
fn charts_height(ui: &egui::Ui, view: &View, side_width: f32) -> f32 {
|
||||
use theme::layout as l;
|
||||
let stacked = speed_height(view)
|
||||
+ theme::space::PANEL_GAP
|
||||
+ where_went::reasons_height(view.not_cached.len());
|
||||
+ where_went::reasons_height(ui, view, side_width);
|
||||
l::CHARTS_HEIGHT.max(stacked)
|
||||
}
|
||||
|
||||
@@ -598,14 +606,15 @@ fn page(ui: &mut egui::Ui, view: &View, asked: Range, hidden_languages: &mut Vec
|
||||
|
||||
match columns {
|
||||
3 => {
|
||||
let [a, b, c] = row(ui, triptych_height(view), &[1, 1, 1]).try_into().expect("three panels");
|
||||
let third = style::span_width(ui, 3, 1);
|
||||
let [a, b, c] = row(ui, triptych_height(ui, view, third), &[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]);
|
||||
|
||||
// "Over time" over two columns; "Speed" and the reasons stacked in the third, together as tall.
|
||||
let height = charts_height(view);
|
||||
let height = charts_height(ui, view, third);
|
||||
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));
|
||||
@@ -620,7 +629,8 @@ fn page(ui: &mut egui::Ui, view: &View, asked: Range, hidden_languages: &mut Vec
|
||||
close_row(ui, &[wide, speed, reasons]);
|
||||
}
|
||||
2 => {
|
||||
let reasons = where_went::reasons_height(view.not_cached.len());
|
||||
let half = style::span_width(ui, 2, 1);
|
||||
let reasons = where_went::reasons_height(ui, view, half);
|
||||
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));
|
||||
@@ -628,7 +638,7 @@ fn page(ui: &mut egui::Ui, view: &View, asked: Range, hidden_languages: &mut Vec
|
||||
close_row(ui, &[a, b]);
|
||||
let height = l::TRIPTYCH_HEIGHT
|
||||
.max(table_height(l::LANGUAGES_FIXED_HEIGHT, view.languages.len()))
|
||||
.max(problems_height(view));
|
||||
.max(problems_height(ui, view, half));
|
||||
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));
|
||||
|
||||
@@ -114,7 +114,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 +140,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");
|
||||
}
|
||||
|
||||
@@ -197,8 +197,8 @@ pub mod layout {
|
||||
pub const CHARTS_HEIGHT: f32 = 516.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;
|
||||
/// "Why compiles were not cacheable" needs this much beside its reasons: padding, title and the room under it.
|
||||
pub const REASONS_FIXED_HEIGHT: f32 = 66.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.
|
||||
@@ -207,8 +207,6 @@ pub mod layout {
|
||||
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;
|
||||
/// "Speed" needs this much per language with a histogram.
|
||||
pub const HISTOGRAM_HEIGHT: f32 = 85.0;
|
||||
}
|
||||
|
||||
+99
-18
@@ -2,7 +2,10 @@
|
||||
//! 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 std::sync::Arc;
|
||||
|
||||
use eframe::egui::{self, Color32, Sense, Stroke, Ui};
|
||||
use eframe::epaint::text::Galley;
|
||||
use sccache_dash_api::View;
|
||||
|
||||
use crate::fmt;
|
||||
@@ -54,30 +57,108 @@ 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 name, numbers and the two small paragraphs.
|
||||
struct Block {
|
||||
name: Arc<Galley>,
|
||||
count: Arc<Galley>,
|
||||
share: Arc<Galley>,
|
||||
meaning: Arc<Galley>,
|
||||
/// `None` when sccache gives nothing to do.
|
||||
action: Option<Arc<Galley>>,
|
||||
/// The first line: the name, or as tall as the name when it wraps.
|
||||
row: f32,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
/// Its height, counting the room each part is given.
|
||||
fn height(&self) -> f32 {
|
||||
let line = theme::space::LINE;
|
||||
let mut height = self.row + line + self.meaning.size().y + line;
|
||||
if let Some(action) = &self.action {
|
||||
height += action.size().y + line;
|
||||
}
|
||||
height
|
||||
}
|
||||
}
|
||||
|
||||
/// How far the name is from the numbers, and from the dot.
|
||||
const NAME_GAP: f32 = 8.0;
|
||||
|
||||
/// 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 dot = theme::drawing::SEVERITY_DOT + NAME_GAP;
|
||||
let name_width = (width - dot - count_width - share_width - 2.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 small = |text: &str| style::galley(ui, theme::small(ui, text), true, width);
|
||||
Block {
|
||||
row: theme::space::ROW.max(name.size().y + 6.0),
|
||||
name,
|
||||
count,
|
||||
share,
|
||||
meaning: small(&r.meaning),
|
||||
action: (!r.action.is_empty()).then(|| small(&r.action)),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// "Why compiles were not cacheable": each reason 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 under it, in small print, what it means and what to do.
|
||||
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);
|
||||
for (index, (reason, block)) in view.not_cached.iter().zip(&blocks).enumerate() {
|
||||
if index > 0 {
|
||||
let (gap, _) = ui.allocate_exact_size(egui::vec2(width, theme::space::BETWEEN_PARTS), Sense::hover());
|
||||
ui.painter().hline(gap.x_range(), gap.center().y.round() + 0.5, Stroke::new(1.0, p.grid));
|
||||
}
|
||||
let (row, _) = ui.allocate_exact_size(egui::vec2(width, block.row), Sense::hover());
|
||||
let painter = ui.painter();
|
||||
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.circle_filled(egui::pos2(row.left() + side / 2.0, name_top + 8.0), side / 2.0, dot);
|
||||
painter.galley(egui::pos2(row.left() + side + NAME_GAP, name_top), block.name.clone(), p.text);
|
||||
let share_left = row.right() - block.share.size().x;
|
||||
let at = |galley: &Arc<Galley>, right: f32| {
|
||||
egui::pos2(right - galley.size().x, row.top() + (block.row - galley.size().y) / 2.0)
|
||||
};
|
||||
painter.galley(at(&block.share, row.right()), block.share.clone(), p.text);
|
||||
painter.galley(at(&block.count, share_left - NAME_GAP), block.count.clone(), p.text);
|
||||
for galley in std::iter::once(&block.meaning).chain(block.action.as_ref()) {
|
||||
let (place, _) = ui.allocate_exact_size(galley.size(), Sense::hover());
|
||||
ui.painter().galley(place.min, galley.clone(), p.muted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 + 1.0);
|
||||
let blocks = blocks(ui, view, inner);
|
||||
let gaps = blocks.len().saturating_sub(1) as f32 * (theme::space::BETWEEN_PARTS + theme::space::LINE);
|
||||
let content: f32 = blocks.iter().map(Block::height).sum();
|
||||
theme::layout::REASONS_FIXED_HEIGHT + content.max(theme::space::ROW) + gaps
|
||||
}
|
||||
|
||||
/// "By language": one row per language, with hits, misses, errors, the hit rate
|
||||
|
||||
Reference in new issue
Block a user