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 {
22            start_time: Instant::now(),
23            operation,
24            mark_frame,
25        }
26    }
27
28    pub fn finish(self) -> Duration {
29        let duration = self.start_time.elapsed();
30        info!(
31            operation = self.operation,
32            duration_us = duration.as_micros(),
33            "Operation completed"
34        );
35
36        // If frame marking is enabled, mark the frame completion
37        if self.mark_frame {
38            tracy_client::frame_mark();
39        }
40
41        duration
42    }
43}