1use std::ffi::OsStr;
2use std::fmt;
3
4use heim_common::prelude::*;
5use heim_common::units::Information;
6
7use crate::sys;
8
9pub struct IoCounters(sys::IoCounters);
21
22wrap!(IoCounters, sys::IoCounters);
23
24impl IoCounters {
25 pub fn device_name(&self) -> &OsStr {
27 self.as_ref().device_name()
28 }
29
30 pub fn read_count(&self) -> u64 {
32 self.as_ref().read_count()
33 }
34
35 pub fn write_count(&self) -> u64 {
37 self.as_ref().write_count()
38 }
39
40 pub fn read_bytes(&self) -> Information {
42 self.as_ref().read_bytes()
43 }
44
45 pub fn write_bytes(&self) -> Information {
47 self.as_ref().write_bytes()
48 }
49}
50
51impl fmt::Debug for IoCounters {
52 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
53 f.debug_struct("IoCounters")
54 .field("device_name", &self.device_name())
55 .field("read_count", &self.read_count())
56 .field("write_count", &self.write_count())
57 .field("read_bytes", &self.read_bytes())
58 .field("write_bytes", &self.write_bytes())
59 .finish()
60 }
61}
62
63pub fn io_counters() -> impl Stream<Item = Result<IoCounters>> {
72 sys::io_counters().map_ok(Into::into)
73}
74
75pub fn io_counters_physical() -> impl Stream<Item = Result<IoCounters>> {
80 sys::io_counters_physical().map_ok(Into::into)
81}