1use std::time::Instant;
5
6pub struct StageTimer {
10 prefix: &'static str,
11 pub(crate) enabled: bool,
12 started: Instant,
13}
14
15impl StageTimer {
16 pub fn new(prefix: &'static str) -> Self {
17 Self {
18 prefix,
19 enabled: std::env::var_os("AFT_VIEW_PROFILE").is_some(),
20 started: Instant::now(),
21 }
22 }
23
24 pub fn finish(&mut self, stage: &str, detail: std::fmt::Arguments<'_>) {
25 #[cfg(any(test, feature = "test-support"))]
26 crate::test_allocations::heap_marker(self.prefix, stage);
27 if self.enabled {
28 eprintln!(
29 "view_profile {}.{stage} ms={:.3} {detail}",
30 self.prefix,
31 self.started.elapsed().as_secs_f64() * 1000.0
32 );
33 }
34 self.started = Instant::now();
35 }
36}