@@ -19,6 +19,8 @@ pub struct Stats {
19
19
packets : u64 ,
20
20
/// Number of bytes processed since start or last reset.
21
21
bytes : u64 ,
22
+ /// Number of packets which we were not able to send.
23
+ invalid : u64 ,
22
24
/// When packet processing has started.
23
25
start : Instant ,
24
26
/// Interval for producing stats
@@ -36,18 +38,25 @@ impl Default for Stats {
36
38
last_stat : Instant :: now ( ) ,
37
39
packets : Default :: default ( ) ,
38
40
bytes : Default :: default ( ) ,
41
+ invalid : Default :: default ( ) ,
39
42
sender : None ,
40
43
interval : None ,
41
44
}
42
45
}
43
46
}
44
47
45
48
impl Stats {
46
- /// Updates the statistics with a packet containing given number of bytes
49
+ /// Updates the statistics with a packet containing given number of bytes.
50
+ /// If `bytes` is 0, this is to indicate that packet was not sent and
51
+ /// should increase the "invalid" packet count.
47
52
///
48
53
/// Sends summary of statistics if it is time to send them.
49
54
fn update ( & mut self , bytes : u64 ) {
50
- self . packets += 1 ;
55
+ if bytes == 0 {
56
+ self . invalid += 1
57
+ } else {
58
+ self . packets += 1 ;
59
+ }
51
60
self . bytes += bytes;
52
61
if let Some ( val) = self . interval {
53
62
if self . last_stat . elapsed ( ) > val {
@@ -71,9 +80,14 @@ impl Stats {
71
80
let bps = ( self . bytes as f64 * 8_f64 ) / elapsed. as_secs_f64 ( ) ;
72
81
let mbps = ( self . bytes as f64 / ( 1024 * 1024 ) as f64 ) / elapsed. as_secs_f64 ( ) ;
73
82
83
+ let packet_count = match self . invalid {
84
+ 0 => format ! ( "{} packets" , self . packets) ,
85
+ _ => format ! ( "{} packets ({} not sent)" , self . packets, self . invalid) ,
86
+ } ;
87
+
74
88
format ! (
75
- "{} packets , {} bytes in {}ms / {:.3}pps, {:.3}bps ({:.3} MBps)" ,
76
- self . packets ,
89
+ "{}, {} bytes in {}ms / {:.3}pps, {:.3}bps ({:.3} MBps)" ,
90
+ packet_count ,
77
91
self . bytes,
78
92
elapsed. as_millis( ) ,
79
93
pps,
@@ -86,6 +100,7 @@ impl Stats {
86
100
fn reset ( & mut self ) {
87
101
self . bytes = 0 ;
88
102
self . packets = 0 ;
103
+ self . invalid = 0 ;
89
104
self . start = Instant :: now ( ) ;
90
105
}
91
106
0 commit comments