Package trclib.timer
Class TrcElapsedTimer
java.lang.Object
trclib.timer.TrcElapsedTimer
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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTrcElapsedTimer
(String instanceName, double averageWindow) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptiondouble
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
printElapsedTime
(TrcDbgTrace tracer) 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
reset()
This method resets the performance data.toString()
This method returns the performance data in string form.
-
Field Details
-
instanceName
-
averageWindow
private final long averageWindow -
elapsedTimeQueue
-
minElapsedTime
-
maxElapsedTime
-
totalElapsedTime
private long totalElapsedTime -
startTime
private long startTime
-
-
Constructor Details
-
TrcElapsedTimer
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
This method returns the 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
This method prints the elapsed time info using the given tracer.- Parameters:
tracer
- specifies the tracer to be used to print the info.
-