examples/bench_only_demo.rs
//! Run each child repo's `xtask/examples/nornir-bench.rs`, parse the
//! BenchRun JSON line, and persist it to the warehouse — but skip the
//! cargo-test gate and the release_lineage row.
//!
//! cargo run --release --example bench_only_demo
//!
//! Useful for spinning up the fans + populating `bench_runs` and
//! `bench_results` for warehouse-side queries without going through
//! the full release pipeline.
use std::path::{Path, PathBuf};
use std::process::Command;
use anyhow::{Context, Result, bail};
use nornir::bench::BenchRun;
use nornir::warehouse::Warehouse as _;
use nornir::warehouse::iceberg::IcebergWarehouse;
fn run_bench(repo: &str, root: &Path) -> Result<BenchRun> {
println!("\n🌀 {repo}: cargo run -p xtask --release --example nornir-bench --quiet …");
let out = Command::new("cargo")
.args([
"run",
"-p",
"xtask",
"--release",
"--example",
"nornir-bench",
"--quiet",
])
.current_dir(root)
.output()
.with_context(|| format!("spawn cargo for `{repo}`"))?;
if !out.status.success() {
bail!(
"`{}` bench example failed:\n--- stderr ---\n{}",
repo,
String::from_utf8_lossy(&out.stderr)
);
}
let stdout = String::from_utf8_lossy(&out.stdout);
let last = stdout
.lines()
.map(str::trim)
.filter(|l| !l.is_empty())
.next_back()
.ok_or_else(|| anyhow::anyhow!("`{repo}` bench produced no stdout"))?;
let run: BenchRun = serde_json::from_str(last)
.with_context(|| format!("parse BenchRun JSON from `{repo}` stdout: {last}"))?;
Ok(run)
}
fn main() -> Result<()> {
if std::env::var_os("NORNIR_MACHINE").is_none() {
let host = std::process::Command::new("uname")
.arg("-n")
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.unwrap_or_else(|| "demo-host".to_string());
unsafe { std::env::set_var("NORNIR_MACHINE", &host) };
}
let repos: Vec<(&str, PathBuf)> = vec![
(
"znippy",
std::env::var("ZNIPPY_PATH")
.map(PathBuf::from)
.unwrap_or_else(|_| PathBuf::from(format!("/run/media/{}/T9/git/znippy", std::env::var("USER").unwrap_or_default()))),
),
(
"holger",
std::env::var("HOLGER_PATH")
.map(PathBuf::from)
.unwrap_or_else(|_| PathBuf::from(format!("/run/media/{}/T9/git/holger", std::env::var("USER").unwrap_or_default()))),
),
];
let wh_root = PathBuf::from("/tmp/nornir-demo-warehouse");
std::fs::create_dir_all(&wh_root)?;
let wh = IcebergWarehouse::open(&wh_root)?;
println!("📦 warehouse at {}", wh_root.display());
for (repo, root) in &repos {
let run = run_bench(repo, root)?;
println!(" results:");
for r in &run.results {
let summary = r
.metrics
.iter()
.map(|(k, v)| format!("{k}={v:.2}"))
.collect::<Vec<_>>()
.join(" ");
println!(" • {:30} {summary}", r.name);
}
wh.append_bench_run(repo, &run)
.with_context(|| format!("persist bench run for `{repo}`"))?;
println!(" ✅ persisted to warehouse");
}
println!(
"\n🎉 all repos benched. Query bench_runs / bench_results in {}",
wh_root.display()
);
Ok(())
}