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:
parent
3d8fe46f94
commit
41fec57c00
@ -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 }
|
||||
|
@ -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<Option<System>>,
|
||||
) {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user