Skip to main content

hotshot_new_protocol/coordinator/
metrics.rs

1use std::{sync::Arc, time::Instant};
2
3use hotshot_types::{consensus::ConsensusMetricsValue, traits::metrics::Histogram};
4
5pub struct Metrics {
6    pub(crate) consensus: ConsensusMetricsValue,
7}
8
9impl Metrics {
10    pub fn new(consensus: ConsensusMetricsValue) -> Self {
11        Self { consensus }
12    }
13}
14
15pub struct Measurement {
16    hist: Arc<dyn Histogram>,
17    start: Instant,
18    record: bool,
19}
20
21impl Measurement {
22    pub fn start(h: Arc<dyn Histogram>) -> Self {
23        Self {
24            hist: h,
25            start: Instant::now(),
26            record: true,
27        }
28    }
29}
30
31impl Drop for Measurement {
32    fn drop(&mut self) {
33        if self.record {
34            self.hist.add_point(self.start.elapsed().as_secs_f64());
35        }
36    }
37}
38
39pub fn finish_measurement(_: Option<Measurement>) {}
40
41pub fn ignore_measurement(m: Option<Measurement>) {
42    if let Some(mut m) = m {
43        m.record = false;
44    }
45}