use std::time::Instant;
pub struct StageTimer {
prefix: &'static str,
pub(crate) enabled: bool,
started: Instant,
}
impl StageTimer {
pub fn new(prefix: &'static str) -> Self {
Self {
prefix,
enabled: std::env::var_os("AFT_VIEW_PROFILE").is_some(),
started: Instant::now(),
}
}
pub fn finish(&mut self, stage: &str, detail: std::fmt::Arguments<'_>) {
#[cfg(any(test, feature = "test-support"))]
crate::test_allocations::heap_marker(self.prefix, stage);
if self.enabled {
eprintln!(
"view_profile {}.{stage} ms={:.3} {detail}",
self.prefix,
self.started.elapsed().as_secs_f64() * 1000.0
);
}
self.started = Instant::now();
}
}