deps: bump sysinfo to 0.35 (#1738)

* deps: bump sysinfo, fix cpu

* fix things for at least Linux

* bump some other stuff

* more things

* windows

* more stuff

* display

* ahhhh it's not stable

* redundant f32

* fix freebsd
This commit is contained in:
Clement Tsang 2025-06-09 03:00:09 -04:00 committed by GitHub
parent 7728c76419
commit 1769ee0987
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 106 additions and 136 deletions

106
Cargo.lock generated
View File

@ -192,7 +192,7 @@ dependencies = [
"unicode-ellipsis",
"unicode-segmentation",
"unicode-width 0.2.0",
"windows 0.61.1",
"windows",
]
[[package]]
@ -382,31 +382,6 @@ version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "crossbeam-deque"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]]
name = "crossterm"
version = "0.28.1"
@ -992,6 +967,25 @@ dependencies = [
"libloading",
]
[[package]]
name = "objc2-core-foundation"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c10c2894a6fed806ade6027bcd50662746363a9589d3ec9d9bef30a4e4bc166"
dependencies = [
"bitflags 2.9.1",
]
[[package]]
name = "objc2-io-kit"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71c1c64d6120e51cd86033f67176b1cb66780c2efe34dec55176f77befd93c0a"
dependencies = [
"libc",
"objc2-core-foundation",
]
[[package]]
name = "object"
version = "0.36.7"
@ -1172,26 +1166,6 @@ dependencies = [
"unicode-width 0.2.0",
]
[[package]]
name = "rayon"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
]
[[package]]
name = "redox_syscall"
version = "0.5.12"
@ -1567,17 +1541,16 @@ dependencies = [
[[package]]
name = "sysinfo"
version = "0.30.13"
version = "0.35.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a5b4ddaee55fb2bea2bf0e5000747e5f5c0de765e5a5ff87f4cd106439f4bb3"
checksum = "3c3ffa3e4ff2b324a57f7aeb3c349656c7b127c3c189520251a648102a92496e"
dependencies = [
"cfg-if",
"core-foundation-sys",
"libc",
"memchr",
"ntapi",
"once_cell",
"rayon",
"windows 0.52.0",
"objc2-core-foundation",
"objc2-io-kit",
"windows",
]
[[package]]
@ -1849,16 +1822,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
dependencies = [
"windows-core 0.52.0",
"windows-targets 0.52.6",
]
[[package]]
name = "windows"
version = "0.61.1"
@ -1866,7 +1829,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5ee8f3d025738cb02bad7868bbb5f8a6327501e870bf51f1b455b0a2454a419"
dependencies = [
"windows-collections",
"windows-core 0.61.2",
"windows-core",
"windows-future",
"windows-link",
"windows-numerics",
@ -1878,16 +1841,7 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8"
dependencies = [
"windows-core 0.61.2",
]
[[package]]
name = "windows-core"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [
"windows-targets 0.52.6",
"windows-core",
]
[[package]]
@ -1909,7 +1863,7 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
dependencies = [
"windows-core 0.61.2",
"windows-core",
"windows-link",
"windows-threading",
]
@ -1948,7 +1902,7 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1"
dependencies = [
"windows-core 0.61.2",
"windows-core",
"windows-link",
]

View File

@ -89,7 +89,7 @@ nvml-wrapper = { version = "0.11.0", optional = true, features = ["legacy-functi
regex = "1.11.1"
serde = { version = "1.0.219", features = ["derive"] }
starship-battery = { version = "0.10.1", optional = true }
sysinfo = "=0.30.13"
sysinfo = "=0.35.2"
timeless = "0.0.14-alpha"
toml_edit = { version = "0.22.26", features = ["serde"] }
tui = { version = "0.29.0", package = "ratatui", features = ["unstable-rendered-line-info"] }

View File

@ -92,7 +92,7 @@ impl TimeSeriesData {
}
for (curr, new_data) in self.cpu.iter_mut().zip(cpu.iter()) {
curr.push(new_data.cpu_usage);
curr.push(new_data.usage.into());
}
} else {
for c in &mut self.cpu {

View File

@ -63,7 +63,7 @@ impl Painter {
.label_style(style)
.inner_label(inner)
.start_label(outer)
.ratio(ratio),
.ratio(ratio.into()),
avg_loc,
);
@ -124,7 +124,7 @@ impl Painter {
.label_style(style)
.inner_label(inner_label)
.start_label(start_label)
.ratio(ratio)
.ratio(ratio.into())
.hide_parts(hide_parts),
*row,
);
@ -144,7 +144,7 @@ impl Painter {
}
#[inline]
fn cpu_info(&self, data: &CpuData) -> (String, String, f64, tui::style::Style) {
fn cpu_info(&self, data: &CpuData) -> (String, String, f32, tui::style::Style) {
let (outer, style) = match data.data_type {
CpuDataType::Avg => ("AVG".to_string(), self.styles.avg_cpu_colour),
CpuDataType::Cpu(index) => (
@ -153,8 +153,8 @@ impl Painter {
),
};
let inner = format!("{:>3.0}%", data.cpu_usage.round());
let ratio = data.cpu_usage / 100.0;
let inner = format!("{:>3.0}%", data.usage.round());
let ratio = data.usage / 100.0;
(outer, inner, ratio, style)
}

View File

@ -134,7 +134,7 @@ impl Default for SysinfoSource {
use sysinfo::*;
Self {
system: System::new_with_specifics(RefreshKind::new()),
system: System::new(),
network: Networks::new(),
#[cfg(not(target_os = "linux"))]
temps: Components::new(),
@ -267,11 +267,9 @@ impl DataCollector {
fn refresh_sysinfo_data(&mut self) {
// Refresh the list of objects once every minute. If it's too frequent it can
// cause segfaults.
const LIST_REFRESH_TIME: Duration = Duration::from_secs(60);
let refresh_start = Instant::now();
if self.widgets_to_harvest.use_cpu || self.widgets_to_harvest.use_proc {
self.sys.system.refresh_cpu();
self.sys.system.refresh_cpu_all();
}
if self.widgets_to_harvest.use_mem || self.widgets_to_harvest.use_proc {
@ -279,10 +277,7 @@ impl DataCollector {
}
if self.widgets_to_harvest.use_net {
if refresh_start.duration_since(self.last_collection_time) > LIST_REFRESH_TIME {
self.sys.network.refresh_list();
}
self.sys.network.refresh();
self.sys.network.refresh(true);
}
// sysinfo is used on non-Linux systems for the following:
@ -291,8 +286,13 @@ impl DataCollector {
// - Temperatures and temperature components list.
#[cfg(not(target_os = "linux"))]
{
const LIST_REFRESH_TIME: Duration = Duration::from_secs(60);
let refresh_start = Instant::now();
if self.widgets_to_harvest.use_proc {
self.sys.system.refresh_processes_specifics(
sysinfo::ProcessesToUpdate::All,
true,
sysinfo::ProcessRefreshKind::everything()
.without_environ()
.without_cwd()
@ -302,24 +302,30 @@ impl DataCollector {
// For Windows, sysinfo also handles the users list.
#[cfg(target_os = "windows")]
if refresh_start.duration_since(self.last_collection_time) > LIST_REFRESH_TIME {
self.sys.users.refresh_list();
self.sys.users.refresh();
}
}
if self.widgets_to_harvest.use_temp {
if refresh_start.duration_since(self.last_collection_time) > LIST_REFRESH_TIME {
self.sys.temps.refresh_list();
self.sys.temps.refresh(true);
}
self.sys.temps.refresh();
}
}
#[cfg(target_os = "windows")]
if self.widgets_to_harvest.use_disk {
if refresh_start.duration_since(self.last_collection_time) > LIST_REFRESH_TIME {
self.sys.disks.refresh_list();
for component in self.sys.temps.iter_mut() {
component.refresh();
}
}
#[cfg(target_os = "windows")]
if self.widgets_to_harvest.use_disk {
if refresh_start.duration_since(self.last_collection_time) > LIST_REFRESH_TIME {
self.sys.disks.refresh(true);
}
for disk in self.sys.disks.iter_mut() {
disk.refresh();
}
}
self.sys.disks.refresh();
}
}

View File

@ -14,7 +14,7 @@ pub enum CpuDataType {
#[derive(Debug, Clone)]
pub struct CpuData {
pub data_type: CpuDataType,
pub cpu_usage: f64,
pub usage: f32,
}
pub type CpuHarvest = Vec<CpuData>;

View File

@ -10,11 +10,9 @@ pub fn get_cpu_data_list(sys: &System, show_average_cpu: bool) -> CollectionResu
let mut cpus = vec![];
if show_average_cpu {
let cpu = sys.global_cpu_info();
cpus.push(CpuData {
data_type: CpuDataType::Avg,
cpu_usage: cpu.cpu_usage() as f64,
usage: sys.global_cpu_usage(),
})
}
@ -24,7 +22,7 @@ pub fn get_cpu_data_list(sys: &System, show_average_cpu: bool) -> CollectionResu
.enumerate()
.map(|(i, cpu)| CpuData {
data_type: CpuDataType::Cpu(i),
cpu_usage: cpu.cpu_usage() as f64,
usage: cpu.cpu_usage(),
})
.collect::<Vec<_>>(),
);

View File

@ -19,7 +19,7 @@ struct ProcessRow {
#[serde(deserialize_with = "pid")]
pid: i32,
#[serde(deserialize_with = "percent_cpu")]
percent_cpu: f64,
percent_cpu: f32,
}
pub(crate) struct FreeBSDProcessExt;
@ -30,7 +30,7 @@ impl UnixProcessExt for FreeBSDProcessExt {
true
}
fn backup_proc_cpu(pids: &[Pid]) -> io::Result<HashMap<Pid, f64>> {
fn backup_proc_cpu(pids: &[Pid]) -> io::Result<HashMap<Pid, f32>> {
if pids.is_empty() {
return Ok(HashMap::new());
}
@ -60,7 +60,7 @@ where
s.parse().map_err(serde::de::Error::custom)
}
fn percent_cpu<'de, D>(deserializer: D) -> Result<f64, D::Error>
fn percent_cpu<'de, D>(deserializer: D) -> Result<f32, D::Error>
where
D: Deserializer<'de>,
{

View File

@ -18,7 +18,7 @@ impl UnixProcessExt for MacOSProcessExt {
true
}
fn backup_proc_cpu(pids: &[Pid]) -> io::Result<HashMap<Pid, f64>> {
fn backup_proc_cpu(pids: &[Pid]) -> io::Result<HashMap<Pid, f32>> {
let output = Command::new("ps")
.args(["-o", "pid=,pcpu=", "-p"])
.arg(

View File

@ -3,6 +3,7 @@
use std::{io, time::Duration};
use hashbrown::HashMap;
use itertools::Itertools;
use sysinfo::{ProcessStatus, System};
use super::{ProcessHarvest, process_status_str};
@ -15,14 +16,14 @@ pub(crate) trait UnixProcessExt {
) -> CollectionResult<Vec<ProcessHarvest>> {
let mut process_vector: Vec<ProcessHarvest> = Vec::new();
let process_hashmap = sys.processes();
let cpu_usage = sys.global_cpu_info().cpu_usage() as f64 / 100.0;
let num_processors = sys.cpus().len() as f64;
let cpu_usage = sys.global_cpu_usage() / 100.0;
let num_processors = sys.cpus().len();
for process_val in process_hashmap.values() {
let name = if process_val.name().is_empty() {
let process_cmd = process_val.cmd();
if process_cmd.len() > 1 {
process_cmd[0].clone()
if let Some(name) = process_cmd.first() {
name.to_string_lossy().to_string()
} else {
process_val
.exe()
@ -32,30 +33,34 @@ pub(crate) trait UnixProcessExt {
.unwrap_or(String::new())
}
} else {
process_val.name().to_string()
process_val.name().to_string_lossy().to_string()
};
let command = {
let command = process_val.cmd().join(" ");
let command = process_val
.cmd()
.iter()
.map(|s| s.to_string_lossy())
.join(" ");
if command.is_empty() {
name.to_string()
name.clone()
} else {
command
}
};
let pcu = {
let usage = process_val.cpu_usage() as f64;
if unnormalized_cpu || num_processors == 0.0 {
let usage = process_val.cpu_usage();
if unnormalized_cpu || num_processors == 0 {
usage
} else {
usage / num_processors
usage / num_processors as f32
}
};
let process_cpu_usage = if use_current_cpu_total && cpu_usage > 0.0 {
pcu / cpu_usage
} else {
pcu
} as f32;
};
let disk_usage = process_val.disk_usage();
let process_state = {
@ -119,11 +124,11 @@ pub(crate) trait UnixProcessExt {
let cpu_usages = Self::backup_proc_cpu(&cpu_usage_unknown_pids)?;
for process in &mut process_vector {
if cpu_usages.contains_key(&process.pid) {
process.cpu_usage_percent = if unnormalized_cpu || num_processors == 0.0 {
process.cpu_usage_percent = if unnormalized_cpu || num_processors == 0 {
*cpu_usages.get(&process.pid).unwrap()
} else {
*cpu_usages.get(&process.pid).unwrap() / num_processors
} as f32;
*cpu_usages.get(&process.pid).unwrap() / num_processors as f32
};
}
}
}
@ -136,7 +141,7 @@ pub(crate) trait UnixProcessExt {
false
}
fn backup_proc_cpu(_pids: &[Pid]) -> io::Result<HashMap<Pid, f64>> {
fn backup_proc_cpu(_pids: &[Pid]) -> io::Result<HashMap<Pid, f32>> {
Ok(HashMap::default())
}

View File

@ -2,6 +2,8 @@
use std::time::Duration;
use itertools::Itertools;
use super::{ProcessHarvest, process_status_str};
use crate::collection::{DataCollector, error::CollectionResult};
@ -17,14 +19,14 @@ pub fn sysinfo_process_data(
let mut process_vector: Vec<ProcessHarvest> = Vec::new();
let process_hashmap = sys.processes();
let cpu_usage = sys.global_cpu_info().cpu_usage() as f64 / 100.0;
let cpu_usage = sys.global_cpu_usage() / 100.0;
let num_processors = sys.cpus().len();
for process_val in process_hashmap.values() {
let name = if process_val.name().is_empty() {
let process_cmd = process_val.cmd();
if process_cmd.len() > 1 {
process_cmd[0].clone()
process_cmd[0].to_string_lossy().to_string()
} else {
process_val
.exe()
@ -34,30 +36,35 @@ pub fn sysinfo_process_data(
.unwrap_or(String::new())
}
} else {
process_val.name().to_string()
process_val.name().to_string_lossy().to_string()
};
let command = {
let command = process_val.cmd().join(" ");
let command = process_val
.cmd()
.iter()
.map(|s| s.to_string_lossy())
.join(" ");
if command.is_empty() {
name.to_string()
name.clone()
} else {
command
}
};
let pcu = {
let usage = process_val.cpu_usage() as f64;
let usage = process_val.cpu_usage();
if unnormalized_cpu || num_processors == 0 {
usage
} else {
usage / (num_processors as f64)
usage / num_processors as f32
}
};
let process_cpu_usage = if use_current_cpu_total && cpu_usage > 0.0 {
pcu / cpu_usage
} else {
pcu
} as f32;
};
let disk_usage = process_val.disk_usage();
let process_state = (process_status_str(process_val.status()), 'R');

View File

@ -16,7 +16,7 @@ pub fn get_temperature_data(
if Filter::optional_should_keep(filter, &name) {
temperatures.push(TempSensorData {
name,
temperature: Some(component.temperature()),
temperature: component.temperature(),
});
}
}

View File

@ -32,14 +32,14 @@ impl ColumnHeader for CpuWidgetColumn {
pub enum CpuWidgetTableData {
All,
Entry { data_type: CpuDataType, usage: f64 },
Entry { data_type: CpuDataType, usage: f32 },
}
impl CpuWidgetTableData {
pub fn from_cpu_data(data: &CpuData) -> CpuWidgetTableData {
CpuWidgetTableData::Entry {
data_type: data.data_type,
usage: data.cpu_usage,
usage: data.usage,
}
}
}