Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"] }
Expand Down
15 changes: 15 additions & 0 deletions src-tauri/src/gpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f32> {
(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))]
Expand Down Expand Up @@ -252,6 +260,13 @@ pub(crate) fn pci_ids_lookup(db: &str, vendor: u16, device: u16) -> Option<Strin
mod tests {
use super::*;

#[test]
fn deci_celsius_converts_and_drops_unreported_values() {
assert_eq!(deci_celsius(523), Some(52.3));
assert_eq!(deci_celsius(0), None);
assert_eq!(deci_celsius(u32::MAX), None);
}

fn inst(pid: u32, engine: u32, engine_type: &str) -> EngineInstance {
EngineInstance {
pid,
Expand Down
62 changes: 59 additions & 3 deletions src-tauri/src/gpu/windows.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -22,6 +31,49 @@ struct Adapter {
vendor: Option<&'static str>,
dedicated: u64,
shared: u64,
kernel: Option<KernelAdapter>,
}

/// The adapter as the graphics kernel knows it, for its performance data.
struct KernelAdapter(u32);

impl KernelAdapter {
fn open(luid: LUID) -> Option<Self> {
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<f32> {
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::<D3DKMT_ADAPTER_PERFDATA>() 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.
Expand Down Expand Up @@ -174,6 +226,10 @@ fn adapters() -> Vec<Adapter> {
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
Expand Down Expand Up @@ -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),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ describe("App", () => {
render(<App />);
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" });
Expand Down
8 changes: 6 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -422,7 +422,11 @@ export default function App() {
{gpu && gpu.card.utilization !== null && (
<SideGauge
label="GPU"
value={formatPercent(gpu.card.utilization, 0)}
value={
gpu.card.temperature === null
? formatPercent(gpu.card.utilization, 0)
: `${formatPercent(gpu.card.utilization, 0)} · ${formatTemperature(gpu.card.temperature)}`
}
fraction={gpu.card.utilization / 100}
/>
)}
Expand Down
5 changes: 5 additions & 0 deletions src/lib/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}
2 changes: 1 addition & 1 deletion src/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function snapshot(overrides: Partial<Snapshot> = {}): Snapshot {
memoryTotal: 12 * GIB,
sharedUsed: GIB / 4,
sharedTotal: 8 * GIB,
temperature: null,
temperature: 58,
},
],
processes: PROCESSES,
Expand Down
2 changes: 2 additions & 0 deletions src/views/OverviewView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions src/views/PerformanceView.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 (
Expand Down
Loading