Package org.anchoranalysis.core.time
Class ExecutionTimeRecorder
Object
ExecutionTimeRecorder
- Direct Known Subclasses:
ExecutionTimeRecorderIgnore
Records the execution-time of particular operations.
- Author:
- Owen Feehan
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract boolean
isOperationAlreadyRecorded
(String operationIdentifier) Has a particular operation already been recorded?abstract long
measureTime
(boolean start, String... operationIdentifiers) IndicatesoperationIdentifier
is being recorded, and returns the current clock timestamp.abstract RecordedExecutionTimes
The execution-times that have been recorded.abstract void
recordExecutionTime
(String operationIdentifier, long millis) Records the execution-time of a particular operation.<E extends Exception>
voidrecordExecutionTime
(String operationIdentifier, CheckedRunnable<E> operation) Executes anoperation
while recording the execution-time - without a return type.<T,
E extends Exception>
TrecordExecutionTime
(String operationIdentifier, CheckedSupplier<T, E> operation) Executes anoperation
while recording the execution-time - with a return type.void
recordExecutionTimeUnchecked
(String operationIdentifier, Runnable operation) Executes anoperation
while recording the execution-time - without a return type, and without throwing an exception..void
recordTimeDifferenceBetween
(String operationIdentifier, long startTimestamp, long endTimestamp) Records the execution-time of a particular operation by subtracting the start-time from the end time.
-
Constructor Details
-
ExecutionTimeRecorder
public ExecutionTimeRecorder()
-
-
Method Details
-
recordedTimes
The execution-times that have been recorded.- Returns:
- newly created
RecordedExecutionTimes
that describes the execution-times.
-
recordExecutionTime
Records the execution-time of a particular operation.- Parameters:
operationIdentifier
- a string uniquely identifying the operation.millis
- how long the operation took in milliseconds.
-
isOperationAlreadyRecorded
Has a particular operation already been recorded?- Parameters:
operationIdentifier
- a string uniquely identifying the operation.- Returns:
- true if the operation has already been recorded at least once, false otherwise.
-
recordExecutionTimeUnchecked
Executes anoperation
while recording the execution-time - without a return type, and without throwing an exception..Operation times are always executed, even they throw an Exception or otherwise end in failure.
- Parameters:
operationIdentifier
- an identifier for this type of write-operation, under which execution-times are aggregated.operation
- the operation to execute
-
recordExecutionTime
public <E extends Exception> void recordExecutionTime(String operationIdentifier, CheckedRunnable<E> operation) throws E Executes anoperation
while recording the execution-time - without a return type.Operation times are always executed, even they throw an Exception or otherwise end in failure.
- Type Parameters:
E
- type of an exception thatoperation
may throw.- Parameters:
operationIdentifier
- an identifier for this type of write-operation, under which execution-times are aggregated.operation
- the operation to execute- Throws:
E
- ifoperation
throws this exception;
-
recordExecutionTime
public <T,E extends Exception> T recordExecutionTime(String operationIdentifier, CheckedSupplier<T, E> operation) throws EExecutes anoperation
while recording the execution-time - with a return type.Operation times are always executed, even they throw an Exception or otherwise end in failure.
- Type Parameters:
T
- return-type ofoperation
.E
- type of an exception thatoperation
may throw.- Parameters:
operationIdentifier
- an identifier for this type of write-operation, under which execution-times are aggregated.operation
- the operation to execute- Returns:
- the value returned by
operation
. - Throws:
E
- ifoperation
throws this exception,
-
recordTimeDifferenceBetween
public void recordTimeDifferenceBetween(String operationIdentifier, long startTimestamp, long endTimestamp) Records the execution-time of a particular operation by subtracting the start-time from the end time.- Parameters:
operationIdentifier
- a string uniquely identifying the operation.startTimestamp
- a system clock timestamp (in milliseconds since the epoch) for when the operation began.endTimestamp
- a system clock timestamp (in milliseconds since the epoch) for when the operation ended.
-
measureTime
IndicatesoperationIdentifier
is being recorded, and returns the current clock timestamp.- Parameters:
start
- true, if this time indicates the start of an operation. false, if it only describes the end.operationIdentifiers
- all possible identifiers that may subsequently be used to record an end-time for this operation.- Returns:
- the a system clock timestamp (in milliseconds since the epoch).
-