Repository navigation
Refactor perfmon counter enums into oshi-common - #3164
Conversation
Move performance counter enum definitions from oshi-core driver classes into oshi.driver.common.windows.perfmon (oshi-common) so they are available to both JNA and FFM implementations. - Extract PdhCounterProperty and PdhCounterWildcardProperty as standalone interfaces in oshi-common - Move instance filter constants (TOTAL_INSTANCE, etc.) and GPU constants into PerfmonConstants - Create enum-only classes in oshi-common: ProcessInformation, ProcessorInformation, MemoryInformation, PagingFile, PhysicalDisk, SystemInformation, ThreadInformation, GpuInformation - Rename oshi-core driver classes to *JNA, retaining only the static query methods - Remove nested interfaces from PerfCounterQuery and PerfCounterWildcardQuery - Update all callers to import enums from oshi-common
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📜 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). (7)
🧰 Additional context used🧠 Learnings (3)📚 Learning: 2026-03-29T20:03:00.830ZApplied to files:
📚 Learning: 2026-03-29T20:01:06.452ZApplied to files:
📚 Learning: 2026-04-06T04:45:51.516ZApplied to files:
🔇 Additional comments (3)
📝 WalkthroughWalkthroughCounter property enums and PDH/WMI counter metadata were moved into a shared common package ( Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java (1)
173-183: Generic bound could be tightened for the reflection lookup.
testWildcardCountersboundsT extends PdhCounterWildcardProperty, but line 182 assumesTis an enum (callsgetEnumConstants()). ConsiderT extends Enum<T> & PdhCounterWildcardPropertyto statically guarantee the cast and avoid@SuppressWarnings("unchecked"). Not a behavior change — just a nit aligned with howHkeyPerformanceDataUtildeclares the same bound.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java` around lines 173 - 183, The generic bound on testWildcardCounters should be tightened so T is statically known to be an enum that implements PdhCounterWildcardProperty; change the signature from <T extends PdhCounterWildcardProperty> to <T extends Enum<T> & PdhCounterWildcardProperty> (matching HkeyPerformanceDataUtil) so the reflective call to getEnumConstants() is type-safe and you can remove the `@SuppressWarnings`("unchecked") around the expectedSize computation where getEnumConstants() is used.oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java (1)
96-120: Optional: tighten the generic bound to enforcePdhCounterPropertyat compile time.The unchecked cast
((PdhCounterProperty) prop)at line 106 relies on callers passing an enum that implements the interface, but the signature only constrainsT extends Enum<T>. Now thatPdhCounterPropertyis a top-level public interface inoshi-common, you could strengthen the bounds onqueryValues/queryValuesFromPDHto<T extends Enum<T> & PdhCounterProperty>and drop the casts. Note this is a (source-compatible but binary-incompatible) API tightening, so it can be deferred.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java` around lines 96 - 120, The method queryValuesFromPDH currently accepts T extends Enum<T> and performs an unchecked cast to PdhCounterProperty; change the generic bound to <T extends Enum<T> & PdhCounterProperty> on queryValuesFromPDH (and similarly on any sibling queryValues method) so the compiler knows enum constants implement PdhCounterProperty and you can remove casts like ((PdhCounterProperty) prop); update references within the method that use getInstance()/getCounter() (used when calling PerfDataUtil.createCounter) accordingly and leave the rest of the logic (PerfCounterQuery.localizeIfNeeded, PerfCounterQueryHandler usage) intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationJNA.java`:
- Around line 60-63: querySystemCounters in ProcessorInformationJNA currently
calls PerfCounterQuery unguarded; add the same PerfmonDisabled.PERF_OS_DISABLED
gate used by queryProcessorCounters/queryInterruptCounters so we avoid PDH/WMI
calls when perfmon is disabled. In querySystemCounters(), check
PerfmonDisabled.PERF_OS_DISABLED at the top and return an empty Map if true;
otherwise proceed to call PerfCounterQuery.queryValues with PROCESSOR and
WIN32_PERF_RAW_DATA_PERF_OS_PROCESSOR_WHERE_NAME_TOTAL.
In
`@oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java`:
- Around line 56-57: The Javadoc for parameter propertyEnum in
PerfCounterWildcardQuery incorrectly links to PdhCounterProperty; update all
occurrences (the `@param` lines at the documented sites) to reference
oshi.driver.common.windows.perfmon.PdhCounterWildcardProperty instead so the
docs match the actual expected interface (see the casts to
PdhCounterWildcardProperty in this class around the code that performs casting
at the locations corresponding to the previous lines ~141 and ~173). Ensure each
`@link` tag uses the fully qualified PdhCounterWildcardProperty name.
---
Nitpick comments:
In `@oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java`:
- Around line 96-120: The method queryValuesFromPDH currently accepts T extends
Enum<T> and performs an unchecked cast to PdhCounterProperty; change the generic
bound to <T extends Enum<T> & PdhCounterProperty> on queryValuesFromPDH (and
similarly on any sibling queryValues method) so the compiler knows enum
constants implement PdhCounterProperty and you can remove casts like
((PdhCounterProperty) prop); update references within the method that use
getInstance()/getCounter() (used when calling PerfDataUtil.createCounter)
accordingly and leave the rest of the logic (PerfCounterQuery.localizeIfNeeded,
PerfCounterQueryHandler usage) intact.
In `@oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java`:
- Around line 173-183: The generic bound on testWildcardCounters should be
tightened so T is statically known to be an enum that implements
PdhCounterWildcardProperty; change the signature from <T extends
PdhCounterWildcardProperty> to <T extends Enum<T> & PdhCounterWildcardProperty>
(matching HkeyPerformanceDataUtil) so the reflective call to getEnumConstants()
is type-safe and you can remove the `@SuppressWarnings`("unchecked") around the
expectedSize computation where getEnumConstants() is used.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 17257639-c828-41fe-a806-85833a9cbd2b
📒 Files selected for processing (33)
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/GpuInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/MemoryInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PagingFile.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PdhCounterProperty.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PdhCounterWildcardProperty.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfmonConstants.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PhysicalDisk.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessorInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/SystemInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ThreadInformation.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/GpuInformationJNA.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverage.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/MemoryInformationJNA.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/PagingFileJNA.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskJNA.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformationJNA.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessorInformation.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationJNA.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/SystemInformationJNA.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/ThreadInformationJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtil.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemory.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java
💤 Files with no reviewable changes (1)
- oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessorInformation.java
📜 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). (7)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (8)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.
Applied to files:
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PdhCounterProperty.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PdhCounterWildcardProperty.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/MemoryInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PagingFile.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfmonConstants.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PhysicalDisk.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/GpuInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/SystemInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessorInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ThreadInformation.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.
Applied to files:
oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStore.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtil.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformationJNA.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationJNA.java
📚 Learning: 2026-04-08T00:58:10.736Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3125
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:131-133
Timestamp: 2026-04-08T00:58:10.736Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceJNA.java` and `oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java`, the `getPowerSources()` method intentionally returns a singleton list wrapping a single `getPowerSource("System Battery")` call, and the enumeration loop short-circuits after the first eligible battery pack. This matches the longstanding JNA behavior and is not a bug. A broader refactor to support zero-or-more batteries across both implementations is planned for a later date. Do not flag this as an issue.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemory.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemory.java
📚 Learning: 2026-04-11T05:51:52.684Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3139
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java:36-58
Timestamp: 2026-04-11T05:51:52.684Z
Learning: In OSHI's `LinuxGpuStats` (oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java), the abstract `nvml*` methods (nvmlGetVramUsed, nvmlGetCoreClockMhz, nvmlGetMemoryClockMhz, nvmlGetTemperature, nvmlGetPowerDraw, nvmlGetFanSpeedPercent) are contractually expected to return `-1` (long or double) on failure. The base class applies `if (val >= 0)` guards before using any NVML result and falls through to sysfs/hwmon paths when negative. Subclasses (LinuxGpuStatsJNA, LinuxGpuStatsFFM) correctly pass through the -1 sentinel unchanged — do not flag this as a missing clamp or contract violation.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/GpuInformationJNA.java
📚 Learning: 2026-04-12T19:34:59.050Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:59.050Z
Learning: The counterintuitive naming of `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` in OSHI (where a higher value means MORE performance and LESS efficiency, so P-cores get higher values than E-cores) is intentionally inherited from Microsoft's `PROCESSOR_RELATIONSHIP.EfficiencyClass` Win32 API: "A core with a higher value for the efficiency class has intrinsically greater performance and less efficiency." OSHI follows this same convention for cross-platform consistency. Do not flag P-cores being assigned higher efficiency values as a bug.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationJNA.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessorInformation.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemory.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java
📚 Learning: 2026-04-06T04:45:51.516Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.
Applied to files:
oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java
🔇 Additional comments (21)
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/GpuInformation.java (1)
5-60: LGTM — clean enum-only extraction.Both
GpuEnginePropertyandGpuAdapterMemoryPropertycorrectly implementPdhCounterWildcardProperty, the first-element-as-instance-filter convention is preserved, and the class is properly sealed (final+ private constructor). Matches the JNA consumer signatures inGpuInformationJNA.oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PdhCounterProperty.java (1)
1-21: LGTM.Interface contract matches the previous nested
PerfCounterQuery.PdhCounterPropertyand aligns with usages across the new *JNA query classes.oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java (1)
25-27: LGTM — import and call-site rewiring is consistent.
GpuAdapterMemoryPropertyis correctly sourced fromoshi.driver.common.windows.perfmon.GpuInformation, and the query call delegates toGpuInformationJNA.queryGpuAdapterMemoryCounters()without altering the downstream logic.Also applies to: 498-499
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PdhCounterWildcardProperty.java (1)
1-16: LGTM.Contract matches the previous nested interface and is correctly consumed by the new common enums (
PhysicalDiskProperty,ProcessorTickCountProperty,ThreadPerformanceProperty, GPU enums, etc.).oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.java (1)
18-20: LGTM — consistent rewiring toGpuInformationJNA.Both
getGpuTicks()andqueryAdapterMemory()correctly switch to the JNA query entrypoints while sourcing the enum types from the shared common package.Also applies to: 98-98, 314-315
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStore.java (1)
27-28: LGTM.Import and call-site updates align with the split; returned
Pair<List<String>, Map<PhysicalDiskProperty, List<Long>>>shape is preserved.Also applies to: 226-227
oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java (1)
21-22: LGTM.
getOpenFileDescriptors()correctly switches toProcessInformationJNA.queryHandles()while sourcingHandleCountPropertyfrom the shared common package. Null-handling and accumulation logic preserved.Also applies to: 273-273
oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java (1)
16-17: LGTM. Import swap and callsite rename are consistent:ProcessPerformancePropertynow resolved fromoshi.driver.common.windows.perfmon, andqueryProcessCounters()is delegated toProcessInformationJNA. The enum constants referenced (IDPROCESS, CREATINGPROCESSID, etc.) are unchanged in the moved enum.oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtil.java (1)
32-32: LGTM. Import re-pointed to the externalizedoshi.driver.common.windows.perfmon.PdhCounterWildcardProperty; generic bounds on lines 71 and 199 continue to compile against the new interface (samegetCounter()contract).oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverage.java (1)
12-13: LGTM. Property enum imports moved tooshi.driver.common.windows.perfmon.*; queries delegate toSystemInformationJNA.queryProcessorQueueLength()andProcessInformationJNA.queryIdleProcessCounters(). Return types and enum constants used (PROCESSORQUEUELENGTH,PERCENTPROCESSORTIME,ELAPSEDTIME) are preserved per the relevant code snippets.Also applies to: 87-87, 119-120
oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java (1)
17-19: LGTM.ThreadPerformancePropertynow imported fromoshi.driver.common.windows.perfmon.ThreadInformation, and bothqueryThreadCounters()overloads delegated toThreadInformationJNA. Enum constants used throughout (IDPROCESS, IDTHREAD, PERCENTUSERTIME, etc.) are unchanged.Also applies to: 115-116
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java (1)
31-40: LGTM. Enum imports are sourced fromoshi.driver.common.windows.perfmon.{ProcessorInformation,SystemInformation}, and all six perfmon callsites (querySystemCounters,queryFrequencyCounters,queryProcessorCounters,queryProcessorCapacityCounters,queryContextSwitchCounters,queryInterruptCounters) route through the JNA classes. Return signatures match per the ProcessorInformationJNA snippets.Also applies to: 222-222, 255-256, 371-372, 499-510
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemory.java (1)
20-23: LGTM. Imports correctly re-target shared enums andJNAdriver classes;querySwapUsed/queryPageSwapskeep the same map-lookup semantics withgetOrDefault(..., 0L).Also applies to: 87-87, 102-102
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/MemoryInformation.java (1)
13-43: LGTM. Clean extraction:PageSwapPropertywithPAGESINPUTPERSEC/PAGESOUTPUTPERSEC(null instance, counter strings"Pages Input/sec"/"Pages Output/sec") preserves the prior contract and matchesMemoryInformationJNA's usage. Private constructor on the holder class prevents instantiation.oshi-core/src/main/java/oshi/driver/windows/perfmon/GpuInformationJNA.java (1)
34-46:⚠️ Potential issue | 🟠 MajorAdd
PerfmonDisabledguard for GPU counters.
GpuInformationJNAviolates the established pattern: all other perfmon query classes (PagingFileJNA,MemoryInformationJNA,PhysicalDiskJNA) check aPerfmonDisabled.*flag before calling the underlying query method. This class delegates unconditionally toPerfCounterWildcardQuery.queryInstancesAndValuesFromPDH()without such a guard.A
PERF_GPU_DISABLEDconstant should be added toPerfmonDisabled, and bothqueryGpuEngineCounters()andqueryGpuAdapterMemoryCounters()should guard against it, returning empty collections when disabled.⛔ Skipped due to learnings
Learnt from: dbwiddis Repo: oshi/oshi PR: 3139 File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java:36-58 Timestamp: 2026-04-11T05:51:52.684Z Learning: In OSHI's `LinuxGpuStats` (oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java), the abstract `nvml*` methods (nvmlGetVramUsed, nvmlGetCoreClockMhz, nvmlGetMemoryClockMhz, nvmlGetTemperature, nvmlGetPowerDraw, nvmlGetFanSpeedPercent) are contractually expected to return `-1` (long or double) on failure. The base class applies `if (val >= 0)` guards before using any NVML result and falls through to sysfs/hwmon paths when negative. Subclasses (LinuxGpuStatsJNA, LinuxGpuStatsFFM) correctly pass through the -1 sentinel unchanged — do not flag this as a missing clamp or contract violation.Learnt from: dbwiddis Repo: oshi/oshi PR: 3117 File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65 Timestamp: 2026-04-05T05:40:45.797Z Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.oshi-core/src/main/java/oshi/driver/windows/perfmon/SystemInformationJNA.java (1)
22-51: LGTM!Both methods follow the established disabled-gate + delegate pattern consistently.
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.java (1)
17-92: LGTM!Clean extraction of counter-property enums; instance filters now sourced from
PerfmonConstants, preserving prior string values.oshi-core/src/main/java/oshi/driver/windows/perfmon/ThreadInformationJNA.java (1)
24-62: LGTM!Rename and import rewiring look correct.
oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformationJNA.java (1)
27-69: LGTM!All three methods correctly gate on the appropriate
PerfmonDisabledflag and delegate toPerfCounterWildcardQuery.oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ThreadInformation.java (1)
15-48: LGTM!Enum definitions and counter strings preserved verbatim from the previous location.
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessorInformation.java (1)
16-147: LGTM!Counter/instance definitions cleanly extracted into a definitions-only holder implementing the shared
PdhCounter[Wildcard]Propertyinterfaces.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3164 +/- ##
============================================
- Coverage 57.79% 57.78% -0.02%
============================================
Files 316 324 +8
Lines 17392 17394 +2
Branches 3069 3069
============================================
- Hits 10052 10051 -1
- Misses 5860 5863 +3
Partials 1480 1480
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:
|
- Add PERF_OS_DISABLED guard to querySystemCounters in ProcessorInformationJNA for consistency with sibling methods - Fix PerfCounterWildcardQuery javadoc @link references to use PdhCounterWildcardProperty instead of PdhCounterProperty - Tighten generic bounds on PerfCounterQuery.queryValues and queryValuesFromPDH to <T extends Enum<T> & PdhCounterProperty>, removing unchecked casts - Tighten PerfmonDriversTest.testWildcardCounters bound to <T extends Enum<T> & PdhCounterWildcardProperty>, use getDeclaringClass() to remove @SuppressWarnings("unchecked") - Shorten fully qualified @link references to simple names
Summary
Move Windows performance counter enum definitions from
oshi-coredriver classes intooshi-common(oshi.driver.common.windows.perfmonpackage) so they are available to both JNA and FFM implementations.Changes
New standalone interfaces in oshi-common:
PdhCounterProperty— extracted from nested interface inPerfCounterQueryPdhCounterWildcardProperty— extracted from nested interface inPerfCounterWildcardQueryNew enum-only classes in oshi-common (counter definitions only, no query methods):
ProcessInformation,ProcessorInformation,MemoryInformation,PagingFilePhysicalDisk,SystemInformation,ThreadInformation,GpuInformationRenamed JNA driver classes in oshi-core (query methods only, import enums from oshi-common):
ProcessInformationJNA,ProcessorInformationJNA,MemoryInformationJNA,PagingFileJNAPhysicalDiskJNA,SystemInformationJNA,ThreadInformationJNA,GpuInformationJNAOther changes:
TOTAL_INSTANCE,NOT_TOTAL_INSTANCES,TOTAL_OR_IDLE_INSTANCES,NOT_TOTAL_INSTANCE_PATTERN) and GPU engine constants intoPerfmonConstantsPdhCounterPropertyandPdhCounterWildcardPropertyinterfaces fromPerfCounterQueryandPerfCounterWildcardQueryoshi.driver.common.windows.perfmon.*and use*JNAquery classesMotivation
This is preparation for FFM-based perfmon implementations in
oshi-core-java25. The counter enum definitions need to be shared between JNA and FFM code paths, so they belong inoshi-commonwhich both modules depend on.33 files changed, 774 insertions(+), 602 deletions(-)
Summary by CodeRabbit