|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjodd.datetime.JStopWatch
public class JStopWatch
Nice thread-aware stopwatch that supports time spans, cumulative times and laps. Useful for all kind of profiling, time measurements etc.
| Field Summary | |
|---|---|
protected java.util.List<long[]> |
laps
List of all laps. |
protected java.lang.String |
name
Optional stopwatch name. |
protected boolean |
running
Running flag. |
protected long |
spanTime
Last elapsed time. |
protected long |
startTime
Last start time. |
protected long |
stopTime
Last stop time. |
protected long |
totalTime
Cumulative elapsed time. |
| Constructor Summary | |
|---|---|
JStopWatch()
Starts the stopwatch. |
|
JStopWatch(boolean putInThread)
|
|
JStopWatch(java.lang.String name)
Starts the named stopwatch. |
|
JStopWatch(java.lang.String name,
boolean assignToCurrentThread)
Starts the stopwatch. |
|
| Method Summary | |
|---|---|
protected void |
assignToCurrentThread()
Puts current stopwatch in current thread. |
long |
elapsed()
Returns total elapsed time from the start() in ms. |
static java.lang.String |
formatTimeSpan(long millis)
Formats time spans. |
long[] |
getLapTimes(int index)
Returns lap times for 1-based lap index. |
java.lang.String |
getName()
Returns stopwatch name. |
static JStopWatch |
getThreadStopWatch()
Returns thread-assigned stop watch. |
boolean |
isRunning()
Returns true if stopwatch is running. |
long |
lap()
Marks a lap and returns its length. |
protected long |
lap(long lap)
|
long |
restart()
Restarts the stopwatch. |
long |
span()
Stops the stopwatch and returns total time span for last start-stop sequence. |
long |
start()
Starts the stopwatch. |
long |
stop()
Stops the stopwatch if running. |
java.lang.String |
toString()
Returns total elapsed time as formatted string from the last start. |
long |
total()
Stops the stopwatch and returns total cumulative time in ms. |
int |
totalLaps()
Returns the total number of laps up to this moment. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected java.lang.String name
protected long startTime
protected long stopTime
protected long spanTime
protected long totalTime
protected boolean running
protected java.util.List<long[]> laps
| Constructor Detail |
|---|
public JStopWatch()
public JStopWatch(boolean putInThread)
public JStopWatch(java.lang.String name)
public JStopWatch(java.lang.String name,
boolean assignToCurrentThread)
| Method Detail |
|---|
protected void assignToCurrentThread()
public static JStopWatch getThreadStopWatch()
public java.lang.String getName()
public boolean isRunning()
true if stopwatch is running.
public long start()
stop() must be called prior to restart.
Returns starting time in milliseconds.
public long restart()
public long stop()
public long elapsed()
start() in ms.
public long total()
public long span()
public long lap()
protected long lap(long lap)
public int totalLaps()
public long[] getLapTimes(int index)
null if laps are not used or if index is invalid.
public java.lang.String toString()
toString in class java.lang.Objectpublic static java.lang.String formatTimeSpan(long millis)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||