Package org.forgerock.openidm.util
Class DurationStatistics
java.lang.Object
org.forgerock.openidm.util.DurationStatistics
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 -
Method Summary
Modifier and TypeMethodDescriptionlongcount()Get number of timesstopNanoTime(long)was called, to record a data point.longmax()Get running-maximum time-delta, in nanoseconds.longmean()Get (approximate) running-average time-delta, in nanoseconds.longmin()Get running-minimum time-delta, in nanoseconds.static longnanoToMillis(long nano) Converts nanoseconds to milliseconds, and rounds the result.static longGets a start-time, in nanoseconds, for the current thread.longstdDev()Get (approximate) running-standard-deviation of time-delta, in nanoseconds.voidstopNanoTime(long startNanoTime) Calculates and records the time-duration, sincestartNanoTime()occurred in the current thread.longsum()Get aggregate summation of time-deltas, in nanoseconds.
-
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 callstopNanoTime(long).- Returns:
- Start-time, in nanoseconds
-
stopNanoTime
public void stopNanoTime(long startNanoTime) Calculates and records the time-duration, sincestartNanoTime()occurred in the current thread. Calling thread must be the same thread used to callstartNanoTime().- 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 timesstopNanoTime(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
-