use std::os::raw::c_char;
use objc2::rc::autoreleasepool;
use objc2_foundation::NSProcessInfo;
#[link(name = "IOKit", kind = "framework")]
#[allow(dead_code)]
extern "C" {
fn IOServiceMatching(service_name: *const c_char) -> *mut std::ffi::c_void;
fn IOServiceGetMatchingService(master_port: u32, matching: *mut std::ffi::c_void) -> u32;
fn IORegistryEntryCreateCFProperties(
entry: u32,
properties: *mut *mut std::ffi::c_void,
allocator: *mut std::ffi::c_void,
options: u32,
) -> i32;
}
#[allow(clippy::disallowed_methods, dead_code)]
fn main() {
println!("Darwin Metrics - Static GPU Info");
println!("This example displays basic GPU information without ongoing monitoring");
println!("---------------------------------------------------------------");
autoreleasepool(|_| {
println!("System Information:");
unsafe {
let process_info = NSProcessInfo::processInfo();
println!("Hostname: {}", process_info.hostName());
println!("OS Version: {}", process_info.operatingSystemVersionString());
println!(
"Physical Memory: {} GB",
process_info.physicalMemory() as f64 / 1_073_741_824.0
);
println!("Processor Count: {}", process_info.processorCount());
println!("Active Processor Count: {}", process_info.activeProcessorCount());
}
println!("\nGPU Information:");
println!("Note: Due to IOKit memory management issues, only basic info is displayed");
unsafe {
let service_name = std::ffi::CString::new("IOPCIDevice").unwrap();
let matching = IOServiceMatching(service_name.as_ptr());
let master_port = 0; let service = IOServiceGetMatchingService(master_port, matching);
if service != 0 {
println!("Found a PCI device, service ID: {}", service);
println!("GPU Model: Apple GPU");
println!("GPU Memory: Shared with system memory");
} else {
println!("No GPU device found via IOKit");
}
}
println!("\nApple Silicon Info:");
println!(" - Unified memory architecture");
println!(" - High bandwidth memory access");
println!(" - Hardware-accelerated Metal graphics");
});
}