hydro2_network_performance/
stats.rs

1// ---------------- [ File: src/stats.rs ]
2crate::ix!();
3
4/// Tracks performance statistics for network execution.
5#[derive(Setters,Getters,Debug)]
6#[getset(get="pub",set="pub")]
7pub struct PerformanceStats {
8
9    /// The instant when the network execution started.
10    start_time: Instant,
11
12    /// The instant when the network execution ended.
13    end_time: Option<Instant>,
14
15    /// The total number of operators executed.
16    operators_executed: usize,
17
18    /// Running measure of peak memory usage in bytes.
19    peak_memory_bytes:  usize,
20}
21
22impl PerformanceStats {
23    /// Initializes performance measurement.
24    pub fn start() -> Self {
25        Self {
26            start_time: Instant::now(),
27            end_time: None,
28            operators_executed: 0,
29            peak_memory_bytes: 0,
30        }
31    }
32
33    /// Marks the end of measurement.
34    pub fn end(&mut self) {
35        self.end_time = Some(Instant::now());
36    }
37
38    /// Returns the total execution time, if ended.
39    pub fn total_duration(&self) -> Option<Duration> {
40        match self.end_time {
41            Some(t) => Some(t.duration_since(self.start_time)),
42            None => None,
43        }
44    }
45}
46