TUM CCSM Commons

edu.tum.cs.commons.system
Class PerformanceMonitor

java.lang.Object
  extended by edu.tum.cs.commons.system.PerformanceMonitor

public class PerformanceMonitor
extends java.lang.Object

Combines a timer and a memory monitor in a simple utility class. Measures both total memory and the delta between start() and stop().

In order to avoid programming mistakes, the calls to the methods start() and stop() must adhere to a simple protocol:
The PerformanceMonitor can be in on of the three states NOT_RUN, RUNNING, FINISHED.

start() May only be called in state NOT_RUN and stop() may only be called in state RUNNING.

All other calls to start() and stop() result in IllegalArgumentExceptions

Version:
$Revision: 26283 $
Author:
Elmar Juergens, $Author: juergens $
Rating:
GREEN Hash: 11F99E9698215A2906756FE003D9D30A

Method Summary
static PerformanceMonitor create()
          Convenience factory method: Creates a new PerformanceMonitor and starts it.
static PerformanceMonitor create(boolean useMemoryMonitor)
          Convenience factory method: Creates a new PerformanceMonitor and starts it.
 long getDeltaMemUsageInBytes()
          Gets the delta in memory consumption in bytes
 long getDeltaMemUsageInKBs()
          Gets the delta in memory consumption in kilobytes
 long getMaxMemUsageInBytes()
          Gets the maximal memory consumption in bytes
 long getMaxMemUsageInKBs()
          Gets the maximal memory consumption in kilobytes
 long getMilliseconds()
          Gets the measured time in milliseconds
 long getSeconds()
          Gets the measured time in seconds.
 void start()
          Starts the PerformanceMonitor.
 void stop()
          Stops the PerformanceMonitor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static PerformanceMonitor create(boolean useMemoryMonitor)
Convenience factory method: Creates a new PerformanceMonitor and starts it.

Parameters:
useMemoryMonitor - detemines whether the PerformanceMonitor internally uses a MemoryMonitor to measure memory consumption. This requires more resources, since the MemoryMonitor runs its own thread, but promises more precise measurement of maximum memory consumption.

create

public static PerformanceMonitor create()
Convenience factory method: Creates a new PerformanceMonitor and starts it. PerformanceMonitor does not use a MemoryMonitor internally


start

public void start()
Starts the PerformanceMonitor. It will measure time and maximal memory consumption until the method stop() is called.

This method may only be called, if the PerformanceMonitor is in state NOT_RUN. (i.e., after it has been created).

All subsequent calls to this method will result in a IllegalStateException


stop

public void stop()
Stops the PerformanceMonitor.

This method may only be called, if the PerformanceMonitor is in state RUNNING. (i.e., after a call to start()).

If the PerformanceMonitor is in any other state, a call to this method results in an IllegalStateException


getSeconds

public long getSeconds()
Gets the measured time in seconds. (Fractions of seconds are discarded)


getMilliseconds

public long getMilliseconds()
Gets the measured time in milliseconds


getMaxMemUsageInBytes

public long getMaxMemUsageInBytes()
Gets the maximal memory consumption in bytes


getMaxMemUsageInKBs

public long getMaxMemUsageInKBs()
Gets the maximal memory consumption in kilobytes


getDeltaMemUsageInBytes

public long getDeltaMemUsageInBytes()
Gets the delta in memory consumption in bytes


getDeltaMemUsageInKBs

public long getDeltaMemUsageInKBs()
Gets the delta in memory consumption in kilobytes


TUM CCSM Commons

TUM CCSM Commons - 2.7