From 7cee02cfcbced4e9f81c6023038279406388c313 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 26 Sep 2026 04:09:49 +0000 Subject: [PATCH] Show the GPU temperature like Task Manager (v0.2.2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Windows: read it from the graphics kernel (D3DKMTQueryAdapterInfo with KMTQAITYPE_ADAPTERPERFDATA), the source Task Manager's "GPU Temperature" uses; WDDM 2.4+ drivers report it, integrated GPUs usually don't, and then nothing is shown - The sidebar gauge reads "37 % · 58 °C" like Task Manager's sidebar, the overview's GPU tile names the temperature too, and the performance view's facts use the same formatting - Linux already reported it (NVML, hwmon) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BeJhPzCrMkk6o5AxqSheiM --- README.md | 8 +++-- package-lock.json | 4 +-- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 3 +- src-tauri/src/gpu/mod.rs | 15 +++++++++ src-tauri/src/gpu/windows.rs | 62 +++++++++++++++++++++++++++++++++-- src-tauri/tauri.conf.json | 2 +- src/App.test.tsx | 4 ++- src/App.tsx | 8 +++-- src/lib/format.ts | 5 +++ src/test/fixtures.ts | 2 +- src/views/OverviewView.tsx | 2 ++ src/views/PerformanceView.tsx | 10 ++++-- 14 files changed, 111 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 0cafc57..3a4326d 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,9 @@ better organized and in the same night-sky design as [MoonDisk](https://github.c - **Actions**: end, force kill, end the whole process tree, suspend, resume, change priority, show the executable in the file manager - **GPU** — load per graphics card and engine (3D, video decode/encode, copy …), dedicated and - shared video memory, temperature where reported, and a **GPU column per process** (Windows: - the same performance counters Task Manager uses; Linux: NVML for NVIDIA, sysfs for AMD/Intel) + shared video memory, the GPU temperature (like Task Manager, where the driver reports it), and a + **GPU column per process** (Windows: the same performance counters and graphics kernel data + Task Manager uses; Linux: NVML for NVIDIA, sysfs for AMD/Intel) - **Performance** — CPU (total and per core), memory and swap, GPU, disk and network throughput over time with hover read-outs, volumes, and temperature sensors - **Network** — every open TCP/UDP connection and listening port, with the process holding it @@ -105,9 +106,10 @@ but aren't built, tested or released yet. | Open handles | ✓ | planned | | GPU load, memory | ✓ (NVIDIA, AMD; Intel: name, temperature) | ✓ (all vendors) | | GPU load per process | ✓ (NVIDIA) | ✓ | +| GPU temperature | ✓ | ✓ (where the driver reports it, as in Task Manager) | | Network connections | ✓ | ✓ | | Services | systemd | Service Control Manager | -| Temperatures | ✓ | – | +| CPU and other sensor temperatures | ✓ | – | ## Development diff --git a/package-lock.json b/package-lock.json index 2697a9f..ea37167 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "moontask", - "version": "0.2.1", + "version": "0.2.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "moontask", - "version": "0.2.1", + "version": "0.2.2", "license": "MIT", "dependencies": { "@tauri-apps/api": "^2.11.1", diff --git a/package.json b/package.json index c285339..e5002aa 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "moontask", "private": true, - "version": "0.2.1", + "version": "0.2.2", "description": "MoonTask – every process, calmly under the moon.", "license": "MIT", "type": "module", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 126b8f5..914233b 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1922,7 +1922,7 @@ dependencies = [ [[package]] name = "moontask" -version = "0.2.1" +version = "0.2.2" dependencies = [ "libc", "netstat2", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index e20989e..8c943cb 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "moontask" -version = "0.2.1" +version = "0.2.2" description = "MoonTask – every process, calmly under the moon. A local, open-source task manager." authors = ["MoonTask contributors"] license = "MIT" @@ -64,6 +64,7 @@ windows-sys = { version = "0.61.2", features = [ "Win32_System_Threading", "Win32_System_Diagnostics_ToolHelp", "Win32_System_Performance", + "Wdk_Graphics_Direct3D", ] } # Only for DXGI adapter names; the same version sysinfo already pulls in. windows = { version = "0.61.3", features = ["Win32_Graphics_Dxgi"] } diff --git a/src-tauri/src/gpu/mod.rs b/src-tauri/src/gpu/mod.rs index 82fae23..671ba00 100644 --- a/src-tauri/src/gpu/mod.rs +++ b/src-tauri/src/gpu/mod.rs @@ -73,6 +73,14 @@ pub(crate) fn vendor_name(vendor_id: u32) -> Option<&'static str> { } } +/// A temperature in tenths of a degree Celsius, as the Windows graphics +/// kernel reports it. 0 means "not reported"; implausible values are +/// dropped rather than shown. +#[cfg_attr(not(windows), allow(dead_code))] +pub(crate) fn deci_celsius(raw: u32) -> Option { + (1..=1500).contains(&raw).then(|| raw as f32 / 10.0) +} + /// An adapter's LUID in the form the Windows performance counters use in /// their instance names: `luid_0x00000000_0x0000C4F2`. #[cfg_attr(not(windows), allow(dead_code))] @@ -252,6 +260,13 @@ pub(crate) fn pci_ids_lookup(db: &str, vendor: u16, device: u16) -> Option EngineInstance { EngineInstance { pid, diff --git a/src-tauri/src/gpu/windows.rs b/src-tauri/src/gpu/windows.rs index c8c0201..61d467c 100644 --- a/src-tauri/src/gpu/windows.rs +++ b/src-tauri/src/gpu/windows.rs @@ -1,13 +1,22 @@ //! Windows: GPU load and memory from the performance counters Task Manager -//! uses, adapter names and sizes from DXGI. +//! uses, adapter names and sizes from DXGI, and the temperature from the +//! graphics kernel (D3DKMT), like Task Manager's "GPU Temperature". use super::GpuReading; -use super::{aggregate, luid_key, parse_adapter_instance, parse_engine_instance, vendor_name}; +use super::{ + aggregate, deci_celsius, luid_key, parse_adapter_instance, parse_engine_instance, vendor_name, +}; use crate::models::Gpu; use std::collections::HashMap; use windows::Win32::Graphics::Dxgi::{ CreateDXGIFactory1, IDXGIFactory1, DXGI_ADAPTER_FLAG_SOFTWARE, }; +use windows_sys::Wdk::Graphics::Direct3D::{ + D3DKMTCloseAdapter, D3DKMTOpenAdapterFromLuid, D3DKMTQueryAdapterInfo, D3DKMT_ADAPTER_PERFDATA, + D3DKMT_CLOSEADAPTER, D3DKMT_OPENADAPTERFROMLUID, D3DKMT_QUERYADAPTERINFO, + KMTQAITYPE_ADAPTERPERFDATA, +}; +use windows_sys::Win32::Foundation::LUID; use windows_sys::Win32::System::Performance::{ PdhAddEnglishCounterW, PdhCloseQuery, PdhCollectQueryData, PdhGetFormattedCounterArrayW, PdhOpenQueryW, PDH_FMT_COUNTERVALUE_ITEM_W, PDH_FMT_DOUBLE, PDH_HCOUNTER, PDH_HQUERY, @@ -22,6 +31,49 @@ struct Adapter { vendor: Option<&'static str>, dedicated: u64, shared: u64, + kernel: Option, +} + +/// The adapter as the graphics kernel knows it, for its performance data. +struct KernelAdapter(u32); + +impl KernelAdapter { + fn open(luid: LUID) -> Option { + let mut open = D3DKMT_OPENADAPTERFROMLUID { + AdapterLuid: luid, + hAdapter: 0, + }; + // SAFETY: `open` is a valid in/out struct for the call. + let status = unsafe { D3DKMTOpenAdapterFromLuid(&mut open) }; + (status == 0).then_some(KernelAdapter(open.hAdapter)) + } + + /// Degrees Celsius; `None` where the driver doesn't report it (WDDM + /// before 2.4, and most integrated GPUs). + fn temperature(&self) -> Option { + let mut perf = D3DKMT_ADAPTER_PERFDATA::default(); + let mut query = D3DKMT_QUERYADAPTERINFO { + hAdapter: self.0, + Type: KMTQAITYPE_ADAPTERPERFDATA, + pPrivateDriverData: (&mut perf as *mut D3DKMT_ADAPTER_PERFDATA).cast(), + PrivateDriverDataSize: std::mem::size_of::() as u32, + }; + // SAFETY: the adapter is open and `query` points at `perf`, which + // is exactly as large as the size it states. + let status = unsafe { D3DKMTQueryAdapterInfo(&mut query) }; + if status != 0 { + return None; + } + deci_celsius(perf.Temperature) + } +} + +impl Drop for KernelAdapter { + fn drop(&mut self) { + let close = D3DKMT_CLOSEADAPTER { hAdapter: self.0 }; + // SAFETY: the handle came from D3DKMTOpenAdapterFromLuid. + unsafe { D3DKMTCloseAdapter(&close) }; + } } /// An open PDH query with its three wildcard counters. @@ -174,6 +226,10 @@ fn adapters() -> Vec { vendor: vendor_name(desc.VendorId), dedicated: desc.DedicatedVideoMemory as u64, shared: desc.SharedSystemMemory as u64, + kernel: KernelAdapter::open(LUID { + LowPart: desc.AdapterLuid.LowPart, + HighPart: desc.AdapterLuid.HighPart, + }), }); } out @@ -259,7 +315,7 @@ fn to_gpu( memory_used: dedicated_used, shared_total: (a.shared > 0).then_some(a.shared), shared_used, - temperature: None, + temperature: a.kernel.as_ref().and_then(KernelAdapter::temperature), } } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 264723e..2489c6e 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "MoonTask", - "version": "0.2.1", + "version": "0.2.2", "identifier": "io.moontask.app", "build": { "beforeDevCommand": "npm run dev", diff --git a/src/App.test.tsx b/src/App.test.tsx index 1800e24..f70760a 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -141,7 +141,9 @@ describe("App", () => { render(); await screen.findByText("moonbase"); expect(screen.getByRole("region", { name: "GPU: 37.0 %" })).toBeInTheDocument(); - expect(screen.getByText(/NVIDIA GeForce RTX 4070/)).toBeInTheDocument(); + expect(screen.getByText(/NVIDIA GeForce RTX 4070 · 58 °C/)).toBeInTheDocument(); + // Like Task Manager's sidebar: load and temperature. + expect(screen.getByText("37 % · 58 °C")).toBeInTheDocument(); fireEvent.click(screen.getByRole("button", { name: /Processes/ })); const table = await screen.findByRole("treegrid", { name: "Process list" }); diff --git a/src/App.tsx b/src/App.tsx index 2a91518..266abbd 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,7 +4,7 @@ import { useMonitor } from "@/hooks/useMonitor"; import { countDescendants, processId, type SortState, type ViewMode } from "@/lib/processes"; import { ACTION_LABELS, isAllowed, needsConfirmation } from "@/lib/risk"; import { loadSettings, resolveTheme, saveSettings, type Settings } from "@/lib/settings"; -import { formatBytes, formatDuration, formatPercent } from "@/lib/format"; +import { formatBytes, formatDuration, formatPercent, formatTemperature } from "@/lib/format"; import { PRIORITY_LABELS } from "@/lib/labels"; import { primaryGpu } from "@/lib/gpu"; import type { @@ -422,7 +422,11 @@ export default function App() { {gpu && gpu.card.utilization !== null && ( )} diff --git a/src/lib/format.ts b/src/lib/format.ts index f70e755..7fe6ad1 100644 --- a/src/lib/format.ts +++ b/src/lib/format.ts @@ -76,3 +76,8 @@ export function formatFrequency(mhz: number): string { export function formatCount(n: number): string { return n.toLocaleString("en-US"); } + +/** A temperature in whole degrees Celsius, like Task Manager shows it. */ +export function formatTemperature(celsius: number): string { + return `${celsius.toFixed(0)} °C`; +} diff --git a/src/test/fixtures.ts b/src/test/fixtures.ts index 2dfdfd4..2ed0a86 100644 --- a/src/test/fixtures.ts +++ b/src/test/fixtures.ts @@ -127,7 +127,7 @@ export function snapshot(overrides: Partial = {}): Snapshot { memoryTotal: 12 * GIB, sharedUsed: GIB / 4, sharedTotal: 8 * GIB, - temperature: null, + temperature: 58, }, ], processes: PROCESSES, diff --git a/src/views/OverviewView.tsx b/src/views/OverviewView.tsx index ee26195..f3734f9 100644 --- a/src/views/OverviewView.tsx +++ b/src/views/OverviewView.tsx @@ -7,6 +7,7 @@ import { formatFrequency, formatPercent, formatRate, + formatTemperature, } from "@/lib/format"; import type { ProcessRow, Snapshot, SystemInfo } from "@/types/models"; import { primaryGpu } from "@/lib/gpu"; @@ -82,6 +83,7 @@ export function OverviewView({ value={gpu.card.utilization === null ? "–" : formatPercent(gpu.card.utilization)} sub={[ gpu.card.name, + gpu.card.temperature !== null ? formatTemperature(gpu.card.temperature) : null, gpu.card.memoryUsed !== null && gpu.card.memoryTotal !== null ? `${formatBytes(gpu.card.memoryUsed)} / ${formatBytes(gpu.card.memoryTotal)}` : null, diff --git a/src/views/PerformanceView.tsx b/src/views/PerformanceView.tsx index 65225e8..7be9888 100644 --- a/src/views/PerformanceView.tsx +++ b/src/views/PerformanceView.tsx @@ -1,6 +1,12 @@ import { useState, type ReactNode } from "react"; import type { History } from "@/lib/history"; -import { formatBytes, formatFrequency, formatPercent, formatRate } from "@/lib/format"; +import { + formatBytes, + formatFrequency, + formatPercent, + formatRate, + formatTemperature, +} from "@/lib/format"; import type { Gpu, Snapshot, SystemInfo } from "@/types/models"; import { AreaChart, Meter, Sparkline } from "@/components/charts"; import { @@ -371,7 +377,7 @@ function GpuSection({ gpu, index, history }: { gpu: Gpu; index: number; history: : formatBytes(gpu.sharedUsed ?? 0), ]); } - if (gpu.temperature !== null) facts.push(["Temperature", `${gpu.temperature.toFixed(0)} °C`]); + if (gpu.temperature !== null) facts.push(["Temperature", formatTemperature(gpu.temperature)]); if (gpu.vendor) facts.push(["Vendor", gpu.vendor]); return (