Package frc.lib.profiling
Interface Profiler
- All Known Implementing Classes:
EmptyProfiler
,LoggingProfiler
,ValidatingProfiler
Interface supporting profiling calls for measuring and saving runtime performance.
Operates on the idea of a "profile stack", which is just a stack of names with associated profiling metrics. For instance, the following code
Profiler profiler = someProfiler();
profiler.startTick();
profiler.push("Hello")
someExpensiveFunction();
profiler.swap("World")
someLessExpensiveFunction();
profiler.pop();
profiler.endTick();
will produce a profile with three sections:
root
, which describes the time betweenprofiler.startTick()
andprofiler.endTick()
,root.Hello
, which describes the time betweenprofiler.push("Hello")
andprofiler.swap("World")
, androot.World
, which describes the time betweenprofiler.swap("World")
andprofiler.pop()
.
A call to profiler.save()
would output the performance metrics of these sections
in the case of a LoggingProfiler
.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
endTick()
Called at the bottom of the main loop.void
pop()
The profile stack is popped.void
The profile stack is pushed with thelocation
as its top.void
reset()
Reset logger.void
save()
Write profile data to a file.void
Called at the top of the main loop.default void
The top of the profile stack is replaced withlocation
.
-
Method Details
-
startTick
void startTick()Called at the top of the main loop. Indicates the profiler is at "root" and records the start time. Within the main loop, no meaningful work should occur before this call.- Throws:
RuntimeException
- if called twice without a call toendTick
in between.
-
endTick
void endTick()Called at the bottom of the main loop. Indicates the profiler's "root" is finished, and its time usage metrics are updated. Within the main loop, no meaningful work should occur after this call.- Throws:
RuntimeException
- if the profile stack is not empty orstartTick
has not been called.
-
push
The profile stack is pushed with thelocation
as its top. Must be accompanied by a call topop
.- Throws:
RuntimeException
- ifstartTick
hasn't been called yet.
-
pop
void pop()The profile stack is popped. Must be preceded (at some point) by a call topush
.- Throws:
RuntimeException
- ifstartTick
hasn't been called yet or the profile stack is empty.
-
swap
The top of the profile stack is replaced withlocation
. This is equivalent to a call topop
followed immediately by a call topush
.- Throws:
RuntimeException
- if the profile stack is empty.
-
save
void save()Write profile data to a file. -
reset
void reset()Reset logger.
-