Package trclib.timer
Class TrcPerformanceTimer
java.lang.Object
trclib.timer.TrcPerformanceTimer
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 Summary
FieldsModifier and TypeFieldDescriptionprivate int
private final String
private int
private long
private long
private long
private long
private long
private long
private long
-
Constructor Summary
ConstructorsConstructorDescriptionTrcPerformanceTimer
(String instanceName) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptiondouble
This method calculates the average elapsed time so far.double
This method calculates the average interval time so far.double
This method returns the maximum elapsed time since the last reset.double
This method returns the maximum interval time since the last reset.double
This method returns the minimum elapsed time since the last reset.double
This method returns the minimum interval time since the last reset.void
This method is called to record the elapsed time since the last start time.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
-
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
Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the name to identify this instance of the performance timer.
-
-
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. 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.
-