CPU Usage¶
Class to provide a CPU usage indication based on task callback availability.
To use, instantiate a single instance of Profiling::CpuUsage
and call Profiling::CpuUsage::begin()
from the application’s init()
function, passing a callback function to be invoked after calibration has completed.
This function will continue with your application’s normal execution.
See RingTone Player for an example.
CPU usage is calculated over an update period which begins with a call to Profiling::CpuUsage::reset()
.
The actual update period must be managed elsewhere, using a callback timer, web request
or other mechanism. It doesn’t need to be exact as the actual elapsed time in CPU
cycles is used for the calculation.
After the update period has elapsed, call Profiling::CpuUsage::getUtilisation()
to obtain a CPU usage figure.
This figure is obtained using the number of task callbacks made within the update period.
- loop cycles
- Set up repeating task callback and measure invocations between successive calls
- total cycles
- The total number of CPU cycles between calls to
Profiling::CpuUsage::update()
. - used
- total - loop
- utilisation
- used / total
-
class
CpuUsage
¶ Class to provide a CPU usage indication based on task callback availability.
Public Functions
-
void
begin
(InterruptCallback ready)¶ Calibrate the baseline figure for minimum CPU usage.
- Note
- Typically call this in
init()
- Parameters
ready
: Function to call when calibration is complete
-
void
reset
()¶ Reset counters to start a new update period.
-
unsigned
getLoopIterations
()¶ Get the number of task callbacks made so far.
-
uint32_t
getMinLoopCycles
()¶ Get the figure used as the baseline cycle count.
-
unsigned
getUtilisation
()¶ Get the CPU utilisation figure in 1/100ths of a percent.
-
void