Class EpochTickClock
- java.lang.Object
-
- co.elastic.apm.agent.impl.transaction.EpochTickClock
-
- All Implemented Interfaces:
Recyclable
public class EpochTickClock extends java.lang.Object implements Recyclable
This clock makes sure that eachSpan
andTransaction
uses a consistent clock which does not drift in case of NTP updates or leap seconds.The clock is initialized with wall clock time when the transaction starts and from there on uses
System.nanoTime()
in order to be able to measure durations.System.currentTimeMillis()
, which uses wall clock time is not suitable for measuring durations because of the aforementioned possibility of clock drifts.
-
-
Constructor Summary
Constructors Constructor Description EpochTickClock()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getEpochMicros()
long
getEpochMicros(long nanoTime)
long
init()
Initializes and calibrates the clock based on wall clock timelong
init(long epochMicrosWallClock, long nanoTime)
Initializes and calibrates the clock based on wall clock timevoid
init(EpochTickClock other)
Initializes the clock by aligning theoffset
with the offset of another clock.void
resetState()
resets pooled object state so it can be reused
-
-
-
Method Detail
-
init
public void init(EpochTickClock other)
Initializes the clock by aligning theoffset
with the offset of another clock.- Parameters:
other
- the other clock, which has already been initialized
-
init
public long init()
Initializes and calibrates the clock based on wall clock time- Returns:
- the epoch microsecond timestamp at initialization time
-
init
public long init(long epochMicrosWallClock, long nanoTime)
Initializes and calibrates the clock based on wall clock time- Parameters:
epochMicrosWallClock
- the current timestamp in microseconds since epoch, based on wall clock timenanoTime
- the current nanosecond ticks (mostlySystem.nanoTime()
- Returns:
- the epoch microsecond timestamp at initialization time
-
getEpochMicros
public long getEpochMicros()
-
getEpochMicros
public long getEpochMicros(long nanoTime)
-
resetState
public void resetState()
Description copied from interface:Recyclable
resets pooled object state so it can be reused- Specified by:
resetState
in interfaceRecyclable
-
-