specfold_core/trace.rs
1//! Phase timings on stderr when `SPECFOLD_TRACE` is set, for diagnosing slow runs.
2
3use std::sync::OnceLock;
4use std::time::Instant;
5
6fn enabled() -> bool {
7 static ON: OnceLock<bool> = OnceLock::new();
8 *ON.get_or_init(|| std::env::var_os("SPECFOLD_TRACE").is_some())
9}
10
11/// Prints how long a phase took since `start` and returns a new start.
12pub fn phase(name: &str, start: Instant) -> Instant {
13 if enabled() {
14 eprintln!("specfold: {name:<12} {:>7.1} ms", start.elapsed().as_secs_f64() * 1000.0);
15 }
16 Instant::now()
17}