Package io.opentelemetry.sdk.internal
Class MonotonicClock
- java.lang.Object
-
- io.opentelemetry.sdk.internal.MonotonicClock
-
- All Implemented Interfaces:
Clock
@Immutable public final class MonotonicClock extends Object implements Clock
This class provides a mechanism for calculating the epoch time usingSystem.nanoTime()
and a reference epoch timestamp.This is needed because Java has millisecond granularity for epoch times and tracing events are recorded more often.
This clock needs to be re-created periodically in order to re-sync with the kernel clock, and it is not recommended to use only one instance for a very long period of time.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MonotonicClock
create(Clock clock)
Returns aMonotonicClock
.long
nanoTime()
Returns a time measurement with nanosecond precision that can only be used to calculate elapsed time.long
now()
Returns the current epoch timestamp in nanos calculated usingSystem.nanoTime()
since the reference time read in the constructor.
-
-
-
Method Detail
-
create
public static MonotonicClock create(Clock clock)
Returns aMonotonicClock
.- Parameters:
clock
- theClock
to be used to read the current epoch time and nanoTime.- Returns:
- a
MonotonicClock
.
-
now
public long now()
Returns the current epoch timestamp in nanos calculated usingSystem.nanoTime()
since the reference time read in the constructor.
-
nanoTime
public long nanoTime()
Description copied from interface:Clock
Returns a time measurement with nanosecond precision that can only be used to calculate elapsed time.
-
-