Repository navigation
Read GPU utilization from NVML and ADL on Windows - #3686
Conversation
WindowsGpuStats.getGpuUtilization() consulted no vendor API. It ran
LibreHardwareMonitor and then a PDH engine-tick delta, while its five
sibling metrics all run NVML, then ADL, then LHM. LHM is a third-party
application that must be installed and running with its WMI provider, so
for most users the only live path was the tick delta, which needs two
samples and therefore returns the -1 sentinel on the first call.
Adds nvmlGetGpuUtilization and adlGetGpuUtilization as dispatch methods
and inserts them ahead of LHM. The tick delta stays as the last resort:
it is vendor-neutral, covers Intel iGPUs, and sums all engines rather
than just kernel execution.
NvmlUtil{JNA,FFM}.getGpuUtilization already existed and had no caller on
Windows. ADL had no equivalent, but iGPUActivityPercent was already
mapped in Adl.java and already fetched and discarded by the clock
getters, so both twins split their performance-status reader into a raw
field read plus the clock's unit conversion, leaving the new getter as
one more field of the same struct. The FFM offset 24 is the 7th of the
struct's 18 ints, consistent with the existing 72-byte allocation. JNA
picks up the ADL_ODN_CLOCK_UNITS_PER_MHZ constant its twin already had,
in place of a bare division.
The LHM block in getGpuUtilization was a duplicate of the existing
lhmFloatSensor helper and now calls it.
Adds WindowsGpuStatsTest. The class had no test at all despite being the
most source-complex of the three GpuStats implementations, and its
sibling tests exist. Also tightens LinuxGpuStatsTest: no test anywhere
pinned source priority, only source presence, so dropping an NVML branch
from a getter that also has a sysfs fallback would not have failed.
The ADL path is unverified against hardware; the offset is derived from
the struct layout rather than measured on an AMD card.
Fixes #3682
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📜 Recent review details⏰ Context from checks skipped due to timeout. (8)
🧰 Additional context used📓 Path-based instructions (5)oshi-core-ffm/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-common/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*Test.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/src/test/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (3)📚 Learning: 2026-04-11T05:51:49.185ZApplied to files:
📚 Learning: 2026-08-02T23:56:23.866ZApplied to files:
📚 Learning: 2026-08-15T15:43:29.296ZApplied to files:
🔇 Additional comments (8)
📝 WalkthroughWalkthroughWindows GPU utilization now checks NVML and ADL before LHM and PDH fallbacks. JNA and FFM ADL utilities expose GPU activity values. Linux and Windows tests cover source precedence and fallback behavior. ChangesGPU utilization sourcing
Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: ⚪ Minimal · up to The change adds Windows GPU utilization through the existing vendor APIs while preserving fallback behavior, and no actionable merge-blocking risk remains after normal checks and review. Sequence Diagram(s)sequenceDiagram
participant WindowsGpuStats
participant NVML
participant ADL
participant LHM
participant PDH
WindowsGpuStats->>NVML: Query utilization
NVML-->>WindowsGpuStats: Return value or unavailable
WindowsGpuStats->>ADL: Query adapter utilization
ADL-->>WindowsGpuStats: Return value or unavailable
WindowsGpuStats->>LHM: Read GPU Core load
LHM-->>WindowsGpuStats: Return load or unavailable
WindowsGpuStats->>PDH: Calculate engine tick delta
PDH-->>WindowsGpuStats: Return utilization or sentinel
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3686 +/- ##
============================================
- Coverage 80.30% 80.25% -0.05%
Complexity 4307 4307
============================================
Files 707 707
Lines 25520 25520
Branches 4305 4305
============================================
- Hits 20494 20482 -12
- Misses 2809 2819 +10
- Partials 2217 2219 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Fixes #3682.
WindowsGpuStats.getGpuUtilization()consulted no vendor API. It ran LibreHardwareMonitor and then a PDH engine-tick delta, while its five sibling metrics all run NVML, then ADL, then LHM:getTemperaturegetPowerDrawgetCoreClockMhzgetMemoryClockMhzgetFanSpeedPercentgetGpuUtilization(before)getGpuUtilization(after)LHM is a third-party application that must be installed and running with its WMI provider, so for most users the only live path was the tick delta, which needs two samples and therefore returns the
-1sentinel on the first call. This is the same root cause as #3681 on Linux, and less severe: it is not-1forever.The tick delta stays as the last resort. It is vendor-neutral, covers Intel iGPUs, and sums all engines rather than just kernel execution.
The AMD half
NvmlUtil{JNA,FFM}.getGpuUtilizationalready existed and simply had no caller on Windows. ADL had no equivalent — but the value was already being fetched and discarded:iGPUActivityPercentis mapped inAdl.java, and the clock getters already pull that exact struct throughADL2_OverdriveN_PerformanceStatus_Get.So both twins split their performance-status reader into a raw field read plus the clock's unit conversion, leaving the new getter as one more field of the same struct. The FFM offset of 24 is the 7th of the struct's 18 ints, consistent with the existing 72-byte allocation. JNA also picks up the
ADL_ODN_CLOCK_UNITS_PER_MHZconstant its twin already had, in place of a bare division.The LHM block inside
getGpuUtilizationwas a duplicate of the existinglhmFloatSensorhelper and now calls it.Tests
WindowsGpuStatshad no test at all, despite being the most source-complex of the threeGpuStatsimplementations (20 dispatch points, four-deep priority chains) and despite both siblings having one. This PR addsWindowsGpuStatsTest, 23 tests stubbing every dispatch point. Three of them set NVML, ADL, LHM and the PDH counters to four different values at once and assert which one answers, so the tests pin source priority and not merely that some source responds.That gap applied to Linux too: every NVML assertion in
LinuxGpuStatsTestused an emptydrmDevicePath, so dropping an NVML branch from a getter that also has a sysfs fallback would not have failed. Two tests close it — one reads a fully populated amdgpu tree behind a working NVML stub, the other reads the same fixture with NVML silent so the first cannot pass vacuously.Both were mutation-checked: removing the NVML and ADL branches from the Windows chain, and the NVML branch from Linux
getTemperature, fails 5 tests.Verification
Full gate from a clean root —
spotless:apply sortpom:sort checkstyle:check install forbiddenapis:check javadoc:javadoc -Paggregate-coverage— plus-Perror-pronefor NullAway. Green.Not verified on hardware. The NVML path mirrors the Linux one the reporter confirmed on a real NVIDIA card in #3681; the ADL path is untested against an AMD card, and its struct offset is derived from the header layout rather than measured.
Summary by CodeRabbit
New Features
Bug Fixes