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.
This commit is contained in:
Guillaume Gomez 2023-02-27 01:05:58 +00:00
parent 3d8fe46f94
commit 41fec57c00
2 changed files with 10 additions and 14 deletions

View File

@ -24,10 +24,10 @@ bevy_utils = { path = "../bevy_utils", version = "0.9.0" }
# MacOS # MacOS
[target.'cfg(all(target_os="macos"))'.dependencies] [target.'cfg(all(target_os="macos"))'.dependencies]
# Some features of sysinfo are not supported by apple. This will disable those features on apple devices # 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", "apple-app-store",
] } ] }
# Only include when not bevy_dynamic_plugin and on linux/windows/android # 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] [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 }

View File

@ -39,7 +39,7 @@ impl SystemInformationDiagnosticsPlugin {
pub mod internal { pub mod internal {
use bevy_ecs::{prelude::ResMut, system::Local}; use bevy_ecs::{prelude::ResMut, system::Local};
use bevy_log::info; use bevy_log::info;
use sysinfo::{CpuExt, System, SystemExt}; use sysinfo::{CpuExt, CpuRefreshKind, RefreshKind, System, SystemExt};
use crate::{Diagnostic, Diagnostics}; use crate::{Diagnostic, Diagnostics};
@ -69,23 +69,19 @@ pub mod internal {
mut sysinfo: Local<Option<System>>, mut sysinfo: Local<Option<System>>,
) { ) {
if sysinfo.is_none() { 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 { let Some(sys) = sysinfo.as_mut() else {
return; return;
}; };
sys.refresh_cpu(); sys.refresh_cpu_specifics(CpuRefreshKind::new().with_cpu_usage());
sys.refresh_memory(); sys.refresh_memory();
let current_cpu_usage = { let current_cpu_usage = sys.global_cpu_info().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
};
// `memory()` fns return a value in bytes // `memory()` fns return a value in bytes
let total_mem = sys.total_memory() as f64 / BYTES_TO_GIB; let total_mem = sys.total_memory() as f64 / BYTES_TO_GIB;
let used_mem = sys.used_memory() as f64 / BYTES_TO_GIB; let used_mem = sys.used_memory() as f64 / BYTES_TO_GIB;