use super::io_kit::{self, get_dict, get_disks, get_i64, get_string};
use crate::collection::disks::IoCounters;
fn get_device_io(device: io_kit::IoObject) -> anyhow::Result<IoCounters> {
let parent = device.service_parent()?;
let disk_props = device.properties()?;
let parent_props = parent.properties()?;
let name = get_string(&disk_props, "BSD Name")?;
let stats = get_dict(&parent_props, "Statistics")?;
let read_bytes = get_i64(&stats, "Bytes (Read)")? as u64;
let write_bytes = get_i64(&stats, "Bytes (Write)")? as u64;
Ok(IoCounters::new(name, read_bytes, write_bytes))
}
pub fn io_stats() -> anyhow::Result<Vec<IoCounters>> {
Ok(get_disks()?.filter_map(|d| get_device_io(d).ok()).collect())
}