Skip to content

Complete FFM perfmon driver migration - #3170

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:migrate-all-perfmon-drivers
Apr 18, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:migrate-all-perfmon-drivers

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Completes the FFM perfmon driver migration by implementing all remaining FFM perfmon drivers, adding PDH vs WMI comparison tests, and adding JNA vs FFM benchmark comparison tests.

New FFM Drivers

  • GpuInformationFFM — PDH-only (no WMI fallback), queries GPU engine running time
  • PhysicalDiskFFM — PDH with WMI fallback for physical disk counters
  • ThreadInformationFFM — PDH with WMI fallback, custom filter support for thread counters
  • ProcessInformationFFM — Added queryProcessCounters method for per-process PDH counters
  • ProcessorInformationFFM — All 5 methods: tick values, interrupts, DPCs, frequency, context switches

_Base Counter Fix

PDH does not have counters with _Base suffix — those are WMI-specific. When a property name ends with _Base, the FFM code now:

  1. Strips the suffix when building the PDH counter path
  2. Reads SecondValue from the raw counter struct instead of FirstValue

This mirrors the existing JNA behavior in PerfCounter/PerfCounterQueryHandler.

PerfCounterWildcardQueryFFM Enhancements

  • Added queryInstancesAndValuesFromPDH for PDH-only queries (used by GpuInformationFFM)
  • Added customFilter overloads for all query methods

Test Changes

PerfmonDriversTest (JNA) / PerfmonDriversFFMTest (FFM)

  • PDH vs WMI structural comparison for wildcard counters (instance count consistency, map size)
  • Non-wildcard aggregate counter value comparison (closeTo 1.0 with 0.5 tolerance)
  • Empty map guard for wildcard structural assertions

PerfmonComparisonTest (JNA vs FFM benchmark)

  • Side-by-side comparison of all perfmon drivers between JNA and FFM implementations
  • Instance list comparison using order-independent matching (FFM may enumerate in reverse order)
  • Value comparison with tolerance for volatile counters
  • GPU engine instance count comparison

NativeComparisonTest

  • Relaxed process.upTime assertion: max(10%, 300ms) tolerance to account for memoization (300ms default TTL)
  • Relaxed process.residentMemory tolerance from 0.25 to 0.75

Summary by CodeRabbit

  • New Features

    • Completed Windows perfmon FFM driver migration; added GPU engine & adapter memory and additional disk/process/thread/processor counters.
  • Improvements

    • Wildcard counter support for base-suffixed metrics and optional custom filters; smarter PDH/WMI fallback behavior and improved logging; relaxed tolerances for uptime, frequency, and memory comparisons.
  • Tests

    • Large Windows-only test suites added/expanded to cross-validate PDH, WMI, JNA and FFM results across many counters.

@coderabbitai

coderabbitai Bot commented Apr 18, 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: f7bb265e-6ba7-4b9e-9097-39a2686995eb

📥 Commits

Reviewing files that changed from the base of the PR and between 9750868 and 9b4cb19.

📒 Files selected for processing (12)
  • CHANGELOG.md
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java
✅ Files skipped from review due to trivial changes (4)
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.java
🚧 Files skipped from review as they are similar to previous changes (5)
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.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). (6)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.
📚 Learning: 2026-04-17T23:56:43.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
📚 Learning: 2026-04-18T03:18:03.725Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.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-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.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-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
📚 Learning: 2026-04-17T23:52:52.926Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java:47-58
Timestamp: 2026-04-17T23:52:52.926Z
Learning: In `oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java`, the `stopDaemon()` / `startDaemon()` lifecycle pattern (both `public synchronized` instance methods on the same monitor) is intentionally safe: `stopDaemon()` sets `loadAvgThread = null` immediately after `interrupt()`, and `startDaemon()` checks `loadAvgThread != null` under the same lock. Since both methods are synchronized on `this`, they cannot run concurrently, so no double-sampler race is possible. Do not flag this pattern as a race condition.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
🔇 Additional comments (7)
oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java (3)

9-9: Looks good: non-wildcard PDH/WMI comparisons are now explicit.

The tests first validate full counter-map coverage, then compare values through the shared tolerance helper. This keeps failures easier to diagnose by source.

Also applies to: 42-42, 63-68, 73-79, 100-105, 141-146, 160-167


84-87: Looks good: wildcard results are validated without over-matching instances.

The helper now rejects empty wildcard results and validates per-source instance/value alignment, while avoiding brittle PDH-vs-WMI instance-list equality. Based on learnings, queryWildcardCounters intentionally aborts and returns an empty Pair when any addEnglishCounter call fails to preserve instance/value alignment.

Also applies to: 92-95, 110-113, 118-135, 151-155, 172-182, 184-194


197-213: Looks good: the tolerance helper is symmetric and guarded.

Using absolute min/max makes the PDH/WMI comparison order-independent, and the all-zero guard avoids noisy divide-by-zero cases.

oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java (2)

70-84: Guard logic correctly mirrors the JNA customFilter contract.

The !Util.isBlank(customFilter) || !FAILED_QUERY_CACHE.contains(perfObject) condition correctly lets non-blank filters bypass the failed-query cache (always retry PDH), and the cache is only updated on blank-filter failures — matching the JNA reference in oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java:83-103. Note that the FFM version intentionally omits the PERF_DISABLE_ALL_ON_FAILURE global-disable path present in JNA, which is consistent with the prior FFM design and confirmed in the PR summary.


147-149: Useful WMI diagnostic; no-op safe.

Adding a debug log when WMI returns no rows aids troubleshooting the PDH→WMI fallback path without affecting the subsequent loop, which is already a no-op for empty rows.

oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java (2)

43-50: Win7+ vs. legacy dispatch looks correct.

The ternary correctly routes to PROCESSOR_INFORMATION + WIN32_PERF_RAW_DATA_COUNTERS_PROCESSOR_INFORMATION_WHERE_NOT_NAME_LIKE_TOTAL on Win7+ and to PROCESSOR + WIN32_PERF_RAW_DATA_PERF_OS_PROCESSOR_WHERE_NAME_NOT_TOTAL on older systems, aligning with the constants defined in oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfmonConstants.java.


67-70: The implementation is consistent: both queryProcessorCapacityCounters() and queryFrequencyCounters() lack Win7+ gating in both JNA and FFM, unlike queryProcessorCounters() which gates on IS_WIN7_OR_GREATER. This mirrors the JNA implementation and appears intentional.


📝 Walkthrough

Walkthrough

Adds FFM-backed Windows perfmon query helpers (GPU, disk, process, processor, thread), enhances PDH/WMI wildcard query infrastructure with custom-filter and _Base handling, and adds/updates Windows-only cross-validation tests comparing PDH vs WMI and JNA vs FFM.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added #3170 entry under 6.12.0 (in progress) documenting completion of Windows FFM perfmon migration and tests.
New FFM driver classes
oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java, oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.java, oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.java
Added thread-safe utility classes exposing wildcard PDH queries for GPU engine/adapter memory, physical disk, and thread counters (including thread-specific query overload).
Extended FFM drivers
oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java, oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
Added queryProcessCounters() and processor query methods (queryProcessorCounters(), queryProcessorCapacityCounters(), queryFrequencyCounters()), with Windows-version gating for processor counters.
Wildcard PDH/WMI infra
oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java, oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
Added overloads accepting customFilter; PDH-first with WMI fallback and conditional failed-PDH caching; detect _Base suffix and read SecondValue for base counters; logging adjustments and new PDH read semantics.
Tests — FFM drivers
oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.java
New Windows-only JUnit tests validating PDH (FFM) vs WMI query results across many counter groups with structural and value-tolerance assertions (version-gated where applicable).
Tests — comparisons & tweaks
oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java, oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java, oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java
Added JNA vs FFM comparison tests; loosened tolerances and changed uptime assertion in NativeComparisonTest; refactored PerfmonDriversTest to capture PDH/WMI maps and add ratio-based cross-source assertions.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Test
  participant PerfCounterWildcardQueryFFM as FFM_Query
  participant PerfDataUtilFFM as PerfUtil
  participant PDH
  participant WMI
  participant FAILED_CACHE

  Test->>FFM_Query: request query(propertyEnum, perfObject, customFilter?)
  FFM_Query->>PerfUtil: queryInstancesAndValuesFromPDH(..., customFilter)
  PerfUtil->>PDH: add counters and collect raw values (handle _Base -> SecondValue)
  alt PDH returns values
    PDH-->>PerfUtil: values
    PerfUtil-->>FFM_Query: parsed instances & map
    alt customFilter is blank
      FFM_Query-->>FAILED_CACHE: (no failure) ensure PDH success keeps perfObject enabled
    end
    FFM_Query-->>Test: return PDH results
  else PDH fails or returns empty
    PDH-->>PerfUtil: failure/empty
    PerfUtil-->>FFM_Query: PDH failure
    alt customFilter is blank
      FFM_Query->>FAILED_CACHE: add perfObject (disable future PDH attempts)
    end
    FFM_Query->>WMI: fallback query via PerfDataUtilFFM -> WMI
    WMI-->>FFM_Query: rows (may be empty)
    FFM_Query-->>Test: return WMI results
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped through counters, PDH then WMI,
probing GPUs, disks, threads with glee.
Wildcards and _Base values in my stash,
JNA and FFM now tally and clash—
carrots for tests, a perfmon jubilee! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.63% 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 title 'Complete FFM perfmon driver migration' directly and accurately reflects the main objective of the changeset, which is to complete the migration of Windows perfmon drivers to the FFM native layer.

✏️ 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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java (1)

78-128: ⚠️ Potential issue | 🟠 Major

Non-wildcard queryCounters must strip _Base suffix and read SecondValue like the wildcard path.

The legacy JNA PerfCounter constructor strips _Base and flips baseCounter=true unconditionally for both wildcard and non-wildcard counters. The wildcard path queryWildcardCounters correctly implements this via BASE_SUFFIX + readRawCounterValue(..., isBase[p-1]). However, queryCounters at line 94 feeds prop.getCounter() directly into counterPath(...) and hard-codes readRawCounterValue(..., false) at line 111.

The problem is real: ProcessorInformation.TIMESTAMP_SYS100NS("% Processor Time_Base"), ProcessorInformation.PERCENTPROCESSORUTILITY_BASE("% Processor Utility_Base"), and GpuInformation.RUNNING_TIME_BASE("Running Time_Base") are existing non-wildcard enums with _Base suffixes. PDH will fail to add these counters (PDH has no counter called "% Processor Time_Base"), causing them to silently fall back to 0 or be absent, diverging from JNA behavior.

Apply the same transformation for consistency and correctness:

Suggested fix
                 for (T prop : props) {
-                    String path = counterPath(perfObject, prop.getInstance(), prop.getCounter());
+                    String counterName = prop.getCounter();
+                    boolean base = counterName.endsWith(BASE_SUFFIX);
+                    if (base) {
+                        counterName = counterName.substring(0, counterName.length() - BASE_SUFFIX.length());
+                    }
+                    String path = counterPath(perfObject, prop.getInstance(), counterName);
                     try {
-                        counterHandles.put(prop, addEnglishCounter(arena, query, path));
+                        counterHandles.put(prop, addEnglishCounter(arena, query, path));
+                        if (base) {
+                            baseProps.add(prop);
+                        }
                     } catch (Throwable t) {
                         ...
                     }
                 }
                 ...
                 for (var entry : counterHandles.entrySet()) {
                     try {
-                        valueMap.put(entry.getKey(), readRawCounterValue(arena, entry.getValue(), false));
+                        valueMap.put(entry.getKey(),
+                                readRawCounterValue(arena, entry.getValue(), baseProps.contains(entry.getKey())));
                     ...
                 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`
around lines 78 - 128, queryCounters currently uses prop.getCounter() directly
and always calls readRawCounterValue(..., false), which fails for non-wildcard
counters that end with BASE_SUFFIX; update queryCounters (and the loop that
builds counterHandles) to detect if prop.getCounter() endsWith BASE_SUFFIX,
strip that suffix before calling counterPath, record a boolean "isBase" per prop
(or store the base flag alongside the MemorySegment in counterHandles), and when
reading values call readRawCounterValue(arena, entry.getValue(),
isBaseForThatProp) so behavior matches queryWildcardCounters and handles _Base
counters the same way.
🧹 Nitpick comments (2)
oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java (1)

70-84: Cache-then-customFilter interaction may block valid custom-filter PDH queries.

The FAILED_QUERY_CACHE.contains(perfObject) gate at line 72 is shared across all callers regardless of customFilter. If an earlier call with the default filter fails and records perfObject in the cache (line 80), a subsequent caller passing a distinct customFilter (e.g., ThreadInformationFFM.queryThreadCounters(name, threadNum) using procName + "/*") will skip PDH entirely and go straight to WMI — even though a narrower filter might have succeeded.

This is usually benign because a default-filter failure typically means the PDH object itself is unavailable, but worth calling out since the rationale for guarding the cache write on customFilter being blank (correct) is not symmetrically applied to the read.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java`
around lines 70 - 84, The cache read currently ignores the customFilter and
skips PDH for all callers if FAILED_QUERY_CACHE contains perfObject; adjust
queryInstancesAndValues so the FAILED_QUERY_CACHE.contains(perfObject) check is
only consulted when customFilter is blank (i.e., mirror the existing write
guard), so callers passing a non-blank customFilter still attempt
queryInstancesAndValuesFromPDH; keep the existing behavior of adding perfObject
to FAILED_QUERY_CACHE only when Util.isBlank(customFilter) and PDH returns no
instances, and continue to fall back to queryInstancesAndValuesFromWMI when PDH
fails.
oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java (1)

177-183: Consider asserting "both empty or both non-empty" for GPU engines rather than strict size equality.

GPU engine instances are transient (\GPU Engine(*)\Running Time instances come and go as workloads start/stop between the two sampling calls). Strict isEqualTo(jna.getA().size()) can flake on busy systems even when both backends are functioning correctly. Consider allowing a small delta, or just assert that both are either empty or both non-empty (which still proves FFM and JNA produce structurally comparable results).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`
around lines 177 - 183, The current testGpuEngineCounters asserts strict size
equality between ffm.getA() and jna.getA(), which can flake due to transient GPU
engine instances; change the assertion to verify that both lists are either
empty or both non-empty (or allow a small delta) instead of exact equality.
Locate the testGpuEngineCounters method and the variables jna and ffm returned
from GpuInformationJNA.queryGpuEngineCounters() and
GpuInformationFFM.queryGpuEngineCounters(), then replace the isEqualTo(...)
assertion with a check like comparing emptiness flags (e.g.,
assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())) or an
equivalent small-delta size check to avoid flakes.
🤖 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-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`:
- Around line 213-226: In assertWithinRatio, the one-zero branch currently
checks the non-zero value against a hardcoded 1.0 and uses mismatched format
placeholders; change that branch (the if (expected == 0 || actual == 0) block in
assertWithinRatio) to compare the non-zero absolute value against the provided
ratio (e.g., assertThat(nonZero).as(...).isLessThanOrEqualTo(ratio)) instead of
1.0, and fix the .as(...) message to include the correct placeholders/arguments
(include description and nonZero) so the error message prints correctly.

In
`@oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.java`:
- Around line 185-196: The helper assertWildcardStructure currently accepts an
empty Pair as valid; update it to reject empty wildcard query results by failing
when either the instance list is empty or the counter map is empty—i.e., in
assertWildcardStructure (method name) check that instanceCount > 0 and counters
is not empty (and assert/fail with a clear message referencing the wildcard
query string s) before performing the per-counter size checks and expectedSize
assertion; this ensures the empty Pair returned by queryWildcardCounters (which
signals aborted wildcard setup) is treated as a test failure.

In `@oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java`:
- Around line 184-195: The helper assertWildcardStructure currently treats an
empty result as a pass; update assertWildcardStructure(String s,
Pair<List<String>, Map<T, List<Long>>> counterData) to reject empty wildcard
query results by asserting that counterData.getA() (instance list) is not empty
and counterData.getB() (counters map) is not empty before proceeding; this
ensures queryWildcardCounters failures (which return an empty Pair when
addEnglishCounter fails) are surfaced rather than skipping the map-size check,
and keeps the existing logic that computes expectedSize from the first key's
getDeclaringClass().getEnumConstants().

---

Outside diff comments:
In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`:
- Around line 78-128: queryCounters currently uses prop.getCounter() directly
and always calls readRawCounterValue(..., false), which fails for non-wildcard
counters that end with BASE_SUFFIX; update queryCounters (and the loop that
builds counterHandles) to detect if prop.getCounter() endsWith BASE_SUFFIX,
strip that suffix before calling counterPath, record a boolean "isBase" per prop
(or store the base flag alongside the MemorySegment in counterHandles), and when
reading values call readRawCounterValue(arena, entry.getValue(),
isBaseForThatProp) so behavior matches queryWildcardCounters and handles _Base
counters the same way.

---

Nitpick comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`:
- Around line 177-183: The current testGpuEngineCounters asserts strict size
equality between ffm.getA() and jna.getA(), which can flake due to transient GPU
engine instances; change the assertion to verify that both lists are either
empty or both non-empty (or allow a small delta) instead of exact equality.
Locate the testGpuEngineCounters method and the variables jna and ffm returned
from GpuInformationJNA.queryGpuEngineCounters() and
GpuInformationFFM.queryGpuEngineCounters(), then replace the isEqualTo(...)
assertion with a check like comparing emptiness flags (e.g.,
assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())) or an
equivalent small-delta size check to avoid flakes.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java`:
- Around line 70-84: The cache read currently ignores the customFilter and skips
PDH for all callers if FAILED_QUERY_CACHE contains perfObject; adjust
queryInstancesAndValues so the FAILED_QUERY_CACHE.contains(perfObject) check is
only consulted when customFilter is blank (i.e., mirror the existing write
guard), so callers passing a non-blank customFilter still attempt
queryInstancesAndValuesFromPDH; keep the existing behavior of adding perfObject
to FAILED_QUERY_CACHE only when Util.isBlank(customFilter) and PDH returns no
instances, and continue to fall back to queryInstancesAndValuesFromWMI when PDH
fails.
🪄 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: 21a84c46-7b1c-4df9-a2db-6355be7b2d3f

📥 Commits

Reviewing files that changed from the base of the PR and between ae23939 and c57b987.

📒 Files selected for processing (12)
  • CHANGELOG.md
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.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). (8)
  • GitHub Check: Codacy Static Code Analysis
  • 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: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (9)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.
📚 Learning: 2026-04-17T23:56:43.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.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-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.java
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
📚 Learning: 2026-04-17T23:52:52.926Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java:47-58
Timestamp: 2026-04-17T23:52:52.926Z
Learning: In `oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java`, the `stopDaemon()` / `startDaemon()` lifecycle pattern (both `public synchronized` instance methods on the same monitor) is intentionally safe: `stopDaemon()` sets `loadAvgThread = null` immediately after `interrupt()`, and `startDaemon()` checks `loadAvgThread != null` under the same lock. Since both methods are synchronized on `this`, they cannot run concurrently, so no double-sampler race is possible. Do not flag this pattern as a race condition.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.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-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.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-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
🔇 Additional comments (8)
CHANGELOG.md (1)

34-34: LGTM.

The changelog entry accurately captures the perfmon FFM migration and comparison-test coverage.

oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (1)

105-105: LGTM.

The relaxed tolerances and symmetric uptime comparison fit volatile JNA/FFM snapshot timing.

Also applies to: 353-359

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

32-40: LGTM.

The FFM process-counter entry point mirrors the existing JNA perfmon query shape and uses the shared process filter.

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

1-36: LGTM.

The new FFM physical-disk perfmon utility is minimal and consistent with the existing JNA driver pattern.

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

1-47: LGTM.

The new GPU perfmon FFM helper is consistent with the PDH-only counter strategy and keeps the API surface focused.

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

33-49: LGTM.

The Win7+ branching and new processor wildcard query methods align with the existing JNA implementation pattern.

Also applies to: 62-70, 82-90

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

47-62: LGTM — mirrors the JNA ThreadInformation behavior.

The toLowerCase(Locale.ROOT), PDH wildcard (procName + "/*") vs. WMI WHERE Name LIKE ".../_%" split, and fallback when the thread-number-filtered query yields no instances all align with the existing non-FFM driver's contract. Passing the WHERE clause as the perfWmiClass suffix and the PDH filter as a separate customFilter correctly uses the new PerfCounterWildcardQueryFFM overload.

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

147-149: LGTM — helpful diagnostic.

Logging when WMI returns zero rows makes silent empty-result cases easier to debug without changing behavior.

@codecov

codecov Bot commented Apr 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.00000% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.42%. Comparing base (9f0ed05) to head (9b4cb19).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...i/driver/windows/perfmon/ThreadInformationFFM.java 12.50% 7 Missing ⚠️
.../platform/windows/PerfCounterWildcardQueryFFM.java 40.00% 4 Missing and 2 partials ⚠️
...va/oshi/util/platform/windows/PerfDataUtilFFM.java 77.27% 3 Missing and 2 partials ⚠️
...river/windows/perfmon/ProcessorInformationFFM.java 66.66% 1 Missing and 1 partial ⚠️
...oshi/driver/windows/perfmon/GpuInformationFFM.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3170      +/-   ##
============================================
+ Coverage     57.97%   58.42%   +0.45%     
============================================
  Files           333      336       +3     
  Lines         17655    17693      +38     
  Branches       3122     3130       +8     
============================================
+ Hits          10235    10338     +103     
+ Misses         5897     5826      -71     
- Partials       1523     1529       +6     
Flag Coverage Δ
linux 26.10% <0.00%> (+1.24%) ⬆️
macos 29.30% <0.00%> (-0.06%) ⬇️
windows 32.75% <58.00%> (+0.28%) ⬆️

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.

@dbwiddis
dbwiddis force-pushed the migrate-all-perfmon-drivers branch from c57b987 to 9750868 Compare April 18, 2026 03:09

@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

🤖 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-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`:
- Around line 177-183: The testGpuEngineCounters currently only checks that both
returned lists are empty-or-not-empty, which misses mismatched instance counts;
after calling GpuInformationJNA.queryGpuEngineCounters() and
GpuInformationFFM.queryGpuEngineCounters() (variables jna and ffm), change the
assertion so that when both lists are non-empty you assert they match (e.g.,
assertThat(ffm.getA()).containsExactlyInAnyOrderElementsOf(jna.getA()) or at
minimum assertThat(ffm.getA().size()).isEqualTo(jna.getA().size())); keep the
existing empty-vs-nonempty check but add this tighter equality for the instance
list returned by testGpuEngineCounters.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`:
- Around line 290-299: The customFilter branch in queryWildcardCounters uses the
provided string verbatim while the default uses
props[0].getCounter().toLowerCase(Locale.ROOT), causing case-mismatch with
enumInstances which lowercases instance names before Util.wildcardMatch; fix by
normalizing customFilter to lower case (use Locale.ROOT) when computing
instanceFilter (same place as props[0].getCounter().toLowerCase(Locale.ROOT)),
so instanceFilter is always lowercased regardless of whether it came from
propertyEnum or the caller; update any related javadoc for
PerfCounterWildcardQueryFFM.queryInstancesAndValuesFromPDH to document the
lowercase matching if you prefer documenting instead of normalizing.
🪄 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: 6cec6b32-c744-499d-aa9d-545a15107771

📥 Commits

Reviewing files that changed from the base of the PR and between c57b987 and 9750868.

📒 Files selected for processing (12)
  • CHANGELOG.md
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java
✅ Files skipped from review due to trivial changes (3)
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • CHANGELOG.md
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.java
🚧 Files skipped from review as they are similar to previous changes (5)
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.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 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.
📚 Learning: 2026-04-17T23:56:43.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.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-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.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-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
📚 Learning: 2026-04-17T23:52:52.926Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java:47-58
Timestamp: 2026-04-17T23:52:52.926Z
Learning: In `oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java`, the `stopDaemon()` / `startDaemon()` lifecycle pattern (both `public synchronized` instance methods on the same monitor) is intentionally safe: `stopDaemon()` sets `loadAvgThread = null` immediately after `interrupt()`, and `startDaemon()` checks `loadAvgThread != null` under the same lock. Since both methods are synchronized on `this`, they cannot run concurrently, so no double-sampler race is possible. Do not flag this pattern as a race condition.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
🔇 Additional comments (2)
oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java (1)

213-227: Prior concern on assertWithinRatio appears resolved; noting residual edge case for cumulative counters.

The format specifiers and ratio usage are now correct. One residual semantic concern (not re-raising as an issue): for CUMULATIVE_RATIO paths (PageSwap, System, Interrupts, ContextSwitch), if one backend briefly reports 0 while the other reports any real counter tick value, nonZero <= 0.5 will fail. In practice both PDH samples are taken near-simultaneously, so this is unlikely to flake. Worth monitoring if CI flakiness appears.

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

24-46: LGTM.

Clean delegation to PerfCounterWildcardQueryFFM.queryInstancesAndValuesFromPDH (PDH-only, no WMI fallback) matches the PR intent for GPU counters. GpuEngineProperty.RUNNING_TIME_BASE exercises the new _Base handling in PerfDataUtilFFM.

Add remaining FFM perfmon drivers:
- GpuInformationFFM (PDH-only, no WMI fallback)
- PhysicalDiskFFM
- ThreadInformationFFM (with custom filter support)
- ProcessInformationFFM: add queryProcessCounters()
- ProcessorInformationFFM: add queryProcessorCounters,
  queryProcessorCapacityCounters, queryFrequencyCounters

Add custom filter support to FFM wildcard query infrastructure:
- PerfDataUtilFFM: queryWildcardCounters overload with customFilter
- PerfCounterWildcardQueryFFM: queryInstancesAndValues and
  queryInstancesAndValuesFromPDH overloads with customFilter

Add PDH vs WMI value comparison tests:
- PerfmonDriversTest (JNA): assertNonWildcardValuesClose helper
- PerfmonDriversFFMTest (FFM): mirrors JNA test structure

Add JNA vs FFM benchmark comparison:
- PerfmonComparisonTest in oshi-benchmark

Other changes:
- Relax maxFreq tolerance from 0.01 to 0.05 in NativeComparisonTest
- Update CHANGELOG for PR #3170
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