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))
}