massa_models/
stats.rs

1//! Copyright (c) 2022 MASSA LABS <info@massa.net>
2
3use crate::slot::Slot;
4use massa_time::MassaTime;
5use serde::{Deserialize, Serialize};
6use std::fmt::Formatter;
7
8/// execution statistics
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct ExecutionStats {
11    /// time window start
12    pub time_window_start: MassaTime,
13    /// time window end
14    pub time_window_end: MassaTime,
15    /// number of final blocks in the time window
16    pub final_block_count: usize,
17    /// number of final executed operations in the time window
18    pub final_executed_operations_count: usize,
19    /// active execution cursor slot
20    pub active_cursor: Slot,
21    /// final execution cursor slot
22    pub final_cursor: Slot,
23}
24
25impl std::fmt::Display for ExecutionStats {
26    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
27        writeln!(f, "Execution stats:")?;
28        writeln!(
29            f,
30            "\tStart stats timespan time: {}",
31            self.time_window_start.format_instant()
32        )?;
33        writeln!(
34            f,
35            "\tEnd stats timespan time: {}",
36            self.time_window_end.format_instant()
37        )?;
38        writeln!(
39            f,
40            "\tFinal executed block count: {}",
41            self.final_block_count
42        )?;
43        writeln!(
44            f,
45            "\tFinal executed operation count: {}",
46            self.final_executed_operations_count
47        )?;
48        writeln!(f, "\tActive cursor: {}", self.active_cursor)?;
49        writeln!(f, "\tFinal cursor: {}", self.final_cursor)?;
50        Ok(())
51    }
52}
53
54/// stats produced by network module
55#[derive(Debug, Clone, Serialize, Deserialize)]
56pub struct NetworkStats {
57    /// in connections count
58    pub in_connection_count: u64,
59    /// out connections count
60    pub out_connection_count: u64,
61    /// total known peers count
62    pub known_peer_count: u64,
63    /// banned node count
64    pub banned_peer_count: u64,
65    /// active node count
66    pub active_node_count: u64,
67}
68
69impl std::fmt::Display for NetworkStats {
70    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
71        writeln!(f, "Network stats:")?;
72        writeln!(f, "\tIn connections: {}", self.in_connection_count)?;
73        writeln!(f, "\tOut connections: {}", self.out_connection_count)?;
74        writeln!(f, "\tKnown peers: {}", self.known_peer_count)?;
75        writeln!(f, "\tBanned peers: {}", self.banned_peer_count)?;
76        writeln!(f, "\tActive nodes: {}", self.active_node_count)?;
77        Ok(())
78    }
79}
80
81/// stats produced by consensus module
82#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct ConsensusStats {
84    /// start of the time span for stats
85    pub start_timespan: MassaTime,
86    /// end of the time span for stats
87    pub end_timespan: MassaTime,
88    /// number of final blocks
89    pub final_block_count: u64,
90    /// number of stale blocks in memory
91    pub stale_block_count: u64,
92    ///  number of actives cliques
93    pub clique_count: u64,
94}
95
96impl std::fmt::Display for ConsensusStats {
97    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
98        writeln!(f, "Consensus stats:")?;
99        writeln!(
100            f,
101            "\tStart stats timespan time: {}",
102            self.start_timespan.format_instant()
103        )?;
104        writeln!(
105            f,
106            "\tEnd stats timespan time: {}",
107            self.end_timespan.format_instant()
108        )?;
109        writeln!(f, "\tFinal block count: {}", self.final_block_count)?;
110        writeln!(f, "\tStale block count: {}", self.stale_block_count)?;
111        writeln!(f, "\tClique count: {}", self.clique_count)?;
112        Ok(())
113    }
114}
115
116/// stats produced by pool module
117#[derive(Serialize, Deserialize, Debug)]
118pub struct PoolStats {
119    /// number of operations in the pool
120    pub operation_count: u64,
121    /// number of endorsement in the pool
122    pub endorsement_count: u64,
123}
124
125impl std::fmt::Display for PoolStats {
126    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
127        writeln!(f, "Pool stats:")?;
128        writeln!(f, "\tOperations: {}", self.operation_count)?;
129        writeln!(f, "\tEndorsements: {}", self.endorsement_count)?;
130        Ok(())
131    }
132}