diff options
author | ClementTsang <clementjhtsang@gmail.com> | 2019-09-08 01:01:42 -0400 |
---|---|---|
committer | ClementTsang <clementjhtsang@gmail.com> | 2019-09-08 01:01:42 -0400 |
commit | 0050b77cafa2a33adf5275b75fbdf1f4a9adf132 (patch) | |
tree | 57453fd842d52556c5819c844d302a17d747f339 /src/widgets | |
parent | 826bc701c11e5dae9d9e130c215ecdecb48428ce (diff) |
Removed the 'timing' aspect, it was irrelevant.
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/cpu.rs | 19 | ||||
-rw-r--r-- | src/widgets/disks.rs | 21 | ||||
-rw-r--r-- | src/widgets/mem.rs | 9 | ||||
-rw-r--r-- | src/widgets/network.rs | 12 | ||||
-rw-r--r-- | src/widgets/processes.rs | 23 | ||||
-rw-r--r-- | src/widgets/temperature.rs | 15 |
6 files changed, 37 insertions, 62 deletions
diff --git a/src/widgets/cpu.rs b/src/widgets/cpu.rs index 48a419f3..b8a629e1 100644 --- a/src/widgets/cpu.rs +++ b/src/widgets/cpu.rs @@ -1,18 +1,12 @@ use sysinfo::{ProcessorExt, System, SystemExt}; -#[derive(Clone)] +#[derive(Clone, Default)] pub struct CPUData { pub cpu_name : Box<str>, pub cpu_usage : u32, } -#[derive(Clone)] -pub struct TimedCPUPackages { - pub processor_list : Vec<CPUData>, - pub time : std::time::SystemTime, -} - -pub fn get_cpu_data_list(sys : &System) -> Result<TimedCPUPackages, heim::Error> { +pub fn get_cpu_data_list(sys : &System) -> Result<Vec<CPUData>, heim::Error> { let cpu_data = sys.get_processor_list(); let mut cpu_vec = Vec::new(); @@ -23,12 +17,5 @@ pub fn get_cpu_data_list(sys : &System) -> Result<TimedCPUPackages, heim::Error> }) } - Ok(TimedCPUPackages { - processor_list : cpu_vec, - time : std::time::SystemTime::now(), - }) -} - -pub fn is_cpu_data_old() -> bool { - true + Ok(cpu_vec) } diff --git a/src/widgets/disks.rs b/src/widgets/disks.rs index 0739ee4d..7a3ed212 100644 --- a/src/widgets/disks.rs +++ b/src/widgets/disks.rs @@ -1,6 +1,6 @@ use heim_common::prelude::StreamExt; -#[derive(Clone)] +#[derive(Clone, Default)] pub struct DiskInfo { pub name : Box<str>, pub mount_point : Box<str>, @@ -9,25 +9,23 @@ pub struct DiskInfo { pub total_space : u64, } -#[derive(Clone)] -pub struct TimedIOInfo { +#[derive(Clone, Default)] +pub struct IOInfo { 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(get_physical : bool) -> Result<Vec<TimedIOInfo>, heim::Error> { - let mut io_list : Vec<TimedIOInfo> = Vec::new(); +pub async fn get_io_usage_list(get_physical : bool) -> Result<Vec<IOInfo>, heim::Error> { + let mut io_list : Vec<IOInfo> = 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 { + io_list.push(IOInfo { 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(), }) } } @@ -35,11 +33,10 @@ pub async fn get_io_usage_list(get_physical : bool) -> Result<Vec<TimedIOInfo>, let mut counter_stream = heim::disk::io_counters(); while let Some(io) = counter_stream.next().await { let io = io?; - io_list.push(TimedIOInfo { + io_list.push(IOInfo { 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(), }) } } @@ -47,10 +44,6 @@ pub async fn get_io_usage_list(get_physical : bool) -> Result<Vec<TimedIOInfo>, 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(); diff --git a/src/widgets/mem.rs b/src/widgets/mem.rs index 25d3d944..c896351c 100644 --- a/src/widgets/mem.rs +++ b/src/widgets/mem.rs @@ -1,10 +1,9 @@ use heim_common::units::information; -#[derive(Clone)] +#[derive(Clone, Default)] pub struct MemData { pub mem_total : u64, pub mem_used : u64, - pub time : std::time::SystemTime, } pub async fn get_mem_data_list() -> Result<MemData, heim::Error> { @@ -13,7 +12,6 @@ pub async fn get_mem_data_list() -> Result<MemData, heim::Error> { Ok(MemData { mem_total : memory.total().get::<information::megabyte>(), mem_used : memory.total().get::<information::megabyte>() - memory.available().get::<information::megabyte>(), - time : std::time::SystemTime::now(), }) } @@ -23,10 +21,5 @@ pub async fn get_swap_data_list() -> Result<MemData, heim::Error> { Ok(MemData { mem_total : memory.total().get::<information::megabyte>(), mem_used : memory.used().get::<information::megabyte>(), - time : std::time::SystemTime::now(), }) } - -pub fn is_mem_data_old() -> bool { - true -} diff --git a/src/widgets/network.rs b/src/widgets/network.rs index 1e8daad4..3094422b 100644 --- a/src/widgets/network.rs +++ b/src/widgets/network.rs @@ -1,17 +1,15 @@ use sysinfo::{NetworkExt, System, SystemExt}; -#[derive(Clone)] -pub struct TimedNetworkData { +#[derive(Clone, Default)] +pub struct NetworkData { pub rx : u64, pub tx : u64, - pub time : std::time::SystemTime, } -pub fn get_network_data(sys : &System) -> TimedNetworkData { +pub fn get_network_data(sys : &System) -> Result<NetworkData, heim::Error> { let network_data = sys.get_network(); - TimedNetworkData { + Ok(NetworkData { rx : network_data.get_income(), tx : network_data.get_outcome(), - time : std::time::SystemTime::now(), - } + }) } diff --git a/src/widgets/processes.rs b/src/widgets/processes.rs index c8c3412b..b4e90d4d 100644 --- a/src/widgets/processes.rs +++ b/src/widgets/processes.rs @@ -3,6 +3,7 @@ use heim_common::{ units, }; +#[allow(dead_code)] pub enum ProcessSorting { CPU, MEM, @@ -11,7 +12,7 @@ pub enum ProcessSorting { } // Possible process info struct? -#[derive(Clone, Debug)] +#[derive(Clone, Default)] pub struct ProcessInfo { pub pid : u32, pub cpu_usage_percent : f32, @@ -52,14 +53,22 @@ async fn cpu_usage(process : heim::process::Process) -> heim::process::ProcessRe pub async fn get_sorted_processes_list(sorting_method : ProcessSorting, reverse_order : bool) -> Result<Vec<ProcessInfo>, heim::Error> { let mut process_stream = heim::process::processes().map_ok(cpu_usage).try_buffer_unordered(std::usize::MAX); - // TODO: Group together processes - let mut process_vector : Vec<ProcessInfo> = Vec::new(); while let Some(process) = process_stream.next().await { if let Ok(process) = process { let (process, cpu_usage) = process; let mem_measurement = process.memory().await; if let Ok(mem_measurement) = mem_measurement { + /* + // Unsure whether I want to implement this by grouping together process names...? + let mut process_info = process_hashmap.entry(command_name.to_string()).or_insert(ProcessInfo { + command : command_name, + pid : process.pid() as u32, + cpu_usage_percent : cpu_usage.get::<units::ratio::percent>(), + mem_usage_in_mb : mem_measurement.rss().get::<units::information::megabyte>(), + }); + */ + process_vector.push(ProcessInfo { command : process.name().await.unwrap_or_else(|_| "".to_string()), pid : process.pid() as u32, @@ -69,12 +78,16 @@ pub async fn get_sorted_processes_list(sorting_method : ProcessSorting, reverse_ } } } + sort_processes(sorting_method, &mut process_vector, reverse_order); + + Ok(process_vector) +} + +pub fn sort_processes(sorting_method : ProcessSorting, process_vector : &mut Vec<ProcessInfo>, reverse_order : bool) { match sorting_method { ProcessSorting::CPU => process_vector.sort_by(|a, b| get_ordering(a.cpu_usage_percent, b.cpu_usage_percent, reverse_order)), ProcessSorting::MEM => process_vector.sort_by(|a, b| get_ordering(a.mem_usage_in_mb, b.mem_usage_in_mb, reverse_order)), ProcessSorting::PID => process_vector.sort_by(|a, b| get_ordering(a.pid, b.pid, reverse_order)), ProcessSorting::NAME => process_vector.sort_by(|a, b| get_ordering(&a.command, &b.command, reverse_order)), } - - Ok(process_vector) } diff --git a/src/widgets/temperature.rs b/src/widgets/temperature.rs index 632d0ac6..6c153aef 100644 --- a/src/widgets/temperature.rs +++ b/src/widgets/temperature.rs @@ -1,18 +1,12 @@ use heim_common::{prelude::StreamExt, units::thermodynamic_temperature}; -#[derive(Clone)] +#[derive(Clone, Default)] pub struct TempData { pub component_name : Box<str>, pub temperature : f32, } -#[derive(Clone)] -pub struct TimedTempData { - pub temperature_vec : Vec<TempData>, - pub time : std::time::SystemTime, -} - -pub async fn get_temperature_data() -> Result<TimedTempData, heim::Error> { +pub async fn get_temperature_data() -> Result<Vec<TempData>, heim::Error> { let mut temperature_vec : Vec<TempData> = Vec::new(); let mut sensor_data = heim::sensors::temperatures(); @@ -52,8 +46,5 @@ pub async fn get_temperature_data() -> Result<TimedTempData, heim::Error> { } }); - Ok(TimedTempData { - temperature_vec, - time : std::time::SystemTime::now(), - }) + Ok(temperature_vec) } |