From a474ff2511df90d7f7be94c0a3e652f1bc6014a7 Mon Sep 17 00:00:00 2001 From: alu Date: Mon, 10 Aug 2026 10:35:59 -0700 Subject: [PATCH] fix issue with intel cpu temperature label order --- app/proc/drivers/hwmon.go | 25 ++++++++++++++++++++----- app/proc/drivers/rapl.go | 2 +- app/proc/drivers/sys.go | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/proc/drivers/hwmon.go b/app/proc/drivers/hwmon.go index 90466d7..5f600de 100644 --- a/app/proc/drivers/hwmon.go +++ b/app/proc/drivers/hwmon.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "sort" "strconv" "strings" ) @@ -48,13 +49,10 @@ func (r *HwmonDriver) Render(term common.Terminal) error { } temps := t.([]TemperatureSensor) - term.Subheader("Temperature") + term.Subheader(fmt.Sprintf("Temperature %s", r.hwmonDir)) for _, sensor := range temps { - tempC := sensor.TempC - tempF := (tempC * 9 / 5) + 32 - // \033[K clears from cursor to end of line (prevents lingering chars) - term.Print(fmt.Sprintf("%-16s | %.2f °C (%.3f °F)", sensor.Name, tempC, tempF)) + term.Print(fmt.Sprintf("%-16s | %.2f °C", sensor.Name, sensor.TempC)) } return nil @@ -66,6 +64,11 @@ func (r *HwmonDriver) Read() (any, error) { return nil, fmt.Errorf("no temperature inputs found in %s", r.hwmonDir) } + // Sort input paths by numerical index (temp1_input, temp2_input, ... temp10_input) + sort.Slice(inputs, func(i, j int) bool { + return extractSensorIndex(inputs[i]) < extractSensorIndex(inputs[j]) + }) + temps := make([]TemperatureSensor, 0, len(inputs)) for _, inputPath := range inputs { @@ -96,3 +99,15 @@ func (r *HwmonDriver) Read() (any, error) { return temps, nil } + +// Helper to extract the integer index from "temp_input" +func extractSensorIndex(path string) int { + base := filepath.Base(path) + trimmed := strings.TrimPrefix(base, "temp") + trimmed = strings.TrimSuffix(trimmed, "_input") + idx, err := strconv.Atoi(trimmed) + if err != nil { + return 0 + } + return idx +} diff --git a/app/proc/drivers/rapl.go b/app/proc/drivers/rapl.go index c7b3d35..e51c348 100644 --- a/app/proc/drivers/rapl.go +++ b/app/proc/drivers/rapl.go @@ -36,7 +36,7 @@ func (r *RaplDriver) Render(term common.Terminal) error { } power := p.([]PowerSensor) - term.Subheader("Power") + term.Subheader("Power /sys/class/powercap/intel-rapl") for _, sensor := range power { // \033[K clears from cursor to end of line (prevents lingering chars) diff --git a/app/proc/drivers/sys.go b/app/proc/drivers/sys.go index 5236846..cd563b9 100644 --- a/app/proc/drivers/sys.go +++ b/app/proc/drivers/sys.go @@ -25,7 +25,7 @@ func (r *SysDriver) Render(term common.Terminal) error { } clock := c.([]ClockSensor) - term.Subheader("Frequency") + term.Subheader("Frequency /sys/devices/system/cpu/*/cpufreq") for _, sensor := range clock { // \033[K clears from cursor to end of line (prevents lingering chars)