util
Class PerformanceMeter

java.lang.Object
  extended by util.PerformanceMeter

public class PerformanceMeter
extends Object

A class that test the performance of methods within an object. It relies on the ExecutingMethod class, thus all restrictions mentioned there apply.

This class is costructed with an object to be monitored. On construct, all methods of the declaring class of this object with a unique name are recorded. To actually do the metering, code your methods like:

   public void meterMe() {
       performancemeter.enter();
       ...
       performanemeter.exit();
       return;
   }
   
This records the execution time at each method call. Statistics can then be queried from the performance meter.


Nested Class Summary
protected static class PerformanceMeter.BoundList<T>
          Bound lists do not grow above a certain size, they lose elemtns at their head, but retain the very first entry.
 
Field Summary
private  Map<Method,Long> enter
          A lookup table linking method names to enter times to recall for exit.
private  Map<Method,PerformanceMeter.BoundList<Long>> table
          A lookup table matching method names to lists of executin times.
 
Constructor Summary
PerformanceMeter(Object monitor)
          Constructs a new performance meter for the given object.
 
Method Summary
 void enter()
          Called from within a method that should be monitored at method start.
 void exit()
          Called from within a method that should be monitored at method end.
 long getFirstTime(Method monitor)
          Get the first execution time for the given method or -1 if this method was never monitored.
 long getLastTime(Method monitor)
          Get the last execution time for the given method or -1 if this method was never monitored.
 long getMaximumTime(Method monitor)
          Get the maximum time for the given method or -1 if this method was never monitored.
 double getMeanTime(Method monitor)
          Gets the arithmetic average.
 double getMedianTime(Method monitor)
          Gets the median execution time.
 long getMinimumTime(Method monitor)
          Get the minimum time for the given method or -1 if this method was never monitored.
 void printStatistics()
          Prints statistic to system.out
 void printStatistics(PrintStream out)
          Prints statistic to system.out
 void printStatistics(PrintWriter out)
          Prints statistic to system.out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

table

private Map<Method,PerformanceMeter.BoundList<Long>> table
A lookup table matching method names to lists of executin times.


enter

private Map<Method,Long> enter
A lookup table linking method names to enter times to recall for exit.

Constructor Detail

PerformanceMeter

public PerformanceMeter(Object monitor)
Constructs a new performance meter for the given object. All of the methods found in the declaring class are put into a lookup table with an intrinsically empty PerformanceMeter.BoundList. Whenever the enter method is called, we rocord the system time, which is added to the methods list at a call to exit().

Method Detail

enter

public void enter()
Called from within a method that should be monitored at method start. We trace the calling method and record the current system time.


exit

public void exit()
Called from within a method that should be monitored at method end. We trace the calling method and check if this method was entered previously. If so, we record the execution time.


getMinimumTime

public long getMinimumTime(Method monitor)
Get the minimum time for the given method or -1 if this method was never monitored.


getMaximumTime

public long getMaximumTime(Method monitor)
Get the maximum time for the given method or -1 if this method was never monitored.


getFirstTime

public long getFirstTime(Method monitor)
Get the first execution time for the given method or -1 if this method was never monitored.


getLastTime

public long getLastTime(Method monitor)
Get the last execution time for the given method or -1 if this method was never monitored.


getMedianTime

public double getMedianTime(Method monitor)
Gets the median execution time. Involves sorting, rather slow.


getMeanTime

public double getMeanTime(Method monitor)
Gets the arithmetic average.


printStatistics

public void printStatistics()
Prints statistic to system.out


printStatistics

public void printStatistics(PrintStream out)
Prints statistic to system.out


printStatistics

public void printStatistics(PrintWriter out)
Prints statistic to system.out. Only valid entries are printed.