From cc47eee6c90f765447f6f50273d7551c1eab3a2f Mon Sep 17 00:00:00 2001 From: IceSentry Date: Fri, 23 Dec 2022 01:38:33 -0500 Subject: [PATCH 1/6] log system info on startup --- crates/bevy_diagnostic/Cargo.toml | 17 ++++++++++++ crates/bevy_diagnostic/src/lib.rs | 43 ++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/crates/bevy_diagnostic/Cargo.toml b/crates/bevy_diagnostic/Cargo.toml index 2b8a1f2fa0a29..97bef80b22d86 100644 --- a/crates/bevy_diagnostic/Cargo.toml +++ b/crates/bevy_diagnostic/Cargo.toml @@ -17,3 +17,20 @@ bevy_ecs = { path = "../bevy_ecs", version = "0.9.0" } bevy_log = { path = "../bevy_log", version = "0.9.0" } bevy_time = { path = "../bevy_time", version = "0.9.0" } bevy_utils = { path = "../bevy_utils", version = "0.9.0" } + +# iOS or MacOS +[target.'cfg(any(target_os="ios",target_os="macos"))'.dependencies.sysinfo] +version = "0.27.1" +features = ["apple-app-store"] +default-features = false + +# use the unknown ci feature for RPi +[target.'cfg(all(target_os="linux",any(target_arch="aarch64",target_arch="arm")))'.dependencies.sysinfo] +version = "0.27.1" +# this prevents linking to the C interface, which causes some build issues +features = ["unknown-ci"] +default-features = false + +# general case +[dependencies.sysinfo] +version = "0.27.1" diff --git a/crates/bevy_diagnostic/src/lib.rs b/crates/bevy_diagnostic/src/lib.rs index 076618bcde060..fe33f4bcc79c5 100644 --- a/crates/bevy_diagnostic/src/lib.rs +++ b/crates/bevy_diagnostic/src/lib.rs @@ -2,6 +2,7 @@ mod diagnostic; mod entity_count_diagnostics_plugin; mod frame_time_diagnostics_plugin; mod log_diagnostics_plugin; +use bevy_log::info; pub use diagnostic::*; pub use entity_count_diagnostics_plugin::EntityCountDiagnosticsPlugin; pub use frame_time_diagnostics_plugin::FrameTimeDiagnosticsPlugin; @@ -15,10 +16,50 @@ pub struct DiagnosticsPlugin; impl Plugin for DiagnosticsPlugin { fn build(&self, app: &mut App) { - app.init_resource::(); + app.init_resource::() + .add_startup_system(log_system_info); } } /// The width which diagnostic names will be printed as /// Plugin names should not be longer than this value pub const MAX_DIAGNOSTIC_NAME_WIDTH: usize = 32; + +#[derive(Debug)] +// This is required because the Debug trait doesn't detect it's used when it's only used in a print :( +#[allow(dead_code)] +struct SystemInfo { + os: String, + kernel: String, + cpu: String, + core_count: String, + memory: String, +} + +const BYTES_TO_GIB: f64 = 1.0 / 1024.0 / 1024.0 / 1024.0; + +fn log_system_info() { + use sysinfo::{CpuExt, SystemExt}; + + let mut sys = sysinfo::System::new(); + sys.refresh_cpu(); + sys.refresh_memory(); + + let info = SystemInfo { + os: sys + .long_os_version() + .unwrap_or_else(|| String::from("not available")), + kernel: sys + .kernel_version() + .unwrap_or_else(|| String::from("not available")), + cpu: sys.global_cpu_info().brand().trim().to_string(), + core_count: sys + .physical_core_count() + .map(|x| x.to_string()) + .unwrap_or_else(|| String::from("not available")), + // Convert from Bytes to GibiBytes since it's probably what people expect most of the time + memory: format!("{:.1} GiB", sys.total_memory() as f64 * BYTES_TO_GIB), + }; + + info!("{:?}", info); +} From 56814b88370c6a335e4e936da26cadf660a4455f Mon Sep 17 00:00:00 2001 From: IceSentry Date: Fri, 23 Dec 2022 01:57:38 -0500 Subject: [PATCH 2/6] disable default-features --- crates/bevy_diagnostic/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_diagnostic/Cargo.toml b/crates/bevy_diagnostic/Cargo.toml index 97bef80b22d86..374ce06992cd3 100644 --- a/crates/bevy_diagnostic/Cargo.toml +++ b/crates/bevy_diagnostic/Cargo.toml @@ -34,3 +34,4 @@ default-features = false # general case [dependencies.sysinfo] version = "0.27.1" +default-features = false From 86f899f7eec7cba80c20d41085cd28286aa87123 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Fri, 23 Dec 2022 02:11:28 -0500 Subject: [PATCH 3/6] try ci --- crates/bevy_diagnostic/Cargo.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/bevy_diagnostic/Cargo.toml b/crates/bevy_diagnostic/Cargo.toml index 374ce06992cd3..8dc14fba845c4 100644 --- a/crates/bevy_diagnostic/Cargo.toml +++ b/crates/bevy_diagnostic/Cargo.toml @@ -25,11 +25,11 @@ features = ["apple-app-store"] default-features = false # use the unknown ci feature for RPi -[target.'cfg(all(target_os="linux",any(target_arch="aarch64",target_arch="arm")))'.dependencies.sysinfo] -version = "0.27.1" -# this prevents linking to the C interface, which causes some build issues -features = ["unknown-ci"] -default-features = false +# [target.'cfg(all(target_os="linux",any(target_arch="aarch64",target_arch="arm")))'.dependencies.sysinfo] +# version = "0.27.1" +# # this prevents linking to the C interface, which causes some build issues +# features = ["unknown-ci"] +# default-features = false # general case [dependencies.sysinfo] From 32ed55660e02c7aa95e5c319f475cf82ad772d79 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Fri, 23 Dec 2022 02:32:20 -0500 Subject: [PATCH 4/6] clean up --- crates/bevy_diagnostic/Cargo.toml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/crates/bevy_diagnostic/Cargo.toml b/crates/bevy_diagnostic/Cargo.toml index 8dc14fba845c4..060291e18015a 100644 --- a/crates/bevy_diagnostic/Cargo.toml +++ b/crates/bevy_diagnostic/Cargo.toml @@ -21,17 +21,10 @@ bevy_utils = { path = "../bevy_utils", version = "0.9.0" } # iOS or MacOS [target.'cfg(any(target_os="ios",target_os="macos"))'.dependencies.sysinfo] version = "0.27.1" +# Some features of sysinfo are not supported by apple. This will disable those features on apple devices features = ["apple-app-store"] default-features = false -# use the unknown ci feature for RPi -# [target.'cfg(all(target_os="linux",any(target_arch="aarch64",target_arch="arm")))'.dependencies.sysinfo] -# version = "0.27.1" -# # this prevents linking to the C interface, which causes some build issues -# features = ["unknown-ci"] -# default-features = false - -# general case [dependencies.sysinfo] version = "0.27.1" default-features = false From 63b60eace625092454d3543d8208a5710773f029 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Sun, 25 Dec 2022 22:43:29 -0500 Subject: [PATCH 5/6] don't include sysinfo on ios or when using bevy_dynamic --- crates/bevy_diagnostic/src/lib.rs | 44 +++++++++++++++++-------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/crates/bevy_diagnostic/src/lib.rs b/crates/bevy_diagnostic/src/lib.rs index fe33f4bcc79c5..a8eb739ad89a0 100644 --- a/crates/bevy_diagnostic/src/lib.rs +++ b/crates/bevy_diagnostic/src/lib.rs @@ -39,27 +39,31 @@ struct SystemInfo { const BYTES_TO_GIB: f64 = 1.0 / 1024.0 / 1024.0 / 1024.0; fn log_system_info() { - use sysinfo::{CpuExt, SystemExt}; + // NOTE: sysinfo fails to compile when using bevy dynamic or on iOS + #[cfg(not(any(feature = "bevy_dynamic_plugin", target_os = "ios")))] + { + use sysinfo::{CpuExt, SystemExt}; - let mut sys = sysinfo::System::new(); - sys.refresh_cpu(); - sys.refresh_memory(); + let mut sys = sysinfo::System::new(); + sys.refresh_cpu(); + sys.refresh_memory(); - let info = SystemInfo { - os: sys - .long_os_version() - .unwrap_or_else(|| String::from("not available")), - kernel: sys - .kernel_version() - .unwrap_or_else(|| String::from("not available")), - cpu: sys.global_cpu_info().brand().trim().to_string(), - core_count: sys - .physical_core_count() - .map(|x| x.to_string()) - .unwrap_or_else(|| String::from("not available")), - // Convert from Bytes to GibiBytes since it's probably what people expect most of the time - memory: format!("{:.1} GiB", sys.total_memory() as f64 * BYTES_TO_GIB), - }; + let info = SystemInfo { + os: sys + .long_os_version() + .unwrap_or_else(|| String::from("not available")), + kernel: sys + .kernel_version() + .unwrap_or_else(|| String::from("not available")), + cpu: sys.global_cpu_info().brand().trim().to_string(), + core_count: sys + .physical_core_count() + .map(|x| x.to_string()) + .unwrap_or_else(|| String::from("not available")), + // Convert from Bytes to GibiBytes since it's probably what people expect most of the time + memory: format!("{:.1} GiB", sys.total_memory() as f64 * BYTES_TO_GIB), + }; - info!("{:?}", info); + info!("{:?}", info); + } } From bb18ca054d9e5f6f3d0567d2040063b1e7a59b3b Mon Sep 17 00:00:00 2001 From: IceSentry Date: Sun, 25 Dec 2022 23:18:26 -0500 Subject: [PATCH 6/6] better cfg --- crates/bevy_diagnostic/Cargo.toml | 16 ++++++++-------- crates/bevy_diagnostic/src/lib.rs | 12 ++++++++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/crates/bevy_diagnostic/Cargo.toml b/crates/bevy_diagnostic/Cargo.toml index 060291e18015a..7bd1249cbefaa 100644 --- a/crates/bevy_diagnostic/Cargo.toml +++ b/crates/bevy_diagnostic/Cargo.toml @@ -18,13 +18,13 @@ bevy_log = { path = "../bevy_log", version = "0.9.0" } bevy_time = { path = "../bevy_time", version = "0.9.0" } bevy_utils = { path = "../bevy_utils", version = "0.9.0" } -# iOS or MacOS -[target.'cfg(any(target_os="ios",target_os="macos"))'.dependencies.sysinfo] -version = "0.27.1" +# 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 -features = ["apple-app-store"] -default-features = false +sysinfo = { version = "0.27.1", default-features = false, features = [ + "apple-app-store", +] } -[dependencies.sysinfo] -version = "0.27.1" -default-features = false +# 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 } diff --git a/crates/bevy_diagnostic/src/lib.rs b/crates/bevy_diagnostic/src/lib.rs index a8eb739ad89a0..5cef8389ac092 100644 --- a/crates/bevy_diagnostic/src/lib.rs +++ b/crates/bevy_diagnostic/src/lib.rs @@ -39,8 +39,16 @@ struct SystemInfo { const BYTES_TO_GIB: f64 = 1.0 / 1024.0 / 1024.0 / 1024.0; fn log_system_info() { - // NOTE: sysinfo fails to compile when using bevy dynamic or on iOS - #[cfg(not(any(feature = "bevy_dynamic_plugin", target_os = "ios")))] + // 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 = "bevy_dynamic_plugin") + ))] { use sysinfo::{CpuExt, SystemExt};