Tool/software:
How to measure CPU load in an application with FreeRTOS/MCU+ SDK?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software:
How to measure CPU load in an application with FreeRTOS/MCU+ SDK?
An important metric to get an insight about the system performance is the CPU load.
CPU load or utilisation refers to the total active time of the core spent in executing application code (including all the tasks and ISR execution time) divided by the total observation time.
MCU+SDK provides a set of APIs for Task and related computations.
To get CPU load prints at regular intervals:
APIs used:
Steps to add CPU load prints in the code:
static void App_printCpuLoad() { static uint32_t startTime_ms = 0; const uint32_t currTime_ms = ClockP_getTimeUsec()/1000; const uint32_t printInterval_ms = 5000; if (startTime_ms == 0) { startTime_ms = currTime_ms; } else if ( (currTime_ms - startTime_ms) > printInterval_ms ) { const uint32_t cpuLoad = TaskP_loadGetTotalCpuLoad(); DebugP_log("%6d.%3ds : CPU load = %3d.%02d %%\r\n", currTime_ms/1000, currTime_ms%1000, cpuLoad/100, cpuLoad%100 ); startTime_ms = currTime_ms; TaskP_loadResetAll(); } return; }
while (true) { // Print CPU load ClockP_usleep(1000); App_printCpuLoad(); }
Similarly, to get the CPU load at any desired point in the code instead of continuous prints, modify the App_printCpuLoad function as below:
static void App_printCpuLoad()
{
const uint32_t cpuLoad = TaskP_loadGetTotalCpuLoad();
DebugP_log("%6d.%3ds : CPU load = %3d.%02d %%\r\n",
currTime_ms/1000, currTime_ms%1000,
cpuLoad/100, cpuLoad%100 );
TaskP_loadResetAll();
}