Skip to content

Refactor perfmon counter enums into oshi-common - #3164

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:perfmon-split
Apr 16, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:perfmon-split

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Move Windows performance counter enum definitions from oshi-core driver classes into oshi-common (oshi.driver.common.windows.perfmon package) so they are available to both JNA and FFM implementations.

Changes

New standalone interfaces in oshi-common:

  • PdhCounterProperty — extracted from nested interface in PerfCounterQuery
  • PdhCounterWildcardProperty — extracted from nested interface in PerfCounterWildcardQuery

New enum-only classes in oshi-common (counter definitions only, no query methods):

  • ProcessInformation, ProcessorInformation, MemoryInformation, PagingFile
  • PhysicalDisk, SystemInformation, ThreadInformation, GpuInformation

Renamed JNA driver classes in oshi-core (query methods only, import enums from oshi-common):

  • ProcessInformationJNA, ProcessorInformationJNA, MemoryInformationJNA, PagingFileJNA
  • PhysicalDiskJNA, SystemInformationJNA, ThreadInformationJNA, GpuInformationJNA

Other changes:

  • Moved instance filter constants (TOTAL_INSTANCE, NOT_TOTAL_INSTANCES, TOTAL_OR_IDLE_INSTANCES, NOT_TOTAL_INSTANCE_PATTERN) and GPU engine constants into PerfmonConstants
  • Removed nested PdhCounterProperty and PdhCounterWildcardProperty interfaces from PerfCounterQuery and PerfCounterWildcardQuery
  • Updated all callers to import enums from oshi.driver.common.windows.perfmon.* and use *JNA query classes

Motivation

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 in oshi-common which both modules depend on.

33 files changed, 774 insertions(+), 602 deletions(-)

Summary by CodeRabbit

  • Refactor
    • Windows performance counter definitions moved to a shared common layer for reuse.
    • PDH/WMI query logic separated into new JNA-backed driver implementations.
    • Consumer code updated to use the shared definitions and new JNA query entry points; observable behavior and public APIs remain unchanged.

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
@coderabbitai

coderabbitai Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f405e029-1789-48cd-ac79-7b898d9fe7b4

📥 Commits

Reviewing files that changed from the base of the PR and between 2ab5890 and ac02df2.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationJNA.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationJNA.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
📜 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)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (3)
📚 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.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.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/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/PerfCounterQuery.java
🔇 Additional comments (3)
oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java (2)

39-51: LGTM on the import migration.

Imports correctly switched to oshi.driver.common.windows.perfmon.*, matching the refactor that moved counter enum definitions into oshi-common.


173-182: Tightened bound and getDeclaringClass() usage looks good.

The <T extends Enum<T> & PdhCounterWildcardProperty> bound aligns with the shared API (e.g., HkeyPerformanceDataUtil.readPerfDataFromRegistry), and deriving the enum class via getDeclaringClass() cleanly removes the prior unchecked cast.

Minor note: counters.keySet().iterator().next() assumes the map is non-empty. For a Windows-only integration test against live counters this should hold, but if a future counter returns an empty map the failure would surface as NoSuchElementException rather than an assertion error. Not worth changing unless you've seen it flake.

oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java (1)

26-97: LGTM!

Clean refactor: the nested PdhCounterProperty interface is replaced with an import from the shared oshi.driver.common.windows.perfmon package, the instance-filter constants are re-exposed as thin delegates to PerfmonConstants (preserving source/binary compatibility for existing callers), and the tightened <T extends Enum<T> & PdhCounterProperty> bounds on queryValues/queryValuesFromPDH make the use of prop.getInstance() / prop.getCounter() at lines 106-107 type-safe without unchecked casts. Leaving queryValuesFromWMI at <T extends Enum<T>> is also correct since it only uses enum values as WMI field identifiers and never dereferences PDH metadata.


📝 Walkthrough

Walkthrough

Counter property enums and PDH/WMI counter metadata were moved into a shared common package (oshi.driver.common.windows.perfmon) and query implementations were split into JNA-backed classes (*JNA) under oshi.driver.windows.perfmon; all call sites were updated to use the new locations and interfaces.

Changes

Cohort / File(s) Summary
Common counter metadata
oshi-common/.../perfmon/PdhCounterProperty.java, PdhCounterWildcardProperty.java, PerfmonConstants.java, GpuInformation.java, MemoryInformation.java, PagingFile.java, PhysicalDisk.java, ProcessInformation.java, ProcessorInformation.java, SystemInformation.java, ThreadInformation.java
Added/relocated enum-based counter property definitions and two small interfaces plus shared Perfmon constants into oshi.driver.common.windows.perfmon. Removed any PDH query logic from these files so they only expose instance/counter metadata.
JNA query implementations
oshi-core/.../perfmon/*JNA.java (GpuInformationJNA.java, MemoryInformationJNA.java, PagingFileJNA.java, PhysicalDiskJNA.java, ProcessInformationJNA.java, ProcessorInformationJNA.java, SystemInformationJNA.java, ThreadInformationJNA.java)
Introduced/updated JNA-backed query classes providing static methods that perform PDH/WMI queries. These classes import the common enums and implement the previous query entry points removed from the common package.
PerfCounter helpers
oshi-core/.../PerfCounterQuery.java, PerfCounterWildcardQuery.java
Removed nested PDH property interfaces and switched to the new common interfaces; delegated formerly-local instance constants to PerfmonConstants; updated generic bounds to require PdhCounterProperty/PdhCounterWildcardProperty.
Call site updates
oshi-core/.../hardware/platform/windows/*.java, oshi-core/.../software/os/windows/*.java, oshi-core/.../registry/*.java, oshi-core/.../perfmon/PerfmonDriversTest.java
Updated imports and calls to use the new common property enums and the *JNA query implementations across components: CPU, GPU, disk, memory, threads, processes, registry consumers, and tests. Minor signature/generic-bound updates in tests.
Changelog
CHANGELOG.md
Added changelog entry noting the refactor moving perfmon enums into oshi-common for shared use.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

Poem

🐰
Counters hopped from place to place,
Enums now share a common space,
JNA queries lead the dance,
Drivers updated at a glance,
Rabbity cheers for tidy trace!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.40% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Refactor perfmon counter enums into oshi-common' directly and concisely summarizes the main change: moving Windows performance counter enum definitions from oshi-core to oshi-common to enable sharing between JNA and future FFM implementations.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified 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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

testWildcardCounters bounds T extends PdhCounterWildcardProperty, but line 182 assumes T is an enum (calls getEnumConstants()). Consider T extends Enum<T> & PdhCounterWildcardProperty to statically guarantee the cast and avoid @SuppressWarnings("unchecked"). Not a behavior change — just a nit aligned with how HkeyPerformanceDataUtil declares 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 enforce PdhCounterProperty at compile time.

The unchecked cast ((PdhCounterProperty) prop) at line 106 relies on callers passing an enum that implements the interface, but the signature only constrains T extends Enum<T>. Now that PdhCounterProperty is a top-level public interface in oshi-common, you could strengthen the bounds on queryValues/queryValuesFromPDH to <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

📥 Commits

Reviewing files that changed from the base of the PR and between a5f85a8 and 2ab5890.

📒 Files selected for processing (33)
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/GpuInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/MemoryInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PagingFile.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PdhCounterProperty.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PdhCounterWildcardProperty.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfmonConstants.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PhysicalDisk.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessorInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/SystemInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ThreadInformation.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/GpuInformationJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverage.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/MemoryInformationJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/PagingFileJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformationJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessorInformation.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/SystemInformationJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ThreadInformationJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemory.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-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.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PdhCounterWildcardProperty.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/MemoryInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PagingFile.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfmonConstants.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PhysicalDisk.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/GpuInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/SystemInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessorInformation.java
  • oshi-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.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStore.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformationJNA.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-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.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
  • oshi-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.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
  • oshi-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.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.java
  • oshi-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.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationJNA.java
  • oshi-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.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemory.java
  • oshi-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.java
  • oshi-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 GpuEngineProperty and GpuAdapterMemoryProperty correctly implement PdhCounterWildcardProperty, the first-element-as-instance-filter convention is preserved, and the class is properly sealed (final + private constructor). Matches the JNA consumer signatures in GpuInformationJNA.

oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PdhCounterProperty.java (1)

1-21: LGTM.

Interface contract matches the previous nested PerfCounterQuery.PdhCounterProperty and 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.

GpuAdapterMemoryProperty is correctly sourced from oshi.driver.common.windows.perfmon.GpuInformation, and the query call delegates to GpuInformationJNA.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 to GpuInformationJNA.

Both getGpuTicks() and queryAdapterMemory() 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 to ProcessInformationJNA.queryHandles() while sourcing HandleCountProperty from 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: ProcessPerformanceProperty now resolved from oshi.driver.common.windows.perfmon, and queryProcessCounters() is delegated to ProcessInformationJNA. 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 externalized oshi.driver.common.windows.perfmon.PdhCounterWildcardProperty; generic bounds on lines 71 and 199 continue to compile against the new interface (same getCounter() contract).

oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverage.java (1)

12-13: LGTM. Property enum imports moved to oshi.driver.common.windows.perfmon.*; queries delegate to SystemInformationJNA.queryProcessorQueueLength() and ProcessInformationJNA.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. ThreadPerformanceProperty now imported from oshi.driver.common.windows.perfmon.ThreadInformation, and both queryThreadCounters() overloads delegated to ThreadInformationJNA. 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 from oshi.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 and JNA driver classes; querySwapUsed / queryPageSwaps keep the same map-lookup semantics with getOrDefault(..., 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: PageSwapProperty with PAGESINPUTPERSEC / PAGESOUTPUTPERSEC (null instance, counter strings "Pages Input/sec" / "Pages Output/sec") preserves the prior contract and matches MemoryInformationJNA'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 | 🟠 Major

Add PerfmonDisabled guard for GPU counters.

GpuInformationJNA violates the established pattern: all other perfmon query classes (PagingFileJNA, MemoryInformationJNA, PhysicalDiskJNA) check a PerfmonDisabled.* flag before calling the underlying query method. This class delegates unconditionally to PerfCounterWildcardQuery.queryInstancesAndValuesFromPDH() without such a guard.

A PERF_GPU_DISABLED constant should be added to PerfmonDisabled, and both queryGpuEngineCounters() and queryGpuAdapterMemoryCounters() 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 PerfmonDisabled flag and delegate to PerfCounterWildcardQuery.

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]Property interfaces.

@codecov

codecov Bot commented Apr 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.10884% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.78%. Comparing base (a5f85a8) to head (ac02df2).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...river/windows/perfmon/ProcessorInformationJNA.java 17.64% 10 Missing and 4 partials ⚠️
...r/common/windows/perfmon/ProcessorInformation.java 82.00% 9 Missing ⚠️
.../driver/windows/perfmon/ProcessInformationJNA.java 22.22% 5 Missing and 2 partials ⚠️
...i/driver/windows/perfmon/SystemInformationJNA.java 33.33% 2 Missing and 2 partials ⚠️
...oshi/driver/windows/perfmon/GpuInformationJNA.java 0.00% 2 Missing ⚠️
...driver/windows/registry/ThreadPerformanceData.java 0.00% 2 Missing ⚠️
...ware/platform/windows/WindowsCentralProcessor.java 60.00% 2 Missing ⚠️
...shi/hardware/platform/windows/WindowsGpuStats.java 0.00% 1 Missing ⚠️
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              
Flag Coverage Δ
linux ?
macos ?
macos-latest 29.79% <0.00%> (?)
ubuntu-latest 26.42% <0.00%> (?)
windows ?
windows-latest 30.67% <72.10%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- 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
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.

1 participant