Package io.opentelemetry.sdk.trace
Class AnchoredClock
- java.lang.Object
-
- io.opentelemetry.sdk.trace.AnchoredClock
-
@Immutable final class AnchoredClock extends java.lang.Object
A utility for returning wall times anchored to a given point in time. Wall time measurements will not be taken from the system, but instead are computed by adding monotonic time to the anchor point.This is needed because Java has lower granularity for epoch times and tracing events are recorded more often. There is also a performance improvement in avoiding referencing the system's wall time where possible. Instead of computing a true wall time for every timestamp within a trace, we compute it once at the local root and then anchor all descendant span timestamps to this root's timestamp.
-
-
Field Summary
Fields Modifier and Type Field Description private Clock
clock
private long
epochNanos
private long
nanoTime
-
Constructor Summary
Constructors Modifier Constructor Description private
AnchoredClock(Clock clock, long epochNanos, long nanoTime)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AnchoredClock
create(Clock clock)
Returns aAnchoredClock
.(package private) long
now()
Returns the current epoch timestamp in nanos calculated usingSystem.nanoTime()
since the reference time read in the constructor.(package private) long
startTime()
Returns the start time in nanos of thisAnchoredClock
.
-
-
-
Field Detail
-
clock
private final Clock clock
-
epochNanos
private final long epochNanos
-
nanoTime
private final long nanoTime
-
-
Constructor Detail
-
AnchoredClock
private AnchoredClock(Clock clock, long epochNanos, long nanoTime)
-
-
Method Detail
-
create
public static AnchoredClock create(Clock clock)
Returns aAnchoredClock
.- Parameters:
clock
- theClock
to be used to read the current epoch time and nanoTime.- Returns:
- a
MonotonicClock
.
-
now
long now()
Returns the current epoch timestamp in nanos calculated usingSystem.nanoTime()
since the reference time read in the constructor. This time can be used for computing durations.- Returns:
- the current epoch timestamp in nanos.
-
startTime
long startTime()
Returns the start time in nanos of thisAnchoredClock
.
-
-