Repository navigation
Hoist the Windows graphics card WMI fallback into a common base - #3544
Conversation
The two Windows GraphicsCard twins duplicated the four correlation fields, their constructor, and the whole Win32_VideoController enumeration used as a fallback when the display device registry keys yield nothing. Only which driver returns the rows actually differed. New WindowsGraphicsCard in oshi-common holds luidPrefix, lhmParent, pciBusNumber and pciBusId with protected getters, plus a static buildFromWmi. It takes the WmiResult and a CardFactory rather than running the query itself, so each twin supplies only its driver call and its own card type. WindowsGraphicsCardJNA 474 -> 383, WindowsGraphicsCardFFM 287 -> 224. Behavior changes, all adopting what JNA already did: - FIXED: the FFM WMI path lost the PDH LUID fallback. It called DxgiUtil.buildLuidPrefix directly, while FFM's own registry path and both of JNA's paths use the local buildLuidPrefix, which falls back to a PDH instance lookup when DXGI reports an empty LUID. A card enumerated through the WMI path with an empty DXGI LUID therefore got no PDH prefix on FFM, leaving its GPU Engine and Adapter Memory counters unfilterable and its metrics unavailable. FFM was inconsistent with itself here, not only with JNA. - FFM gains JNA's pre-Vista gate on this path. VersionHelpersFFM already exists and is used by WindowsBluetoothDeviceFFM and WindowsOSProcessFFM, so its absence here looks like an omission. Pre-Vista with a modern JDK is not a real combination, so this is a consistency change rather than a functional one. - The working DXGI list always starts fresh from dxgiAdapters, as JNA did; FFM previously passed in its registry path's partially consumed list. Only observable if that loop matched adapters and still returned nothing. No CHANGELOG: the LUID fix only restores metrics on a fallback path that requires the registry enumeration to have produced nothing, and the other two changes are unobservable in practice. New WindowsGraphicsCardTest stubs WmiResult, which is an interface, so the enumeration is testable without Windows. It covers ghost-device skipping, DXGI ordering beating row order, an adapter being consumed by only the first matching row, the DXGI-VRAM-over-AdapterRAM preference, vendor and device ID derivation, blank fields falling back to UNKNOWN, and the PCI correlation fields being deliberately unset on this path.
|
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 (4)
📜 Recent review details⏰ Context from checks skipped due to timeout. (8)
🧰 Additional context used🧠 Learnings (3)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-07-06T19:25:59.225ZApplied to files:
📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
🔇 Additional comments (5)
📝 WalkthroughWalkthroughIntroduces a shared Windows graphics-card base class and WMI builder, migrates JNA and FFM implementations to it, and adds tests covering DXGI matching, ordering, fallback VRAM, metadata, and parent mapping. ChangesWindows graphics-card enumeration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant WindowsGraphicsCardJNA
participant buildFromWmi
participant WMI
participant DXGI
participant CardFactory
WindowsGraphicsCardJNA->>buildFromWmi: delegate WMI fallback construction
buildFromWmi->>WMI: read video-controller rows
buildFromWmi->>DXGI: match PCI IDs and select adapter metadata
buildFromWmi->>CardFactory: construct ordered graphics cards
Possibly related PRs
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❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3544 +/- ##
==========================================
Coverage 79.08% 79.09%
- Complexity 3720 3938 +218
==========================================
Files 701 702 +1
Lines 24187 24238 +51
Branches 4019 4033 +14
==========================================
+ Hits 19128 19170 +42
- Misses 2874 2880 +6
- Partials 2185 2188 +3
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:
|
Item 9c of the cross-OS consistency audit, completing the GPU family after #3542 (NvmlUtil) and #3543 (macOS GpuStats).
What was duplicated
The two Windows
GraphicsCardtwins duplicated the four correlation fields, their constructor, and the wholeWin32_VideoControllerenumeration used as a fallback when the display device registry keys yield nothing. Only which driver returns the rows actually differed.What changed
New
WindowsGraphicsCardin oshi-common holdsluidPrefix,lhmParent,pciBusNumberandpciBusIdwith protected getters, plus a staticbuildFromWmi. It takes theWmiResultand aCardFactoryrather than running the query itself, so each twin supplies only its driver call and its own card type — the factory pattern from #3452.WindowsGraphicsCardJNA474 → 383,WindowsGraphicsCardFFM287 → 224.Behavior changes, all adopting what JNA already did
DxgiUtil.buildLuidPrefixdirectly, while FFM's own registry path and both of JNA's paths use the localbuildLuidPrefix, which falls back to a PDH instance lookup when DXGI reports an empty LUID. A card enumerated through the WMI path with an empty DXGI LUID therefore got no PDH prefix on FFM, leaving its GPU Engine and Adapter Memory counters unfilterable and its metrics unavailable. FFM was inconsistent with itself here, not only with JNA.VersionHelpersFFMalready exists and is used byWindowsBluetoothDeviceFFMandWindowsOSProcessFFM, so its absence here looks like an omission. Pre-Vista with a modern JDK is not a real combination, so this is a consistency change rather than a functional one.dxgiAdapters, as JNA did; FFM previously passed in its registry path's partially consumed list. Only observable if that loop matched adapters and still returned nothing.No CHANGELOG: the LUID fix only restores metrics on a fallback path that requires the registry enumeration to have produced nothing, and the other two are unobservable in practice.
Testing
New
WindowsGraphicsCardTest(9 cases).WmiResultis an interface, so the enumeration is testable without Windows — worth having, because this path only runs when the registry enumeration returns nothing and is otherwise near-unreachable on real hardware. It covers ghost-device skipping, DXGI ordering beating WMI row order, an adapter being consumed by only the first matching row, the DXGI-VRAM-over-AdapterRAM preference, vendor and device ID derivation, blank fields falling back toUNKNOWN, and the PCI correlation fields being deliberately unset on this path.Local gate green: spotless, checkstyle, install, forbiddenapis, javadoc, clean full-reactor build, 1407 tests.
NativeComparisonTest40/40 on macOS. Windows runtime validation is CI-only, which pr.yaml runs automatically.Summary by CodeRabbit
New Features
Bug Fixes