JPDH

Windows Performance Data Helper for Java

Get Started

Why JPDH?

JPDH exposes Windows performance data helper (PDH) in the Java programming language, and provides some additional features that should have been in PDH but are not, such as the possibility to refer to processes by PID instead of process instance name (process instance name can change while PID can't).

JPDH is orders of magnitude faster than WMI and is a good alternative to the latter when performance is critical.

JPDH has been integrated as an alternative to WMI in the JRDS performance collector, where it provides much faster response times.

Code sample

Here's JPDH in action.


    import com.arkanosis.jpdh.Counter;
    import com.arkanosis.jpdh.JPDH;
    import com.arkanosis.jpdh.Query;

    try (Query query = JPDH.openQuery()) {
        Counter diskCounter = query.addCounter("\\PhysicalDisk(_Total)\\Disk Read Bytes/sec");
        Counter cpuCounter = query.addCounter("\\PID(8584)\\% User Time");
        query.collectData();
        System.out.println(diskCounter.getDoubleValue());
        System.out.println(cpuCounter.getIntegerValue());
        query.removeCounter(diskCounter);
    }
                    

Installation

With Maven:


<dependency>
  <groupId>com.arkanosis</groupId>
  <artifactId>jpdh</artifactId>
  <version>1.1.4</version>
</dependency>
                    

With Gradle:


compile("com.arkanosis:jpdh:1.1.4")
                    

Versions history

  • 2019-09-20: version 1.1.4 — Bugfix release. Counters based on the virtual “PID” object sometimes couldn't be initialized while lots of processes were started of stopped.
  • 2017-09-14: version 1.1.3 — Bugfix release. The virtual “PID” object didn't work on localized (eg. German) versions of Windows.
  • 2016-06-08: version 1.1.2 — Bugfix release. Calling Query.removeCounter(counter) on counters associated with dead processes was throwing an exception.
  • 2016-06-01: version 1.1.1 — Bugfix release. Calling Query.removeCounter(counter) on counters associated with dead processes was throwing an exception.
  • 2016-04-19: version 1.1 — Additional “PID” object which maps to the “Process” object for the right process instance and index
  • 2016-04-01: version 1.0 — Initial version exposing PDH features in Java

License

JPDH is Copyright (c) 2016-2019, Jérémie Roquet. JPDH is provided under the terms of the BSD 2-clause license.

Contact

Bug reports, suggestions and pull requests are welcome on GitHub.

Get Connected