Skip to content

Commit

Permalink
Update sysinfo and improve its use a bit (bevyengine#7826)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GuillaumeGomez authored and Shfty committed Mar 19, 2023
1 parent dfe3fee commit 46fc7d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_diagnostic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 46fc7d7

Please sign in to comment.