Launcher benchmark reports go to the telemetry outbox with the benchmark-upload consent; tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-15 03:50:02 +02:00
parent c78f2d3e27
commit bb1c292a40
4 changed files with 84 additions and 1 deletions
+27
View File
@@ -2665,6 +2665,7 @@ dependencies = [
"horizon-bench",
"horizon-friends",
"horizon-prepare",
"horizon-telemetry",
"horizon-theme",
"keyring",
"oo7",
@@ -2688,6 +2689,17 @@ dependencies = [
"zip",
]
[[package]]
name = "horizon-telemetry"
version = "0.1.0"
dependencies = [
"getrandom 0.3.4",
"ruzstd",
"serde",
"serde_json",
"ureq",
]
[[package]]
name = "horizon-theme"
version = "0.1.0"
@@ -4855,6 +4867,15 @@ dependencies = [
"unicode-script",
]
[[package]]
name = "ruzstd"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69e4ce4a039f42bf25920b95667e4d789e98749ab11bbb8d2c2936f788421bb5"
dependencies = [
"twox-hash",
]
[[package]]
name = "ryu"
version = "1.0.23"
@@ -6043,6 +6064,12 @@ dependencies = [
"core_maths",
]
[[package]]
name = "twox-hash"
version = "2.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86a801b3cea342a06d468c8710662aa29e5e05e4f5c0d62f00bbb7f2ad7941c2"
[[package]]
name = "typeid"
version = "1.0.3"
+2
View File
@@ -24,6 +24,8 @@ horizon-prepare = { path = "../crates/horizon-prepare" }
# Join a friend: invite codes (the game does the joining).
horizon-friends = { path = "../crates/horizon-friends" }
horizon-bench = { path = "../crates/horizon-bench" }
# Opt-in data collection: the consent, the outbox and its upload (docs/telemetry.md).
horizon-telemetry = { path = "../crates/horizon-telemetry" }
# The session file's random name.
getrandom = "0.3"
+3 -1
View File
@@ -141,7 +141,9 @@ and OS. Attach it to an issue about the launcher being slow. `horizon-launcher b
on purpose: it starts the launcher `--repeats` times (5; the first start is the cold one, as far
as the OS's file cache allows), switches pages for a few seconds in each, rests 3 seconds to
measure idle CPU, fetches the release list 3 times, and writes one report there with means and
95% confidence intervals. Its window has to be on a screen that is awake. Nothing is uploaded.
95% confidence intervals. Its window has to be on a screen that is awake. Session logs stay on
your machine; a `benchmark` report is uploaded, dated to the day, only if you allowed benchmark
uploads ([data collection](../docs/telemetry.md)).
## Building
+52
View File
@@ -304,6 +304,15 @@ pub fn benchmark(repeats: usize) -> Result<PathBuf, String> {
if let Some(bytes) = binary_bytes() {
report.metric("launcher.binary_bytes", &[bytes]);
}
// Kept for upload only if the player allows benchmark uploads (the outbox checks).
if let Ok(data) = serde_json::to_value(report.for_upload()) {
let item = horizon_telemetry::Item::new(
horizon_telemetry::Source::Launcher,
env!("CARGO_PKG_VERSION"),
horizon_telemetry::Payload::Benchmark(data),
);
let _ = horizon_telemetry::outbox::push(&crate::backend::game_home(), &item);
}
report
.write_to(&crate::backend::data_dir().join("benchmarks"))
.map_err(|e| e.to_string())
@@ -320,3 +329,46 @@ fn app() -> App {
fn binary_bytes() -> Option<f64> {
Some(std::fs::metadata(std::env::current_exe().ok()?).ok()?.len() as f64)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_first_frame_is_the_start_and_close_frames_are_ui_frames() {
let mut perf = Perf::new("test");
perf.keep_local_log(false);
assert!(perf.frame(), "the first frame");
assert!(!perf.frame());
std::thread::sleep(IDLE_GAP + Duration::from_millis(20));
perf.frame();
assert_eq!(
perf.ui_frame_times().len(),
1,
"a resting UI is not a slow frame"
);
perf.record("launcher.release_list_ms", 120.0);
perf.record("launcher.release_list_ms", 80.0);
let report = perf.report();
assert!(report.metrics.contains_key("launcher.start_ms"));
assert!(report.metrics.contains_key("launcher.binary_bytes"));
assert_eq!(report.metrics["launcher.release_list_ms"].mean, 100.0);
assert_eq!(report.frames[0].phase, "ui");
}
#[test]
fn a_bench_window_waits_for_its_first_frame_then_switches_pages() {
let mut perf = Perf::new("test");
perf.keep_local_log(false);
let mut bench = Bench {
out: std::env::temp_dir().join("unused"),
began: None,
page: 0,
idle_cpu: None,
};
assert!(matches!(bench.tick(&perf), Step::Wait));
perf.frame();
assert!(matches!(bench.tick(&perf), Step::Go(1)));
assert!(matches!(bench.tick(&perf), Step::Go(2)));
}
}