From 868941a06508df5e97de0b6e8b2f6b18edd2b902 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Sat, 9 Aug 2025 13:14:02 +0200 Subject: [PATCH] fixed gpu detection - bc unknown lib --- WatcherAgent/src/hardware/disk.rs | 4 +-- WatcherAgent/src/hardware/gpu.rs | 47 ++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/WatcherAgent/src/hardware/disk.rs b/WatcherAgent/src/hardware/disk.rs index fa67966..92ff559 100644 --- a/WatcherAgent/src/hardware/disk.rs +++ b/WatcherAgent/src/hardware/disk.rs @@ -131,7 +131,7 @@ pub fn get_disk_utitlization() -> Result<(f64, f64, f64, f64), Box> { )) // Disk-Temp bleibt 0.0 ohne spezielle Hardware } -pub fn get_disk_temp_for_component(component: &Component) -> Option { +pub fn _get_disk_temp_for_component(component: &Component) -> Option { if let Some(temp) = component.temperature() { Some(temp as f64) } else { @@ -139,7 +139,7 @@ pub fn get_disk_temp_for_component(component: &Component) -> Option { } } -pub fn get_disk_load_for_disk(disk: &Disk) -> Result<(f64, f64, f64, f64), Box> { +pub fn _get_disk_load_for_disk(disk: &Disk) -> Result<(f64, f64, f64, f64), Box> { let usage: DiskUsage = disk.usage(); // Assuming DiskUsage has these methods: diff --git a/WatcherAgent/src/hardware/gpu.rs b/WatcherAgent/src/hardware/gpu.rs index e49c3c0..a041759 100644 --- a/WatcherAgent/src/hardware/gpu.rs +++ b/WatcherAgent/src/hardware/gpu.rs @@ -16,8 +16,9 @@ pub async fn get_gpu_info() -> Result> { let device = nvml.device_by_index(0)?; let (used, total) = get_gpu_vram_usage(&device)?; + let gpu_name = detect_gpu_name(); Ok(GpuInfo { - name: device.name().ok(), + name: Some(gpu_name), current_load: get_gpu_load(&device).ok(), current_temp: get_gpu_temp(&device).ok(), vram_total: Some(total as f64), @@ -39,3 +40,47 @@ pub fn get_gpu_vram_usage(device: &nvml_wrapper::Device) -> Result<(f64, f64), B let mem_info = device.memory_info().unwrap(); Ok((mem_info.used as f64, mem_info.total as f64)) } + +fn detect_gpu_name() -> String { + try_nvml_gpu_name() + .or_else(fallback_gpu_name) + .unwrap_or_else(|| "Unknown GPU".to_string()) +} + +fn try_nvml_gpu_name() -> Option { + let nvml = Nvml::init().ok()?; + let device = nvml.device_by_index(0).ok()?; + device.name().ok().map(|s| s.to_string()) +} + +fn fallback_gpu_name() -> Option { + #[cfg(target_os = "linux")] + { + let output = std::process::Command::new("lshw") + .args(&["-C", "display"]) + .output() + .ok()?; + Some( + String::from_utf8_lossy(&output.stdout) + .lines() + .find(|l| l.contains("product:")) + .map(|l| l.trim().replace("product:", "").trim().to_string()) + .unwrap_or("Unknown GPU".to_string()), + ) + } + + #[cfg(target_os = "windows")] + { + let output = std::process::Command::new("wmic") + .args(&["path", "win32_VideoController", "get", "name"]) + .output() + .ok()?; + Some( + String::from_utf8_lossy(&output.stdout) + .lines() + .nth(1) + .map(|s| s.trim().to_string()) + .unwrap_or("Unknown GPU".to_string()), + ) + } +}