Skip to content

feat(gpu): support Apple Silicon GPU usage and unified memory#12

Merged
narthur merged 3 commits into
mainfrom
feat/macos-apple-silicon-gpu
Jun 2, 2026
Merged

feat(gpu): support Apple Silicon GPU usage and unified memory#12
narthur merged 3 commits into
mainfrom
feat/macos-apple-silicon-gpu

Conversation

@narthur
Copy link
Copy Markdown
Contributor

@narthur narthur commented Jun 2, 2026

Problem

On Apple Silicon Macs, sysmon's GPU usage always showed 0%, and it displayed separate Memory and GPU Memory bars even though the CPU and GPU share a single unified memory pool.

The root cause: detectGPUVendor only knew how to read stats from nvidia-smi (NVIDIA) and rocm-smi (AMD). Neither exists on macOS, so detection fell through to gpuVendorNone → constant 0%. There was also no concept of unified memory, so the redundant two-bar memory layout was always used.

Fix

  • Apple Silicon GPU detection: added a gpuVendorApple vendor, detected on macOS by reading ioreg -r -d 1 -w 0 -c IOAccelerator. GPU usage comes from the Device Utilization % field (the same figure Activity Monitor reports) — no extra tools and no sudo required.
  • Unified memory: added a UnifiedMemory flag to SystemStats. When set, the view renders a single full-width "Unified Memory" bar instead of the misleading Memory / GPU Memory split.
  • Tests for the ioreg parser (parseAppleGPUUsage) and the unified-memory view.
  • README updated.

Testing

  • go vet, go test, and go build all pass.
  • Verified at runtime on an Apple M5: vendor detected as Apple, GPU usage reports a live non-zero value, and the unified-memory bar renders in place of the two-bar split.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added GPU monitoring support for Apple Silicon systems
    • Apple Silicon systems now display unified memory as a single full-width bar instead of separate Memory/GPU Memory bars
    • GPU statistics work automatically on Apple Silicon without additional configuration
  • Documentation

    • Updated GPU feature docs to include Apple Silicon details and unified-memory behavior
  • Tests

    • Added unit tests for Apple GPU usage parsing and unified-memory UI rendering

sysmon previously only knew how to read GPU stats from nvidia-smi and
rocm-smi. On Apple Silicon Macs neither tool exists, so GPU usage always
showed 0%, and the separate "Memory" and "GPU Memory" bars were
misleading since the CPU and GPU share one unified memory pool.

- Detect Apple Silicon's integrated GPU and read "Device Utilization %"
  from `ioreg -c IOAccelerator` (no extra tools or sudo required)
- Add a UnifiedMemory flag and render a single full-width "Unified
  Memory" bar instead of the redundant Memory / GPU Memory split
- Add tests for the ioreg parser and the unified-memory view
- Update README

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 2, 2026 14:58
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: PinePeakDigital/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 29df6f1c-1706-4afe-90c3-0c686009303b

📥 Commits

Reviewing files that changed from the base of the PR and between 09ed3a5 and f7859d9.

📒 Files selected for processing (2)
  • main.go
  • main_test.go

📝 Walkthrough

Walkthrough

This PR adds Apple Silicon GPU support to a system monitoring application. It introduces a UnifiedMemory flag to the SystemStats type, implements GPU vendor detection for Apple via ioreg, adds GPU usage parsing, conditionally renders a unified memory bar on Apple platforms instead of separate Memory/GPU Memory bars, and updates documentation.

Changes

Apple Silicon GPU Support

Layer / File(s) Summary
Type definitions and foundation
main.go
Adds runtime import, introduces UnifiedMemory bool field on SystemStats, and defines gpuVendorApple constant for Apple GPU identification.
Apple GPU vendor detection
main.go
Enhances detectGPUVendor with macOS/arm64 branch that executes ioreg and detects Apple GPU by checking for "Device Utilization %" marker.
Apple GPU usage parsing and tests
main.go, main_test.go
Implements getGPUUsageApple and parseAppleGPUUsage helpers to extract GPU utilization from ioreg output; table-driven test validates parsing across normal values, zeros, edge cases, and error conditions.
Unified memory bar rendering and tests
main.go, main_test.go
View method conditionally renders single full-width "Unified Memory" bar when UnifiedMemory is true, otherwise displays split Memory/GPU Memory bars; test confirms unified bar presence and GPU memory bar absence when enabled.
Stats collection wiring
main.go
Sets UnifiedMemory flag during stats collection based on detected GPU vendor being Apple.
Documentation updates
README.md
Enumerates platform-specific GPU data sources, notes Apple Silicon GPU stats availability via built-in ioreg, and clarifies unified-memory rendering in output format section.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding Apple Silicon GPU usage support and unified memory display to the application.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/macos-apple-silicon-gpu

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds macOS Apple Silicon GPU utilization support and updates the TUI to properly represent unified-memory systems, avoiding misleading “GPU Memory” reporting when CPU/GPU share a single pool.

Changes:

  • Detect Apple GPU on macOS and read GPU usage via ioreg (Device Utilization %) with a new parser.
  • Add SystemStats.UnifiedMemory and render a single full-width “Unified Memory” bar when enabled.
  • Add unit tests for the ioreg parser and unified-memory view; update README with platform/tooling notes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
README.md Documents Apple Silicon GPU stats via ioreg and the unified-memory UI behavior.
main.go Implements Apple GPU vendor detection/usage parsing and unified-memory-aware rendering.
main_test.go Adds tests for parseAppleGPUUsage and unified-memory view output behavior.

Comment thread main.go Outdated
narthur and others added 2 commits June 2, 2026 10:07
Intel Macs also expose IOAccelerator stats via ioreg but have
discrete/non-unified memory. Without an arch gate they would
incorrectly use the Apple GPU parser and unified-memory layout.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Auto-applied low-risk findings:
- Align the unified-memory bar to barWidth*2+spacing so its right edge
  matches the CPU/GPU row above it (was using raw m.width, 1 char wider
  on odd-width terminals).
- Accept a decimal point in the Device Utilization parser so a
  fractional reading isn't silently truncated; add a test case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@narthur narthur merged commit 93d2965 into main Jun 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants