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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use std::ffi::OsStr;
use std::fmt;
use heim_common::prelude::*;
use heim_common::units::Information;
use crate::sys;
pub struct IoCounters(sys::IoCounters);
wrap!(IoCounters, sys::IoCounters);
impl IoCounters {
pub fn device_name(&self) -> &OsStr {
self.as_ref().device_name()
}
pub fn read_count(&self) -> u64 {
self.as_ref().read_count()
}
pub fn write_count(&self) -> u64 {
self.as_ref().write_count()
}
pub fn read_bytes(&self) -> Information {
self.as_ref().read_bytes()
}
pub fn write_bytes(&self) -> Information {
self.as_ref().write_bytes()
}
}
impl fmt::Debug for IoCounters {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("IoCounters")
.field("device_name", &self.device_name())
.field("read_count", &self.read_count())
.field("write_count", &self.write_count())
.field("read_bytes", &self.read_bytes())
.field("write_bytes", &self.write_bytes())
.finish()
}
}
pub async fn io_counters() -> Result<impl Stream<Item = Result<IoCounters>>> {
let inner = sys::io_counters().await?;
Ok(inner.map_ok(Into::into))
}
pub async fn io_counters_physical() -> Result<impl Stream<Item = Result<IoCounters>>> {
let inner = sys::io_counters_physical().await?;
Ok(inner.map_ok(Into::into))
}