org.sormula.operation.monitor
Class OperationTime

java.lang.Object
  extended by org.sormula.operation.monitor.OperationTime
Direct Known Subclasses:
NoOperationTime

public class OperationTime
extends java.lang.Object

Records execution times for subclasses of SqlOperation. The excecution times that may be recorded are prepare (JDBC prepare), write (setting column and where parameters), execute (JDBC execute), and read (reading result set values into row objects). A total time is the sum of all prepare, write, execute, and read times.

An optional parentOperationTime can be set used to hold subtotals of more than on OperationTime.

This class is not thread safe. If more than one thread will be updating times, then synchronize for proper results.

Since:
1.5
Author:
Jeff Miller

Constructor Summary
OperationTime(java.lang.String timingId)
          Constructs for a timing id.
OperationTime(java.lang.String timingId, OperationTime parentOperationTime)
          Constructs for a timing id and a parent summary.
 
Method Summary
 void cancel()
          Cancels recording active time.
protected  java.lang.String format(ElapsedTime et)
          Formats an ElapsedTime into a standard format.
 java.lang.String getDescription()
           
 ElapsedTime getExecuteTime()
           
 ElapsedTime getPrepareTime()
           
 ElapsedTime getReadTime()
           
 java.lang.String getTimingId()
           
 ElapsedTime getTotalTime()
           
 ElapsedTime getWriteTime()
           
 void logTimings()
          Writes prepare, write, execute, and read time to log along with average, total, and percent.
 void pause()
          Stops recording the currently active time until resume() is invoked.
 void resume()
          Starts recording the active time that was paused.
 void setDescription(java.lang.String description)
          Sets description for timings that are logged with logTimings().
protected  void start(ElapsedTime et)
          Starts recording an elapsed time.
 void startExecuteTime()
          Starts recording execute time.
 void startPrepareTime()
          Starts recording prepare time.
 void startReadTime()
          Starts recording read time.
 void startWriteTime()
          Starts recording write time.
 void stop()
          Stops recording the active time that was started with one of the start methods.
 void updateSource(java.lang.StackTraceElement stackTraceElement)
          Records stack trace information and count where timing is initiated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OperationTime

public OperationTime(java.lang.String timingId)
Constructs for a timing id.

Parameters:
timingId - a String that uniquely identifies a set of timings

OperationTime

public OperationTime(java.lang.String timingId,
                     OperationTime parentOperationTime)
Constructs for a timing id and a parent summary.

Parameters:
timingId - a String that uniquely identifies a set of timings
parentOperationTime - an operation time that will record timings; null for none
Method Detail

getTimingId

public java.lang.String getTimingId()
Returns:
timing id that was supplied in constructor

getDescription

public java.lang.String getDescription()
Returns:
description supplied by setDescription(String)

setDescription

public void setDescription(java.lang.String description)
Sets description for timings that are logged with logTimings(). A good description to use would be SqlOperation.getSql().

Parameters:
description - human readable label for timings when they are logged

startPrepareTime

public void startPrepareTime()
Starts recording prepare time. Use stop() to stop recording.


startWriteTime

public void startWriteTime()
Starts recording write time. Use stop() to stop recording.


startExecuteTime

public void startExecuteTime()
Starts recording execute time. Use stop() to stop recording.


startReadTime

public void startReadTime()
Starts recording read time. Use stop() to stop recording.


start

protected void start(ElapsedTime et)
Starts recording an elapsed time. et will be set as the active time. Methods cancel(), stop(), pause(), and resume() act upon the active time.

Parameters:
et - elapsed time to start

stop

public void stop()
Stops recording the active time that was started with one of the start methods. The total pause time is subtracted from total time between start/stop.


cancel

public void cancel()
Cancels recording active time.


pause

public void pause()
Stops recording the currently active time until resume() is invoked. Zero or more pause/resume pairs may be invoked.


resume

public void resume()
Starts recording the active time that was paused.


getPrepareTime

public ElapsedTime getPrepareTime()
Returns:
prepare time

getWriteTime

public ElapsedTime getWriteTime()
Returns:
write time

getExecuteTime

public ElapsedTime getExecuteTime()
Returns:
execute time

getReadTime

public ElapsedTime getReadTime()
Returns:
read time

getTotalTime

public ElapsedTime getTotalTime()
Returns:
sum of prepare, write, execute, and read time

updateSource

public void updateSource(java.lang.StackTraceElement stackTraceElement)
Records stack trace information and count where timing is initiated. Parent operation time is updated also.

Parameters:
stackTraceElement - the location on the stack where operation was initiated

logTimings

public void logTimings()
Writes prepare, write, execute, and read time to log along with average, total, and percent.


format

protected java.lang.String format(ElapsedTime et)
Formats an ElapsedTime into a standard format.

Parameters:
et - elapsed time to format
Returns:
et formatted into a String