[SOLVED] Heap Monitroing with systemview

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] Heap Monitroing with systemview

    Hello All,

    I successfully integrated segger's RTT and system view to my project and can see monitor the freertos task.

    I am now trying to integrate heap allocation feature, this is specifically desired for the malloc and not for freertos heap.

    I am using Keil for project compilation and here is my attempt to view heap

    In main:

    Source Code

    1. // Initialize RTT
    2. SEGGER_RTT_Init();
    3. void* pHeapStart = &__heap_base;
    4. size_t HeapSize = (size_t)(&__heap_limit - &__heap_base);
    5. SEGGER_SYSVIEW_HeapDefine(pHeapStart, pHeapStart, HeapSize, 4);
    6. SEGGER_SYSVIEW_Conf();

    and in one of the task I have following code:

    Source Code

    1. SEGGER_SYSVIEW_RecordEnterISR();
    2. void* ptr = malloc(512);
    3. void* pHeapStart = &__heap_base;
    4. SEGGER_SYSVIEW_HeapAlloc(pHeapStart, ptr, 512);
    5. SEGGER_SYSVIEW_RecordExitISR();

    Segger's system view gives following output, please see attached image



    I am not sure how why allocated bytes are coming to be zero.

    Any pointers will be greatly appreciated.
    Images
    • Segger_systemview_heap.png

      15.83 kB, 1,750×139, viewed 476 times
  • The call to SEGGER_SYSVIEW_HeapDefine() sends a message to the SystemView receiver, so it need to be placed somewhere where it can be sent after you have connected to the target. I have placed it within the function _cbSendSystemDesc(); that will ensure that SystemView gets it when you connect to the target. Then the pointers and allocation sizes should show up.

    Note that if you connect to your application while it is running, the Used/Free/Load heap numbers will not be accurate. You need to record from application boot for these numbers to make sense. I'm not sure how SEGGER have envisioned the heap-measurement to work properly if you connect to a running target. I think they would need to add a configuration message that can update SystemView on the current heap state (that you then would have to extract from your allocator).
  • Thanks for the reply...

    I updated my code with following

    Source Code

    1. SEGGER_SYSVIEW_Conf();
    2. SEGGER_SYSVIEW_Start();
    3. void* pHeapStart = &__heap_base;
    4. size_t HeapSize = (size_t)(&__heap_limit - &__heap_base);
    5. SEGGER_SYSVIEW_HeapDefine(pHeapStart, pHeapStart, HeapSize, 4);


    SEGGER_SYSVIEW_Start(); was missing from my original code and putting heap definition after this line seems to work.

    It works even with the running target