@Immutable public final class MonotonicClock extends Object implements Clock
System.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.
Modifier and Type | Method and Description |
---|---|
static MonotonicClock |
create(Clock clock)
Returns a
MonotonicClock . |
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 using
System.nanoTime() since
the reference time read in the constructor. |
public static MonotonicClock create(Clock clock)
MonotonicClock
.clock
- the Clock
to be used to read the current epoch time and nanoTime.MonotonicClock
.public long now()
System.nanoTime()
since
the reference time read in the constructor.public long nanoTime()
Clock