diff --git a/src/main.rs b/src/main.rs index 91fbecba..94206a49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,11 +9,15 @@ mod window; async fn main() -> Result<(), Box> { // Initialize let refresh_interval = 1; // TODO: Make changing this possible! + let get_physical_io = false; let mut sys = System::new(); - let mut list_of_timed_processes : Vec = Vec::new(); + let mut list_of_timed_processes : Vec = Vec::new(); + let mut list_of_timed_io : Vec> = Vec::new(); + let mut list_of_timed_physical_io : Vec> = Vec::new(); loop { + dbg!("Start data loop..."); sys.refresh_system(); // Get data, potentially store? @@ -22,19 +26,35 @@ async fn main() -> Result<(), Box> { let list_of_disks = disks::get_disk_usage_list().await?; for disk in list_of_disks { - println!("{} is mounted on {}: {}/{} free.", disk.name, disk.mount_point, disk.avail_space as f64, disk.total_space as f64); + dbg!("{} is mounted on {}: {}/{} free.", disk.name, disk.mount_point, disk.avail_space as f64, disk.total_space as f64); // TODO: Check if this is valid } + list_of_timed_io.push(disks::get_io_usage_list(false).await?); + list_of_timed_physical_io.push(disks::get_io_usage_list(true).await?); + + if !list_of_timed_io.is_empty() { + for io in list_of_timed_io.last().unwrap() { + dbg!("IO counter for {} at {:?}: {} writes, {} reads.", &io.mount_point, io.time, io.write_bytes, io.read_bytes); + } + } + if !list_of_timed_physical_io.is_empty() { + for io in list_of_timed_physical_io.last().unwrap() { + dbg!("Physical IO counter for {} at {:?}: {} writes, {} reads.", &io.mount_point, io.time, io.write_bytes, io.read_bytes); + } + } + list_of_timed_processes.push(cpu::get_cpu_data_list(&sys)); + if !list_of_timed_processes.is_empty() { let current_cpu_time = list_of_timed_processes.last().unwrap().time; for cpu in &list_of_timed_processes.last().unwrap().processor_list { - println!("CPU {} has {}% usage at timestamp {:?}!", cpu.cpu_name, cpu.cpu_usage, current_cpu_time); + dbg!("CPU {} has {}% usage at timestamp {:?}!", &cpu.cpu_name, cpu.cpu_usage, current_cpu_time); } } // Send to drawing module + dbg!("End data loop..."); window::draw_terminal(); // Repeat on interval diff --git a/src/widgets/cpu.rs b/src/widgets/cpu.rs index d462c2a7..8cc11a75 100644 --- a/src/widgets/cpu.rs +++ b/src/widgets/cpu.rs @@ -5,12 +5,12 @@ pub struct CPUData { pub cpu_usage : u32, } -pub struct TimedCPUPackagesStruct { +pub struct TimedCPUPackages { pub processor_list : Vec, pub time : std::time::SystemTime, } -pub fn get_cpu_data_list(sys : &System) -> TimedCPUPackagesStruct { +pub fn get_cpu_data_list(sys : &System) -> TimedCPUPackages { let cpu_data = sys.get_processor_list(); let mut cpu_vec = Vec::new(); @@ -21,12 +21,12 @@ pub fn get_cpu_data_list(sys : &System) -> TimedCPUPackagesStruct { }) } - TimedCPUPackagesStruct { + TimedCPUPackages { processor_list : cpu_vec, time : std::time::SystemTime::now(), } } -pub fn clear_old_cpu_data() -> bool { +pub fn is_cpu_data_old() -> bool { true } diff --git a/src/widgets/disks.rs b/src/widgets/disks.rs index e21f3e13..2ef6d6e0 100644 --- a/src/widgets/disks.rs +++ b/src/widgets/disks.rs @@ -7,29 +7,47 @@ pub struct DiskInfo { pub total_space : u64, } -pub struct IOInfo { - pub name : Box, +pub struct TimedIOInfo { + pub mount_point : Box, pub read_bytes : u64, pub write_bytes : u64, + pub time : std::time::SystemTime, } -pub async fn get_io_usage_list() -> Result, heim::Error> { - let mut io_list : Vec = Vec::new(); - let mut counters = heim::disk::io_counters(); - while let Some(counter) = counters.next().await { - dbg!(counter?); +pub async fn get_io_usage_list(get_physical : bool) -> Result, heim::Error> { + let mut io_list : Vec = Vec::new(); + if get_physical { + let mut physical_counter_stream = heim::disk::io_counters_physical(); + while let Some(io) = physical_counter_stream.next().await { + let io = io?; + io_list.push(TimedIOInfo { + mount_point : Box::from(io.device_name().to_str().unwrap_or("Name Unavailable")), + read_bytes : io.read_bytes().get::(), + write_bytes : io.write_bytes().get::(), + time : std::time::SystemTime::now(), + }) + } } - - println!("\n\n--- Per physical disk ---\n"); - - let mut counters = heim::disk::io_counters_physical(); - while let Some(counter) = counters.next().await { - dbg!(counter?); + else { + let mut counter_stream = heim::disk::io_counters(); + while let Some(io) = counter_stream.next().await { + let io = io?; + io_list.push(TimedIOInfo { + mount_point : Box::from(io.device_name().to_str().unwrap_or("Name Unavailable")), + read_bytes : io.read_bytes().get::(), + write_bytes : io.write_bytes().get::(), + time : std::time::SystemTime::now(), + }) + } } Ok(io_list) } +pub fn is_io_data_old() -> bool { + true +} + pub async fn get_disk_usage_list() -> Result, heim::Error> { let mut vec_disks : Vec = Vec::new(); let mut partitions_stream = heim::disk::partitions_physical(); @@ -38,15 +56,12 @@ pub async fn get_disk_usage_list() -> Result, heim::Error> { let part = part?; let usage = heim::disk::usage(part.mount_point().to_path_buf()).await?; - println!( - "{:<17} {:<10} {:<10} {:<10} {:<10} {}", - part.device().unwrap().to_str().unwrap(), - usage.total().get::(), - usage.used().get::(), - usage.free().get::(), - part.file_system().as_str(), - part.mount_point().to_string_lossy(), - ); + vec_disks.push(DiskInfo { + avail_space : usage.free().get::(), + total_space : usage.total().get::(), + mount_point : Box::from(part.mount_point().to_str().unwrap_or("Name Unavailable")), + name : Box::from(part.device().unwrap_or_else(|| std::ffi::OsStr::new("Name Unavailable")).to_str().unwrap_or("Name Unavailable")), + }); } Ok(vec_disks)