Package oshi.util.platform.windows
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 classPerfCounterQuery.CounterDataSourceSource of performance counter data.static interfacePerfCounterQuery.PdhCounterPropertyContract for Counter Property Enums -
Field Summary
Fields Modifier and Type Field Description protected com.sun.jna.platform.win32.COM.WbemcliUtil.WmiQuery<T>counterQuerystatic java.lang.StringNOT_TOTAL_INSTANCEConstantNOT_TOTAL_INSTANCE="^ + TOTAL_INSTANCE"static java.lang.StringNOT_TOTAL_INSTANCESConstantNOT_TOTAL_INSTANCES="^ + TOTAL_INSTANCES"protected PerfCounterQueryHandlerpdhQueryHandlerprotected java.lang.StringperfObjectprotected java.lang.StringperfWmiClassprotected java.lang.Class<T>propertyEnumprotected java.lang.StringqueryKeyprotected PerfCounterQuery.CounterDataSourcesourcestatic java.lang.StringTOTAL_INSTANCEConstantTOTAL_INSTANCE="_Total"static java.lang.StringTOTAL_INSTANCESConstantTOTAL_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 resultsPerfCounterQuery(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 booleaninitPdhCounters()Initialize PDH counters for this data source.protected voidinitWmiCounters()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.booleansetDataSource(PerfCounterQuery.CounterDataSource source)Set the Data Source for these countersprotected voidunInitPdhCounters()Uninitialize PDH counters for this data source.protected voidunInitWmiCounters()Uninitializes the WMI query object needed to retrieve counters for this data source, allowing it to be garbage collected.
-
Field Details
-
propertyEnum
-
perfObject
protected final java.lang.String perfObject -
perfWmiClass
protected final java.lang.String perfWmiClass -
queryKey
protected final java.lang.String queryKey -
source
-
pdhQueryHandler
-
counterQuery
-
TOTAL_INSTANCE
public static final java.lang.String TOTAL_INSTANCEConstantTOTAL_INSTANCE="_Total"- See Also:
- Constant Field Values
-
TOTAL_INSTANCES
public static final java.lang.String TOTAL_INSTANCESConstantTOTAL_INSTANCES="*_Total"- See Also:
- Constant Field Values
-
NOT_TOTAL_INSTANCE
public static final java.lang.String NOT_TOTAL_INSTANCEConstantNOT_TOTAL_INSTANCE="^ + TOTAL_INSTANCE"- See Also:
- Constant Field Values
-
NOT_TOTAL_INSTANCES
public static final java.lang.String NOT_TOTAL_INSTANCESConstantNOT_TOTAL_INSTANCES="^ + TOTAL_INSTANCES"- See Also:
- Constant Field Values
-
-
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 implementsPerfCounterQuery.PdhCounterPropertyand 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 timeperfWmiClass- 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 implementsPerfCounterQuery.PdhCounterPropertyand 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 timeperfWmiClass- The WMI PerfData_RawData_* class corresponding to the PDH objectqueryKey- An optional key for PDH counter updates; defaults to the PDH object name
-
-
Method Details
-
setDataSource
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
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.
-