summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorClementTsang <clementjhtsang@gmail.com>2019-09-17 00:24:36 -0400
committerClementTsang <clementjhtsang@gmail.com>2019-09-17 00:24:36 -0400
commitdb06f8201f9f0bdfe5b8dc5791a04e22cfd99381 (patch)
tree28de2d448175ba2c1919a4fccbffda625ffa1795 /src/app
parentb9ff7efa2149cb8d77a2038b41b9f92fd0284b05 (diff)
Potential fix for windows processes.
Diffstat (limited to 'src/app')
-rw-r--r--src/app/data_collection.rs2
-rw-r--r--src/app/data_collection/processes.rs48
-rw-r--r--src/app/process_killer.rs2
3 files changed, 17 insertions, 35 deletions
diff --git a/src/app/data_collection.rs b/src/app/data_collection.rs
index ed0676a8..793d9e1b 100644
--- a/src/app/data_collection.rs
+++ b/src/app/data_collection.rs
@@ -93,7 +93,7 @@ impl DataState {
push_if_valid(&mem::get_mem_data_list().await, &mut self.data.memory);
push_if_valid(&mem::get_swap_data_list().await, &mut self.data.swap);
set_if_valid(
- &processes::get_sorted_processes_list(&mut self.prev_idle, &mut self.prev_non_idle, &mut self.prev_pid_stats).await,
+ &processes::get_sorted_processes_list(&self.sys, &mut self.prev_idle, &mut self.prev_non_idle, &mut self.prev_pid_stats).await,
&mut self.data.list_of_processes,
);
diff --git a/src/app/data_collection/processes.rs b/src/app/data_collection/processes.rs
index 65b47d12..02eb3bb7 100644
--- a/src/app/data_collection/processes.rs
+++ b/src/app/data_collection/processes.rs
@@ -1,8 +1,5 @@
-use heim_common::{
- prelude::{StreamExt, TryStreamExt},
- units,
-};
use std::{collections::HashMap, process::Command};
+use sysinfo::{ProcessExt, System, SystemExt};
#[derive(Clone)]
pub enum ProcessSorting {
@@ -24,7 +21,7 @@ pub struct ProcessData {
pub pid : u32,
pub cpu_usage_percent : f64,
pub mem_usage_percent : Option<f64>,
- pub mem_usage_mb : Option<u64>,
+ pub mem_usage_kb : Option<u64>,
pub command : String,
}
@@ -97,14 +94,6 @@ fn get_ordering<T : std::cmp::PartialOrd>(a_val : T, b_val : T, reverse_order :
}
}
-async fn non_linux_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?; // TODO: For windows, make it like the linux check
- let usage_2 = process.cpu_usage().await?;
-
- Ok((process, usage_2 - usage_1))
-}
-
fn get_process_cpu_stats(pid : u32) -> std::io::Result<f64> {
let mut path = std::path::PathBuf::new();
path.push("/proc");
@@ -151,7 +140,7 @@ fn convert_ps(process : &str, cpu_usage_percentage : f64, prev_pid_stats : &mut
pid : 0,
command : "".to_string(),
mem_usage_percent : None,
- mem_usage_mb : None,
+ mem_usage_kb : None,
cpu_usage_percent : 0_f64,
});
}
@@ -164,13 +153,13 @@ fn convert_ps(process : &str, cpu_usage_percentage : f64, prev_pid_stats : &mut
pid,
command,
mem_usage_percent,
- mem_usage_mb : None,
+ mem_usage_kb : None,
cpu_usage_percent : linux_cpu_usage(pid, cpu_usage_percentage, prev_pid_stats)?,
})
}
pub async fn get_sorted_processes_list(
- prev_idle : &mut f64, prev_non_idle : &mut f64, prev_pid_stats : &mut std::collections::HashMap<String, f64>,
+ sys : &System, prev_idle : &mut f64, prev_non_idle : &mut f64, prev_pid_stats : &mut std::collections::HashMap<String, f64>,
) -> crate::utils::error::Result<Vec<ProcessData>> {
let mut process_vector : Vec<ProcessData> = Vec::new();
@@ -194,24 +183,15 @@ pub async fn get_sorted_processes_list(
else if cfg!(target_os = "windows") {
// Windows
- // TODO: DO NOT USE HEIM!
- let mut process_stream = heim::process::processes().map_ok(non_linux_cpu_usage).try_buffer_unordered(std::usize::MAX);
-
- let mut process_vector : Vec<ProcessData> = 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 {
- process_vector.push(ProcessData {
- command : process.name().await.unwrap_or_else(|_| "".to_string()),
- pid : process.pid() as u32,
- cpu_usage_percent : f64::from(cpu_usage.get::<units::ratio::percent>()),
- mem_usage_percent : None,
- mem_usage_mb : Some(mem_measurement.rss().get::<units::information::megabyte>()),
- });
- }
- }
+ let process_hashmap = sys.get_process_list();
+ for process_val in process_hashmap.values() {
+ process_vector.push(ProcessData {
+ pid : process_val.pid() as u32,
+ command : process_val.name().to_string(),
+ mem_usage_percent : None,
+ mem_usage_kb : Some(process_val.memory()),
+ cpu_usage_percent : f64::from(process_val.cpu_usage()),
+ });
}
}
else if cfg!(target_os = "macos") {
diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs
index e91034c4..2e74de16 100644
--- a/src/app/process_killer.rs
+++ b/src/app/process_killer.rs
@@ -9,10 +9,12 @@ pub fn kill_process_given_pid(pid : u64) -> crate::utils::error::Result<()> {
}
else if cfg!(target_os = "windows") {
// Windows
+ // See how sysinfo does it... https://docs.rs/sysinfo/0.9.5/sysinfo/trait.ProcessExt.html
debug!("Sorry, Windows support is not implemented yet!");
}
else if cfg!(target_os = "macos") {
// TODO: macOS
+ // See how sysinfo does it... https://docs.rs/sysinfo/0.9.5/sysinfo/trait.ProcessExt.html
debug!("Sorry, macOS support is not implemented yet!");
}
else {