Package oshi.util.platform.windows
Class PerfDataUtil
java.lang.Object
oshi.util.platform.windows.PerfDataUtil
Helper class to centralize the boilerplate portions of PDH counter setup and allow applications to easily add, query,
and remove counters.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classEncapsulates the three string components of a performance counter -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final booleanprivate static final org.slf4j.Loggerprivate static final com.sun.jna.platform.win32.Pdhprivate static final com.sun.jna.platform.win32.WinDef.DWORDByReferenceprivate static final com.sun.jna.platform.win32.BaseTSD.DWORD_PTR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanaddCounter(com.sun.jna.platform.win32.WinNT.HANDLEByReference query, String path, com.sun.jna.platform.win32.WinNT.HANDLEByReference p) Adds a pdh counter to a querystatic booleancloseQuery(com.sun.jna.platform.win32.WinNT.HANDLEByReference q) Close a pdh querystatic PerfDataUtil.PerfCountercreateCounter(String object, String instance, String counter) Create a Performance Counterstatic booleanopenQuery(com.sun.jna.platform.win32.WinNT.HANDLEByReference q) Open a pdh querystatic longqueryCounter(com.sun.jna.platform.win32.WinNT.HANDLEByReference counter) Get value of pdh counterstatic longquerySecondCounter(com.sun.jna.platform.win32.WinNT.HANDLEByReference counter) Get value of pdh counter's second value (base counters)static booleanremoveCounter(com.sun.jna.platform.win32.WinNT.HANDLEByReference p) Remove a pdh counterstatic longupdateQueryTimestamp(com.sun.jna.platform.win32.WinNT.HANDLEByReference query) Update a query and get the timestamp
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
PZERO
private static final com.sun.jna.platform.win32.BaseTSD.DWORD_PTR PZERO -
PDH_FMT_RAW
private static final com.sun.jna.platform.win32.WinDef.DWORDByReference PDH_FMT_RAW -
PDH
private static final com.sun.jna.platform.win32.Pdh PDH -
IS_VISTA_OR_GREATER
private static final boolean IS_VISTA_OR_GREATER
-
-
Constructor Details
-
PerfDataUtil
private PerfDataUtil()
-
-
Method Details
-
createCounter
public static PerfDataUtil.PerfCounter createCounter(String object, String instance, String counter) Create a Performance Counter- Parameters:
object- The object/path for the counterinstance- The instance of the counter, or null if no instancecounter- The counter name- Returns:
- A PerfCounter object encapsulating the object, instance, and counter
-
updateQueryTimestamp
public static long updateQueryTimestamp(com.sun.jna.platform.win32.WinNT.HANDLEByReference query) Update a query and get the timestamp- Parameters:
query- The query to update all counters in- Returns:
- The update timestamp of the first counter in the query
-
openQuery
public static boolean openQuery(com.sun.jna.platform.win32.WinNT.HANDLEByReference q) Open a pdh query- Parameters:
q- pointer to the query- Returns:
- true if successful
-
closeQuery
public static boolean closeQuery(com.sun.jna.platform.win32.WinNT.HANDLEByReference q) Close a pdh query- Parameters:
q- pointer to the query- Returns:
- true if successful
-
queryCounter
public static long queryCounter(com.sun.jna.platform.win32.WinNT.HANDLEByReference counter) Get value of pdh counter- Parameters:
counter- The counter to get the value of- Returns:
- long value of the counter, or negative value representing an error code
-
querySecondCounter
public static long querySecondCounter(com.sun.jna.platform.win32.WinNT.HANDLEByReference counter) Get value of pdh counter's second value (base counters)- Parameters:
counter- The counter to get the value of- Returns:
- long value of the counter's second value, or negative value representing an error code
-
addCounter
public static boolean addCounter(com.sun.jna.platform.win32.WinNT.HANDLEByReference query, String path, com.sun.jna.platform.win32.WinNT.HANDLEByReference p) Adds a pdh counter to a query- Parameters:
query- Pointer to the query to add the counterpath- String name of the PerfMon counter. For Vista+, must be in English. Must localize this path for pre-Vista.p- Pointer to the counter- Returns:
- true if successful
-
removeCounter
public static boolean removeCounter(com.sun.jna.platform.win32.WinNT.HANDLEByReference p) Remove a pdh counter- Parameters:
p- pointer to the counter- Returns:
- true if successful
-