summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorClementTsang <clementjhtsang@gmail.com>2019-09-09 00:09:58 -0400
committerClementTsang <clementjhtsang@gmail.com>2019-09-09 00:09:58 -0400
commitff89f1187f13f2f4568f5677f18a1567dbc73931 (patch)
tree185203154e0e2acb4e7ecbd89991c9233d093cf2 /src/widgets
parent471209f511f9a23edf35529cf04cd6fa23e1b408 (diff)
Began working on populating fields.
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/mem.rs12
-rw-r--r--src/widgets/mod.rs96
-rw-r--r--src/widgets/processes.rs12
-rw-r--r--src/widgets/temperature.rs2
4 files changed, 61 insertions, 61 deletions
diff --git a/src/widgets/mem.rs b/src/widgets/mem.rs
index c896351c..3fa03ef9 100644
--- a/src/widgets/mem.rs
+++ b/src/widgets/mem.rs
@@ -2,16 +2,16 @@ use heim_common::units::information;
#[derive(Clone, Default)]
pub struct MemData {
- pub mem_total : u64,
- pub mem_used : u64,
+ pub mem_total_in_mb : u64,
+ pub mem_used_in_mb : u64,
}
pub async fn get_mem_data_list() -> Result<MemData, heim::Error> {
let memory = heim::memory::memory().await?;
Ok(MemData {
- mem_total : memory.total().get::<information::megabyte>(),
- mem_used : memory.total().get::<information::megabyte>() - memory.available().get::<information::megabyte>(),
+ mem_total_in_mb : memory.total().get::<information::megabyte>(),
+ mem_used_in_mb : memory.total().get::<information::megabyte>() - memory.available().get::<information::megabyte>(),
})
}
@@ -19,7 +19,7 @@ pub async fn get_swap_data_list() -> Result<MemData, heim::Error> {
let memory = heim::memory::swap().await?;
Ok(MemData {
- mem_total : memory.total().get::<information::megabyte>(),
- mem_used : memory.used().get::<information::megabyte>(),
+ mem_total_in_mb : memory.total().get::<information::megabyte>(),
+ mem_used_in_mb : memory.used().get::<information::megabyte>(),
})
}
diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs
index c99832c1..36c42cd6 100644
--- a/src/widgets/mod.rs
+++ b/src/widgets/mod.rs
@@ -7,7 +7,6 @@ pub mod temperature;
use sysinfo::{System, SystemExt};
-#[derive(Default)]
pub struct App<'a> {
pub should_quit : bool,
pub list_of_cpu_packages : Vec<cpu::CPUData>,
@@ -20,6 +19,9 @@ pub struct App<'a> {
pub list_of_processes : Vec<processes::ProcessData>,
pub list_of_disks : Vec<disks::DiskData>,
pub title : &'a str,
+ process_sorting_type : processes::ProcessSorting,
+ process_sorting_reverse : bool,
+ sys : System,
}
fn set_if_valid<T : std::clone::Clone>(result : &Result<T, heim::Error>, value_to_set : &mut T) {
@@ -30,72 +32,70 @@ fn set_if_valid<T : std::clone::Clone>(result : &Result<T, heim::Error>, value_t
impl<'a> App<'a> {
pub fn new(title : &str) -> App {
- let mut app = App::default();
- app.title = title;
- app
+ App {
+ title,
+ process_sorting_type : processes::ProcessSorting::NAME, // TODO: Change this based on input args...
+ sys : System::new(), // TODO: Evaluate whether this will cause efficiency issues...
+ list_of_cpu_packages : Vec::new(),
+ list_of_disks : Vec::new(),
+ list_of_physical_io : Vec::new(),
+ list_of_io : Vec::new(),
+ list_of_processes : Vec::new(),
+ list_of_temperature : Vec::new(),
+ network : network::NetworkData::default(),
+ memory : mem::MemData::default(),
+ swap : mem::MemData::default(),
+ should_quit : false,
+ process_sorting_reverse : false,
+ }
}
pub fn on_key(&mut self, c : char) {
match c {
'q' => self.should_quit = true,
+ 'c' => {
+ self.process_sorting_type = processes::ProcessSorting::CPU;
+ //processes::sort_processes(&self.process_sorting_type, &mut self.list_of_processes, self.process_sorting_reverse);
+ // TODO: This CANNOT run while it is updating...
+ }
+ 'm' => {
+ self.process_sorting_type = processes::ProcessSorting::MEM;
+ //processes::sort_processes(&self.process_sorting_type, &mut self.list_of_processes, self.process_sorting_reverse);
+ }
+ 'p' => {
+ self.process_sorting_type = processes::ProcessSorting::PID;
+ //processes::sort_processes(&self.process_sorting_type, &mut self.list_of_processes, self.process_sorting_reverse);
+ }
+ 'n' => {
+ self.process_sorting_type = processes::ProcessSorting::NAME;
+ //processes::sort_processes(&self.process_sorting_type, &mut self.list_of_processes, self.process_sorting_reverse);
+ }
+ 'r' => {
+ self.process_sorting_reverse = !self.process_sorting_reverse;
+ //processes::sort_processes(&self.process_sorting_type, &mut self.list_of_processes, self.process_sorting_reverse);
+ }
_ => {}
}
}
pub async fn update_data(&mut self) {
- // Initialize
- let mut sys = System::new();
-
- sys.refresh_system();
- sys.refresh_network();
+ self.sys.refresh_system();
+ self.sys.refresh_network();
// What we want to do: For timed data, if there is an error, just do not add. For other data, just don't update!
- set_if_valid(&network::get_network_data(&sys), &mut self.network);
- set_if_valid(&cpu::get_cpu_data_list(&sys), &mut self.list_of_cpu_packages);
+ set_if_valid(&network::get_network_data(&self.sys), &mut self.network);
+ set_if_valid(&cpu::get_cpu_data_list(&self.sys), &mut self.list_of_cpu_packages);
// TODO: Joining all futures would be better...
- set_if_valid(&processes::get_sorted_processes_list(processes::ProcessSorting::NAME, false).await, &mut self.list_of_processes);
+ set_if_valid(
+ &processes::get_sorted_processes_list(&self.process_sorting_type, self.process_sorting_reverse).await,
+ &mut self.list_of_processes,
+ );
set_if_valid(&disks::get_disk_usage_list().await, &mut self.list_of_disks);
set_if_valid(&disks::get_io_usage_list(false).await, &mut self.list_of_io);
set_if_valid(&disks::get_io_usage_list(true).await, &mut self.list_of_physical_io);
set_if_valid(&mem::get_mem_data_list().await, &mut self.memory);
set_if_valid(&mem::get_swap_data_list().await, &mut self.swap);
set_if_valid(&temperature::get_temperature_data().await, &mut self.list_of_temperature);
-
- /*
- // DEBUG - output results
- for process in &list_of_processes {
- println!(
- "Process: {} with PID {}, CPU: {}%, MEM: {} MB",
- process.command, process.pid, process.cpu_usage_percent, process.mem_usage_in_mb,
- );
- }
- for disk in &list_of_disks {
- println!("{} is mounted on {}: {} used.", disk.name, disk.mount_point, disk.used_space as f64 / disk.total_space as f64);
- // TODO: Check if this is valid
- }
-
- for io in &list_of_io {
- println!("IO counter for {}: {} writes, {} reads.", &io.mount_point, io.write_bytes, io.read_bytes);
- }
-
- for io in &list_of_physical_io {
- println!("Physical IO counter for {}: {} writes, {} reads.", &io.mount_point, io.write_bytes, io.read_bytes);
- }
-
- for cpu in &list_of_cpu_packages {
- println!("CPU {} has {}% usage!", &cpu.cpu_name, cpu.cpu_usage);
- }
-
- println!("Memory usage: {} out of {} is used", memory.mem_used, memory.mem_total);
-
- println!("Memory usage: {} out of {} is used", swap.mem_used, swap.mem_total);
-
- for sensor in &list_of_temperature {
- println!("Sensor for {} is at {} degrees Celsius", sensor.component_name, sensor.temperature);
- }
-
- println!("Network: {} rx, {} tx", network.rx, network.tx);
- */
}
}
diff --git a/src/widgets/processes.rs b/src/widgets/processes.rs
index 20f6b3b2..88942e16 100644
--- a/src/widgets/processes.rs
+++ b/src/widgets/processes.rs
@@ -15,7 +15,7 @@ pub enum ProcessSorting {
#[derive(Clone, Default)]
pub struct ProcessData {
pub pid : u32,
- pub cpu_usage_percent : f32,
+ pub cpu_usage_percent : f64,
pub mem_usage_in_mb : u64,
pub command : String,
}
@@ -44,13 +44,13 @@ fn get_ordering<T : std::cmp::PartialOrd>(a_val : T, b_val : T, reverse_order :
async fn cpu_usage(process : heim::process::Process) -> heim::process::ProcessResult<(heim::process::Process, heim_common::units::Ratio)> {
let usage_1 = process.cpu_usage().await?;
- futures_timer::Delay::new(std::time::Duration::from_millis(100)).await?;
+ futures_timer::Delay::new(std::time::Duration::from_millis(100)).await?; // TODO: This is causing MASSIVE PROBLEMS WITH THE EVENT LOOP!
let usage_2 = process.cpu_usage().await?;
Ok((process, usage_2 - usage_1))
}
-pub async fn get_sorted_processes_list(sorting_method : ProcessSorting, reverse_order : bool) -> Result<Vec<ProcessData>, heim::Error> {
+pub async fn get_sorted_processes_list(sorting_method : &ProcessSorting, reverse_order : bool) -> Result<Vec<ProcessData>, heim::Error> {
let mut process_stream = heim::process::processes().map_ok(cpu_usage).try_buffer_unordered(std::usize::MAX);
let mut process_vector : Vec<ProcessData> = Vec::new();
@@ -72,18 +72,18 @@ pub async fn get_sorted_processes_list(sorting_method : ProcessSorting, reverse_
process_vector.push(ProcessData {
command : process.name().await.unwrap_or_else(|_| "".to_string()),
pid : process.pid() as u32,
- cpu_usage_percent : cpu_usage.get::<units::ratio::percent>(),
+ cpu_usage_percent : f64::from(cpu_usage.get::<units::ratio::percent>()),
mem_usage_in_mb : mem_measurement.rss().get::<units::information::megabyte>(),
});
}
}
}
- sort_processes(sorting_method, &mut process_vector, reverse_order);
+ sort_processes(&sorting_method, &mut process_vector, reverse_order);
Ok(process_vector)
}
-pub fn sort_processes(sorting_method : ProcessSorting, process_vector : &mut Vec<ProcessData>, reverse_order : bool) {
+pub fn sort_processes(sorting_method : &ProcessSorting, process_vector : &mut Vec<ProcessData>, 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)),
diff --git a/src/widgets/temperature.rs b/src/widgets/temperature.rs
index 6c153aef..f564647f 100644
--- a/src/widgets/temperature.rs
+++ b/src/widgets/temperature.rs
@@ -14,7 +14,7 @@ pub async fn get_temperature_data() -> Result<Vec<TempData>, heim::Error> {
if let Ok(sensor) = sensor {
temperature_vec.push(TempData {
component_name : Box::from(sensor.unit()),
- temperature : sensor.current().get::<thermodynamic_temperature::degree_celsius>(),
+ temperature : sensor.current().get::<thermodynamic_temperature::degree_celsius>(), // TODO: Allow for toggling this!
});
}
}