Skip to content

obs-gpu-status: macOS GPU utilization from IOKit PerformanceStatistics - #1262

Merged
zackees merged 4 commits into
obs-rust:masterfrom
vpacher:feat/1026-macos-iokit-usage
Oct 17, 2026
Merged

zackees merged 4 commits into
obs-rust:masterfrom
vpacher:feat/1026-macos-iokit-usage

Conversation

@vpacher

@vpacher vpacher commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Fixes #1026
Refs #1025

What and why

On macOS the GPU: x% label (#1025, #1236) shows GPU: n/a, because no source reads the render GPU. This PR adds one: IOKit's PerformanceStatistics dictionary of the render GPU's IOAccelerator service, key Device Utilization %.

The issue says that the key is unverified on Apple Silicon. On an M1 Max (macOS 26.7.1), AGXAcceleratorG13X has it, together with Renderer Utilization % and Tiler Utilization %. The headline is Device Utilization %, the whole GPU. Renderer and Tiler are parts of it and do not stand in for it.

This PR:

  1. Adds iokit::device_utilization(stats) (Tier 1). It takes the dictionary's number entries. A missing key or a value outside 0 to 100 gives Unavailable.
  2. Adds accelerator_statistics(registry_id) in src/platform/macos.rs. It finds the service with IORegistryEntryIDMatching (the registry ID from obs-gpu-status: Pick the macOS render GPU by registry ID #1195), copies the dictionary with IORegistryEntryCreateCFProperty, and returns its number entries. IOKit and CoreFoundation open at run time through libloading, as the rest of the macOS code does, so the crate links no framework.
  3. Adds IokitSource to platform::usage_sources() on macOS, after NVML. Its JSON source name is iokit (usage.source in GetStats.gpuAcceleration).
  4. Adds the label's sample to the probe example.
  5. Updates docs/gpu-status.md (the source and a macOS screenshot).

Not in this PR: Windows. The PDH sampler from #1228 is not wired into usage_sources() yet (#1022, #1025).

RED → GREEN

  • RED 9f00f38: Tier 1 tests on a PerformanceStatistics dictionary captured from the M1 Max while the GPU was busy. With a stub that returns Unavailable, 2 fail: the captured dictionary (expected 25 %) and the 0 and 100 bounds. A missing key and values outside 0 to 100 pass with the stub.
  • GREEN 9384e14: 129/129 crate tests pass.
  • 2689b33 (reader and wiring): 129/129, with the source name in the existing names test. clippy -D warnings is clean for aarch64-apple-darwin and x86_64-pc-windows-msvc. Linux cannot be cross-built from macOS (soldr#2874); PR CI builds it. fmt is clean.
  • Real hardware (probe, M1 Max, macOS 26.7.1): the render adapter is RegistryId(0x100000b5b), the ID that ioreg shows for AGXAcceleratorG13X. The label sample is Some(UsageSample { percent: 13, source: Iokit }) with the Mac in normal use, and percent: 99 under a Metal compute load. ioreg shows "Device Utilization %"=99 at the same time. One sample takes about 0.6 ms (research: GPU utilization readout in the status bar, merged with the acceleration light #1004 asked for the polling cost per source).
  • Real app (docs: Worker skill: run the real app before closing a user-facing feature #948): a RelWithDebInfo build of this branch (cmake --preset macos, ENABLE_BROWSER=OFF) on the same M1 Max. PR CI skips the macOS app build for this Rust-only change, so it was built locally. The status bar showed GPU: 0% with a green dot (version 33.0.0-beta6-1520-g2689b3356), then GPU: 99% under a Metal compute load (ioreg: Device Utilization % 98). The startup log is unchanged. f932102 adds that status bar to docs/gpu-status.md:

GPU: 99% with a green dot on macOS

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (a flag change under cmake/ or build-aux/ runs the full builds) and cross-checked with clang and MSVC (not applicable: no flag changes)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (not applicable: new code, no C original)

🤖 Generated with Claude Code

vpacher and others added 4 commits October 17, 2026 17:52
…#1026)

Tier 1 tests for iokit::device_utilization on a PerformanceStatistics
dictionary captured from an M1 Max (macOS 26.7.1) while the GPU was
busy. The stub returns Unavailable: the captured dictionary and the 0
and 100 bounds fail; a missing key and values outside 0 to 100 pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…st#1026)

iokit::device_utilization takes the PerformanceStatistics number entries
and returns Device Utilization % as the whole-GPU percent. Renderer and
Tiler Utilization % are parts of the GPU and do not stand in for it. A
missing key or a value outside 0 to 100 is Unavailable. 129/129 crate
tests pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
platform::usage_sources() gets an IOKit source on macOS. It reads the
PerformanceStatistics dictionary of the IOAccelerator service with the
render adapter's registry ID (obs-rust#1195) through IORegistryEntryIDMatching
and IORegistryEntryCreateCFProperty, and gives its number entries to
iokit::device_utilization. IOKit and CoreFoundation open at run time
through libloading, as the rest of the macOS code does. The JSON source
name is "iokit".

The probe prints the label's sample. On an M1 Max (macOS 26.7.1) the
render adapter is 0x100000b5b (AGXAcceleratorG13X); the sample is 13 %
idle and 99 % under a Metal compute load, the same as ioreg, in about
0.6 ms. clippy -D warnings is clean for macOS and Windows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The status bar of this branch's app on an M1 Max under a Metal compute
load: GPU: 99% with a green dot (ioreg: Device Utilization % 98).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher marked this pull request as ready for review October 17, 2026 16:14
@vpacher
vpacher requested a review from zackees as a code owner October 17, 2026 16:14
@vpacher
vpacher marked this pull request as draft October 17, 2026 16:14
@vpacher
vpacher marked this pull request as ready for review October 17, 2026 16:31
@zackees
zackees added this pull request to the merge queue Oct 17, 2026
Merged via the queue into obs-rust:master with commit 6fe04a5 Oct 17, 2026
25 of 26 checks passed
vpacher added a commit to vpacher/obs-studio that referenced this pull request Oct 17, 2026
The features ledger line for the GPU: x% label names all three
platforms and their sources: NVML and gpu_busy_percent on Linux, IOKit
on macOS (obs-rust#1262, merged before the ledger existed) and PDH on Windows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vpacher added a commit to vpacher/obs-studio that referenced this pull request Oct 17, 2026
The features ledger line for the GPU: x% label names all three
platforms and their sources: NVML and gpu_busy_percent on Linux, IOKit
on macOS (obs-rust#1262, merged before the ledger existed) and PDH on Windows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 17, 2026
…t#1264)

* obs-gpu-status: Windows GPU: x% from PDH (RED, Refs obs-rust#1025)

Source::Pdh names the Windows PDH GPU Engine counters (obs-rust#1022) in the
JSON; the stub name is empty, so source_names fails. A Windows-only
test requires usage_sources() to ask NVML, then PDH; it fails on
Windows, where PDH is not wired in yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* obs-gpu-status: Windows GPU: x% from PDH (GREEN, Refs obs-rust#1025)

platform::usage_sources() asks the PDH GPU Engine counters (obs-rust#1022,
LUID (obs-rust#1198) through pdh_utilization, the busiest engine as Task
Manager shows it, for every vendor. NVML cannot map the LUID to a PCI
address yet, so PDH also reads NVIDIA GPUs on Windows. One sample
blocks for 100 ms on the obs-gpu-usage thread, never the UI thread.
The JSON source name is "pdh". 125/125 crate tests pass on macOS;
clippy -D warnings is clean for macOS and x86_64-pc-windows-msvc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: GPU: x% ledger line covers macOS and Windows (Refs obs-rust#1025)

The features ledger line for the GPU: x% label names all three
platforms and their sources: NVML and gpu_busy_percent on Linux, IOKit
on macOS (obs-rust#1262, merged before the ledger existed) and PDH on Windows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher deleted the feat/1026-macos-iokit-usage branch October 17, 2026 18:03
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.

obs-gpu-status: macOS GPU utilization from IOKit PerformanceStatistics

2 participants