Package trclib.timer

Class TrcPerformanceTimer

java.lang.Object
trclib.timer.TrcPerformanceTimer

public class TrcPerformanceTimer extends Object
This class implements a performance timer to record elapsed time and interval time of a periodic task. 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. It also records the min and max elapsed/interval time values it has seen since the last reset.
  • Field Details

    • instanceName

      private final String instanceName
    • startTime

      private long startTime
    • totalElapsedTime

      private long totalElapsedTime
    • minElapsedTime

      private long minElapsedTime
    • maxElapsedTime

      private long maxElapsedTime
    • elapsedCount

      private int elapsedCount
    • totalIntervalTime

      private long totalIntervalTime
    • minIntervalTime

      private long minIntervalTime
    • maxIntervalTime

      private long maxIntervalTime
    • intervalCount

      private int intervalCount
  • Constructor Details

    • TrcPerformanceTimer

      public TrcPerformanceTimer(String instanceName)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the name to identify this instance of the performance timer.
  • 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. It also records the interval time since the last call to recordStartTime. It also checks if the interval time is the minimum or maximum it has seen since last reset.
    • recordEndTime

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

      public double getAverageElapsedTime()
      This method calculates the average elapsed time so far.
      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.
    • getAverageIntervalTime

      public double getAverageIntervalTime()
      This method calculates the average interval time so far.
      Returns:
      average interval time in seconds.
    • getMinIntervalTime

      public double getMinIntervalTime()
      This method returns the minimum interval time since the last reset.
      Returns:
      minimum interval time in seconds.
    • getMaxIntervalTime

      public double getMaxIntervalTime()
      This method returns the maximum interval time since the last reset.
      Returns:
      maximum interval time in seconds.