From 6f7573df118e78be4a7abf840e1482f86c8eb308 Mon Sep 17 00:00:00 2001 From: Diana <5275194+DianaNites@users.noreply.github.com> Date: Wed, 14 Sep 2022 01:57:42 -0700 Subject: [PATCH 1/4] More human friendly temperature sensor names This makes the names more human friendly, and possible to distinguish from each other --- src/app/data_harvester/temperature/linux.rs | 46 ++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/app/data_harvester/temperature/linux.rs b/src/app/data_harvester/temperature/linux.rs index a6b283b81..018164fc2 100644 --- a/src/app/data_harvester/temperature/linux.rs +++ b/src/app/data_harvester/temperature/linux.rs @@ -100,7 +100,51 @@ fn get_from_hwmon( let temp_label = file_path.join(name.replace("input", "label")); let temp_label = fs::read_to_string(temp_label).ok(); - let name = match (&hwmon_name, &temp_label) { + // Do some messing around to get a more sensible name for sensors + // + // - For GPUs, this will use the kernel device name, ex `card0` + // - For nvme drives, this will also use the kernel name, ex `nvme0`. + // This is found differently than for GPUs + // - For whatever acpitz is, on my machine this is now `thermal_zone0`. + // - For k10temp, this will still be k10temp, but it has to be handled special. + let human_hwmon_name = { + let device = path.join("device"); + // This will exist for GPUs but not others, this is how + // we find their kernel name + let drm = device.join("drm"); + if drm.exists() { + // This should never actually be empty + let mut gpu = String::new(); + for card in drm.read_dir()? { + let card = card?; + let name = card.file_name().to_str().unwrap_or_default().to_owned(); + if name.starts_with("card") { + gpu = name; + break; + } + } + Some(gpu) + } else { + // This little mess is to account for stuff like k10temp + // This is needed because the `device` symlink + // points to `nvme*` for nvme drives, but to PCI buses for anything else + // If the first character is alphabetic, + // its an actual name like k10temp or nvme0, not a PCI bus + let link = fs::read_link(device)? + .file_name() + .map(|f| f.to_str().unwrap_or_default().to_owned()) + .unwrap(); + if link.as_bytes()[0].is_ascii_alphabetic() { + Some(link) + } else { + // No idea why rust thinks this may have been moved + // in a previous loop iteration and needs a clone + hwmon_name.clone() + } + } + }; + + let name = match (&human_hwmon_name, &temp_label) { (Some(name), Some(label)) => format!("{}: {}", name.trim(), label.trim()), (None, Some(label)) => label.to_string(), (Some(name), None) => name.to_string(), From f2943e7a9e844b4ae7695d9a549ae241fceda98f Mon Sep 17 00:00:00 2001 From: Diana <5275194+DianaNites@users.noreply.github.com> Date: Sun, 18 Sep 2022 08:49:50 -0700 Subject: [PATCH 2/4] Keep hwmon sensor name for GPUs --- src/app/data_harvester/temperature/linux.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/app/data_harvester/temperature/linux.rs b/src/app/data_harvester/temperature/linux.rs index 018164fc2..9d4ed73bb 100644 --- a/src/app/data_harvester/temperature/linux.rs +++ b/src/app/data_harvester/temperature/linux.rs @@ -114,16 +114,20 @@ fn get_from_hwmon( let drm = device.join("drm"); if drm.exists() { // This should never actually be empty - let mut gpu = String::new(); + let mut gpu = None; for card in drm.read_dir()? { let card = card?; let name = card.file_name().to_str().unwrap_or_default().to_owned(); if name.starts_with("card") { - gpu = name; + if let Some(hwmon_name) = hwmon_name.as_ref() { + gpu = Some(format!("{} ({})", name, hwmon_name.trim())); + } else { + gpu = Some(name) + } break; } } - Some(gpu) + gpu } else { // This little mess is to account for stuff like k10temp // This is needed because the `device` symlink From 4d2fc8c1fb2f4d75a7f8722900461edb3703cdc8 Mon Sep 17 00:00:00 2001 From: Diana <5275194+DianaNites@users.noreply.github.com> Date: Sun, 18 Sep 2022 08:55:17 -0700 Subject: [PATCH 3/4] Keep hwmon sensor name for non-GPUs too --- src/app/data_harvester/temperature/linux.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/data_harvester/temperature/linux.rs b/src/app/data_harvester/temperature/linux.rs index 9d4ed73bb..4348b9cfd 100644 --- a/src/app/data_harvester/temperature/linux.rs +++ b/src/app/data_harvester/temperature/linux.rs @@ -139,10 +139,12 @@ fn get_from_hwmon( .map(|f| f.to_str().unwrap_or_default().to_owned()) .unwrap(); if link.as_bytes()[0].is_ascii_alphabetic() { - Some(link) + if let Some(hwmon_name) = hwmon_name.as_ref() { + Some(format!("{} ({})", link, hwmon_name.trim())) + } else { + Some(link) + } } else { - // No idea why rust thinks this may have been moved - // in a previous loop iteration and needs a clone hwmon_name.clone() } } From c227fcd5e527650581ebff8d9173cd654c2041c7 Mon Sep 17 00:00:00 2001 From: Diana <5275194+DianaNites@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:22:08 -0700 Subject: [PATCH 4/4] fix device path --- src/app/data_harvester/temperature/linux.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/data_harvester/temperature/linux.rs b/src/app/data_harvester/temperature/linux.rs index 4348b9cfd..5fec10595 100644 --- a/src/app/data_harvester/temperature/linux.rs +++ b/src/app/data_harvester/temperature/linux.rs @@ -108,7 +108,7 @@ fn get_from_hwmon( // - For whatever acpitz is, on my machine this is now `thermal_zone0`. // - For k10temp, this will still be k10temp, but it has to be handled special. let human_hwmon_name = { - let device = path.join("device"); + let device = file_path.join("device"); // This will exist for GPUs but not others, this is how // we find their kernel name let drm = device.join("drm");