From 41fec57c000fd2fab1f4fdca83bc07d80f745e90 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 27 Feb 2023 01:05:58 +0000 Subject: [PATCH] Update sysinfo and improve its use a bit (#7826) I made a few internal fixes in sysinfo so why not be able to benefit from them? :) I explain the other changes directly in diff comments. --- crates/bevy_diagnostic/Cargo.toml | 4 ++-- .../system_information_diagnostics_plugin.rs | 20 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/crates/bevy_diagnostic/Cargo.toml b/crates/bevy_diagnostic/Cargo.toml index 4788528c7a38d..c2e8fb80afa50 100644 --- a/crates/bevy_diagnostic/Cargo.toml +++ b/crates/bevy_diagnostic/Cargo.toml @@ -24,10 +24,10 @@ bevy_utils = { path = "../bevy_utils", version = "0.9.0" } # MacOS [target.'cfg(all(target_os="macos"))'.dependencies] # Some features of sysinfo are not supported by apple. This will disable those features on apple devices -sysinfo = { version = "0.27.1", default-features = false, features = [ +sysinfo = { version = "0.28.1", default-features = false, features = [ "apple-app-store", ] } # Only include when not bevy_dynamic_plugin and on linux/windows/android [target.'cfg(any(target_os = "linux", target_os = "windows", target_os = "android"))'.dependencies] -sysinfo = { version = "0.27.1", default-features = false } +sysinfo = { version = "0.28.1", default-features = false } diff --git a/crates/bevy_diagnostic/src/system_information_diagnostics_plugin.rs b/crates/bevy_diagnostic/src/system_information_diagnostics_plugin.rs index 3c1f1d467f6de..096c9b13a6925 100644 --- a/crates/bevy_diagnostic/src/system_information_diagnostics_plugin.rs +++ b/crates/bevy_diagnostic/src/system_information_diagnostics_plugin.rs @@ -39,7 +39,7 @@ impl SystemInformationDiagnosticsPlugin { pub mod internal { use bevy_ecs::{prelude::ResMut, system::Local}; use bevy_log::info; - use sysinfo::{CpuExt, System, SystemExt}; + use sysinfo::{CpuExt, CpuRefreshKind, RefreshKind, System, SystemExt}; use crate::{Diagnostic, Diagnostics}; @@ -69,23 +69,19 @@ pub mod internal { mut sysinfo: Local>, ) { if sysinfo.is_none() { - *sysinfo = Some(System::new_all()); + *sysinfo = Some(System::new_with_specifics( + RefreshKind::new() + .with_cpu(CpuRefreshKind::new().with_cpu_usage()) + .with_memory(), + )); } let Some(sys) = sysinfo.as_mut() else { return; }; - sys.refresh_cpu(); + sys.refresh_cpu_specifics(CpuRefreshKind::new().with_cpu_usage()); sys.refresh_memory(); - let current_cpu_usage = { - let mut usage = 0.0; - let cpus = sys.cpus(); - for cpu in cpus { - usage += cpu.cpu_usage(); // NOTE: this returns a value from 0.0 to 100.0 - } - // average - usage / cpus.len() as f32 - }; + let current_cpu_usage = sys.global_cpu_info().cpu_usage(); // `memory()` fns return a value in bytes let total_mem = sys.total_memory() as f64 / BYTES_TO_GIB; let used_mem = sys.used_memory() as f64 / BYTES_TO_GIB;