Class PerfDataUtil

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

public final class PerfDataUtil
extends java.lang.Object
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 Classes 
    Modifier and Type Class Description
    static class  PerfDataUtil.PerfCounter  
  • Method Summary

    Modifier and Type Method Description
    static boolean addCounter​(com.sun.jna.platform.win32.WinNT.HANDLEByReference query, java.lang.String path, com.sun.jna.platform.win32.WinNT.HANDLEByReference p)
    Adds a pdh counter to a query
    static boolean closeQuery​(com.sun.jna.platform.win32.WinNT.HANDLEByReference q)
    Close a pdh query
    static PerfDataUtil.PerfCounter createCounter​(java.lang.String object, java.lang.String instance, java.lang.String counter)
    Create a Performance Counter
    static boolean openQuery​(com.sun.jna.platform.win32.WinNT.HANDLEByReference q)
    Open a pdh query
    static long queryCounter​(com.sun.jna.platform.win32.WinNT.HANDLEByReference counter)
    Get value of pdh counter
    static boolean removeCounter​(com.sun.jna.platform.win32.WinNT.HANDLEByReference p)
    Remove a pdh counter
    static long updateQueryTimestamp​(com.sun.jna.platform.win32.WinNT.HANDLEByReference query)
    Update a query and get the timestamp

    Methods inherited from class java.lang.Object

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

    • createCounter

      public static PerfDataUtil.PerfCounter createCounter​(java.lang.String object, java.lang.String instance, java.lang.String counter)
      Create a Performance Counter
      Parameters:
      object - The object/path for the counter
      instance - The instance of the counter, or null if no instance
      counter - 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
    • addCounter

      public static boolean addCounter​(com.sun.jna.platform.win32.WinNT.HANDLEByReference query, java.lang.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 counter
      path - String name of the PerfMon counter
      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