diff options
author | ClementTsang <clementjhtsang@gmail.com> | 2019-09-07 16:39:17 -0400 |
---|---|---|
committer | ClementTsang <clementjhtsang@gmail.com> | 2019-09-07 16:39:17 -0400 |
commit | f9b98c71ec3dbd6d152e210be8aa61cfcfac35ad (patch) | |
tree | 22c292dcd27340e623f1affb27362a69cdfc5929 /src/widgets | |
parent | 153a2590b0bfe5a221072c8775b388757a02d740 (diff) |
Set up disk to use heim
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/cpu.rs | 8 | ||||
-rw-r--r-- | src/widgets/disks.rs | 59 |
2 files changed, 41 insertions, 26 deletions
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<CPUData>, 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<str>, +pub struct TimedIOInfo { + pub mount_point : Box<str>, pub read_bytes : u64, pub write_bytes : u64, + pub time : std::time::SystemTime, } -pub async fn get_io_usage_list() -> Result<Vec<IOInfo>, heim::Error> { - let mut io_list : Vec<IOInfo> = 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<Vec<TimedIOInfo>, heim::Error> { + let mut io_list : Vec<TimedIOInfo> = 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::<heim_common::units::information::megabyte>(), + write_bytes : io.write_bytes().get::<heim_common::units::information::megabyte>(), + 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::<heim_common::units::information::megabyte>(), + write_bytes : io.write_bytes().get::<heim_common::units::information::megabyte>(), + time : std::time::SystemTime::now(), + }) + } } Ok(io_list) } +pub fn is_io_data_old() -> bool { + true +} + pub async fn get_disk_usage_list() -> Result<Vec<DiskInfo>, heim::Error> { let mut vec_disks : Vec<DiskInfo> = Vec::new(); let mut partitions_stream = heim::disk::partitions_physical(); @@ -38,15 +56,12 @@ pub async fn get_disk_usage_list() -> Result<Vec<DiskInfo>, 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::<heim_common::units::information::megabyte>(), - usage.used().get::<heim_common::units::information::megabyte>(), - usage.free().get::<heim_common::units::information::megabyte>(), - part.file_system().as_str(), - part.mount_point().to_string_lossy(), - ); + vec_disks.push(DiskInfo { + avail_space : usage.free().get::<heim_common::units::information::megabyte>(), + total_space : usage.total().get::<heim_common::units::information::megabyte>(), + 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) |