walker_common/utils/
measure.rs

1//! Measuring the time of operations
2
3use std::time::{Duration, SystemTime};
4
5pub struct MeasureTime(SystemTime);
6
7impl MeasureTime {
8    pub fn new() -> Self {
9        Self(SystemTime::now())
10    }
11}
12
13impl Default for MeasureTime {
14    fn default() -> Self {
15        Self::new()
16    }
17}
18
19impl Drop for MeasureTime {
20    fn drop(&mut self) {
21        match self.0.elapsed() {
22            Ok(duration) => {
23                // truncate to seconds, good enough
24                let duration = Duration::from_secs(duration.as_secs());
25                log::info!("Processing took {}", humantime::format_duration(duration))
26            }
27            Err(err) => log::warn!("Unable to measure processing time: {err}"),
28        }
29    }
30}