Package org.freedesktop.dbus.utils
Class TimeMeasure
java.lang.Object
org.freedesktop.dbus.utils.TimeMeasure
Utility class for time measurements.
Instances may be reset for reuse.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longStart time in nanoseconds.private final TimeMeasure.ITimeMeasureFormatFormatter used fortoString() -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance, used a formatter converting everything >= 5000 ms to seconds (X.Y -> 6.1).TimeMeasure(TimeMeasure.ITimeMeasureFormat _formatter) Create a new instance using _ts millis as -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the elapsed time in milliseconds.longgetElapsedFormatted(DateFormat _dateFormat) Formats the elapsed time using the given dateFormatter.(package private) StringgetElapsedFormatted(DateFormat _dateFormat, long _elapsedTime) Same as above, used for proper unit testing.longReturns the elapsed time in seconds.longReturns the start time in milliseconds.final TimeMeasurereset()Resets the start time.(package private) voidsetStartTm(long _tm) Change the start time (for unit testing only!).toString()Returns the elapsed time in milliseconds formatted as string.
-
Field Details
-
startTm
private volatile long startTmStart time in nanoseconds. -
tmf
Formatter used fortoString()
-
-
Constructor Details
-
TimeMeasure
Create a new instance using _ts millis as- Parameters:
_formatter- formatter to use for toString() call
-
TimeMeasure
public TimeMeasure()Create a new instance, used a formatter converting everything >= 5000 ms to seconds (X.Y -> 6.1).
-
-
Method Details
-
reset
Resets the start time.- Returns:
- the object
-
getStartTime
public long getStartTime()Returns the start time in milliseconds.- Returns:
- start time in ms
-
getElapsed
public long getElapsed()Returns the elapsed time in milliseconds.- Returns:
- elapsed time in ms
-
getElapsedSeconds
public long getElapsedSeconds()Returns the elapsed time in seconds.- Returns:
- elapsed time in seconds
-
getElapsedFormatted
Formats the elapsed time using the given dateFormatter. If null is given, a new Formatter with format HH:mm:ss.SSS will be used. The timezone of the given dateFormatter will always be set to 'UTC' to avoid any timezone related offsets.- Parameters:
_dateFormat- date format- Returns:
- formatted string
-
getElapsedFormatted
Same as above, used for proper unit testing.- Parameters:
_dateFormat-_elapsedTime-- Returns:
- formatted string
-
setStartTm
void setStartTm(long _tm) Change the start time (for unit testing only!).- Parameters:
_tm-
-
getElapsedAndReset
public long getElapsedAndReset() -
toString
Returns the elapsed time in milliseconds formatted as string.
-