Skip to content

obs-gpu-status: Windows GPU utilization through PDH GPU Engine counters - #1228

Merged
zackees merged 2 commits into
masterfrom
feat/1022-pdh-gpu-engine
Oct 17, 2026
Merged

zackees merged 2 commits into
masterfrom
feat/1022-pdh-gpu-engine

Conversation

@zackees

@zackees zackees commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Refs #1022

Design

  • src/pdh.rs (platform-neutral): PdhInstance and parse_pdh_instance for pid_<n>_luid_0x<hi>_0x<lo>_phys_<n>_eng_<n>_engtype_<type> (hex case-insensitive; engtype is everything after engtype_, e.g. Compute_0). pdh_utilization(samples, luid, pid) keeps the render adapter's LUID (from obs-gpu-status: Pick the Windows render GPU by LUID #1198), and only pid when given. It sums each engine (phys, eng) over processes and takes the busiest engine, which is Task Manager's whole-adapter value. It clamps to 0..=100 and rounds; with no match it returns Unavailable.
  • src/platform/windows.rs: gpu_engine_samples() uses raw FFI to pdh.dll: PdhOpenQueryW, PdhAddEnglishCounterW(\GPU Engine(*)\Utilization Percentage), two PdhCollectQueryData calls 100 ms apart, then PdhGetFormattedCounterArrayW(PDH_FMT_DOUBLE|PDH_FMT_NOCAP100). That call is sized through PDH_MORE_DATA and retried when instances churn. Each unsafe block has a SAFETY comment. The query is closed by a Drop guard. It is exposed through platform/mod.rs's cfg_select!; other OSes return an empty Vec.
  • Tiers: Tier 1 only. This is new code with no C original, so Tiers 2 and 3 do not apply.

RED: 158e288

Tier 1 tests in tests/gpu_status/pdh.rs use captured-style instance lists: several engines, two adapters, several processes, a per-pid share, garbage names, a >100 clamp and rounding. Against the stubs, 8 failed and 2 passed (rejects_garbage and unavailable_without_match, because the stubs already return None/Unavailable).

GREEN: fad2dec

soldr cargo test -p obs-gpu-status: 97 passed (rebased onto #1224), 0 failed. ./lint passes.

Cross-compile

uv run ci/local_gate.py --lane cross passes. It runs clippy and dylint and links every test binary for x86_64-pc-windows-msvc (including gpu_status.exe) and for macOS.

Not verified

All of these need a Windows host, so this PR uses Refs, not Fixes.

@zackees
zackees force-pushed the feat/1022-pdh-gpu-engine branch from bd46ede to fad2dec Compare October 17, 2026 11:42
@zackees
zackees enabled auto-merge October 17, 2026 11:42
@zackees
zackees added this pull request to the merge queue Oct 17, 2026
Merged via the queue into master with commit 7ecdb9f Oct 17, 2026
31 checks passed
zackees added a commit that referenced this pull request Oct 17, 2026
#1228 reads the Windows GPU engine counters through PDH; the crate's
#[link(name = "pdh")] doesn't reach the final link of a Rust staticlib, so
obs64.exe failed with LNK2019 on PdhOpenQueryW and four more (master full run
39033323680). The frontend links pdh on Windows next to the staticlib.
@zackees
zackees deleted the feat/1022-pdh-gpu-engine branch October 26, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant