Repository navigation
Complete FFM perfmon driver migration - #3170
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (12)
✅ Files skipped from review due to trivial changes (4)
🚧 Files skipped from review as they are similar to previous changes (5)
📜 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)
🧰 Additional context used🧠 Learnings (8)📓 Common learnings📚 Learning: 2026-04-17T23:56:43.867ZApplied to files:
📚 Learning: 2026-04-18T03:18:03.725ZApplied to files:
📚 Learning: 2026-04-12T19:34:59.050ZApplied to files:
📚 Learning: 2026-04-17T23:43:33.461ZApplied to files:
📚 Learning: 2026-04-03T02:07:47.621ZApplied to files:
📚 Learning: 2026-03-29T20:03:00.830ZApplied to files:
📚 Learning: 2026-04-17T23:52:52.926ZApplied to files:
🔇 Additional comments (7)
📝 WalkthroughWalkthroughAdds 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 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 | 🟠 MajorNon-wildcard
queryCountersmust strip_Basesuffix and readSecondValuelike the wildcard path.The legacy JNA
PerfCounterconstructor strips_Baseand flipsbaseCounter=trueunconditionally for both wildcard and non-wildcard counters. The wildcard pathqueryWildcardCounterscorrectly implements this viaBASE_SUFFIX+readRawCounterValue(..., isBase[p-1]). However,queryCountersat line 94 feedsprop.getCounter()directly intocounterPath(...)and hard-codesreadRawCounterValue(..., false)at line 111.The problem is real:
ProcessorInformation.TIMESTAMP_SYS100NS("% Processor Time_Base"),ProcessorInformation.PERCENTPROCESSORUTILITY_BASE("% Processor Utility_Base"), andGpuInformation.RUNNING_TIME_BASE("Running Time_Base")are existing non-wildcard enums with_Basesuffixes. 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 ofcustomFilter. If an earlier call with the default filter fails and recordsperfObjectin the cache (line 80), a subsequent caller passing a distinctcustomFilter(e.g.,ThreadInformationFFM.queryThreadCounters(name, threadNum)usingprocName + "/*") 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
customFilterbeing 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 Timeinstances come and go as workloads start/stop between the two sampling calls). StrictisEqualTo(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
📒 Files selected for processing (12)
CHANGELOG.mdoshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.javaoshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.javaoshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.javaoshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.javaoshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.javaoshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-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.javaoshi-core/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversTest.javaoshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.javaoshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-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.javaoshi-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.javaoshi-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 JNAThreadInformationbehavior.The
toLowerCase(Locale.ROOT), PDH wildcard (procName + "/*") vs. WMIWHERE 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 theWHEREclause as theperfWmiClasssuffix and the PDH filter as a separatecustomFiltercorrectly uses the newPerfCounterWildcardQueryFFMoverload.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 Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c57b987 to
9750868
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (12)
CHANGELOG.mdoshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.javaoshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/GpuInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PhysicalDiskFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ThreadInformationFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core-java25/src/test/java/oshi/driver/windows/perfmon/PerfmonDriversFFMTest.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-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.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-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 onassertWithinRatioappears resolved; noting residual edge case for cumulative counters.The format specifiers and
ratiousage are now correct. One residual semantic concern (not re-raising as an issue): forCUMULATIVE_RATIOpaths (PageSwap,System,Interrupts,ContextSwitch), if one backend briefly reports0while the other reports any real counter tick value,nonZero <= 0.5will 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_BASEexercises the new_Basehandling inPerfDataUtilFFM.
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
9750868 to
9b4cb19
Compare
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
queryProcessCountersmethod for per-process PDH counters_BaseCounter FixPDH does not have counters with
_Basesuffix — those are WMI-specific. When a property name ends with_Base, the FFM code now:SecondValuefrom the raw counter struct instead ofFirstValueThis mirrors the existing JNA behavior in
PerfCounter/PerfCounterQueryHandler.PerfCounterWildcardQueryFFM Enhancements
queryInstancesAndValuesFromPDHfor PDH-only queries (used by GpuInformationFFM)customFilteroverloads for all query methodsTest Changes
PerfmonDriversTest (JNA) / PerfmonDriversFFMTest (FFM)
PerfmonComparisonTest (JNA vs FFM benchmark)
NativeComparisonTest
process.upTimeassertion:max(10%, 300ms)tolerance to account for memoization (300ms default TTL)process.residentMemorytolerance from 0.25 to 0.75Summary by CodeRabbit
New Features
Improvements
Tests