gondola_core/monitoring/
run_statistics.rs

1// This file is part of gaps-online-software and published 
2// under the GPLv3 license
3
4use crate::prelude::*;
5
6/// Keep track of run related statistics, errors
7#[derive(Debug, Copy, Clone)]
8#[cfg_attr(feature="pybindings",pyclass)]
9pub struct RunStatistics {
10  /// The number of events we have recorded
11  pub n_events_rec      : usize,
12  /// The number of packets going through 
13  /// the event processing
14  pub evproc_npack      : usize,
15  /// The first event id we saw
16  pub first_evid        : u32,
17  /// The last event id we saw
18  pub last_evid         : u32,
19  /// The number of times we encountered 
20  /// a deserialization issue
21  pub n_err_deser       : usize,
22  /// The number of times we encountered 
23  /// an issue while sending over zmq
24  pub n_err_zmq_send    : usize,
25  /// The number of times we encountered
26  /// an issue with a wrong channel identifier
27  pub n_err_chid_wrong  : usize,
28  /// How many times did we read out an incorrect
29  /// tail?
30  pub n_err_tail_wrong  : usize,
31  /// The number of times we failed a crc32 check
32  pub n_err_crc32_wrong : usize,
33}
34
35impl RunStatistics {
36  
37  pub fn new() -> Self {
38    Self {
39      n_events_rec      : 0,
40      evproc_npack      : 0,
41      first_evid        : 0,
42      last_evid         : 0,
43      n_err_deser       : 0,
44      n_err_zmq_send    : 0,
45      n_err_chid_wrong  : 0,
46      n_err_tail_wrong  : 0,
47      n_err_crc32_wrong : 0,
48    }
49  }
50
51  pub fn get_n_anticipated(&self) -> i32 {
52    self.last_evid as i32 - self.first_evid as i32
53  }
54}
55
56impl fmt::Display for RunStatistics {
57  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
58    let mut resp = String::from("<RunStatistics:\n");
59    resp += &(format!("  first event id : {}\n", self.first_evid));
60    resp += &(format!("  last  event id : {}\n", self.last_evid));
61    resp += &(format!("  --> expected {} event (ids)\n", self.get_n_anticipated()));
62    resp += &(format!("  event_processing #packets : {}\n", self.evproc_npack));
63    if self.get_n_anticipated() != self.evproc_npack as i32 {
64      resp += &(format!("  --> discrepancy of {} event (ids)\n", self.get_n_anticipated() - self.evproc_npack as i32))
65    }
66    resp += &(format!("  event_processing n tail err : {}\n", self.n_err_tail_wrong));
67    resp += &(format!("  event_processing n chid err : {}\n", self.n_err_chid_wrong));
68    write!(f, "{}", resp)
69  }
70}
71
72#[cfg(feature="pybindings")]
73pythonize!(RunStatistics);