From bb1c292a40c79b3a9e6c08a8cf727ebb94ad3709 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 15 Oct 2026 03:50:02 +0200 Subject: [PATCH] Launcher benchmark reports go to the telemetry outbox with the benchmark-upload consent; tests Co-Authored-By: Claude Opus 5.5 --- launcher/Cargo.lock | 27 +++++++++++++++++++++++ launcher/Cargo.toml | 2 ++ launcher/README.md | 4 +++- launcher/src/perf.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/launcher/Cargo.lock b/launcher/Cargo.lock index eb76e92f3..868d4fc76 100644 --- a/launcher/Cargo.lock +++ b/launcher/Cargo.lock @@ -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" diff --git a/launcher/Cargo.toml b/launcher/Cargo.toml index db7a58150..dadff4db1 100644 --- a/launcher/Cargo.toml +++ b/launcher/Cargo.toml @@ -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" diff --git a/launcher/README.md b/launcher/README.md index 9478c6e13..6f841ad24 100644 --- a/launcher/README.md +++ b/launcher/README.md @@ -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 diff --git a/launcher/src/perf.rs b/launcher/src/perf.rs index 09fcd4265..18b5d5d33 100644 --- a/launcher/src/perf.rs +++ b/launcher/src/perf.rs @@ -304,6 +304,15 @@ pub fn benchmark(repeats: usize) -> Result { 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 { 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))); + } +}