Class MonotonicClock

  • All Implemented Interfaces:
    Clock

    @Immutable
    public final class MonotonicClock
    extends Object
    implements Clock
    This class provides a mechanism for calculating the epoch time using 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.

    • Method Detail

      • create

        public static MonotonicClock create​(Clock clock)
        Returns a MonotonicClock.
        Parameters:
        clock - the Clock 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 using System.nanoTime() since the reference time read in the constructor.
        Specified by:
        now in interface Clock
        Returns:
        the current epoch timestamp in nanos.
      • 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.
        Specified by:
        nanoTime in interface Clock
        Returns:
        a time measurement with nanosecond precision that can only be used to calculate elapsed time.