1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use std::time::Duration;
#[derive(Default, Debug, Clone)]
pub struct VolumeSpeed {
pub read: f64,
pub write: f64,
}
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct VolumeStat {
pub read_bytes: u64,
pub write_bytes: u64,
}
impl VolumeStat {
#[inline]
pub fn compute_speed(
&self,
volume_stat_after_this: &VolumeStat,
interval: Duration,
) -> VolumeSpeed {
let seconds = interval.as_secs_f64();
let d_read = volume_stat_after_this.read_bytes - self.read_bytes;
let d_write = volume_stat_after_this.write_bytes - self.write_bytes;
let read = d_read as f64 / seconds;
let write = d_write as f64 / seconds;
VolumeSpeed {
read,
write,
}
}
}