Show live thermal readings in Galaxy

This commit is contained in:
firestar5683
2026-11-23 11:30:12 -06:00
parent 0ea99a0128
commit 3693294b10
4 changed files with 75 additions and 9 deletions
+1 -1
View File
@@ -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))):
@@ -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
@@ -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(), {})
@@ -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 = {
<section class="gx-card gx-monitor__metric"><span>Processes</span><strong>{{ snapshot.processCount ?? '—' }}</strong><small>Uptime {{ uptime }}</small></section>
<section class="gx-card gx-monitor__metric"><span>{{ snapshot.deviceType === 'tici' ? 'Internal storage' : 'Storage' }}</span><strong>{{ number(snapshot.storage.usedGiB) }} GiB</strong><small>{{ number(snapshot.storage.totalGiB) }} GiB total<span v-if="snapshot.deviceType === 'tici'"> · {{ number(snapshot.storage.freeGiB) }} GiB free</span></small></section>
<section v-if="snapshot.deviceType === 'tici' && snapshot.recordingStorage" class="gx-card gx-monitor__metric"><span>Recording drive</span><strong>{{ number(snapshot.recordingStorage.usedGiB) }} GiB</strong><small>{{ number(snapshot.recordingStorage.totalGiB) }} GiB total · {{ number(snapshot.recordingStorage.freeGiB) }} GiB free</small></section>
<section class="gx-card gx-monitor__metric"><span>Onboard CPU temperature</span><strong>{{ number(sensor('cpuTempC', 'onboardMaxAgeMs'), ' °C') }}</strong></section>
<section class="gx-card gx-monitor__metric"><span>Onboard GPU temperature</span><strong>{{ number(sensor('gpuTempC', 'onboardMaxAgeMs'), ' °C') }}</strong></section>
<section class="gx-card gx-monitor__metric"><span>eGPU hotspot temperature</span><strong>{{ number(sensor('hotspotTempC', 'maxAgeMs'), ' °C') }}</strong></section>
<section class="gx-card gx-monitor__metric"><span>eGPU temperature</span><strong>{{ number(sensor('gpuEdgeTempC', 'maxAgeMs'), ' °C') }}</strong></section>
<section class="gx-card gx-monitor__metric"><span>eGPU VRAM</span><strong>{{ vramUsed == null ? '—' : number(vramUsed / 1073741824) + ' GiB' }}</strong><small v-if="vramTotal != null">{{ number(vramTotal / 1073741824) }} GiB total</small><progress v-if="vramTotal> 0 && vramUsed != null" :value="vramUsed" :max="vramTotal" aria-label="eGPU VRAM usage"></progress></section>
<section v-if="cpuTemp != null" class="gx-card gx-monitor__metric"><span>Onboard CPU temperature</span><strong>{{ number(cpuTemp, ' °C') }}</strong></section>
<section v-if="gpuTemp != null" class="gx-card gx-monitor__metric"><span>Onboard GPU temperature</span><strong>{{ number(gpuTemp, ' °C') }}</strong></section>
<section v-if="hotspotTemp != null" class="gx-card gx-monitor__metric"><span>eGPU hotspot temperature</span><strong>{{ number(hotspotTemp, ' °C') }}</strong></section>
</div>
<details class="gx-card gx-monitor__cores"><summary>CPU cores</summary><div><span v-for="core in snapshot.cores" :key="core.name">{{ core.name.toUpperCase() }} <b>{{ number(core.percent, '%') }}</b><progress v-if="core.percent != null" :value="core.percent" max="100" :aria-label="core.name + ' usage'"></progress></span></div></details>
<div class="gx-monitor__filters"><input class="gx-field" type="search" v-model="query" aria-label="Search processes" placeholder="Search feature, process, PID or user…"><GalaxySelect class="gx-field gx-field--full" v-model="scope" aria-label="Process group"><option value="comma">Comma processes</option><option value="users">Apps and services</option><option value="all">All processes</option></GalaxySelect></div>