deps: update sysctl to 0.5.2, procfs to 0.14.1 (#894)
This commit is contained in:
parent
17ca30c023
commit
b2c301b1fe
|
@ -544,6 +544,27 @@ version = "1.6.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
|
||||
dependencies = [
|
||||
"errno-dragonfly",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "errno-dragonfly"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "event-listener"
|
||||
version = "2.5.2"
|
||||
|
@ -910,6 +931,12 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "io-lifetimes"
|
||||
version = "0.7.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.3"
|
||||
|
@ -948,9 +975,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.124"
|
||||
version = "0.2.137"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50"
|
||||
checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
|
@ -962,6 +989,12 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.0.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.7"
|
||||
|
@ -1289,15 +1322,15 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "procfs"
|
||||
version = "0.12.0"
|
||||
version = "0.14.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0941606b9934e2d98a3677759a971756eb821f75764d0e0d26946d08e74d9104"
|
||||
checksum = "2dfb6451c91904606a1abe93e83a8ec851f45827fa84273f256ade45dc095818"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"byteorder",
|
||||
"hex",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"rustix",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1388,6 +1421,20 @@ version = "0.1.21"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.35.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"io-lifetimes",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.10"
|
||||
|
@ -1558,9 +1605,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "sysctl"
|
||||
version = "0.4.6"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "225e483f02d0ad107168dc57381a8a40c3aeea6abe47f37506931f861643cfa8"
|
||||
checksum = "f99d037b2bef227ab8963f4b0acc33ecbb1f9a2e7365add7789372b387ec19e1"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"byteorder",
|
||||
|
@ -1620,18 +1667,18 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.30"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
|
||||
checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.30"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
|
||||
checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -97,7 +97,7 @@ libc = "0.2.124"
|
|||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
heim = { version = "0.1.0-rc.1", features = ["cpu", "disk", "net", "sensors"] }
|
||||
procfs = { version = "0.12.0", default-features = false }
|
||||
procfs = { version = "0.14.1", default-features = false }
|
||||
smol = "1.2.5"
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
|
@ -110,7 +110,7 @@ winapi = "0.3.9"
|
|||
|
||||
[target.'cfg(target_os = "freebsd")'.dependencies]
|
||||
serde_json = { version = "1.0.82" }
|
||||
sysctl = { version = "0.4.6", optional = true }
|
||||
sysctl = { version = "0.5.2", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "2.0.4"
|
||||
|
|
|
@ -1256,7 +1256,7 @@ impl App {
|
|||
'k' => self.on_up_key(),
|
||||
'j' => self.on_down_key(),
|
||||
'f' => {
|
||||
self.frozen_state.toggle(&self.data_collection);
|
||||
self.frozen_state.toggle(&self.data_collection); // TODO: Unthawing should force a full data refresh and redraw immediately.
|
||||
}
|
||||
'c' => {
|
||||
if let BottomWidgetType::Proc = self.current_widget.widget_type {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
//! Process data collection for Linux.
|
||||
|
||||
use std::collections::hash_map::Entry;
|
||||
|
||||
use fxhash::{FxHashMap, FxHashSet};
|
||||
use procfs::process::{Process, Stat};
|
||||
use sysinfo::ProcessStatus;
|
||||
|
@ -15,23 +13,11 @@ use crate::Pid;
|
|||
/// If it's equal or greater, then we instead refer to the command for the name.
|
||||
const MAX_STAT_NAME_LEN: usize = 15;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct PrevProcDetails {
|
||||
pub total_read_bytes: u64,
|
||||
pub total_write_bytes: u64,
|
||||
pub cpu_time: u64,
|
||||
pub process: Process,
|
||||
}
|
||||
|
||||
impl PrevProcDetails {
|
||||
fn new(pid: Pid) -> error::Result<Self> {
|
||||
Ok(Self {
|
||||
total_read_bytes: 0,
|
||||
total_write_bytes: 0,
|
||||
cpu_time: 0,
|
||||
process: Process::new(pid)?,
|
||||
})
|
||||
}
|
||||
total_read_bytes: u64,
|
||||
total_write_bytes: u64,
|
||||
cpu_time: u64,
|
||||
}
|
||||
|
||||
fn calculate_idle_values(line: String) -> Point {
|
||||
|
@ -113,14 +99,11 @@ fn get_linux_cpu_usage(
|
|||
}
|
||||
|
||||
fn read_proc(
|
||||
prev_proc: &PrevProcDetails, stat: &Stat, cpu_usage: f64, cpu_fraction: f64,
|
||||
prev_proc: &PrevProcDetails, process: &Process, cpu_usage: f64, cpu_fraction: f64,
|
||||
use_current_cpu_total: bool, time_difference_in_secs: u64, mem_total_kb: u64,
|
||||
user_table: &mut UserTable,
|
||||
) -> error::Result<(ProcessHarvest, u64)> {
|
||||
use std::convert::TryFrom;
|
||||
|
||||
let process = &prev_proc.process;
|
||||
|
||||
let stat = process.stat()?;
|
||||
let (command, name) = {
|
||||
let truncated_name = stat.comm.as_str();
|
||||
if let Ok(cmdline) = process.cmdline() {
|
||||
|
@ -157,14 +140,14 @@ fn read_proc(
|
|||
process_state_char,
|
||||
);
|
||||
let (cpu_usage_percent, new_process_times) = get_linux_cpu_usage(
|
||||
stat,
|
||||
&stat,
|
||||
cpu_usage,
|
||||
cpu_fraction,
|
||||
prev_proc.cpu_time,
|
||||
use_current_cpu_total,
|
||||
);
|
||||
let parent_pid = Some(stat.ppid);
|
||||
let mem_usage_bytes = u64::try_from(stat.rss_bytes()?).unwrap_or(0);
|
||||
let mem_usage_bytes = stat.rss_bytes()?;
|
||||
let mem_usage_kb = mem_usage_bytes / 1024;
|
||||
let mem_usage_percent = mem_usage_kb as f64 / mem_total_kb as f64 * 100.0;
|
||||
|
||||
|
@ -198,7 +181,7 @@ fn read_proc(
|
|||
(0, 0, 0, 0)
|
||||
};
|
||||
|
||||
let uid = process.owner;
|
||||
let uid = process.uid()?;
|
||||
|
||||
Ok((
|
||||
ProcessHarvest {
|
||||
|
@ -238,49 +221,27 @@ pub fn get_process_data(
|
|||
.filter_map(|dir| {
|
||||
if let Ok(dir) = dir {
|
||||
if let Ok(pid) = dir.file_name().to_string_lossy().trim().parse::<Pid>() {
|
||||
let mut fresh = false;
|
||||
if let Entry::Vacant(entry) = pid_mapping.entry(pid) {
|
||||
if let Ok(ppd) = PrevProcDetails::new(pid) {
|
||||
entry.insert(ppd);
|
||||
fresh = true;
|
||||
} else {
|
||||
// Bail early.
|
||||
return None;
|
||||
}
|
||||
let Ok(process) = Process::new(pid) else {
|
||||
return None;
|
||||
};
|
||||
let prev_proc_details = pid_mapping.entry(pid).or_default();
|
||||
|
||||
if let Some(prev_proc_details) = pid_mapping.get_mut(&pid) {
|
||||
let stat;
|
||||
let stat_live;
|
||||
if fresh {
|
||||
stat = &prev_proc_details.process.stat;
|
||||
} else if let Ok(s) = prev_proc_details.process.stat() {
|
||||
stat_live = s;
|
||||
stat = &stat_live;
|
||||
} else {
|
||||
// Bail early.
|
||||
return None;
|
||||
}
|
||||
if let Ok((process_harvest, new_process_times)) = read_proc(
|
||||
prev_proc_details,
|
||||
&process,
|
||||
cpu_usage,
|
||||
cpu_fraction,
|
||||
use_current_cpu_total,
|
||||
time_difference_in_secs,
|
||||
mem_total_kb,
|
||||
user_table,
|
||||
) {
|
||||
prev_proc_details.cpu_time = new_process_times;
|
||||
prev_proc_details.total_read_bytes = process_harvest.total_read_bytes;
|
||||
prev_proc_details.total_write_bytes = process_harvest.total_write_bytes;
|
||||
|
||||
if let Ok((process_harvest, new_process_times)) = read_proc(
|
||||
prev_proc_details,
|
||||
stat,
|
||||
cpu_usage,
|
||||
cpu_fraction,
|
||||
use_current_cpu_total,
|
||||
time_difference_in_secs,
|
||||
mem_total_kb,
|
||||
user_table,
|
||||
) {
|
||||
prev_proc_details.cpu_time = new_process_times;
|
||||
prev_proc_details.total_read_bytes =
|
||||
process_harvest.total_read_bytes;
|
||||
prev_proc_details.total_write_bytes =
|
||||
process_harvest.total_write_bytes;
|
||||
|
||||
pids_to_clear.remove(&pid);
|
||||
return Some(process_harvest);
|
||||
}
|
||||
pids_to_clear.remove(&pid);
|
||||
return Some(process_harvest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue