Skip to content

Sysinfo improvements #9243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions crates/bevy_diagnostic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ bevy_log = { path = "../bevy_log", version = "0.12.0-dev" }
bevy_time = { path = "../bevy_time", version = "0.12.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.12.0-dev" }

# MacOS
[target.'cfg(all(target_os="macos"))'.dependencies]
# iOS
[target.'cfg(all(target_os="ios"))'.dependencies]
Comment on lines +24 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this also needed for macOS? from sysinfo docs it seems it is https://docs.rs/sysinfo/latest/sysinfo/#use-in-binaries-running-inside-the-macos-or-ios-sandboxstores

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if running it in a VM. Talk about a nightmare...

# Some features of sysinfo are not supported by apple. This will disable those features on apple devices
sysinfo = { version = "0.29.0", default-features = false, features = [
sysinfo = { version = "0.29.6", 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.29.0", default-features = false }
[target.'cfg(not(target_os = "ios"))'.dependencies]
sysinfo = { version = "0.29.6", default-features = false }
31 changes: 13 additions & 18 deletions crates/bevy_diagnostic/src/system_information_diagnostics_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use bevy_app::prelude::*;
/// * windows,
/// * android,
/// * macos
/// * freebsd
///
/// NOT supported when using the `bevy/dynamic` feature even when using previously mentioned targets
#[derive(Default)]
Expand All @@ -27,15 +28,7 @@ impl SystemInformationDiagnosticsPlugin {
}

// NOTE: sysinfo fails to compile when using bevy dynamic or on iOS and does nothing on wasm
#[cfg(all(
any(
target_os = "linux",
target_os = "windows",
target_os = "android",
target_os = "macos"
),
not(feature = "dynamic_linking")
))]
#[cfg(all(not(target_os = "ios"), not(feature = "dynamic_linking")))]
pub mod internal {
use bevy_ecs::{prelude::ResMut, system::Local};
use bevy_log::info;
Expand All @@ -46,6 +39,10 @@ pub mod internal {
const BYTES_TO_GIB: f64 = 1.0 / 1024.0 / 1024.0 / 1024.0;

pub(crate) fn setup_system(mut diagnostics: ResMut<DiagnosticsStore>) {
if !System::IS_SUPPORTED {
bevy_log::warn!("This platform and/or configuration is not supported!");
return;
}
diagnostics.add(
Diagnostic::new(
super::SystemInformationDiagnosticsPlugin::CPU_USAGE,
Expand All @@ -68,6 +65,9 @@ pub mod internal {
mut diagnostics: Diagnostics,
mut sysinfo: Local<Option<System>>,
) {
if !System::IS_SUPPORTED {
return;
}
if sysinfo.is_none() {
*sysinfo = Some(System::new_with_specifics(
RefreshKind::new()
Expand Down Expand Up @@ -107,6 +107,9 @@ pub mod internal {
}

pub(crate) fn log_system_info() {
if !System::IS_SUPPORTED {
return;
}
let mut sys = sysinfo::System::new();
sys.refresh_cpu();
sys.refresh_memory();
Expand All @@ -131,15 +134,7 @@ pub mod internal {
}
}

#[cfg(not(all(
any(
target_os = "linux",
target_os = "windows",
target_os = "android",
target_os = "macos"
),
not(feature = "dynamic_linking")
)))]
#[cfg(any(target_os = "ios", feature = "dynamic_linking"))]
pub mod internal {
pub(crate) fn setup_system() {
bevy_log::warn!("This platform and/or configuration is not supported!");
Expand Down