Bump sysinfo from 0.29 to 0.30 (#11484)

# Description
Bumps `sysinfo` to 0.30.

* Changelog
 https://github.com/GuillaumeGomez/sysinfo/blob/master/CHANGELOG.md#0304

# User-Facing Changes
N/A
This commit is contained in:
nibon7 2024-01-05 19:31:29 +08:00 committed by GitHub
parent ad95e4cc27
commit 7e26b4fcc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 100 additions and 90 deletions

24
Cargo.lock generated
View File

@ -2697,7 +2697,7 @@ dependencies = [
"percent-encoding", "percent-encoding",
"reedline", "reedline",
"rstest", "rstest",
"sysinfo", "sysinfo 0.30.4",
"unicode-segmentation", "unicode-segmentation",
"uuid", "uuid",
"which 5.0.0", "which 5.0.0",
@ -2876,7 +2876,7 @@ dependencies = [
"serde_urlencoded", "serde_urlencoded",
"serde_yaml", "serde_yaml",
"sha2", "sha2",
"sysinfo", "sysinfo 0.30.4",
"tabled", "tabled",
"terminal_size 0.3.0", "terminal_size 0.3.0",
"titlecase", "titlecase",
@ -3060,7 +3060,7 @@ dependencies = [
"ntapi", "ntapi",
"once_cell", "once_cell",
"procfs", "procfs",
"sysinfo", "sysinfo 0.30.4",
"windows 0.52.0", "windows 0.52.0",
] ]
@ -4089,7 +4089,7 @@ dependencies = [
"polars-error", "polars-error",
"rayon", "rayon",
"smartstring", "smartstring",
"sysinfo", "sysinfo 0.29.11",
"version_check", "version_check",
] ]
@ -5280,10 +5280,24 @@ dependencies = [
"libc", "libc",
"ntapi", "ntapi",
"once_cell", "once_cell",
"rayon",
"winapi", "winapi",
] ]
[[package]]
name = "sysinfo"
version = "0.30.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "717570a2533606f81f8cfac02a1915a620e725ffb78f6fc5e259769a4d747407"
dependencies = [
"cfg-if",
"core-foundation-sys",
"libc",
"ntapi",
"once_cell",
"rayon",
"windows 0.52.0",
]
[[package]] [[package]]
name = "tabled" name = "tabled"
version = "0.14.0" version = "0.14.0"

View File

@ -37,7 +37,7 @@ miette = { version = "5.10", features = ["fancy-no-backtrace"] }
once_cell = "1.18" once_cell = "1.18"
percent-encoding = "2" percent-encoding = "2"
pathdiff = "0.2" pathdiff = "0.2"
sysinfo = "0.29" sysinfo = "0.30"
unicode-segmentation = "1.10" unicode-segmentation = "1.10"
uuid = { version = "1.6.0", features = ["v4"] } uuid = { version = "1.6.0", features = ["v4"] }
which = "5.0.0" which = "5.0.0"

View File

@ -32,7 +32,7 @@ use std::{
sync::atomic::Ordering, sync::atomic::Ordering,
time::Instant, time::Instant,
}; };
use sysinfo::SystemExt; use sysinfo::System;
// According to Daniel Imms @Tyriar, we need to do these this way: // According to Daniel Imms @Tyriar, we need to do these this way:
// <133 A><prompt><133 B><command><133 C><command output> // <133 A><prompt><133 B><command><133 C><command output>
@ -135,17 +135,6 @@ pub fn evaluate_repl(
use_color, use_color,
); );
start_time = std::time::Instant::now();
let sys = sysinfo::System::new();
perf(
"get sysinfo",
start_time,
file!(),
line!(),
column!(),
use_color,
);
if let Some(s) = prerun_command { if let Some(s) = prerun_command {
eval_source( eval_source(
engine_state, engine_state,
@ -428,7 +417,7 @@ pub fn evaluate_repl(
match input { match input {
Ok(Signal::Success(s)) => { Ok(Signal::Success(s)) => {
let hostname = sys.host_name(); let hostname = System::host_name();
let history_supports_meta = let history_supports_meta =
matches!(config.history_file_format, HistoryFileFormat::Sqlite); matches!(config.history_file_format, HistoryFileFormat::Sqlite);
if history_supports_meta && !s.is_empty() && line_editor.has_last_command_context() if history_supports_meta && !s.is_empty() && line_editor.has_last_command_context()

View File

@ -80,7 +80,7 @@ serde_json = "1.0"
serde_urlencoded = "0.7" serde_urlencoded = "0.7"
serde_yaml = "0.9" serde_yaml = "0.9"
sha2 = "0.10" sha2 = "0.10"
sysinfo = "0.29" sysinfo = "0.30"
tabled = { version = "0.14.0", features = ["color"], default-features = false } tabled = { version = "0.14.0", features = ["color"], default-features = false }
terminal_size = "0.3" terminal_size = "0.3"
titlecase = "2.0" titlecase = "2.0"

View File

@ -4,7 +4,7 @@ use nu_protocol::{
record, Category, Example, IntoPipelineData, LazyRecord, PipelineData, Record, ShellError, record, Category, Example, IntoPipelineData, LazyRecord, PipelineData, Record, ShellError,
Signature, Span, Type, Value, Signature, Span, Type, Value,
}; };
use sysinfo::{Pid, PidExt, ProcessExt, ProcessRefreshKind, RefreshKind, System, SystemExt}; use sysinfo::{MemoryRefreshKind, Pid, ProcessRefreshKind, RefreshKind, System};
const ENV_PATH_SEPARATOR_CHAR: char = { const ENV_PATH_SEPARATOR_CHAR: char = {
#[cfg(target_family = "windows")] #[cfg(target_family = "windows")]
{ {
@ -98,8 +98,9 @@ impl LazySystemInfoRecord {
} }
"system" => { "system" => {
// only get information requested // only get information requested
let system_opt = let system_opt = SystemOpt::from((system_option, || {
SystemOpt::from((system_option, || RefreshKind::new().with_memory())); RefreshKind::new().with_memory(MemoryRefreshKind::everything())
}));
let system = system_opt.get_system(); let system = system_opt.get_system();
@ -135,53 +136,66 @@ impl LazySystemInfoRecord {
"virtual_memory" => Value::filesize(p.virtual_memory() as i64, self.span), "virtual_memory" => Value::filesize(p.virtual_memory() as i64, self.span),
"status" => Value::string(p.status().to_string(), self.span), "status" => Value::string(p.status().to_string(), self.span),
"root" => { "root" => {
if let Some(filename) = p.exe().parent() { if let Some(path) = p.exe().and_then(|p| p.parent()) {
Value::string(filename.to_string_lossy().to_string(), self.span) Value::string(path.to_string_lossy().to_string(), self.span)
} else { } else {
Value::nothing(self.span) Value::nothing(self.span)
} }
}, },
"cwd" => Value::string(p.cwd().to_string_lossy().to_string(), self.span), "cwd" => {
"exe_path" => Value::string(p.exe().to_string_lossy().to_string(), self.span), if let Some(path) = p.cwd() {
Value::string(path.to_string_lossy().to_string(), self.span)
}else{
Value::nothing(self.span)
}
},
"exe_path" => {
if let Some(path)= p.exe() {
Value::string(path.to_string_lossy().to_string(), self.span)
}else{
Value::nothing(self.span)
}
},
"command" => Value::string(p.cmd().join(" "), self.span), "command" => Value::string(p.cmd().join(" "), self.span),
"name" => Value::string(p.name().to_string(), self.span), "name" => Value::string(p.name().to_string(), self.span),
"environment" => { "environment" => {
let mut env_rec = Record::new(); let mut env_rec = Record::new();
for val in p.environ() { for val in p.environ() {
if let Some((key, value)) = val.split_once('=') { if let Some((key, value)) = val.split_once('=') {
let is_env_var_a_list = { let is_env_var_a_list = {
{
#[cfg(target_family = "windows")]
{ {
#[cfg(target_family = "windows")] key == "Path" || key == "PATHEXT" || key == "PSMODULEPATH" || key == "PSModulePath"
{ }
key == "Path" || key == "PATHEXT" || key == "PSMODULEPATH" || key == "PSModulePath" #[cfg(not(target_family = "windows"))]
} {
#[cfg(not(target_family = "windows"))] key == "PATH" || key == "DYLD_FALLBACK_LIBRARY_PATH"
{
key == "PATH" || key == "DYLD_FALLBACK_LIBRARY_PATH"
}
} }
};
if is_env_var_a_list {
let items = value.split(ENV_PATH_SEPARATOR_CHAR).map(|r| Value::string(r.to_string(), self.span)).collect::<Vec<_>>();
env_rec.push(key.to_string(), Value::list(items, self.span));
} else if key == "LS_COLORS" { // LS_COLORS is a special case, it's a colon separated list of key=value pairs
let items = value.split(':').map(|r| Value::string(r.to_string(), self.span)).collect::<Vec<_>>();
env_rec.push(key.to_string(), Value::list(items, self.span));
} else {
env_rec.push(key.to_string(), Value::string(value.to_string(), self.span));
} }
};
if is_env_var_a_list {
let items = value.split(ENV_PATH_SEPARATOR_CHAR).map(|r| Value::string(r.to_string(), self.span)).collect::<Vec<_>>();
env_rec.push(key.to_string(), Value::list(items, self.span));
} else if key == "LS_COLORS" { // LS_COLORS is a special case, it's a colon separated list of key=value pairs
let items = value.split(':').map(|r| Value::string(r.to_string(), self.span)).collect::<Vec<_>>();
env_rec.push(key.to_string(), Value::list(items, self.span));
} else {
env_rec.push(key.to_string(), Value::string(value.to_string(), self.span));
} }
} }
Value::record(env_rec, self.span) }
}, Value::record(env_rec, self.span)
},
}, },
self.span, self.span,
)) ))
} else { } else {
// If we can't get the process information, just return the system information // If we can't get the process information, just return the system information
// only get information requested // only get information requested
let system_opt = let system_opt = SystemOpt::from((system_option, || {
SystemOpt::from((system_option, || RefreshKind::new().with_memory())); RefreshKind::new().with_memory(MemoryRefreshKind::everything())
}));
let system = system_opt.get_system(); let system = system_opt.get_system();
Ok(Value::record( Ok(Value::record(
@ -228,7 +242,7 @@ impl<'a> LazyRecord<'a> for LazySystemInfoRecord {
.without_disk_usage() .without_disk_usage()
.without_user(), .without_user(),
) )
.with_memory(); .with_memory(MemoryRefreshKind::everything());
// only get information requested // only get information requested
let system = System::new_with_specifics(rk); let system = System::new_with_specifics(rk);

View File

@ -8,7 +8,7 @@ use nu_protocol::{
}; };
use std::time::{Duration, UNIX_EPOCH}; use std::time::{Duration, UNIX_EPOCH};
use sysinfo::{ use sysinfo::{
ComponentExt, CpuExt, CpuRefreshKind, DiskExt, NetworkExt, System, SystemExt, UserExt, Components, CpuRefreshKind, Disks, Networks, System, Users, MINIMUM_CPU_UPDATE_INTERVAL,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -106,14 +106,12 @@ pub fn trim_cstyle_null(s: String) -> String {
} }
pub fn disks(span: Span) -> Value { pub fn disks(span: Span) -> Value {
let mut sys = System::new(); let disks = Disks::new_with_refreshed_list();
sys.refresh_disks();
sys.refresh_disks_list();
let mut output = vec![]; let mut output = vec![];
for disk in sys.disks() { for disk in disks.list() {
let device = trim_cstyle_null(disk.name().to_string_lossy().to_string()); let device = trim_cstyle_null(disk.name().to_string_lossy().to_string());
let typ = trim_cstyle_null(String::from_utf8_lossy(disk.file_system()).to_string()); let typ = trim_cstyle_null(disk.file_system().to_string_lossy().to_string());
let record = record! { let record = record! {
"device" => Value::string(device, span), "device" => Value::string(device, span),
@ -131,12 +129,10 @@ pub fn disks(span: Span) -> Value {
} }
pub fn net(span: Span) -> Value { pub fn net(span: Span) -> Value {
let mut sys = System::new(); let networks = Networks::new_with_refreshed_list();
sys.refresh_networks();
sys.refresh_networks_list();
let mut output = vec![]; let mut output = vec![];
for (iface, data) in sys.networks() { for (iface, data) in networks.list() {
let record = record! { let record = record! {
"name" => Value::string(trim_cstyle_null(iface.to_string()), span), "name" => Value::string(trim_cstyle_null(iface.to_string()), span),
"sent" => Value::filesize(data.total_transmitted() as i64, span), "sent" => Value::filesize(data.total_transmitted() as i64, span),
@ -154,7 +150,7 @@ pub fn cpu(span: Span) -> Value {
// We must refresh the CPU twice a while apart to get valid usage data. // We must refresh the CPU twice a while apart to get valid usage data.
// In theory we could just sleep MINIMUM_CPU_UPDATE_INTERVAL, but I've noticed that // In theory we could just sleep MINIMUM_CPU_UPDATE_INTERVAL, but I've noticed that
// that gives poor results (error of ~5%). Decided to wait 2x that long, somewhat arbitrarily // that gives poor results (error of ~5%). Decided to wait 2x that long, somewhat arbitrarily
std::thread::sleep(System::MINIMUM_CPU_UPDATE_INTERVAL * 2); std::thread::sleep(MINIMUM_CPU_UPDATE_INTERVAL * 2);
sys.refresh_cpu_specifics(CpuRefreshKind::new().with_cpu_usage()); sys.refresh_cpu_specifics(CpuRefreshKind::new().with_cpu_usage());
let mut output = vec![]; let mut output = vec![];
@ -163,7 +159,7 @@ pub fn cpu(span: Span) -> Value {
// Round to 1DP (chosen somewhat arbitrarily) so people aren't misled by high-precision floats. // Round to 1DP (chosen somewhat arbitrarily) so people aren't misled by high-precision floats.
let rounded_usage = (cpu.cpu_usage() * 10.0).round() / 10.0; let rounded_usage = (cpu.cpu_usage() * 10.0).round() / 10.0;
let load_avg = sys.load_average(); let load_avg = System::load_average();
let load_avg = trim_cstyle_null(format!( let load_avg = trim_cstyle_null(format!(
"{:.2}, {:.2}, {:.2}", "{:.2}, {:.2}, {:.2}",
load_avg.one, load_avg.five, load_avg.fifteen load_avg.one, load_avg.five, load_avg.fifteen
@ -211,42 +207,39 @@ pub fn mem(span: Span) -> Value {
} }
pub fn host(span: Span) -> Value { pub fn host(span: Span) -> Value {
let mut sys = System::new();
sys.refresh_users_list();
let mut record = Record::new(); let mut record = Record::new();
if let Some(name) = sys.name() { if let Some(name) = System::name() {
record.push("name", Value::string(trim_cstyle_null(name), span)); record.push("name", Value::string(trim_cstyle_null(name), span));
} }
if let Some(version) = sys.os_version() { if let Some(version) = System::os_version() {
record.push("os_version", Value::string(trim_cstyle_null(version), span)); record.push("os_version", Value::string(trim_cstyle_null(version), span));
} }
if let Some(long_version) = sys.long_os_version() { if let Some(long_version) = System::long_os_version() {
record.push( record.push(
"long_os_version", "long_os_version",
Value::string(trim_cstyle_null(long_version), span), Value::string(trim_cstyle_null(long_version), span),
); );
} }
if let Some(version) = sys.kernel_version() { if let Some(version) = System::kernel_version() {
record.push( record.push(
"kernel_version", "kernel_version",
Value::string(trim_cstyle_null(version), span), Value::string(trim_cstyle_null(version), span),
); );
} }
if let Some(hostname) = sys.host_name() { if let Some(hostname) = System::host_name() {
record.push("hostname", Value::string(trim_cstyle_null(hostname), span)); record.push("hostname", Value::string(trim_cstyle_null(hostname), span));
} }
record.push( record.push(
"uptime", "uptime",
Value::duration(1000000000 * sys.uptime() as i64, span), Value::duration(1000000000 * System::uptime() as i64, span),
); );
// Creates a new SystemTime from the specified number of whole seconds // Creates a new SystemTime from the specified number of whole seconds
let d = UNIX_EPOCH + Duration::from_secs(sys.boot_time()); let d = UNIX_EPOCH + Duration::from_secs(System::boot_time());
// Create DateTime from SystemTime // Create DateTime from SystemTime
let datetime = DateTime::<Local>::from(d); let datetime = DateTime::<Local>::from(d);
// Convert to local time and then rfc3339 // Convert to local time and then rfc3339
@ -254,11 +247,16 @@ pub fn host(span: Span) -> Value {
record.push("boot_time", Value::string(timestamp_str, span)); record.push("boot_time", Value::string(timestamp_str, span));
let mut users = vec![]; let users = Users::new_with_refreshed_list();
for user in sys.users() {
let mut users_list = vec![];
for user in users.list() {
let mut groups = vec![]; let mut groups = vec![];
for group in user.groups() { for group in user.groups() {
groups.push(Value::string(trim_cstyle_null(group.to_string()), span)); groups.push(Value::string(
trim_cstyle_null(group.name().to_string()),
span,
));
} }
let record = record! { let record = record! {
@ -266,24 +264,22 @@ pub fn host(span: Span) -> Value {
"groups" => Value::list(groups, span), "groups" => Value::list(groups, span),
}; };
users.push(Value::record(record, span)); users_list.push(Value::record(record, span));
} }
if !users.is_empty() { if !users.is_empty() {
record.push("sessions", Value::list(users, span)); record.push("sessions", Value::list(users_list, span));
} }
Value::record(record, span) Value::record(record, span)
} }
pub fn temp(span: Span) -> Value { pub fn temp(span: Span) -> Value {
let mut sys = System::new(); let components = Components::new_with_refreshed_list();
sys.refresh_components();
sys.refresh_components_list();
let mut output = vec![]; let mut output = vec![];
for component in sys.components() { for component in components.list() {
let mut record = record! { let mut record = record! {
"unit" => Value::string(component.label(), span), "unit" => Value::string(component.label(), span),
"temp" => Value::float(component.temperature() as f64, span), "temp" => Value::float(component.temperature() as f64, span),

View File

@ -15,7 +15,7 @@ bench = false
[dependencies] [dependencies]
libc = "0.2" libc = "0.2"
log = "0.4" log = "0.4"
sysinfo = "0.29" sysinfo = "0.30"
[target.'cfg(target_family = "unix")'.dependencies] [target.'cfg(target_family = "unix")'.dependencies]
nix = { version = "0.27", default-features = false, features = ["fs", "term", "process", "signal"] } nix = { version = "0.27", default-features = false, features = ["fs", "term", "process", "signal"] }

View File

@ -1,5 +1,3 @@
use sysinfo::SystemExt;
pub fn get_os_name() -> &'static str { pub fn get_os_name() -> &'static str {
std::env::consts::OS std::env::consts::OS
} }
@ -13,8 +11,7 @@ pub fn get_os_family() -> &'static str {
} }
pub fn get_kernel_version() -> String { pub fn get_kernel_version() -> String {
let sys = sysinfo::System::new(); match sysinfo::System::kernel_version() {
match sys.kernel_version() {
Some(v) => v, Some(v) => v,
None => "unknown".to_string(), None => "unknown".to_string(),
} }