Class ExecutionTimeRecorder

Object
ExecutionTimeRecorder
Direct Known Subclasses:
ExecutionTimeRecorderIgnore

public abstract class ExecutionTimeRecorder extends Object
Records the execution-time of particular operations.
Author:
Owen Feehan
  • Constructor Details

    • ExecutionTimeRecorder

      public ExecutionTimeRecorder()
  • Method Details

    • recordedTimes

      public abstract RecordedExecutionTimes recordedTimes()
      The execution-times that have been recorded.
      Returns:
      newly created RecordedExecutionTimes that describes the execution-times.
    • recordExecutionTime

      public abstract void recordExecutionTime(String operationIdentifier, long millis)
      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

      public abstract boolean isOperationAlreadyRecorded(String operationIdentifier)
      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

      public void recordExecutionTimeUnchecked(String operationIdentifier, Runnable operation)
      Executes an operation 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 an operation 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 that operation 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 - if operation throws this exception;
    • recordExecutionTime

      public <T, E extends Exception> T recordExecutionTime(String operationIdentifier, CheckedSupplier<T,E> operation) throws E
      Executes an operation 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 of operation.
      E - type of an exception that operation 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 - if operation 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

      public abstract long measureTime(boolean start, String... operationIdentifiers)
      Indicates operationIdentifier 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).