Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
tap::arch::Profiler Class Reference

#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.
 

Detailed Description

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:

void foo()
{
}
void bar()
{
PROFILE(profiler, foo, ());
}
void baz()
{
PROFILE(profiler, bar, ());
}
#define PROFILE(profiler, func, params)
Definition profiler.hpp:40

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:

void foo(int i)
{
if (i == 0) return;
PROFILE(profiler, foo, (i - 1));
}
IUnit i
Definition dimensional_smooth_pid.hpp:2

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.

Constructor & Destructor Documentation

◆ Profiler()

tap::arch::Profiler::Profiler ( tap::Drivers drivers)

Member Function Documentation

◆ getData()

ProfilerData tap::arch::Profiler::getData ( std::size_t  key)
inline
Returns
The data associated with some particular key.

◆ pop()

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.

Parameters
[in]keyThe key that was returned by push associated with the profile that you would like to stop timing.

◆ push()

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.

Parameters
[in]profileThe name of the profile. Should be a unique const char * (i.e. string comparison is not used, instead raw pointer comparison is used).
Returns
A "key" that then must be passed to the pop function to stop the stopwatch timer and update the profiles associated ProfilerData.

◆ reset()

void tap::arch::Profiler::reset ( std::size_t  key)
inline

Reset the ProfilerData associated with some particular key.

Member Data Documentation

◆ AVG_LOW_PASS_ALPHA

constexpr float tap::arch::Profiler::AVG_LOW_PASS_ALPHA = 0.01f
staticconstexpr

Low pass alpha to be used when averaging time it takes for some code to run.

◆ MAX_PROFILED_ELEMENTS

constexpr std::size_t tap::arch::Profiler::MAX_PROFILED_ELEMENTS = 128
staticconstexpr

Max number of profiles that the profiler can store information about.


The documentation for this class was generated from the following files: