Package trclib.robotcore
Class TrcLoopProfiler
java.lang.Object
trclib.robotcore.TrcLoopProfiler
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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final String
private long
private long
private long
private long
private final HashMap<String,
TrcLoopProfiler.ProfilePoint> private long
-
Constructor Summary
ConstructorsConstructorDescriptionTrcLoopProfiler
(String instanceName) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptiondouble
This method returns the current time in nano second precision.double
This method returns the loop start time stamp in seconds.void
printPerformanceMetrics
(TrcDbgTrace tracer) This method prints the performance metrics of loop profiler.void
This method is called to record the loop start time.void
recordProfilePointElapsedTime
(String name, long startNanoTime, boolean inLoop) This method records the elapsed time of the specified profile point.void
reset()
This method resets the profiler data.toString()
This method returns the instance name.
-
Field Details
-
profilePoints
-
loopStartNanoTime
private long loopStartNanoTime -
totalLoopIntervalTime
private long totalLoopIntervalTime -
minLoopIntervalTime
private long minLoopIntervalTime -
maxLoopIntervalTime
private long maxLoopIntervalTime -
loopCount
private long loopCount -
instanceName
-
-
Constructor Details
-
TrcLoopProfiler
Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the name to identify this instance of the loop profiler.
-
-
Method Details
-
toString
This method returns the 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
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
This method prints the performance metrics of loop profiler.- Parameters:
tracer
- specifies the tracer to be used for printing the performance metrics.
-