Repository navigation
Extract shared WindowsGpuStats logic into common base class - #3277
Conversation
Move all GPU metrics business logic (tick aggregation, utilization calculation, VRAM/shared memory queries, temperature/power/clock/fan fallback chains) into a common abstract WindowsGpuStats class. JNA and FFM subclasses implement 18 abstract dispatch methods for NVML, ADL, PDH (GpuInformation), and LHM WMI calls. Eliminates ~222 lines of duplicated logic between the two implementations. Partial fix for #3274 (Issue 1: JNA/FFM parallel implementations)
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
🧰 Additional context used🧠 Learnings (2)📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
🔇 Additional comments (18)
📝 WalkthroughWalkthroughIntroduces a shared abstract ChangesWindows GPU Stats Base Class and Adapters
Sequence Diagram(s)sequenceDiagram
participant Client
participant WindowsGpuStats as WindowsGpuStats<br/>(base)
participant JNA as WindowsGpuStatsJNA
participant NvmlUtil as NvmlUtilJNA
participant AdlUtil as AdlUtilJNA
participant LhmSensor as LhmSensorJNA
Client->>WindowsGpuStats: getTemperature()
WindowsGpuStats->>WindowsGpuStats: checkOpen()
WindowsGpuStats->>WindowsGpuStats: isNvmlAvailable()?
alt NVML available
WindowsGpuStats->>JNA: nvmlGetTemperature(device)
JNA->>NvmlUtil: getTemperature(device)
NvmlUtil-->>JNA: temp value
JNA-->>WindowsGpuStats: temp value
else ADL available
WindowsGpuStats->>JNA: adlGetTemperature(index)
JNA->>AdlUtil: getTemperature(index)
AdlUtil-->>JNA: temp value
JNA-->>WindowsGpuStats: temp value
else LHM fallback
WindowsGpuStats->>WindowsGpuStats: lhmFloatSensor("Temperature")
WindowsGpuStats->>LhmSensor: queryLhmSensors()
LhmSensor-->>WindowsGpuStats: sensor values
WindowsGpuStats-->>WindowsGpuStats: extract by name
end
WindowsGpuStats-->>Client: temperature or -1
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 #3277 +/- ##
=========================================
Coverage 74.75% 74.75%
Complexity 73 73
=========================================
Files 410 410
Lines 15894 15894
Branches 2534 2534
=========================================
Hits 11882 11882
- Misses 2549 2550 +1
+ Partials 1463 1462 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Addresses Issue 1 (JNA ↔ FFM Parallel Implementations) from #3274 for the WindowsGpuStats class (222 lines duplicated).
Changes
oshi-common/.../WindowsGpuStats.java(483 lines) — all business logic for GPU metricsWindowsGpuStatsJNA(311→121 lines) — native dispatch onlyWindowsGpuStatsFFM(287→121 lines) — native dispatch onlyPattern
The common base class holds all GPU metrics logic:
Subclasses implement 18 abstract methods that dispatch to platform-specific utilities:
queryGpuEngineCounters(),queryGpuAdapterMemoryCounters()queryLhmSensors()isNvmlAvailable(),nvmlFindDevice(),nvmlFindDeviceByName(),nvmlGet*()isAdlAvailable(),adlFindAdapterIndex(),adlGet*()Testing
Notes
dActive < 0 || dIdle < 0) ingetGpuUtilization()that JNA lacked. The common class includes this guard (safer behavior).Summary by CodeRabbit
New Features
Refactor