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 TypeMethodDescriptionvoidendTick()Called at the bottom of the main loop.voidpop()The profile stack is popped.voidThe profile stack is pushed with thelocationas its top.voidreset()Reset logger.voidsave()Write profile data to a file.voidCalled at the top of the main loop.default voidThe 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 toendTickin 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 orstartTickhas not been called.
-
push
The profile stack is pushed with thelocationas its top. Must be accompanied by a call topop.- Throws:
RuntimeException- ifstartTickhasn't been called yet.
-
pop
void pop()The profile stack is popped. Must be preceded (at some point) by a call topush.- Throws:
RuntimeException- ifstartTickhasn'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 topopfollowed 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.
-