public class ElapsedTime
extends java.lang.Object
getCount()
, is incremented
for each start/stop so that an average elapsed time can be calculated, getAverageTime()
.Constructor and Description |
---|
ElapsedTime(java.lang.String name)
Constructs for name and no other totals.
|
ElapsedTime(java.lang.String name,
ElapsedTime total,
ElapsedTime parent)
Constructs for name, total, and parent.
|
Modifier and Type | Method and Description |
---|---|
protected void |
add(long elpasedNanos)
Adds nanoseconds to this time and adds to total and parent if they are not
null.
|
void |
cancel()
|
protected java.lang.String |
format(long nanoseconds)
Formats the elapsed time using the current time format.
|
long |
getAverageTime() |
int |
getCount() |
java.lang.String |
getFormattedAverageTime() |
java.lang.String |
getFormattedTime() |
java.lang.String |
getName() |
ElapsedTime |
getParent() |
long |
getTime() |
java.lang.String |
getTimeFormat()
Gets the format string to use by
getFormattedTime() and
getFormattedAverageTime() . |
ElapsedTime |
getTotal() |
boolean |
isFirstIgnored() |
boolean |
isIgnoreFirst() |
void |
pause()
Stops recording time until
resume() is invoked. |
void |
resume()
Starts recording the after pause.
|
void |
setIgnoreFirst(boolean ignoreFirst)
Sets what to do with the first time recorded.
|
void |
setTimeFormat(java.lang.String timeFormat)
Sets the format string to use when formatting time.
|
void |
start()
Starts recording elapsed time.
|
void |
stop()
Stops recording elapsed time.
|
public ElapsedTime(java.lang.String name)
name
- name to display in log filepublic ElapsedTime(java.lang.String name, ElapsedTime total, ElapsedTime parent)
name
- name to display in log filetotal
- elapsed times are summed into this total; null for noneparent
- elapsed times are summed into this parent total; null for nonepublic java.lang.String getName()
public ElapsedTime getTotal()
public ElapsedTime getParent()
public void start()
public void stop()
public void cancel()
public void pause()
resume()
is invoked. Zero
or more pause/resume pairs may be invoked.public void resume()
protected void add(long elpasedNanos)
elpasedNanos
- nanoseconds to add; positive to add or negative to subtractpublic long getTime()
public long getAverageTime()
public boolean isIgnoreFirst()
public void setIgnoreFirst(boolean ignoreFirst)
stop()
is used) is a rough way to exclude class loading
times which may skew the average time for all occurrences.ignoreFirst
- true to ignore the first time; false to record all timespublic boolean isFirstIgnored()
public java.lang.String getTimeFormat()
getFormattedTime()
and
getFormattedAverageTime()
.String.format(String, Object...)
format to usepublic void setTimeFormat(java.lang.String timeFormat)
String.format(String, Object...)
is used
to format.timeFormat
- String.format(String, Object...)
format to usepublic java.lang.String getFormattedTime()
public java.lang.String getFormattedAverageTime()
protected java.lang.String format(long nanoseconds)
nanoseconds
- time in nanoseconds