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.

LP-AM263: How can I trace CPU and memory utilization?

Part Number: LP-AM263


I am using LP-AM263 and I want to know how can I trace the CPU and memory utilization step by step in my program

Have any idea or tools I can use?

  • Hi Charlie, 

    CPU Load trace:

    The below code snippet will be useful to calculate CPU load for your program. You can change the time interval (default I've shared is for 5 seconds, i.e., CPU load will be printed every 5 seconds). The CPU load is calculated with respect to the time IDLE task was running.

    #include "FreeRTOS.h"
    #include "task.h"
    #include <kernel/dpl/TaskP.h>
    #include <kernel/dpl/ClockP.h>
    
    TaskStatus_t gTaskStatusArr[32] ={0};
    uint32_t gNumTask = 0U;
    
    void print_cpu_load()
    {
        static uint32_t start_time = 0;
        uint32_t print_interval_in_secs = 5;
        uint32_t cur_time = ClockP_getTimeUsec()/1000;
        uint32_t totalRunTime = 0U;
    
        if(start_time==0)
        {
            start_time = cur_time;
        }
        else
        if( (cur_time-start_time) >= (print_interval_in_secs*1000) )
        {
            uint32_t cpu_load = TaskP_loadGetTotalCpuLoad();
    
            DebugP_log(" %6d.%3ds : CPU load = %3d.%02d %%\r\n",
                cur_time/1000, cur_time%1000,
                cpu_load/100, cpu_load%100 );
    
            start_time = cur_time;
            gNumTask = uxTaskGetSystemState(&gTaskStatusArr[0], 32U, &totalRunTime);
            TaskP_loadResetAll();
        }
    }

    Memory Trace:

    To get the memory usage statistics of heap, you can use APIs provided by FreeRTOS DPL (HeapP.c)

    Make sure to include the FreeRTOS library and the required HeapP files, then call 

    void   HeapP_getHeapStats( HeapP_Object *heap, HeapP_MemStats * pHeapStats )
    
    This will give you data about:
    • Size of largest free block in heap
    • Size of smallest free block in heap
    • number of free blocks in heap
    • Available free Heap space in bytes
    • Number of successful allocations, frees, 
    • Minimum ever free bytes remaining

    Regards,
    Shaunak