Skip to content

Introduce PerfCounterQueryExecutor with common perfmon methods - #3268

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:refactor/perfmon-executor
May 19, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:refactor/perfmon-executor

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 18, 2026 •

Copy link
Copy Markdown
Member

Closes #3258, closes #3261

Introduces a PerfCounterQueryExecutor interface in oshi-common with 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 checks PerfmonDisabledFFM, fixing the inconsistency where FFM drivers previously skipped this check.

New in oshi-common:

  • PerfCounterQueryExecutor interface — queryValues, queryInstancesAndValues, queryInstancesAndValuesFromWMI, queryInstancesAndValuesFromPDH, isPerfXxxDisabled, isWin7OrGreater

New 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

    • Expanded Windows performance queries to include GPU (engine & adapter memory), memory/page-swap, paging-file usage, disk, process, thread, processor, and system counters with multi-instance results where applicable.
  • Refactor

    • Added a unified performance-counter executor interface plus two concrete implementations to standardize and simplify retrieving Windows perf data across multiple subsystems.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8a73df10-9182-448f-a7ed-810e710af902

📥 Commits

Reviewing files that changed from the base of the PR and between 66351f0 and 0fceddd.

📒 Files selected for processing (11)
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/GpuInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/MemoryInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PagingFile.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounterQueryExecutor.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PhysicalDisk.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessorInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/SystemInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ThreadInformation.java
  • oshi-core-ffm/src/main/java/oshi/driver/windows/perfmon/PerfCounterQueryExecutorFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/PerfCounterQueryExecutorJNA.java
🚧 Files skipped from review as they are similar to previous changes (10)
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/MemoryInformation.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/PerfCounterQueryExecutorJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/GpuInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/SystemInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ThreadInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounterQueryExecutor.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessorInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PhysicalDisk.java
  • oshi-core-ffm/src/main/java/oshi/driver/windows/perfmon/PerfCounterQueryExecutorFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.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). (12)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: JMH Benchmarks, windows-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/PagingFile.java
🔇 Additional comments (1)
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PagingFile.java (1)

7-12: LGTM!

Also applies to: 51-62


📝 Walkthrough

Walkthrough

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

Changes

Windows perfmon query abstraction and adoption

Layer / File(s) Summary
PerfCounterQueryExecutor interface
oshi-common/.../PerfCounterQueryExecutor.java
Defines the contract for querying Windows performance counters with generic methods for fixed counters, multi-instance wildcard queries (incl. custom filters), WMI/PDH-specific paths, and capability checks for counter disablement and OS version gating.
FFM implementation
oshi-core-ffm/.../PerfCounterQueryExecutorFFM.java
Singleton implementation delegating to FFM query utilities (PerfCounterQueryFFM, PerfCounterWildcardQueryFFM) and exposing disablement flags and Windows version checks via cached properties.
JNA implementation
oshi-core/.../PerfCounterQueryExecutorJNA.java
Singleton implementation delegating to JNA query utilities (PerfCounterQuery, PerfCounterWildcardQuery) and exposing disablement flags and Windows version checks via static properties.
GPU, disk, memory, and paging queries
oshi-common/.../GpuInformation.java, oshi-common/.../PhysicalDisk.java, oshi-common/.../MemoryInformation.java, oshi-common/.../PagingFile.java
Adds executor-aware helpers for GPU engine/adapter memory, physical disk instances (exclude _Total), page swaps, and paging-file percent usage; each returns empty results when relevant perf categories are disabled.
Processor and system queries
oshi-common/.../ProcessorInformation.java, oshi-common/.../SystemInformation.java
Adds multiple processor-related query helpers (per-processor ticks with Win7+ selection, capacity, interrupts, frequency, cooked performance) plus system counters for context switches and processor queue length, all using the executor and gating on disabled counters.
Process and thread queries
oshi-common/.../ProcessInformation.java, oshi-common/.../ThreadInformation.java
Adds process counters, handle-count queries, idle-processor-time queries, and two thread-counter overloads (all instances and process/thread-filtered with fallback) using the executor and disabled-counter checks.

Sequence Diagram

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

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • oshi/oshi#3164: Overlaps with adding back bulk query* methods and enum/metadata changes used by the new executor-aware helpers.
  • oshi/oshi#3168: Adds similar query helpers and FFM-backed query infrastructure that aligns with these executor adaptations.
  • oshi/oshi#3213: Adds parity tests comparing JNA vs FFM behavior for filtered ThreadInformation.queryThreadCounters overload.

"I nibble bytes beneath the hood,
I hop through counters where they stood,
With executor in paw I bind the land,
FFM and JNA now work hand in hand,
A hopping cheer for queries grand!" 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 49.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: introducing a PerfCounterQueryExecutor interface with common perfmon methods, which is the primary objective.
Linked Issues check ✅ Passed The PR fully addresses both linked issues: #3258 (common PerfCounterQueryExecutor interface reduces duplication across JNA/FFM) and #3261 (PerfmonDisabled checks now consistently integrated into the abstraction).
Out of Scope Changes check ✅ Passed All changes are directly in scope: the new PerfCounterQueryExecutor interface, two implementations (JNA and FFM), and eight perfmon driver classes updated to use the executor—no unrelated changes detected.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7d74add and 66351f0.

📒 Files selected for processing (11)
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/GpuInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/MemoryInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PagingFile.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounterQueryExecutor.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PhysicalDisk.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessorInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/SystemInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ThreadInformation.java
  • oshi-core-ffm/src/main/java/oshi/driver/windows/perfmon/PerfCounterQueryExecutorFFM.java
  • oshi-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.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/SystemInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ThreadInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PhysicalDisk.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/GpuInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessorInformation.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PagingFile.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/ProcessInformation.java
  • oshi-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!

Comment on lines +151 to +157
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);

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

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

Comment on lines +73 to +102
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 + "/*");
}

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Suggested change
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

codecov Bot commented May 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 76 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.48%. Comparing base (7d74add) to head (0fceddd).

Files with missing lines Patch % Lines
...r/common/windows/perfmon/ProcessorInformation.java 0.00% 20 Missing ⚠️
...r/windows/perfmon/PerfCounterQueryExecutorFFM.java 0.00% 11 Missing ⚠️
...r/windows/perfmon/PerfCounterQueryExecutorJNA.java 0.00% 11 Missing ⚠️
...ver/common/windows/perfmon/ProcessInformation.java 0.00% 9 Missing ⚠️
...iver/common/windows/perfmon/ThreadInformation.java 0.00% 8 Missing ⚠️
...iver/common/windows/perfmon/SystemInformation.java 0.00% 6 Missing ⚠️
...iver/common/windows/perfmon/MemoryInformation.java 0.00% 3 Missing ⚠️
...oshi/driver/common/windows/perfmon/PagingFile.java 0.00% 3 Missing ⚠️
...hi/driver/common/windows/perfmon/PhysicalDisk.java 0.00% 3 Missing ⚠️
.../driver/common/windows/perfmon/GpuInformation.java 0.00% 2 Missing ⚠️
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     
Flag Coverage Δ
linux 38.32% <0.00%> (-0.19%) ⬇️
macos 38.90% <0.00%> (-0.19%) ⬇️
windows 46.63% <0.00%> (-0.25%) ⬇️

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.

, #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.
@dbwiddis
dbwiddis force-pushed the refactor/perfmon-executor branch from 66351f0 to 0fceddd Compare May 18, 2026 23:56
@dbwiddis
dbwiddis merged commit 278e937 into oshi:master May 19, 2026
18 of 19 checks passed
@dbwiddis
dbwiddis deleted the refactor/perfmon-executor branch May 19, 2026 00:06
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.

Inconsistency: PerfmonDisabled check missing from FFM perfmon drivers Reduce duplication: introduce common PerfCounterQuery interface

1 participant