|
Fang-Robotics-MCB
Fang Robotics Team Codebase
|
#include <profiler.hpp>
Classes | |
| struct | ProfilerData |
Public Member Functions | |
| Profiler (tap::Drivers *drivers) | |
| std::size_t | push (const char *profile) |
| void | pop (std::size_t key) |
| ProfilerData | getData (std::size_t key) |
| void | reset (std::size_t key) |
| Reset the ProfilerData associated with some particular key. | |
Static Public Attributes | |
| static constexpr std::size_t | MAX_PROFILED_ELEMENTS = 128 |
| Max number of profiles that the profiler can store information about. | |
| static constexpr float | AVG_LOW_PASS_ALPHA = 0.01f |
| Low pass alpha to be used when averaging time it takes for some code to run. | |
An object that stores information about the time it takes to run code. User can add an item to the profiler by pushing a profile to the profiler, running their function, then popping the profile id from the profiler after the function has finished.
The PROFILE macro allows you to interact with the profiler without using the profiler's functions directly. For example, the PROFILE can be used as follows:
In the example above, profiler is a pointer to a valid Profiler class. If you call baz, it will add the profile "bar" and "foo" to the profiler.
The profiler is limited in size to MAX_PROFILED_ELEMENTS. Once a element is registered with the profiler, the profiler will keep track of the min, max, and rolling average time (in microseconds) it takes to run the code associated with the profile. The profiled elements can then be inspected using a debugger, or in the future can be accessed via the terminal serial (not yet implemented).
One known limitation is this profiler doesn't handle recursion well. For example, consider the following:
In this example, the PROFILE macro will overwrite the entry in the profiler in a way that makes the profiler information not useful for the foo function, so it is recommended that you do not use the PROFILE macro for a recursive call.
| tap::arch::Profiler::Profiler | ( | tap::Drivers * | drivers | ) |
|
inline |
| void tap::arch::Profiler::pop | ( | std::size_t | key | ) |
"Pops" a profile data, to stop the stopwatch that is timing how long some code takes to run.
| [in] | key | The key that was returned by push associated with the profile that you would like to stop timing. |
| std::size_t tap::arch::Profiler::push | ( | const char * | profile | ) |
"Push" a profile to the profiler. Can be a new profile that the profiler has never seen or a profile that is already in the profiler. Starts the stopwatch timer associated with the profile.
| [in] | profile | The name of the profile. Should be a unique const char * (i.e. string comparison is not used, instead raw pointer comparison is used). |
pop function to stop the stopwatch timer and update the profiles associated ProfilerData.
|
inline |
Reset the ProfilerData associated with some particular key.
|
staticconstexpr |
Low pass alpha to be used when averaging time it takes for some code to run.
|
staticconstexpr |
Max number of profiles that the profiler can store information about.