mirror of
https://github.com/nushell/nushell
synced 2024-11-10 07:04:13 +00:00
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:
parent
ad95e4cc27
commit
7e26b4fcc2
8 changed files with 100 additions and 90 deletions
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -2697,7 +2697,7 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
"reedline",
|
||||
"rstest",
|
||||
"sysinfo",
|
||||
"sysinfo 0.30.4",
|
||||
"unicode-segmentation",
|
||||
"uuid",
|
||||
"which 5.0.0",
|
||||
|
@ -2876,7 +2876,7 @@ dependencies = [
|
|||
"serde_urlencoded",
|
||||
"serde_yaml",
|
||||
"sha2",
|
||||
"sysinfo",
|
||||
"sysinfo 0.30.4",
|
||||
"tabled",
|
||||
"terminal_size 0.3.0",
|
||||
"titlecase",
|
||||
|
@ -3060,7 +3060,7 @@ dependencies = [
|
|||
"ntapi",
|
||||
"once_cell",
|
||||
"procfs",
|
||||
"sysinfo",
|
||||
"sysinfo 0.30.4",
|
||||
"windows 0.52.0",
|
||||
]
|
||||
|
||||
|
@ -4089,7 +4089,7 @@ dependencies = [
|
|||
"polars-error",
|
||||
"rayon",
|
||||
"smartstring",
|
||||
"sysinfo",
|
||||
"sysinfo 0.29.11",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
|
@ -5280,10 +5280,24 @@ dependencies = [
|
|||
"libc",
|
||||
"ntapi",
|
||||
"once_cell",
|
||||
"rayon",
|
||||
"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]]
|
||||
name = "tabled"
|
||||
version = "0.14.0"
|
||||
|
|
|
@ -37,7 +37,7 @@ miette = { version = "5.10", features = ["fancy-no-backtrace"] }
|
|||
once_cell = "1.18"
|
||||
percent-encoding = "2"
|
||||
pathdiff = "0.2"
|
||||
sysinfo = "0.29"
|
||||
sysinfo = "0.30"
|
||||
unicode-segmentation = "1.10"
|
||||
uuid = { version = "1.6.0", features = ["v4"] }
|
||||
which = "5.0.0"
|
||||
|
|
|
@ -32,7 +32,7 @@ use std::{
|
|||
sync::atomic::Ordering,
|
||||
time::Instant,
|
||||
};
|
||||
use sysinfo::SystemExt;
|
||||
use sysinfo::System;
|
||||
|
||||
// According to Daniel Imms @Tyriar, we need to do these this way:
|
||||
// <133 A><prompt><133 B><command><133 C><command output>
|
||||
|
@ -135,17 +135,6 @@ pub fn evaluate_repl(
|
|||
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 {
|
||||
eval_source(
|
||||
engine_state,
|
||||
|
@ -428,7 +417,7 @@ pub fn evaluate_repl(
|
|||
|
||||
match input {
|
||||
Ok(Signal::Success(s)) => {
|
||||
let hostname = sys.host_name();
|
||||
let hostname = System::host_name();
|
||||
let history_supports_meta =
|
||||
matches!(config.history_file_format, HistoryFileFormat::Sqlite);
|
||||
if history_supports_meta && !s.is_empty() && line_editor.has_last_command_context()
|
||||
|
|
|
@ -80,7 +80,7 @@ serde_json = "1.0"
|
|||
serde_urlencoded = "0.7"
|
||||
serde_yaml = "0.9"
|
||||
sha2 = "0.10"
|
||||
sysinfo = "0.29"
|
||||
sysinfo = "0.30"
|
||||
tabled = { version = "0.14.0", features = ["color"], default-features = false }
|
||||
terminal_size = "0.3"
|
||||
titlecase = "2.0"
|
||||
|
|
|
@ -4,7 +4,7 @@ use nu_protocol::{
|
|||
record, Category, Example, IntoPipelineData, LazyRecord, PipelineData, Record, ShellError,
|
||||
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 = {
|
||||
#[cfg(target_family = "windows")]
|
||||
{
|
||||
|
@ -98,8 +98,9 @@ impl LazySystemInfoRecord {
|
|||
}
|
||||
"system" => {
|
||||
// only get information requested
|
||||
let system_opt =
|
||||
SystemOpt::from((system_option, || RefreshKind::new().with_memory()));
|
||||
let system_opt = SystemOpt::from((system_option, || {
|
||||
RefreshKind::new().with_memory(MemoryRefreshKind::everything())
|
||||
}));
|
||||
|
||||
let system = system_opt.get_system();
|
||||
|
||||
|
@ -135,53 +136,66 @@ impl LazySystemInfoRecord {
|
|||
"virtual_memory" => Value::filesize(p.virtual_memory() as i64, self.span),
|
||||
"status" => Value::string(p.status().to_string(), self.span),
|
||||
"root" => {
|
||||
if let Some(filename) = p.exe().parent() {
|
||||
Value::string(filename.to_string_lossy().to_string(), self.span)
|
||||
if let Some(path) = p.exe().and_then(|p| p.parent()) {
|
||||
Value::string(path.to_string_lossy().to_string(), self.span)
|
||||
} else {
|
||||
Value::nothing(self.span)
|
||||
}
|
||||
},
|
||||
"cwd" => Value::string(p.cwd().to_string_lossy().to_string(), self.span),
|
||||
"exe_path" => Value::string(p.exe().to_string_lossy().to_string(), self.span),
|
||||
"cwd" => {
|
||||
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),
|
||||
"name" => Value::string(p.name().to_string(), self.span),
|
||||
"environment" => {
|
||||
let mut env_rec = Record::new();
|
||||
for val in p.environ() {
|
||||
if let Some((key, value)) = val.split_once('=') {
|
||||
let is_env_var_a_list = {
|
||||
"environment" => {
|
||||
let mut env_rec = Record::new();
|
||||
for val in p.environ() {
|
||||
if let Some((key, value)) = val.split_once('=') {
|
||||
let is_env_var_a_list = {
|
||||
{
|
||||
#[cfg(target_family = "windows")]
|
||||
{
|
||||
#[cfg(target_family = "windows")]
|
||||
{
|
||||
key == "Path" || key == "PATHEXT" || key == "PSMODULEPATH" || key == "PSModulePath"
|
||||
}
|
||||
#[cfg(not(target_family = "windows"))]
|
||||
{
|
||||
key == "PATH" || key == "DYLD_FALLBACK_LIBRARY_PATH"
|
||||
}
|
||||
key == "Path" || key == "PATHEXT" || key == "PSMODULEPATH" || key == "PSModulePath"
|
||||
}
|
||||
#[cfg(not(target_family = "windows"))]
|
||||
{
|
||||
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,
|
||||
))
|
||||
} else {
|
||||
// If we can't get the process information, just return the system information
|
||||
// only get information requested
|
||||
let system_opt =
|
||||
SystemOpt::from((system_option, || RefreshKind::new().with_memory()));
|
||||
let system_opt = SystemOpt::from((system_option, || {
|
||||
RefreshKind::new().with_memory(MemoryRefreshKind::everything())
|
||||
}));
|
||||
let system = system_opt.get_system();
|
||||
|
||||
Ok(Value::record(
|
||||
|
@ -228,7 +242,7 @@ impl<'a> LazyRecord<'a> for LazySystemInfoRecord {
|
|||
.without_disk_usage()
|
||||
.without_user(),
|
||||
)
|
||||
.with_memory();
|
||||
.with_memory(MemoryRefreshKind::everything());
|
||||
// only get information requested
|
||||
let system = System::new_with_specifics(rk);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use nu_protocol::{
|
|||
};
|
||||
use std::time::{Duration, UNIX_EPOCH};
|
||||
use sysinfo::{
|
||||
ComponentExt, CpuExt, CpuRefreshKind, DiskExt, NetworkExt, System, SystemExt, UserExt,
|
||||
Components, CpuRefreshKind, Disks, Networks, System, Users, MINIMUM_CPU_UPDATE_INTERVAL,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -106,14 +106,12 @@ pub fn trim_cstyle_null(s: String) -> String {
|
|||
}
|
||||
|
||||
pub fn disks(span: Span) -> Value {
|
||||
let mut sys = System::new();
|
||||
sys.refresh_disks();
|
||||
sys.refresh_disks_list();
|
||||
let disks = Disks::new_with_refreshed_list();
|
||||
|
||||
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 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! {
|
||||
"device" => Value::string(device, span),
|
||||
|
@ -131,12 +129,10 @@ pub fn disks(span: Span) -> Value {
|
|||
}
|
||||
|
||||
pub fn net(span: Span) -> Value {
|
||||
let mut sys = System::new();
|
||||
sys.refresh_networks();
|
||||
sys.refresh_networks_list();
|
||||
let networks = Networks::new_with_refreshed_list();
|
||||
|
||||
let mut output = vec![];
|
||||
for (iface, data) in sys.networks() {
|
||||
for (iface, data) in networks.list() {
|
||||
let record = record! {
|
||||
"name" => Value::string(trim_cstyle_null(iface.to_string()), 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.
|
||||
// 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
|
||||
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());
|
||||
|
||||
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.
|
||||
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!(
|
||||
"{:.2}, {:.2}, {:.2}",
|
||||
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 {
|
||||
let mut sys = System::new();
|
||||
sys.refresh_users_list();
|
||||
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
if let Some(long_version) = sys.long_os_version() {
|
||||
if let Some(long_version) = System::long_os_version() {
|
||||
record.push(
|
||||
"long_os_version",
|
||||
Value::string(trim_cstyle_null(long_version), span),
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(version) = sys.kernel_version() {
|
||||
if let Some(version) = System::kernel_version() {
|
||||
record.push(
|
||||
"kernel_version",
|
||||
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(
|
||||
"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
|
||||
let d = UNIX_EPOCH + Duration::from_secs(sys.boot_time());
|
||||
let d = UNIX_EPOCH + Duration::from_secs(System::boot_time());
|
||||
// Create DateTime from SystemTime
|
||||
let datetime = DateTime::<Local>::from(d);
|
||||
// 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));
|
||||
|
||||
let mut users = vec![];
|
||||
for user in sys.users() {
|
||||
let users = Users::new_with_refreshed_list();
|
||||
|
||||
let mut users_list = vec![];
|
||||
for user in users.list() {
|
||||
let mut groups = vec![];
|
||||
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! {
|
||||
|
@ -266,24 +264,22 @@ pub fn host(span: Span) -> Value {
|
|||
"groups" => Value::list(groups, span),
|
||||
};
|
||||
|
||||
users.push(Value::record(record, span));
|
||||
users_list.push(Value::record(record, span));
|
||||
}
|
||||
|
||||
if !users.is_empty() {
|
||||
record.push("sessions", Value::list(users, span));
|
||||
record.push("sessions", Value::list(users_list, span));
|
||||
}
|
||||
|
||||
Value::record(record, span)
|
||||
}
|
||||
|
||||
pub fn temp(span: Span) -> Value {
|
||||
let mut sys = System::new();
|
||||
sys.refresh_components();
|
||||
sys.refresh_components_list();
|
||||
let components = Components::new_with_refreshed_list();
|
||||
|
||||
let mut output = vec![];
|
||||
|
||||
for component in sys.components() {
|
||||
for component in components.list() {
|
||||
let mut record = record! {
|
||||
"unit" => Value::string(component.label(), span),
|
||||
"temp" => Value::float(component.temperature() as f64, span),
|
||||
|
|
|
@ -15,7 +15,7 @@ bench = false
|
|||
[dependencies]
|
||||
libc = "0.2"
|
||||
log = "0.4"
|
||||
sysinfo = "0.29"
|
||||
sysinfo = "0.30"
|
||||
|
||||
[target.'cfg(target_family = "unix")'.dependencies]
|
||||
nix = { version = "0.27", default-features = false, features = ["fs", "term", "process", "signal"] }
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use sysinfo::SystemExt;
|
||||
|
||||
pub fn get_os_name() -> &'static str {
|
||||
std::env::consts::OS
|
||||
}
|
||||
|
@ -13,8 +11,7 @@ pub fn get_os_family() -> &'static str {
|
|||
}
|
||||
|
||||
pub fn get_kernel_version() -> String {
|
||||
let sys = sysinfo::System::new();
|
||||
match sys.kernel_version() {
|
||||
match sysinfo::System::kernel_version() {
|
||||
Some(v) => v,
|
||||
None => "unknown".to_string(),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue