new feature: gpu support

This commit is contained in:
2025-08-11 12:04:55 -07:00
parent a4f69a5f7d
commit 20278d67f1
11 changed files with 525 additions and 33 deletions
+26
View File
@@ -0,0 +1,26 @@
// gpu.rs
use gfxinfo::active_gpu;
#[derive(Debug, Clone, serde::Serialize)]
pub struct GpuMetrics {
pub name: String,
pub utilization_gpu_pct: u32, // 0..100
pub mem_used_bytes: u64,
pub mem_total_bytes: u64,
// pub vendor: String,
}
pub fn collect_all_gpus() -> Result<Vec<GpuMetrics>, Box<dyn std::error::Error>> {
let gpu = active_gpu()?; // Use ? to unwrap Result
let info = gpu.info();
let metrics = GpuMetrics {
name: gpu.model().to_string(),
utilization_gpu_pct: info.load_pct() as u32,
mem_used_bytes: info.used_vram(),
mem_total_bytes: info.total_vram(),
// vendor: gpu.vendor().to_string(),
};
Ok(vec![metrics])
}