feat: add more useful debug information to system metadata
This commit is contained in:
parent
4a46c0e438
commit
7739275353
5 changed files with 1055 additions and 42 deletions
964
Cargo.lock
generated
964
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -4,7 +4,6 @@ members = ["engine","subcrates/zen_core"]
|
||||||
|
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
lazy_static = "1.5.0"
|
|
||||||
parking_lot = "0.12.3"
|
parking_lot = "0.12.3"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
|
@ -17,7 +17,7 @@ regex = "1.11.1"
|
||||||
rustyline = { version = "15.0.0", features = ["derive", "rustyline-derive"] }
|
rustyline = { version = "15.0.0", features = ["derive", "rustyline-derive"] }
|
||||||
thiserror = "2.0.11"
|
thiserror = "2.0.11"
|
||||||
# Tokio is heavy but so far its the best option, we should make better use of it or switch to another runtime.
|
# Tokio is heavy but so far its the best option, we should make better use of it or switch to another runtime.
|
||||||
tokio = { version = "1.44.1", features = ["fs", "macros", "parking_lot", "rt-multi-thread"] }
|
tokio = { version = "1.44.1", features = ["macros", "parking_lot", "rt-multi-thread"] }
|
||||||
wgpu = "24.0.3"
|
wgpu = "24.0.3"
|
||||||
winit = "0.30.9"
|
winit = "0.30.9"
|
||||||
bytemuck = "1.21.0"
|
bytemuck = "1.21.0"
|
||||||
|
@ -39,3 +39,5 @@ image = "0.25.6"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
built = { version = "0.7.7", features = ["chrono"] }
|
built = { version = "0.7.7", features = ["chrono"] }
|
||||||
|
build-print = "0.1.1"
|
||||||
|
cargo-lock = "10.1.0"
|
||||||
|
|
100
engine/build.rs
100
engine/build.rs
|
@ -1,3 +1,99 @@
|
||||||
fn main() {
|
use std::process::Command;
|
||||||
built::write_built_file().expect("Failed to write build information");
|
use std::env;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::fs::OpenOptions;
|
||||||
|
use std::io::Write;
|
||||||
|
use build_print::*;
|
||||||
|
use cargo_lock::Lockfile;
|
||||||
|
|
||||||
|
fn get_git_info() -> String {
|
||||||
|
match Command::new("git").arg("describe").arg("--always").arg("--dirty").output() {
|
||||||
|
Ok(output) if output.status.success() => {
|
||||||
|
String::from_utf8_lossy(&output.stdout).trim().to_string()
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
match Command::new("git").arg("rev-parse").arg("--abbrev-ref").arg("HEAD").output() {
|
||||||
|
Ok(output) if output.status.success() => {
|
||||||
|
let head = String::from_utf8_lossy(&output.stdout);
|
||||||
|
let head = head.trim();
|
||||||
|
if head == "HEAD" {
|
||||||
|
"DETACHED".to_string()
|
||||||
|
} else {
|
||||||
|
//TDDO: properly parse branch hashes
|
||||||
|
format!("BRANCH: {}", head)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => "UNKNOWN".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
if let Err(e) = built::write_built_file() {
|
||||||
|
panic!("{e}");
|
||||||
|
}
|
||||||
|
let out_dir = env::var("OUT_DIR").unwrap();
|
||||||
|
let dest_path = Path::new(&out_dir).join("built.rs");
|
||||||
|
let proj_root = env!("CARGO_MANIFEST_DIR").to_string();
|
||||||
|
let tmp = format!("{}/../Cargo.lock",proj_root);
|
||||||
|
let lockfile_path = Path::new(&tmp).canonicalize().expect("INvalid");
|
||||||
|
|
||||||
|
|
||||||
|
let cargo_version = match Command::new("cargo").arg("--version").output() {
|
||||||
|
Ok(output) if output.status.success() => {
|
||||||
|
String::from_utf8_lossy(&output.stdout).trim().to_string()
|
||||||
|
}
|
||||||
|
_ => "unknown".to_string(),
|
||||||
|
};
|
||||||
|
info!("{cargo_version}");
|
||||||
|
|
||||||
|
let rustc_version = match Command::new("rustc").arg("--version").output() {
|
||||||
|
Ok(output) if output.status.success() => {
|
||||||
|
String::from_utf8_lossy(&output.stdout).trim().to_string()
|
||||||
|
}
|
||||||
|
_ => "unknown".to_string(),
|
||||||
|
};
|
||||||
|
info!("{rustc_version}");
|
||||||
|
|
||||||
|
let git_info = get_git_info();
|
||||||
|
info!("Git Info: {}", git_info);
|
||||||
|
|
||||||
|
let mut built_rs = match OpenOptions::new().append(true).open(&dest_path) {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(e) => {
|
||||||
|
error!("Could not open built.rs for appending: {}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
writeln!(built_rs, "pub const GIT_COMMIT_HASH: &str = \"{}\";", git_info).unwrap();
|
||||||
|
|
||||||
|
match Lockfile::load(lockfile_path) {
|
||||||
|
Ok(lockfile) => {
|
||||||
|
let dependencies_to_track = ["tokio", "winit", "wgpu"];
|
||||||
|
|
||||||
|
for package in lockfile.packages {
|
||||||
|
let name = package.name.as_str();
|
||||||
|
if dependencies_to_track.contains(&name) {
|
||||||
|
let version = package.version.to_string();
|
||||||
|
writeln!(
|
||||||
|
built_rs,
|
||||||
|
"pub const {}_VERSION: &str = \"{}\";",
|
||||||
|
name.to_uppercase().replace('-', "_"),
|
||||||
|
version
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
error!("Error loading Cargo.lock: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::println!("cargo:rerun-if-changed=Cargo.lock");
|
||||||
|
std::println!("cargo:rerun-if-changed=.git/HEAD");
|
||||||
|
std::println!("cargo:rerun-if-changed=.git/index");
|
||||||
|
}
|
|
@ -195,8 +195,10 @@ impl CPU {
|
||||||
);
|
);
|
||||||
sys.refresh_cpu_all();
|
sys.refresh_cpu_all();
|
||||||
|
|
||||||
|
|
||||||
let cpu_opt = sys.cpus().first();
|
let cpu_opt = sys.cpus().first();
|
||||||
|
|
||||||
|
|
||||||
let brand = cpu_opt
|
let brand = cpu_opt
|
||||||
.map(|cpu| cpu.brand().into())
|
.map(|cpu| cpu.brand().into())
|
||||||
.unwrap_or(CPUBrand::Other("unknown".into()));
|
.unwrap_or(CPUBrand::Other("unknown".into()));
|
||||||
|
@ -464,16 +466,20 @@ impl SystemMemory {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct CompileInfo {
|
pub struct EngineInfo {
|
||||||
pub timestamp: String,
|
pub timestamp: String,
|
||||||
pub pkg_version: String,
|
pub pkg_version: String,
|
||||||
pub pkg_name: String,
|
pub pkg_name: String,
|
||||||
pub target_arch: String,
|
pub target_arch: String,
|
||||||
pub target_os: String,
|
pub target_os: String,
|
||||||
pub target_env: String,
|
pub target_env: String,
|
||||||
|
pub rustc_version: String,
|
||||||
|
pub wgpu_version: String,
|
||||||
|
pub winit_version: String,
|
||||||
|
pub commit_hash: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompileInfo {
|
impl EngineInfo {
|
||||||
pub fn current() -> Self {
|
pub fn current() -> Self {
|
||||||
Self {
|
Self {
|
||||||
timestamp: build_info::BUILT_TIME_UTC.to_string(),
|
timestamp: build_info::BUILT_TIME_UTC.to_string(),
|
||||||
|
@ -482,6 +488,10 @@ impl CompileInfo {
|
||||||
target_arch: build_info::CFG_TARGET_ARCH.to_string(),
|
target_arch: build_info::CFG_TARGET_ARCH.to_string(),
|
||||||
target_os: build_info::CFG_OS.to_string(),
|
target_os: build_info::CFG_OS.to_string(),
|
||||||
target_env: build_info::CFG_ENV.to_string(),
|
target_env: build_info::CFG_ENV.to_string(),
|
||||||
|
rustc_version: build_info::RUSTC_VERSION.to_string(),
|
||||||
|
wgpu_version: build_info::WGPU_VERSION.to_string(),
|
||||||
|
winit_version: build_info::WGPU_VERSION.to_string(),
|
||||||
|
commit_hash: build_info::GIT_COMMIT_HASH.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,13 +501,21 @@ impl CompileInfo {
|
||||||
- Timestamp: {}\n\
|
- Timestamp: {}\n\
|
||||||
- Package: {} v{}\n\
|
- Package: {} v{}\n\
|
||||||
- Target: {} {} {}\n\
|
- Target: {} {} {}\n\
|
||||||
|
- Rustc version: {}\n\
|
||||||
|
- Wgpu version: {}\n\
|
||||||
|
- Winit version: {}\n\
|
||||||
|
- commit_hash: {}\n\
|
||||||
",
|
",
|
||||||
self.timestamp,
|
self.timestamp,
|
||||||
self.pkg_name,
|
self.pkg_name,
|
||||||
self.pkg_version,
|
self.pkg_version,
|
||||||
self.target_arch,
|
self.target_arch,
|
||||||
self.target_os,
|
self.target_os,
|
||||||
self.target_env
|
self.target_env,
|
||||||
|
self.rustc_version,
|
||||||
|
self.wgpu_version,
|
||||||
|
self.winit_version,
|
||||||
|
self.commit_hash
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -507,7 +525,7 @@ pub struct SystemMetadata {
|
||||||
pub cpu: CPU,
|
pub cpu: CPU,
|
||||||
pub memory: SystemMemory,
|
pub memory: SystemMemory,
|
||||||
pub gpus: Vec<GPU>,
|
pub gpus: Vec<GPU>,
|
||||||
pub compile_info: CompileInfo,
|
pub compile_info: EngineInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SystemMetadata {
|
impl SystemMetadata {
|
||||||
|
@ -516,7 +534,7 @@ impl SystemMetadata {
|
||||||
cpu: CPU::current(),
|
cpu: CPU::current(),
|
||||||
memory: SystemMemory::current(),
|
memory: SystemMemory::current(),
|
||||||
gpus: GPU::current(),
|
gpus: GPU::current(),
|
||||||
compile_info: CompileInfo::current(),
|
compile_info: EngineInfo::current(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue