Class PlatformMonitor

java.lang.Object
org.eclipse.jetty.toolchain.perf.PlatformMonitor
All Implemented Interfaces:
Runnable

public class PlatformMonitor extends Object implements Runnable
Helper class that reports a number of information about the JVM and the OS, useful to monitor the JVM during a benchmark.
Typical usage:
 PlatformMonitor monitor = new PlatformMonitor();
 Start start = monitor.start();
 if (start != null)
 {
     // Monitoring started, print out
     // initial platform information.
     System.err.println(start);

     // Perform benchmark

     Stop stop = monitor.stop();
     if (stop != null)
     {
         // Monitoring stopped, print out
         // ending platform information.
         System.err.println(stop);
     }
 }
 
PlatformMonitor supports multiple concurrent invocations to start() and stop(), so that it can be used on a server when multiple clients sends to the server a "start monitor" message. Calls to start() and stop() must be paired and a PlatformMonitor.Start object is returned for the first paired start() call, and a PlatformMonitor.Stop object is returned for the last paired stop() call.
GC activity is being polled, by default every 250 ms, see setMemoryPollInterval(long). If the benchmark triggers GC at a higher rate, the results reported by this class may be inaccurate.
  • Constructor Details

    • PlatformMonitor

      public PlatformMonitor()
  • Method Details

    • getMemoryPollInterval

      public long getMemoryPollInterval()
    • setMemoryPollInterval

      public void setMemoryPollInterval​(long gcPollInterval)
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • start

      public PlatformMonitor.Start start()
      Starts monitoring the platform.
      This method returns a PlatformMonitor.Start object the first time it is invoked, or the first time it is invoked after paired stop() calls. For example:
       PlatformMonitor monitor = new PlatformMonitor();
      
       Start start = monitor.start(); // first start call, start != null
       start = monitor.start();       // second start call, start == null
       Stop stop = monitor.stop();    // first stop call, stop == null
       stop = monitor.stop();         // last stop call, stop != null
      
       start = monitor.start();       // first start call after paired stops, start != null
       stop = monitor.stop();         // paired stop call, stop != null
       
      Returns:
      a PlatformMonitor.Start object if the monitoring started, null for additional calls to this method not paired with a stop() call.
      See Also:
      stop()
    • stop

      public PlatformMonitor.Stop stop()
      Stops the monitoring of the platform.
      Returns:
      a PlatformMonitor.Stop object if the monitoring stopped, null for calls to this method not paired with the first start() call.
      See Also:
      start()