Class PerfCounterQuery<T extends java.lang.Enum<T>>

java.lang.Object
oshi.util.platform.windows.PerfCounterQuery<T>
Direct Known Subclasses:
PerfCounterWildcardQuery

@NotThreadSafe
public class PerfCounterQuery<T extends java.lang.Enum<T>>
extends java.lang.Object
Encapsulates information for a Performance Counter query.

An instance of this class should only be instantiated and used within the context of a single thread.

  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  PerfCounterQuery.CounterDataSource
    Source of performance counter data.
    static interface  PerfCounterQuery.PdhCounterProperty
    Contract for Counter Property Enums
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected com.sun.jna.platform.win32.COM.WbemcliUtil.WmiQuery<T> counterQuery  
    static java.lang.String NOT_TOTAL_INSTANCE
    Constant NOT_TOTAL_INSTANCE="^ + TOTAL_INSTANCE"
    static java.lang.String NOT_TOTAL_INSTANCES
    Constant NOT_TOTAL_INSTANCES="^ + TOTAL_INSTANCES"
    protected PerfCounterQueryHandler pdhQueryHandler  
    protected java.lang.String perfObject  
    protected java.lang.String perfWmiClass  
    protected java.lang.Class<T> propertyEnum  
    protected java.lang.String queryKey  
    protected PerfCounterQuery.CounterDataSource source  
    static java.lang.String TOTAL_INSTANCE
    Constant TOTAL_INSTANCE="_Total"
    static java.lang.String TOTAL_INSTANCES
    Constant TOTAL_INSTANCES="*_Total"
  • Constructor Summary

    Constructors 
    Constructor Description
    PerfCounterQuery​(java.lang.Class<T> propertyEnum, java.lang.String perfObject, java.lang.String perfWmiClass)
    Construct a new object to hold performance counter data source and results
    PerfCounterQuery​(java.lang.Class<T> propertyEnum, java.lang.String perfObject, java.lang.String perfWmiClass, java.lang.String queryKey)
    Construct a new object to hold performance counter data source and results
  • Method Summary

    Modifier and Type Method Description
    protected boolean initPdhCounters()
    Initialize PDH counters for this data source.
    protected void initWmiCounters()
    Initialize the WMI query object needed to retrieve counters for this data source.
    java.util.Map<T,​java.lang.Long> queryValues()
    Query the current data source (PDH or WMI) for the Performance Counter values corresponding to the property enum.
    boolean setDataSource​(PerfCounterQuery.CounterDataSource source)
    Set the Data Source for these counters
    protected void unInitPdhCounters()
    Uninitialize PDH counters for this data source.
    protected void unInitWmiCounters()
    Uninitializes the WMI query object needed to retrieve counters for this data source, allowing it to be garbage collected.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • PerfCounterQuery

      public PerfCounterQuery​(java.lang.Class<T> propertyEnum, java.lang.String perfObject, java.lang.String perfWmiClass)
      Construct a new object to hold performance counter data source and results
      Parameters:
      propertyEnum - An enum which implements PerfCounterQuery.PdhCounterProperty and contains the WMI field (Enum value) and PDH Counter string (instance and counter)
      perfObject - The PDH object for this counter; all counters on this object will be refreshed at the same time
      perfWmiClass - The WMI PerfData_RawData_* class corresponding to the PDH object
    • PerfCounterQuery

      public PerfCounterQuery​(java.lang.Class<T> propertyEnum, java.lang.String perfObject, java.lang.String perfWmiClass, java.lang.String queryKey)
      Construct a new object to hold performance counter data source and results
      Parameters:
      propertyEnum - An enum which implements PerfCounterQuery.PdhCounterProperty and contains the WMI field (Enum value) and PDH Counter string (instance and counter)
      perfObject - The PDH object for this counter; all counters on this object will be refreshed at the same time
      perfWmiClass - The WMI PerfData_RawData_* class corresponding to the PDH object
      queryKey - An optional key for PDH counter updates; defaults to the PDH object name
  • Method Details

    • setDataSource

      public boolean setDataSource​(PerfCounterQuery.CounterDataSource source)
      Set the Data Source for these counters
      Parameters:
      source - The source of data
      Returns:
      Whether the data source was successfully set
    • initPdhCounters

      protected boolean initPdhCounters()
      Initialize PDH counters for this data source. Adds necessary counters to a PDH Query.
      Returns:
      True if the counters were successfully added.
    • unInitPdhCounters

      protected void unInitPdhCounters()
      Uninitialize PDH counters for this data source. Removes necessary counters from the PDH Query, releasing their handles.
    • initWmiCounters

      protected void initWmiCounters()
      Initialize the WMI query object needed to retrieve counters for this data source.
    • unInitWmiCounters

      protected void unInitWmiCounters()
      Uninitializes the WMI query object needed to retrieve counters for this data source, allowing it to be garbage collected.
    • queryValues

      public java.util.Map<T,​java.lang.Long> queryValues()
      Query the current data source (PDH or WMI) for the Performance Counter values corresponding to the property enum.
      Returns:
      A map of the values by the counter enum.