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 eachSpanandTransactionuses 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 longgetEpochMicros()longgetEpochMicros(long nanoTime)longinit()Initializes and calibrates the clock based on wall clock timelonginit(long epochMicrosWallClock, long nanoTime)Initializes and calibrates the clock based on wall clock timevoidinit(EpochTickClock other)Initializes the clock by aligning theoffsetwith the offset of another clock.voidresetState()resets pooled object state so it can be reused
-
-
-
Method Detail
-
init
public void init(EpochTickClock other)
Initializes the clock by aligning theoffsetwith 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:Recyclableresets pooled object state so it can be reused- Specified by:
resetStatein interfaceRecyclable
-
-