Class TrcLoopProfiler

java.lang.Object
trclib.robotcore.TrcLoopProfiler

public class TrcLoopProfiler extends Object
This class implements a loop profiler for recording the elapsed time of various segments of code in a periodic loop. This is useful to identify the culprit if the loop time is unacceptably long. This can be used in profiling task loops, periodic thread loops or even the main robot loop.
  • Field Details

    • profilePoints

      private final HashMap<String,TrcLoopProfiler.ProfilePoint> profilePoints
    • loopStartNanoTime

      private long loopStartNanoTime
    • totalLoopIntervalTime

      private long totalLoopIntervalTime
    • minLoopIntervalTime

      private long minLoopIntervalTime
    • maxLoopIntervalTime

      private long maxLoopIntervalTime
    • loopCount

      private long loopCount
    • instanceName

      private final String instanceName
  • Constructor Details

    • TrcLoopProfiler

      public TrcLoopProfiler(String instanceName)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the name to identify this instance of the loop profiler.
  • Method Details

    • toString

      public String toString()
      This method returns the instance name.
      Overrides:
      toString in class Object
      Returns:
      instance name.
    • reset

      public void reset()
      This method resets the profiler data.
    • getHighPrecisionCurrentTime

      public double getHighPrecisionCurrentTime()
      This method returns the current time in nano second precision.
      Returns:
      current time in seconds.
    • recordLoopStartTime

      public void recordLoopStartTime()
      This method is called to record the loop 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.
    • getLoopStartTime

      public double getLoopStartTime()
      This method returns the loop start time stamp in seconds.
      Returns:
      loop start time in seconds.
    • recordProfilePointElapsedTime

      public void recordProfilePointElapsedTime(String name, long startNanoTime, boolean inLoop)
      This method records the elapsed time of the specified profile point.
      Parameters:
      name - specifies the name of the profile point.
      startNanoTime - specifies the start nanao time for calculating elapsed time.
      inLoop - specifies true if the profile point is inside the loop.
    • printPerformanceMetrics

      public void printPerformanceMetrics(TrcDbgTrace tracer)
      This method prints the performance metrics of loop profiler.
      Parameters:
      tracer - specifies the tracer to be used for printing the performance metrics.