com.waveset.util
Class MethodTimer

java.lang.Object
  extended bycom.waveset.util.MethodTimer
All Implemented Interfaces:
java.lang.Comparable

public class MethodTimer
extends java.lang.Object
implements java.lang.Comparable

A simple class to keep track of how long a method call takes. It is controlled by Waveset.Properties entries to turn off timings, collect stack traces, and set stack depth. The basic idea is to construct one, then call exit() when the method is done. This keeps a static map of all of the calls and their cumulative statistics, and renders reports for the gui (called from debug/Show_Timings.jsp).


Nested Class Summary
static class MethodTimer.HistoryEntry
          A simple class to store a history entry, used for charting performance
static class MethodTimer.StackTraceEntry
          A simple class to get the current stack trace, wrap it for storage in a collection or map, and keep track of a count.
 
Field Summary
static java.lang.String code_id
           
static byte GET_AVERAGE_DATA
           
static byte GET_MAX_DATA
           
static byte GET_MIN_DATA
           
 
Constructor Summary
MethodTimer(java.lang.String name, java.lang.Class c)
          Create a MethodTimer and start the clock.
MethodTimer(java.lang.String methodName, java.lang.String className)
          Create a MethodTimer and start the clock.
 
Method Summary
static void clear()
           
 int compareTo(java.lang.Object o)
          For the interface Comparable
static void dump()
           
 long elapsedTime()
          How much time has elapsed since the MethodTimer was constructed
 void exit(boolean errorOccurred)
          Must be called at the exit of a timed routine.
static java.util.List generateDisplayData(java.util.List in, int numBuckets, int maxMinOrAve, boolean timeBasedBuckets)
          walk through the list, making datapoints for the display applet Get the first and last dates, make up 20 buckets, generate the data The returned list is a list of HistoryEntry elements, with the event times normalized and the data either averaged, max'ed or min'ed
static java.lang.String getVariables()
           
static java.util.List itemHistoryToList(java.lang.String itemName)
          Build a list of entries in time-order, oldest first.
static void itemStackTracesToHtml(java.lang.StringBuffer sb, java.lang.String itemName)
           
static java.util.List itemStacktracesToList(MethodTimer mt)
           
static void remove(java.lang.String name)
           
static void setItemHistoryLength(java.lang.String itemName, int size)
          Set the item history length.
static void toHtml(java.lang.StringBuffer sb)
           
static void toHtml(java.lang.StringBuffer sb, java.lang.String removeLink)
           
static void toHtml(java.lang.StringBuffer sb, java.lang.String removeLink, java.lang.String detailsLink, java.lang.String historyLink, java.lang.String historyDataLink)
           
static java.util.List toList(java.lang.String removeLink, java.lang.String detailsLink, java.lang.String historyLink, java.lang.String historyDataLink)
           
static java.util.List toList(java.lang.String removeLink, java.lang.String detailsLink, java.lang.String historyLink, java.lang.String historyDataLink, boolean showTotalTime, boolean stripClassNames)
           
static void toPlainText(java.lang.StringBuffer sb)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

GET_MAX_DATA

public static final byte GET_MAX_DATA
See Also:
Constant Field Values

GET_MIN_DATA

public static final byte GET_MIN_DATA
See Also:
Constant Field Values

GET_AVERAGE_DATA

public static final byte GET_AVERAGE_DATA
See Also:
Constant Field Values
Constructor Detail

MethodTimer

public MethodTimer(java.lang.String name,
                   java.lang.Class c)
Create a MethodTimer and start the clock.

Parameters:
name - name to be logged. Handy to be type specific, like "get( " + type + " )"

MethodTimer

public MethodTimer(java.lang.String methodName,
                   java.lang.String className)
Create a MethodTimer and start the clock.

Method Detail

elapsedTime

public long elapsedTime()
How much time has elapsed since the MethodTimer was constructed


compareTo

public int compareTo(java.lang.Object o)
For the interface Comparable

Specified by:
compareTo in interface java.lang.Comparable

exit

public void exit(boolean errorOccurred)
Must be called at the exit of a timed routine. Can be called multiple times, will only record the first one so that it may be used like: MethodTimer mt = new MethodTimer("login times", this.getClass()); try { post("/lighthouse/login.jsp", data, "display its contents"); } catch (Exception ex) { mt.exit(true); throw ex; } finally { mt.exit(false); }


remove

public static void remove(java.lang.String name)

clear

public static void clear()

dump

public static void dump()

itemStackTracesToHtml

public static void itemStackTracesToHtml(java.lang.StringBuffer sb,
                                         java.lang.String itemName)

setItemHistoryLength

public static void setItemHistoryLength(java.lang.String itemName,
                                        int size)
Set the item history length. 0 disables keeping history. This will delete the existing history items.


itemHistoryToList

public static java.util.List itemHistoryToList(java.lang.String itemName)
Build a list of entries in time-order, oldest first.


generateDisplayData

public static java.util.List generateDisplayData(java.util.List in,
                                                 int numBuckets,
                                                 int maxMinOrAve,
                                                 boolean timeBasedBuckets)
walk through the list, making datapoints for the display applet Get the first and last dates, make up 20 buckets, generate the data The returned list is a list of HistoryEntry elements, with the event times normalized and the data either averaged, max'ed or min'ed


itemStacktracesToList

public static java.util.List itemStacktracesToList(MethodTimer mt)

toHtml

public static void toHtml(java.lang.StringBuffer sb)

toHtml

public static void toHtml(java.lang.StringBuffer sb,
                          java.lang.String removeLink)

toHtml

public static void toHtml(java.lang.StringBuffer sb,
                          java.lang.String removeLink,
                          java.lang.String detailsLink,
                          java.lang.String historyLink,
                          java.lang.String historyDataLink)

toPlainText

public static void toPlainText(java.lang.StringBuffer sb)

getVariables

public static java.lang.String getVariables()

toList

public static java.util.List toList(java.lang.String removeLink,
                                    java.lang.String detailsLink,
                                    java.lang.String historyLink,
                                    java.lang.String historyDataLink)

toList

public static java.util.List toList(java.lang.String removeLink,
                                    java.lang.String detailsLink,
                                    java.lang.String historyLink,
                                    java.lang.String historyDataLink,
                                    boolean showTotalTime,
                                    boolean stripClassNames)