Skip to content

Commit

Permalink
Try #5454:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Dec 26, 2022
2 parents b6066c3 + 63b60ea commit 7c468bf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
11 changes: 11 additions & 0 deletions crates/bevy_diagnostic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ 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"
# Some features of sysinfo are not supported by apple. This will disable those features on apple devices
features = ["apple-app-store"]
default-features = false

[dependencies.sysinfo]
version = "0.27.1"
default-features = false
47 changes: 46 additions & 1 deletion crates/bevy_diagnostic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,10 +16,54 @@ pub struct DiagnosticsPlugin;

impl Plugin for DiagnosticsPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<Diagnostics>();
app.init_resource::<Diagnostics>()
.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() {
// 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 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);
}
}

0 comments on commit 7c468bf

Please sign in to comment.