ferrite_logging/
metrics.rs

1use std::time::{Duration, Instant};
2use tracing::{info, info_span};
3
4pub struct PerformanceMetrics {
5    start_time: Instant,
6    operation: &'static str,
7    mark_frame: bool,
8}
9
10impl PerformanceMetrics {
11    pub fn new(operation: &'static str, mark_frame: bool) -> Self {
12        let span = info_span!("performance_measurement",
13            operation = operation,
14            start_time = ?Instant::now()
15        );
16
17        span.in_scope(|| {
18            info!("Starting operation: {}", operation);
19        });
20
21        Self { start_time: Instant::now(), operation, mark_frame }
22    }
23
24    pub fn finish(self) -> Duration {
25        let duration = self.start_time.elapsed();
26        info!(
27            operation = self.operation,
28            duration_us = duration.as_micros(),
29            "Operation completed"
30        );
31
32        // If frame marking is enabled, mark the frame completion
33        if self.mark_frame {
34            tracy_client::frame_mark();
35        }
36
37        duration
38    }
39}