Package trclib.timer

Class TrcHighPrecisionTime

java.lang.Object
trclib.timer.TrcHighPrecisionTime

public class TrcHighPrecisionTime extends Object
This class provides high precision time with nanosecond precision but not necessarily nanosecond resolution (that is, how frequently the value changes). There is no guarantee except that the resolution is at least as good as that of System.currentTimeMillis().
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final String
     
    private double
     
    private long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor: Creates an instance of the object.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the current time in seconds.
    double
    This method returns the elapsed time in seconds since the last recorded timestamp.
    double
    getElapsedTime(double epochTime)
    This method returns the elapsed time in seconds of the specified epoch time from the recorded epoch timestamp.
    void
    This method is called to take a snapshot of the current nano time as the start timestamp and the corresponding current time in milliseconds.
    This method returns the performance data in string form.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • instanceName

      private final String instanceName
    • timestampNano

      private volatile long timestampNano
    • timestampEpoch

      private volatile double timestampEpoch
  • Constructor Details

    • TrcHighPrecisionTime

      public TrcHighPrecisionTime(String instanceName)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the instance name of the time object.
  • Method Details

    • toString

      public String toString()
      This method returns the performance data in string form.
      Overrides:
      toString in class Object
      Returns:
      performance data in string form.
    • recordTimestamp

      public void recordTimestamp()
      This method is called to take a snapshot of the current nano time as the start timestamp and the corresponding current time in milliseconds.
    • getElapsedTime

      public double getElapsedTime()
      This method returns the elapsed time in seconds since the last recorded timestamp.
      Returns:
      elapsed time from last recorded timestamp in seconds.
    • getElapsedTime

      public double getElapsedTime(double epochTime)
      This method returns the elapsed time in seconds of the specified epoch time from the recorded epoch timestamp.
      Parameters:
      epochTime - specifies the epoch time to compute the elapsed time from the recorded epoch timestamp.
      Returns:
      elapsed time in seconds from the recorded epoch timestamp.
    • getCurrentTime

      public double getCurrentTime()
      Returns the current time in seconds. Note that while the unit of time of the return value is in seconds, the precision is in nanoseconds but not necessarily nanosecond resolution (that is, how frequently the value changes). There is no guarantee except that the resolution is at least as good as that of System.currentTimeMillis().
      Returns:
      the time difference in seconds, between the current time and midnight, January 1, 1970 UTC with nanosecond precision.