mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-10 06:34:16 +00:00
Potential fix for windows processes.
This commit is contained in:
parent
b9ff7efa21
commit
db06f8201f
8 changed files with 24 additions and 41 deletions
|
@ -8,6 +8,7 @@ keywords = ["cli", "monitoring-tool", "process", "system", "top"]
|
|||
license = "MIT"
|
||||
categories = ["command-line-utilities"]
|
||||
description = "A graphical top clone."
|
||||
readme = "README.md"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# bottom
|
||||
|
||||
[![Build Status](https://travis-ci.com/ClementTsang/rustop.svg?token=1wvzVgp94E1TZyPNs8JF&branch=master)](https://travis-ci.com/ClementTsang/rustop)
|
||||
[![Build Status](https://travis-ci.com/ClementTsang/rustop.svg?token=1wvzVgp94E1TZyPNs8JF&branch=master)](https://travis-ci.com/ClementTsang/rustop) [![crates.io link](https://img.shields.io/crates/v/bottom.svg)](https://crates.io/crates/bottom)
|
||||
|
||||
A top clone, written in Rust. Inspired by both [gtop](https://github.com/aksakalli/gtop) and [gotop](https://github.com/cjbassi/gotop)
|
||||
|
||||
|
|
2
TODO.md
2
TODO.md
|
@ -46,8 +46,6 @@ Note this will probably migrate to GitHub's native Issues; this was mostly for p
|
|||
|
||||
* Truncate columns if needed for tables
|
||||
|
||||
* Refactor everything because it's a mess
|
||||
|
||||
* Test for Windows support, mac support, other. May be doable, depends on sysinfo and how much I know about other OSes probably.
|
||||
|
||||
* Efficiency!!!
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
||||
|
|
|
@ -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") {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -101,9 +101,9 @@ pub fn update_process_row(app_data : &data_collection::Data) -> Vec<Vec<String>>
|
|||
if let Some(mem_usage) = process.mem_usage_percent {
|
||||
mem_usage
|
||||
}
|
||||
else if let Some(mem_usage_in_mb) = process.mem_usage_mb {
|
||||
else if let Some(mem_usage_kb) = process.mem_usage_kb {
|
||||
if let Some(mem_data) = app_data.memory.last() {
|
||||
mem_usage_in_mb as f64 / mem_data.mem_total_in_mb as f64 * 100_f64
|
||||
(mem_usage_kb / 1024) as f64 / mem_data.mem_total_in_mb as f64 * 100_f64
|
||||
}
|
||||
else {
|
||||
0_f64
|
||||
|
|
|
@ -96,7 +96,9 @@ fn main() -> error::Result<()> {
|
|||
let tx = tx.clone();
|
||||
thread::spawn(move || {
|
||||
let input = input();
|
||||
input.enable_mouse_mode().unwrap();
|
||||
if cfg!(target_os = "linux") {
|
||||
input.enable_mouse_mode().unwrap();
|
||||
}
|
||||
let reader = input.read_sync();
|
||||
for event in reader {
|
||||
match event {
|
||||
|
|
Loading…
Reference in a new issue