Class PerfDataUtilFFM

java.lang.Object
oshi.util.platform.windows.PerfDataUtilFFM

public final class PerfDataUtilFFM extends Object
Helper class to centralize the boilerplate portions of PDH counter setup using the FFM API.

This utility collects counter data with a single call to PdhCollectQueryData, which yields valid results for raw counters. OSHI queries raw counter values and computes rates in Java rather than using PDH formatted rate counters, which would require two samples separated by an interval.

  • Method Details

    • queryCounters

      public static <T extends Enum<T> & oshi.driver.common.windows.perfmon.PdhCounterProperty> Map<T,Long> queryCounters(Class<T> propertyEnum, String perfObject)
      Query multiple PDH counter values in a single query, one per enum constant.
      Type Parameters:
      T - An enum implementing PdhCounterProperty
      Parameters:
      propertyEnum - The enum class whose constants define the counters to query
      perfObject - The PDH object name (e.g., "Process")
      Returns:
      An EnumMap of values indexed by enum constant. May contain a subset of constants if individual counters fail to add or read. Returns an empty map if the query itself fails to open or collect.
    • queryWildcardCounters

      public static <T extends Enum<T> & oshi.driver.common.windows.perfmon.PdhCounterWildcardProperty> oshi.util.tuples.Pair<List<String>, Map<T, List<Long>>> queryWildcardCounters(Class<T> propertyEnum, String perfObject)
      Query wildcard PDH counter values for all instances matching the filter defined by the first enum constant.
      Type Parameters:
      T - An enum implementing PdhCounterWildcardProperty
      Parameters:
      propertyEnum - The enum class whose constants define the counters to query. The first constant defines the instance filter; remaining constants define counter names.
      perfObject - The PDH object name (e.g., "Process")
      Returns:
      A pair of (instances, valueMap) where valueMap is indexed by enum constant (excluding the first). Returns empty list and empty map on failure.
    • queryWildcardCounters

      public static <T extends Enum<T> & oshi.driver.common.windows.perfmon.PdhCounterWildcardProperty> oshi.util.tuples.Pair<List<String>, Map<T, List<Long>>> queryWildcardCounters(Class<T> propertyEnum, String perfObject, String customFilter)
      Query wildcard PDH counter values for all instances matching the given filter or the default from the first enum constant.
      Type Parameters:
      T - An enum implementing PdhCounterWildcardProperty
      Parameters:
      propertyEnum - The enum class whose constants define the counters to query. The first constant defines the default instance filter; remaining constants define counter names.
      perfObject - The PDH object name (e.g., "Process")
      customFilter - A custom instance filter to use. If null, uses the first element of the property enum.
      Returns:
      A pair of (instances, valueMap) where valueMap is indexed by enum constant (excluding the first). Returns empty list and empty map on failure.