Skip to content

Reduce duplication: introduce common PerfCounterQuery interface #3258

Description

@dbwiddis

Problem

9 perfmon driver classes in each module (oshi-core and oshi-core-ffm) follow the same pattern — calling queryValues or queryInstancesAndValues with constants from oshi-common. Only the utility class name differs (PerfCounterQuery vs PerfCounterQueryFFM).

Estimated duplicated code: ~545 lines across 18 files.

Example

oshi-core (MemoryInformationJNA.java):

public static Map<PageSwapProperty, Long> queryPageSwaps() {
    if (PerfmonDisabled.PERF_OS_DISABLED) {
        return Collections.emptyMap();
    }
    return PerfCounterQuery.queryValues(PageSwapProperty.class, MEMORY, WIN32_PERF_RAW_DATA_PERF_OS_MEMORY);
}

oshi-core-ffm (MemoryInformationFFM.java):

public static Map<PageSwapProperty, Long> queryPageSwaps() {
    return PerfCounterQueryFFM.queryValues(PageSwapProperty.class, MEMORY, WIN32_PERF_RAW_DATA_PERF_OS_MEMORY);
}

Proposal

Introduce a common PerfCounterQuery interface in oshi-common that both JNA and FFM implementations satisfy. The perfmon drivers could then be single implementations in oshi-common, parameterized by the query utility.

Additionally, the PerfmonDisabled check is present in JNA but absent in FFM — this inconsistency should be resolved by incorporating the check into the abstraction layer itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions