Class DurationStatistics

java.lang.Object
org.forgerock.openidm.util.DurationStatistics

public class DurationStatistics extends Object
Thread-safe statistics class for time-durations, that calculates accurate count, min, and max values, and approximate mean and standard-deviation, with minimal memory consumption and low-latency under thread-contention.

Online mean and standard-deviation are calculated using the B. P. Welford (1962) technique.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Get number of times stopNanoTime(long) was called, to record a data point.
    long
    max()
    Get running-maximum time-delta, in nanoseconds.
    long
    Get (approximate) running-average time-delta, in nanoseconds.
    long
    min()
    Get running-minimum time-delta, in nanoseconds.
    static long
    nanoToMillis(long nano)
    Converts nanoseconds to milliseconds, and rounds the result.
    static long
    Gets a start-time, in nanoseconds, for the current thread.
    long
    Get (approximate) running-standard-deviation of time-delta, in nanoseconds.
    void
    stopNanoTime(long startNanoTime)
    Calculates and records the time-duration, since startNanoTime() occurred in the current thread.
    long
    sum()
    Get aggregate summation of time-deltas, in nanoseconds.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DurationStatistics

      public DurationStatistics()
      Creates a new instance.
  • Method Details

    • startNanoTime

      public static long startNanoTime()
      Gets a start-time, in nanoseconds, for the current thread. Calling thread must be the same thread used to call stopNanoTime(long).
      Returns:
      Start-time, in nanoseconds
    • stopNanoTime

      public void stopNanoTime(long startNanoTime)
      Calculates and records the time-duration, since startNanoTime() occurred in the current thread. Calling thread must be the same thread used to call startNanoTime().
      Parameters:
      startNanoTime - Start-time, in nanoseconds
    • max

      public long max()
      Get running-maximum time-delta, in nanoseconds.
      Returns:
      Max time-delta, in nanoseconds
    • min

      public long min()
      Get running-minimum time-delta, in nanoseconds.
      Returns:
      Min time-delta, in nanoseconds
    • mean

      public long mean()
      Get (approximate) running-average time-delta, in nanoseconds.
      Returns:
      Approximate average time-delta, in nanoseconds
    • stdDev

      public long stdDev()
      Get (approximate) running-standard-deviation of time-delta, in nanoseconds.
      Returns:
      Approximate standard-deviation of time-delta, in nanoseconds
    • count

      public long count()
      Get number of times stopNanoTime(long) was called, to record a data point.
      Returns:
      Number of data points recorded
    • sum

      public long sum()
      Get aggregate summation of time-deltas, in nanoseconds.
      Returns:
      Summation of time-deltas, in nanoseconds
    • nanoToMillis

      public static long nanoToMillis(long nano)
      Converts nanoseconds to milliseconds, and rounds the result.
      Parameters:
      nano - Nanoseconds
      Returns:
      Milliseconds