Class HkeyPerformanceDataUtil

java.lang.Object
oshi.driver.common.windows.registry.HkeyPerformanceDataUtil

@ThreadSafe public abstract class HkeyPerformanceDataUtil extends Object
Base class for HKEY_PERFORMANCE_DATA utilities. Contains the common logic for building the counter name/index map and resolving counter indices from enum definitions. Subclasses provide the platform-specific native call to read the registry string array.
  • Field Details

    • HKEY_PERFORMANCE_TEXT

      public static final String HKEY_PERFORMANCE_TEXT
      Registry key containing English counter name/index pairs.
      See Also:
    • COUNTER

      public static final String COUNTER
      Registry value name for the counter text.
      See Also:
  • Constructor Details

    • HkeyPerformanceDataUtil

      protected HkeyPerformanceDataUtil()
      Subclass-only constructor.
  • Method Details

    • buildCounterIndexMap

      protected static Map<String,Integer> buildCounterIndexMap(String[] counterText)
      Builds the counter index map from a string array of alternating index/name pairs.

      The array format is pairs of "<index>", "<name>". The first pair is a length/count entry (e.g., "1", "1847") followed by actual counter definitions such as "2", "System", "4", "Memory", "6", "% Processor Time", .... Even positions (0, 2, 4, ...) hold numeric index strings and odd positions (1, 3, 5, ...) hold the corresponding counter names.

      Parameters:
      counterText - The string array from the registry, or null if the read failed
      Returns:
      An unmodifiable map of counter name to index
    • getCounterIndices

      protected static <T extends Enum<T> & PdhCounterWildcardProperty> Pair<Integer, EnumMap<T,Integer>> getCounterIndices(String objectName, Class<T> counterEnum, Map<String,Integer> counterIndexMap)
      Looks up the counter index values for the given counter object and the enum of counter names.
      Type Parameters:
      T - An enum containing the counters, whose class is passed as counterEnum
      Parameters:
      objectName - The counter object to look up the index for
      counterEnum - The Enum containing counters to look up the indices for. The first Enum value will be ignored.
      counterIndexMap - The map of counter names to their indices
      Returns:
      A Pair containing the index of the counter object as the first element, and an EnumMap mapping counter enum values to their index as the second element, if the lookup is successful; null otherwise.