From 3693294b1015dc418bda1401582cc6bc6767ebaa Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Mon, 23 Nov 2026 11:30:12 -0600 Subject: [PATCH] Show live thermal readings in Galaxy --- openpilot/starpilot/galaxy/evidence.py | 2 +- openpilot/starpilot/galaxy/system_monitor.py | 38 +++++++++++++++++++ .../tests/test_system_monitor_runtime.py | 30 +++++++++++++++ .../starpilot/galaxy/web/js/system-monitor.js | 14 +++---- 4 files changed, 75 insertions(+), 9 deletions(-) diff --git a/openpilot/starpilot/galaxy/evidence.py b/openpilot/starpilot/galaxy/evidence.py index 154e5d3cdf..a177af15cc 100644 --- a/openpilot/starpilot/galaxy/evidence.py +++ b/openpilot/starpilot/galaxy/evidence.py @@ -19,7 +19,7 @@ class EvidenceSnapshot(SimpleNamespace): class EvidenceSource: SERVICES = ('deviceState', 'pandaStates', 'carState', 'selfdriveState', 'carParams', 'peripheralState', - 'lateralDelay', 'lateralTorqueParameters', 'vehicleParameters') + 'lateralDelay', 'lateralTorqueParameters', 'vehicleParameters', 'chestnutGpuState') def __init__(self, messages=None, *, mono=time.monotonic_ns, boot=lambda: time.clock_gettime_ns(getattr(time, 'CLOCK_BOOTTIME', time.CLOCK_MONOTONIC))): diff --git a/openpilot/starpilot/galaxy/system_monitor.py b/openpilot/starpilot/galaxy/system_monitor.py index b606023f8d..f12b7b9ada 100644 --- a/openpilot/starpilot/galaxy/system_monitor.py +++ b/openpilot/starpilot/galaxy/system_monitor.py @@ -63,6 +63,42 @@ class SystemMonitor: except OSError: return {'usedGiB': None, 'totalGiB': None, 'freeGiB': None} + def _thermal_vitals(self): + if self.messages is None: + return {} + try: + sm = self.messages.snapshot() + if sm is None: + return {} + now = self.clock() + except (OSError, RuntimeError, AttributeError, TypeError, ValueError): + return {} + + def reading(name): + try: + stamp = int(sm.logMonoTime[name]) + age = max(now - stamp / 1e9, now - sm.recv_time[name]) + if (sm.seen[name] and sm.alive[name] and sm.valid[name] and stamp > sm.after_mono_ns and + stamp / 1e9 <= now and sm.recv_time[name] <= now and 0 <= age < 5): + return sm[name], round((5 - age) * 1000) + except (AttributeError, KeyError, TypeError, ValueError, OverflowError): + pass + return None, 0 + + def temperature(samples): + return max((round(value, 1) for value in samples if math.isfinite(value) and 0 < value <= 150), default=None) + + device, onboard_age = reading('deviceState') + if device is None: + return {} + vitals = {'cpuTempC': temperature(device.cpuTempC), 'gpuTempC': temperature(device.gpuTempC), + 'onboardMaxAgeMs': onboard_age} + if device.chestnutPresent: + gpu, gpu_age = reading('chestnutGpuState') + if gpu is not None: + vitals.update(hotspotTempC=temperature((gpu.tempC,)), maxAgeMs=gpu_age) + return vitals + def _recording_storage_usage(self): # Only C3 supports an added recording drive. A directory on userdata is # not a second drive, and mount changes must not leave a stale SSD reading. @@ -182,5 +218,7 @@ class SystemMonitor: 'storage': storage, 'recordingStorage': recording_storage, 'uptimeSeconds': uptime, 'processCount': len(rows), 'processes': rows, } + if vitals := self._thermal_vitals(): + result['vitals'] = vitals self.previous, self.cpu_previous, self.previous_time = process_ticks, cpu_now, now return result diff --git a/openpilot/starpilot/galaxy/tests/test_system_monitor_runtime.py b/openpilot/starpilot/galaxy/tests/test_system_monitor_runtime.py index f99b08731b..29b2d5581b 100644 --- a/openpilot/starpilot/galaxy/tests/test_system_monitor_runtime.py +++ b/openpilot/starpilot/galaxy/tests/test_system_monitor_runtime.py @@ -179,3 +179,33 @@ class BatteryVoltageTest(unittest.TestCase): source.snapshot=lambda:None self.assertIsNone(monitor._battery_voltage()) self.assertIsNone(SystemMonitor()._battery_voltage()) + + +class ThermalVitalsTest(unittest.TestCase): + def test_hottest_real_sensor_and_only_fresh_attached_gpu(self): + class Snapshot(SimpleNamespace): + def __getitem__(self, key): + return self.data[key] + + device = SimpleNamespace(cpuTempC=[0., 43.5, 42.8, float('nan')], gpuTempC=[41.5, 42.2], chestnutPresent=True) + names = ('deviceState', 'chestnutGpuState') + sm = Snapshot(data={'deviceState': device, 'chestnutGpuState': SimpleNamespace(tempC=72)}, + seen=dict.fromkeys(names, True), alive=dict.fromkeys(names, True), valid=dict.fromkeys(names, True), + logMonoTime=dict.fromkeys(names, 9_000_000_000), recv_time=dict.fromkeys(names, 9.), + after_mono_ns=8_000_000_000) + monitor = SystemMonitor(messages=SimpleNamespace(snapshot=lambda: sm), clock=lambda: 10.) + self.assertEqual(monitor._thermal_vitals(), {'cpuTempC': 43.5, 'gpuTempC': 42.2, 'onboardMaxAgeMs': 4000, + 'hotspotTempC': 72, 'maxAgeMs': 4000}) + device.chestnutPresent = False + self.assertNotIn('hotspotTempC', monitor._thermal_vitals()) + device.chestnutPresent = True + sm.valid['chestnutGpuState'] = False + self.assertNotIn('hotspotTempC', monitor._thermal_vitals()) + sm.valid['chestnutGpuState'] = True + sm.logMonoTime['chestnutGpuState'] = 10_000_000_001 + self.assertNotIn('hotspotTempC', monitor._thermal_vitals()) + sm.recv_time['deviceState'] = 5. + self.assertEqual(monitor._thermal_vitals(), {}) + sm.recv_time['deviceState'] = 9. + sm.after_mono_ns = 9_000_000_000 + self.assertEqual(monitor._thermal_vitals(), {}) diff --git a/openpilot/starpilot/galaxy/web/js/system-monitor.js b/openpilot/starpilot/galaxy/web/js/system-monitor.js index 1bcc603c43..000a474ced 100644 --- a/openpilot/starpilot/galaxy/web/js/system-monitor.js +++ b/openpilot/starpilot/galaxy/web/js/system-monitor.js @@ -22,14 +22,14 @@ export const SystemMonitor = { const s = this.snapshot?.uptimeSeconds return s === null || s === undefined ? "—" : `${Math.floor(s / 3600)}h ${Math.floor(s / 60) % 60}m` }, - vramUsed() { return vital(this.snapshot, "memoryUsedBytes", "memoryMaxAgeMs") }, - vramTotal() { return vital(this.snapshot, "memoryTotalBytes", "memoryMaxAgeMs") }, + cpuTemp() { return vital(this.snapshot, "cpuTempC", "onboardMaxAgeMs") }, + gpuTemp() { return vital(this.snapshot, "gpuTempC", "onboardMaxAgeMs") }, + hotspotTemp() { return vital(this.snapshot, "hotspotTempC", "maxAgeMs") }, }, methods: { number: displayNumber, feature: processFeature, state: processState, - sensor(field, budget) { return vital(this.snapshot, field, budget) }, sortBy(key) { if (this.sort === key) this.descending = !this.descending; else { this.sort = key; this.descending = ["cpu", "memoryMiB"].includes(key) } }, arrow(key) { return this.sort === key ? (this.descending ? " ↓" : " ↑") : "" }, ariaSort(key) { return this.sort !== key ? "none" : this.descending ? "descending" : "ascending" }, @@ -48,11 +48,9 @@ export const SystemMonitor = {
Processes{{ snapshot.processCount ?? '—' }}Uptime {{ uptime }}
{{ snapshot.deviceType === 'tici' ? 'Internal storage' : 'Storage' }}{{ number(snapshot.storage.usedGiB) }} GiB{{ number(snapshot.storage.totalGiB) }} GiB total · {{ number(snapshot.storage.freeGiB) }} GiB free
Recording drive{{ number(snapshot.recordingStorage.usedGiB) }} GiB{{ number(snapshot.recordingStorage.totalGiB) }} GiB total · {{ number(snapshot.recordingStorage.freeGiB) }} GiB free
-
Onboard CPU temperature{{ number(sensor('cpuTempC', 'onboardMaxAgeMs'), ' °C') }}
-
Onboard GPU temperature{{ number(sensor('gpuTempC', 'onboardMaxAgeMs'), ' °C') }}
-
eGPU hotspot temperature{{ number(sensor('hotspotTempC', 'maxAgeMs'), ' °C') }}
-
eGPU temperature{{ number(sensor('gpuEdgeTempC', 'maxAgeMs'), ' °C') }}
-
eGPU VRAM{{ vramUsed == null ? '—' : number(vramUsed / 1073741824) + ' GiB' }}{{ number(vramTotal / 1073741824) }} GiB total
+
Onboard CPU temperature{{ number(cpuTemp, ' °C') }}
+
Onboard GPU temperature{{ number(gpuTemp, ' °C') }}
+
eGPU hotspot temperature{{ number(hotspotTemp, ' °C') }}
CPU cores
{{ core.name.toUpperCase() }} {{ number(core.percent, '%') }}