176 lines
7.2 KiB
Rust
176 lines
7.2 KiB
Rust
//! 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
|
|
// (and the tests) build anywhere.
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod app;
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod cards;
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod extras;
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod net;
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod overtime;
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod problems;
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod raw;
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod speed;
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod style;
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod theme;
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod where_went;
|
|
|
|
/// The canvas in `index.html` the page is drawn on.
|
|
pub const CANVAS_ID: &str = "the_canvas_id";
|
|
|
|
/// Open the dashboard page in the browser.
|
|
pub fn open() {
|
|
#[cfg(target_arch = "wasm32")]
|
|
web::open();
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
eprintln!(
|
|
"sccache-dash-ui is a web page: build it with `trunk build` in crates/ui. \
|
|
There is no native window yet."
|
|
);
|
|
}
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod web {
|
|
use super::{app::Dashboard, CANVAS_ID};
|
|
|
|
pub fn open() {
|
|
use wasm_bindgen::JsCast;
|
|
|
|
let canvas = web_sys::window()
|
|
.and_then(|window| window.document())
|
|
.and_then(|document| document.get_element_by_id(CANVAS_ID))
|
|
.and_then(|element| element.dyn_into::<web_sys::HtmlCanvasElement>().ok())
|
|
.unwrap_or_else(|| panic!("index.html has no canvas named #{CANVAS_ID}"));
|
|
|
|
wasm_bindgen_futures::spawn_local(async move {
|
|
let options = eframe::WebOptions::default();
|
|
eframe::WebRunner::new()
|
|
.start(canvas, options, Box::new(|cc| Ok(Box::new(Dashboard::new(cc)))))
|
|
.await
|
|
.unwrap_or_else(|error| panic!("eframe failed to start: {error:?}"));
|
|
});
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use sccache_dash_api::{Range, View};
|
|
|
|
/// A view with something in every part of the page.
|
|
const SAMPLE: &str = r#"{
|
|
"range": "24h",
|
|
"generated_at": 1764300000,
|
|
"server": {
|
|
"status": "Running",
|
|
"version": "0.18.0",
|
|
"client_version": "0.18.0",
|
|
"cache_location": "Local disk: \"/home/me/.cache/sccache\"",
|
|
"cache_size": 10726353131,
|
|
"max_cache_size": 10737418240,
|
|
"error": null
|
|
},
|
|
"totals": {
|
|
"requests": 5610, "executed": 5610, "hits": 2815, "misses": 2795,
|
|
"not_cacheable": 0, "unsupported_compiler": 0, "not_compile": 0,
|
|
"timeouts": 3, "read_errors": 2, "write_errors": 1, "other_errors": 0,
|
|
"compile_fails": 12, "forced_recaches": 4, "cache_writes": 2795
|
|
},
|
|
"previous": {
|
|
"requests": 5000, "executed": 5000, "hits": 2000, "misses": 3000,
|
|
"not_cacheable": 0, "unsupported_compiler": 0, "not_compile": 0,
|
|
"timeouts": 0, "read_errors": 0, "write_errors": 0, "other_errors": 0,
|
|
"compile_fails": 9, "forced_recaches": 0, "cache_writes": 3000
|
|
},
|
|
"timing": { "avg_hit_read_ms": 0.72, "avg_cache_write_ms": 310.0, "avg_compile_ms": 8050.0 },
|
|
"time_saved": {
|
|
"seconds": 11100.0, "interval_90": [9700.0, 12600.0], "hits_left_out": 7,
|
|
"note": "Low on purpose."
|
|
},
|
|
"build_times": [
|
|
{ "language": "Rust", "compiles": 3256, "mean_ms": 7780.0, "median_ms": 7100.0,
|
|
"p90_ms": 21200.0,
|
|
"bins": [
|
|
{ "from_ms": 1000.0, "to_ms": 1778.28, "compiles": 120 },
|
|
{ "from_ms": 1778.28, "to_ms": 3162.28, "compiles": 980 }
|
|
] },
|
|
{ "language": "CUDA", "compiles": 0, "mean_ms": 0.0, "median_ms": 0.0,
|
|
"p90_ms": 0.0, "bins": [] }
|
|
],
|
|
"languages": [
|
|
{ "name": "Rust", "hits": 229, "misses": 3256, "errors": 0 },
|
|
{ "name": "C/C++", "hits": 2082, "misses": 0, "errors": 0 }
|
|
],
|
|
"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 },
|
|
{ "start": 1764290600, "hits": 0, "misses": 0, "other": 0, "errors": 0, "saved_seconds": 0.0,
|
|
"languages": [], "reset": false, "gap": true },
|
|
{ "start": 1764291200, "hits": 4, "misses": 4, "other": 0, "errors": 0, "saved_seconds": 30.0,
|
|
"languages": [["C/C++", 4, 4]], "reset": true, "gap": false }
|
|
],
|
|
"problems": [
|
|
{ "severity": "Warning", "title": "Rust hit rate 8%", "detail": "Most Rust compiles miss." }
|
|
],
|
|
"extras": [ { "title": "Multi-level cache", "rows": [["Levels", "2"]] } ],
|
|
"raw": { "stats": { "compile_requests": 5610 }, "version": "0.18.0" },
|
|
"summary_markdown": "**Cache:** 50%"
|
|
}"#;
|
|
|
|
#[test]
|
|
fn a_view_deserialises() {
|
|
let view: View = serde_json::from_str(SAMPLE).expect("the sample is a View");
|
|
assert_eq!(view.range, Some(Range::Day));
|
|
assert_eq!(view.totals.hit_rate(), Some(2815.0 / 5610.0));
|
|
assert_eq!(view.server.version.as_deref(), Some("0.18.0"));
|
|
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].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");
|
|
}
|
|
|
|
#[test]
|
|
fn an_empty_view_deserialises() {
|
|
// Every field is present, as the server always sends them; several are empty.
|
|
let view: View = serde_json::from_str(
|
|
r#"{"range": null, "generated_at": 0, "server": {"status": "NotRunning"},
|
|
"totals": {
|
|
"requests": 0, "executed": 0, "hits": 0, "misses": 0, "not_cacheable": 0,
|
|
"unsupported_compiler": 0, "not_compile": 0, "timeouts": 0, "read_errors": 0,
|
|
"write_errors": 0, "other_errors": 0, "compile_fails": 0, "forced_recaches": 0,
|
|
"cache_writes": 0
|
|
},
|
|
"previous": null,
|
|
"timing": {
|
|
"avg_hit_read_ms": null, "avg_cache_write_ms": null, "avg_compile_ms": null
|
|
},
|
|
"time_saved": {"seconds": 0.0, "hits_left_out": 0, "note": ""},
|
|
"languages": [], "not_cached": [], "buckets": [], "problems": [], "extras": [],
|
|
"raw": null, "summary_markdown": ""}"#,
|
|
)
|
|
.expect("an empty view is still a View");
|
|
assert_eq!(view.totals.hit_rate(), None);
|
|
assert_eq!(view.time_saved.interval_90, None);
|
|
assert!(view.build_times.is_empty());
|
|
assert!(view.raw.is_null());
|
|
}
|
|
}
|