fixed gpu detection - bc unknown lib

This commit is contained in:
2025-08-09 13:14:02 +02:00
parent 2b9e1eccb5
commit 868941a065
2 changed files with 48 additions and 3 deletions

View File

@@ -131,7 +131,7 @@ pub fn get_disk_utitlization() -> Result<(f64, f64, f64, f64), Box<dyn Error>> {
)) // Disk-Temp bleibt 0.0 ohne spezielle Hardware
}
pub fn get_disk_temp_for_component(component: &Component) -> Option<f64> {
pub fn _get_disk_temp_for_component(component: &Component) -> Option<f64> {
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<f64> {
}
}
pub fn get_disk_load_for_disk(disk: &Disk) -> Result<(f64, f64, f64, f64), Box<dyn Error>> {
pub fn _get_disk_load_for_disk(disk: &Disk) -> Result<(f64, f64, f64, f64), Box<dyn Error>> {
let usage: DiskUsage = disk.usage();
// Assuming DiskUsage has these methods:

View File

@@ -16,8 +16,9 @@ pub async fn get_gpu_info() -> Result<GpuInfo, Box<dyn Error>> {
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<String> {
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<String> {
#[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()),
)
}
}