Package trclib.timer

Class TrcElapsedTimer

java.lang.Object
trclib.timer.TrcElapsedTimer

public class TrcElapsedTimer extends Object
This class implements an elapsed timer to record elapsed time. It is a performance monitoring tool. It is especially important for PID controlled loops that the loops are executed at a high enough frequency or they will oscillate wildly. This class records the elapsed time of some operations in an averaging window queue. To calculate the average elapsed time, all elapsed time values recorded in the averaging window queue are averaged. It also records the min and max elapsed time values it has seen since the last reset.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TrcElapsedTimer(String instanceName, double averageWindow)
    Constructor: Creates an instance of the object.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    This method calculates the average elapsed time within the given time window.
    double
    This method returns the last recorded elapsed time in seconds.
    double
    This method returns the maximum elapsed time since the last reset.
    double
    This method returns the minimum elapsed time since the last reset.
    void
    This method prints the elapsed time info using the given tracer.
    void
    This method is called to record the elapsed time since the last start time into the elapsed time queue.
    void
    This method is called in a loop to have its period time measured.
    void
    This method is called to record the start time.
    void
    This method resets the performance data.
    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
  • Constructor Details

    • TrcElapsedTimer

      public TrcElapsedTimer(String instanceName, double averageWindow)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the name to identify this instance of the timer.
      averageWindow - specifies the time window in seconds for averaging elapsed time.
  • 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.
    • reset

      public void reset()
      This method resets the performance data.
    • recordStartTime

      public void recordStartTime()
      This method is called to record the start time.
    • recordEndTime

      public void recordEndTime()
      This method is called to record the elapsed time since the last start time into the elapsed time queue. It also checks if the elapsed time is the minimum or maximum it has seen since last reset.
    • recordPeriodTime

      public void recordPeriodTime()
      This method is called in a loop to have its period time measured. It records a number of loop periods in a queue for a given time window.
    • getLastElapsedTime

      public double getLastElapsedTime()
      This method returns the last recorded elapsed time in seconds.
      Returns:
      last recorded elapsed time in seconds.
    • getAverageElapsedTime

      public double getAverageElapsedTime()
      This method calculates the average elapsed time within the given time window.
      Returns:
      average elapsed time in seconds.
    • getMinElapsedTime

      public double getMinElapsedTime()
      This method returns the minimum elapsed time since the last reset.
      Returns:
      minimum elapsed time in seconds.
    • getMaxElapsedTime

      public double getMaxElapsedTime()
      This method returns the maximum elapsed time since the last reset.
      Returns:
      maximum elapsed time in seconds.
    • printElapsedTime

      public void printElapsedTime(TrcDbgTrace tracer)
      This method prints the elapsed time info using the given tracer.
      Parameters:
      tracer - specifies the tracer to be used to print the info.