Repository navigation
Introduce PerfCounterQueryExecutor with common perfmon methods - #3268
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (11)
🚧 Files skipped from review as they are similar to previous changes (10)
📜 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). (12)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
🔇 Additional comments (1)
📝 WalkthroughWalkthroughAdds a PerfCounterQueryExecutor interface, FFM and JNA implementations, and updates oshi-common perfmon helper classes to use executor-based query methods for GPU, disk, memory, paging, processor, process, thread, and system counters. ChangesWindows perfmon query abstraction and adoption
Sequence DiagramsequenceDiagram
participant Caller
participant PerfCounterQueryExecutor
participant Backend as FFM/JNA
Caller->>PerfCounterQueryExecutor: queryInstancesAndValuesFromPDH(...)/queryValues(...)
PerfCounterQueryExecutor->>Backend: delegate to PerfCounterQuery/PerfCounterWildcardQuery
Backend-->>PerfCounterQueryExecutor: instances + values
PerfCounterQueryExecutor-->>Caller: Pair<List<String>, Map<...>>
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounterQueryExecutor.java`:
- Around line 15-16: The Javadoc for PerfCounterQueryExecutor currently requires
implementations to check PerfmonDisabled, but the executors instead expose
isPerf*Disabled() so callers perform gating; update the interface Javadoc to
reflect the actual contract: state that implementations perform raw queries and
do NOT perform PerfmonDisabled checks, and that callers must call the provided
isPerf*Disabled() methods (e.g., isPerfCountersDisabled(), isPerfCpuDisabled()
or similar) before invoking query methods; mention the expected behavior when
disabled (methods may return empty results) so future implementers and callers
are clear about responsibility and return semantics.
In
`@oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.java`:
- Around line 151-157: queryIdleProcessCounters currently only checks
executor.isPerfOsDisabled(), but it queries WIN32_PERFPROC process counters and
must respect the process-perfmon disable gate; update the guard in
queryIdleProcessCounters (in ProcessInformation) to check the process counter
flag on PerfCounterQueryExecutor (use executor.isPerfProcDisabled() or combine
with isPerfOsDisabled() as appropriate) and return empty collections when
process counters are disabled before calling executor.queryInstancesAndValues.
In
`@oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ThreadInformation.java`:
- Around line 73-102: Both overloads of queryThreadCounters should short-circuit
when perf process counters are disabled; add an initial check calling
isPerfProcDisabled() in both queryThreadCounters methods and if true immediately
return an empty Pair (e.g., empty List and empty Map using
Collections.emptyList()/emptyMap()) instead of executing the
PerfCounterQueryExecutor; update the overload that takes
(PerfCounterQueryExecutor executor, String name, int threadNum) and the no-name
overload queryThreadCounters(PerfCounterQueryExecutor executor) to perform this
check before any executor.queryInstancesAndValues invocations.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: da9f9df3-5eb5-4f1b-b62d-e671486cb17f
📒 Files selected for processing (11)
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/GpuInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/MemoryInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PagingFile.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounterQueryExecutor.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PhysicalDisk.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessorInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/SystemInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ThreadInformation.javaoshi-core-ffm/src/main/java/oshi/driver/windows/perfmon/PerfCounterQueryExecutorFFM.javaoshi-core/src/main/java/oshi/driver/windows/perfmon/PerfCounterQueryExecutorJNA.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). (9)
- 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 21, macos-latest
- GitHub Check: JMH Benchmarks, windows-latest
- GitHub Check: JMH Benchmarks, ubuntu-latest
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.
Applied to files:
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/MemoryInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/SystemInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ThreadInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PhysicalDisk.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/GpuInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessorInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PagingFile.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounterQueryExecutor.java
🔇 Additional comments (9)
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounterQueryExecutor.java (1)
20-106: LGTM!oshi-core-ffm/src/main/java/oshi/driver/windows/perfmon/PerfCounterQueryExecutorFFM.java (1)
23-80: LGTM!oshi-core/src/main/java/oshi/driver/windows/perfmon/PerfCounterQueryExecutorJNA.java (1)
24-80: LGTM!oshi-common/src/main/java/oshi/driver/common/windows/perfmon/GpuInformation.java (1)
72-92: LGTM!oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PhysicalDisk.java (1)
64-71: LGTM!oshi-common/src/main/java/oshi/driver/common/windows/perfmon/MemoryInformation.java (1)
58-63: LGTM!oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PagingFile.java (1)
57-62: LGTM!oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessorInformation.java (1)
201-284: LGTM!oshi-common/src/main/java/oshi/driver/common/windows/perfmon/SystemInformation.java (1)
82-100: LGTM!
| public static Pair<List<String>, Map<IdleProcessorTimeProperty, List<Long>>> queryIdleProcessCounters( | ||
| PerfCounterQueryExecutor executor) { | ||
| if (executor.isPerfOsDisabled()) { | ||
| return new Pair<>(Collections.emptyList(), Collections.emptyMap()); | ||
| } | ||
| return executor.queryInstancesAndValues(IdleProcessorTimeProperty.class, PROCESS, | ||
| WIN32_PERFPROC_PROCESS_WHERE_IDPROCESS_0); |
There was a problem hiding this comment.
Use the process perfmon disable gate for idle process queries.
This method hits PERFPROC (WIN32_PERFPROC_PROCESS_WHERE_IDPROCESS_0) but only checks isPerfOsDisabled(). If process counters are disabled, it still queries.
Suggested fix
public static Pair<List<String>, Map<IdleProcessorTimeProperty, List<Long>>> queryIdleProcessCounters(
PerfCounterQueryExecutor executor) {
- if (executor.isPerfOsDisabled()) {
+ if (executor.isPerfProcDisabled()) {
return new Pair<>(Collections.emptyList(), Collections.emptyMap());
}
return executor.queryInstancesAndValues(IdleProcessorTimeProperty.class, PROCESS,
WIN32_PERFPROC_PROCESS_WHERE_IDPROCESS_0);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public static Pair<List<String>, Map<IdleProcessorTimeProperty, List<Long>>> queryIdleProcessCounters( | |
| PerfCounterQueryExecutor executor) { | |
| if (executor.isPerfOsDisabled()) { | |
| return new Pair<>(Collections.emptyList(), Collections.emptyMap()); | |
| } | |
| return executor.queryInstancesAndValues(IdleProcessorTimeProperty.class, PROCESS, | |
| WIN32_PERFPROC_PROCESS_WHERE_IDPROCESS_0); | |
| public static Pair<List<String>, Map<IdleProcessorTimeProperty, List<Long>>> queryIdleProcessCounters( | |
| PerfCounterQueryExecutor executor) { | |
| if (executor.isPerfProcDisabled()) { | |
| return new Pair<>(Collections.emptyList(), Collections.emptyMap()); | |
| } | |
| return executor.queryInstancesAndValues(IdleProcessorTimeProperty.class, PROCESS, | |
| WIN32_PERFPROC_PROCESS_WHERE_IDPROCESS_0); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.java`
around lines 151 - 157, queryIdleProcessCounters currently only checks
executor.isPerfOsDisabled(), but it queries WIN32_PERFPROC process counters and
must respect the process-perfmon disable gate; update the guard in
queryIdleProcessCounters (in ProcessInformation) to check the process counter
flag on PerfCounterQueryExecutor (use executor.isPerfProcDisabled() or combine
with isPerfOsDisabled() as appropriate) and return empty collections when
process counters are disabled before calling executor.queryInstancesAndValues.
| public static Pair<List<String>, Map<ThreadPerformanceProperty, List<Long>>> queryThreadCounters( | ||
| PerfCounterQueryExecutor executor) { | ||
| return executor.queryInstancesAndValues(ThreadPerformanceProperty.class, THREAD, | ||
| WIN32_PERF_RAW_DATA_PERF_PROC_THREAD_WHERE_NOT_NAME_LIKE_TOTAL); | ||
| } | ||
|
|
||
| /** | ||
| * Returns thread counters filtered to the specified process name and thread. | ||
| * | ||
| * @param executor the performance counter query executor | ||
| * @param name The process name to filter | ||
| * @param threadNum The thread number to match. -1 matches all threads. | ||
| * @return Thread counters for each thread. | ||
| */ | ||
| public static Pair<List<String>, Map<ThreadPerformanceProperty, List<Long>>> queryThreadCounters( | ||
| PerfCounterQueryExecutor executor, String name, int threadNum) { | ||
| String procName = name.toLowerCase(Locale.ROOT); | ||
| if (threadNum >= 0) { | ||
| Pair<List<String>, Map<ThreadPerformanceProperty, List<Long>>> threads = executor | ||
| .queryInstancesAndValues( | ||
| ThreadPerformanceProperty.class, THREAD, WIN32_PERF_RAW_DATA_PERF_PROC_THREAD | ||
| + " WHERE Name LIKE \"" + procName + "/_%\" AND IDThread=" + threadNum, | ||
| procName + "/*"); | ||
| if (!threads.getA().isEmpty()) { | ||
| return threads; | ||
| } | ||
| } | ||
| return executor.queryInstancesAndValues(ThreadPerformanceProperty.class, THREAD, | ||
| WIN32_PERF_RAW_DATA_PERF_PROC_THREAD + " WHERE Name LIKE \"" + procName + "/_%\"", procName + "/*"); | ||
| } |
There was a problem hiding this comment.
Add isPerfProcDisabled() short-circuit to both thread query overloads.
Both methods execute PERFPROC thread queries without a disable check, so they can still query when process counters are disabled.
Suggested fix
public static Pair<List<String>, Map<ThreadPerformanceProperty, List<Long>>> queryThreadCounters(
PerfCounterQueryExecutor executor) {
+ if (executor.isPerfProcDisabled()) {
+ return new Pair<>(Collections.emptyList(), Collections.emptyMap());
+ }
return executor.queryInstancesAndValues(ThreadPerformanceProperty.class, THREAD,
WIN32_PERF_RAW_DATA_PERF_PROC_THREAD_WHERE_NOT_NAME_LIKE_TOTAL);
}
@@
public static Pair<List<String>, Map<ThreadPerformanceProperty, List<Long>>> queryThreadCounters(
PerfCounterQueryExecutor executor, String name, int threadNum) {
+ if (executor.isPerfProcDisabled()) {
+ return new Pair<>(Collections.emptyList(), Collections.emptyMap());
+ }
String procName = name.toLowerCase(Locale.ROOT);
if (threadNum >= 0) {
Pair<List<String>, Map<ThreadPerformanceProperty, List<Long>>> threads = executor📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public static Pair<List<String>, Map<ThreadPerformanceProperty, List<Long>>> queryThreadCounters( | |
| PerfCounterQueryExecutor executor) { | |
| return executor.queryInstancesAndValues(ThreadPerformanceProperty.class, THREAD, | |
| WIN32_PERF_RAW_DATA_PERF_PROC_THREAD_WHERE_NOT_NAME_LIKE_TOTAL); | |
| } | |
| /** | |
| * Returns thread counters filtered to the specified process name and thread. | |
| * | |
| * @param executor the performance counter query executor | |
| * @param name The process name to filter | |
| * @param threadNum The thread number to match. -1 matches all threads. | |
| * @return Thread counters for each thread. | |
| */ | |
| public static Pair<List<String>, Map<ThreadPerformanceProperty, List<Long>>> queryThreadCounters( | |
| PerfCounterQueryExecutor executor, String name, int threadNum) { | |
| String procName = name.toLowerCase(Locale.ROOT); | |
| if (threadNum >= 0) { | |
| Pair<List<String>, Map<ThreadPerformanceProperty, List<Long>>> threads = executor | |
| .queryInstancesAndValues( | |
| ThreadPerformanceProperty.class, THREAD, WIN32_PERF_RAW_DATA_PERF_PROC_THREAD | |
| + " WHERE Name LIKE \"" + procName + "/_%\" AND IDThread=" + threadNum, | |
| procName + "/*"); | |
| if (!threads.getA().isEmpty()) { | |
| return threads; | |
| } | |
| } | |
| return executor.queryInstancesAndValues(ThreadPerformanceProperty.class, THREAD, | |
| WIN32_PERF_RAW_DATA_PERF_PROC_THREAD + " WHERE Name LIKE \"" + procName + "/_%\"", procName + "/*"); | |
| } | |
| public static Pair<List<String>, Map<ThreadPerformanceProperty, List<Long>>> queryThreadCounters( | |
| PerfCounterQueryExecutor executor) { | |
| if (executor.isPerfProcDisabled()) { | |
| return new Pair<>(Collections.emptyList(), Collections.emptyMap()); | |
| } | |
| return executor.queryInstancesAndValues(ThreadPerformanceProperty.class, THREAD, | |
| WIN32_PERF_RAW_DATA_PERF_PROC_THREAD_WHERE_NOT_NAME_LIKE_TOTAL); | |
| } | |
| /** | |
| * Returns thread counters filtered to the specified process name and thread. | |
| * | |
| * `@param` executor the performance counter query executor | |
| * `@param` name The process name to filter | |
| * `@param` threadNum The thread number to match. -1 matches all threads. | |
| * `@return` Thread counters for each thread. | |
| */ | |
| public static Pair<List<String>, Map<ThreadPerformanceProperty, List<Long>>> queryThreadCounters( | |
| PerfCounterQueryExecutor executor, String name, int threadNum) { | |
| if (executor.isPerfProcDisabled()) { | |
| return new Pair<>(Collections.emptyList(), Collections.emptyMap()); | |
| } | |
| String procName = name.toLowerCase(Locale.ROOT); | |
| if (threadNum >= 0) { | |
| Pair<List<String>, Map<ThreadPerformanceProperty, List<Long>>> threads = executor | |
| .queryInstancesAndValues( | |
| ThreadPerformanceProperty.class, THREAD, WIN32_PERF_RAW_DATA_PERF_PROC_THREAD | |
| " WHERE Name LIKE \"" + procName + "/_%\" AND IDThread=" + threadNum, | |
| procName + "/*"); | |
| if (!threads.getA().isEmpty()) { | |
| return threads; | |
| } | |
| } | |
| return executor.queryInstancesAndValues(ThreadPerformanceProperty.class, THREAD, | |
| WIN32_PERF_RAW_DATA_PERF_PROC_THREAD + " WHERE Name LIKE \"" + procName + "/_%\"", procName + "/*"); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ThreadInformation.java`
around lines 73 - 102, Both overloads of queryThreadCounters should
short-circuit when perf process counters are disabled; add an initial check
calling isPerfProcDisabled() in both queryThreadCounters methods and if true
immediately return an empty Pair (e.g., empty List and empty Map using
Collections.emptyList()/emptyMap()) instead of executing the
PerfCounterQueryExecutor; update the overload that takes
(PerfCounterQueryExecutor executor, String name, int threadNum) and the no-name
overload queryThreadCounters(PerfCounterQueryExecutor executor) to perform this
check before any executor.queryInstancesAndValues invocations.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3268 +/- ##
============================================
- Coverage 73.86% 73.48% -0.38%
Complexity 73 73
============================================
Files 404 406 +2
Lines 16132 16208 +76
Branches 2556 2559 +3
============================================
- Hits 11916 11911 -5
- Misses 2724 2803 +79
- Partials 1492 1494 +2
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:
|
, #3261) Add PerfCounterQueryExecutor interface in oshi-common with JNA and FFM implementations. Add query methods to all 8 perfmon base classes that accept the executor and incorporate the PerfmonDisabled check. This fixes #3261 (missing PerfmonDisabled check in FFM) by design: the common methods check executor.isPerfXxxDisabled() before querying, ensuring consistent behavior regardless of native access layer.
66351f0 to
0fceddd
Compare
Closes #3258, closes #3261
Introduces a
PerfCounterQueryExecutorinterface inoshi-commonwith JNA and FFM singleton implementations. Adds query methods to all 8 perfmon driver base classes.Fixes #3261 by design: The common query methods check
executor.isPerfOsDisabled()/isPerfProcDisabled()/isPerfDiskDisabled()before executing queries. The FFM executor now properly checksPerfmonDisabledFFM, fixing the inconsistency where FFM drivers previously skipped this check.New in oshi-common:
PerfCounterQueryExecutorinterface — queryValues, queryInstancesAndValues, queryInstancesAndValuesFromWMI, queryInstancesAndValuesFromPDH, isPerfXxxDisabled, isWin7OrGreaterNew adapters:
PerfCounterQueryExecutorJNA(oshi-core)PerfCounterQueryExecutorFFM(oshi-core-ffm)Updated base classes (8):
GpuInformation, MemoryInformation, PagingFile, PhysicalDisk, ProcessInformation, ProcessorInformation, SystemInformation, ThreadInformation
LoadAverage is not included as it has a more complex singleton/scheduling pattern.
Summary by CodeRabbit
New Features
Refactor