
Package ca.uhn.fhir.util
Class StopWatch
- java.lang.Object
-
- ca.uhn.fhir.util.StopWatch
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
endCurrentTask()
Finish the counter on the current task (which was started by callingstartTask(String)
.static String
formatMillis(double theMillis)
Formats a number of milliseconds for display (e.g.static String
formatMillis(long theMillis)
Formats a number of milliseconds for display (e.g.String
formatMillisPerOperation(long theNumOperations)
Returns a nice human-readable display of the time taken per operation.String
formatTaskDurations()
Returns a string providing the durations of all tasks collected bystartTask(String)
String
formatThroughput(long theNumOperations, TimeUnit theUnit)
Determine the current throughput per unit of time (specified in theUnit) assuming that theNumOperations operations have happened.String
getEstimatedTimeRemaining(double theCompleteToDate, double theTotal)
Given an amount of something completed so far, and a total amount, calculates how long it will take for something to completelong
getMillis()
long
getMillis(Date theNow)
long
getMillisAndRestart()
long
getMillisPerOperation(long theNumOperations)
Date
getStartedDate()
double
getThroughput(long theNumOperations, TimeUnit theUnit)
Determine the current throughput per unit of time (specified in theUnit) assuming that theNumOperations operations have happened.void
restart()
void
startTask(String theTaskName)
Starts a counter for a sub-taskString
toString()
Formats value in an appropriate format.
-
-
-
Constructor Detail
-
StopWatch
public StopWatch()
Constructor
-
StopWatch
public StopWatch(Date theStart)
Constructor- Parameters:
theStart
- The time to record as the start for this timer
-
StopWatch
public StopWatch(long theStart)
Constructor- Parameters:
theStart
- The time that the stopwatch was started
-
-
Method Detail
-
endCurrentTask
public void endCurrentTask()
Finish the counter on the current task (which was started by callingstartTask(String)
. This method has no effect if no task is currently started so it's ok to call it more than once.
-
formatMillisPerOperation
public String formatMillisPerOperation(long theNumOperations)
Returns a nice human-readable display of the time taken per operation. Note that this may not actually output the number of milliseconds if the time taken per operation was very long (over 10 seconds)- See Also:
formatMillis(long)
-
formatTaskDurations
public String formatTaskDurations()
Returns a string providing the durations of all tasks collected bystartTask(String)
-
formatThroughput
public String formatThroughput(long theNumOperations, TimeUnit theUnit)
Determine the current throughput per unit of time (specified in theUnit) assuming that theNumOperations operations have happened.For example, if this stopwatch has 2 seconds elapsed, and this method is called for theNumOperations=30 and TimeUnit=SECONDS, this method will return 15
- See Also:
getThroughput(long, TimeUnit)
-
getEstimatedTimeRemaining
public String getEstimatedTimeRemaining(double theCompleteToDate, double theTotal)
Given an amount of something completed so far, and a total amount, calculates how long it will take for something to complete- Parameters:
theCompleteToDate
- The amount so fartheTotal
- The total (must be higher than theCompleteToDate- Returns:
- A formatted amount of time
-
getMillis
public long getMillis()
-
getMillisAndRestart
public long getMillisAndRestart()
-
getMillisPerOperation
public long getMillisPerOperation(long theNumOperations)
- Parameters:
theNumOperations
- Ok for this to be 0, it will be treated as 1
-
getStartedDate
public Date getStartedDate()
-
getThroughput
public double getThroughput(long theNumOperations, TimeUnit theUnit)
Determine the current throughput per unit of time (specified in theUnit) assuming that theNumOperations operations have happened.For example, if this stopwatch has 2 seconds elapsed, and this method is called for theNumOperations=30 and TimeUnit=SECONDS, this method will return 15
- See Also:
formatThroughput(long, TimeUnit)
-
restart
public void restart()
-
startTask
public void startTask(String theTaskName)
Starts a counter for a sub-taskThread Safety Note: This method is not threadsafe! Do not use subtasks in a multithreaded environment.
- Parameters:
theTaskName
- Note that if theTaskName is blank or empty, no task is started
-
toString
public String toString()
Formats value in an appropriate format. SeeformatMillis(long)
} for a description of the format- Overrides:
toString
in classObject
- See Also:
formatMillis(long)
-
formatMillis
public static String formatMillis(long theMillis)
Formats a number of milliseconds for display (e.g. in a log file), tailoring the output to how big the value actually is.Example outputs:
- 133ms
- 00:00:10.223
- 1.7 days
- 64 days
-
formatMillis
public static String formatMillis(double theMillis)
Formats a number of milliseconds for display (e.g. in a log file), tailoring the output to how big the value actually is.Example outputs:
- 133ms
- 00:00:10.223
- 1.7 days
- 64 days
-
-