Heap logging

Hi,

I have an application based on SDK6 example that I run on DA14531 devkit PRO. I wrote a makefile to use GCC compiler. Now, I am running into hardfaults in some random situations and I would like to debug the problem. I replace da14531.lib with da14531_with_heap_logging.lib, defined CFG_LOG_HEAP_USAGE in da1458x_config_advanced.h, added heaps structs with extern keyword `extern struct mem_usage_log heap_usage_env     __SECTION_ZERO("retention_mem_area0"); ` (for all 4 heaps) and now I am trying to print some data from those structs, but they always all 0. Any idea?

Best regards,
Michal

Parents Reply Children
  • Hi Michal,

    Thank you for the reply.
    The CFG_LOG_HEAP_USAGE definition is designed to work with Keil IDE.
    In order to do that with GCC you will have to implement your own disp_heaplog function.
    The disp_heaplog function uses the following structs to print the Heap usage:

    // Heap logging structs
    struct mem_usage_log heap_usage_env     __SECTION_ZERO("retention_mem_area0");
    struct mem_usage_log heap_usage_db      __SECTION_ZERO("retention_mem_area0");
    struct mem_usage_log heap_usage_msg     __SECTION_ZERO("retention_mem_area0");
    struct mem_usage_log heap_usage_nonRet  __SECTION_ZERO("retention_mem_area0");


    Best Regards,
    OV_Renesas

  • Hi,

    as I wrote, I defined this struct with "extern" keyword, assuming that they are defined elsewhere and that I will be able to use their content. However that is not a case, all struct's fields are always 0. Any idea?

    Best regards,
    Michal

  • Hi Michal, the heap logging works identically to Kiel with GCC.  You need to replace the :da14531.lib in properties->c/c++ general/Libraries tab (if using eclipse, if not then in your lib linking in your makefile) with the da14531_with_heap_logging.lib

    Double check your configuration file, the CFG_LOG_HEAP_USAGE gets undefined later down in the file.

    Then make your heap log variables as extern in the file you wish to print them. 

    This should work from here.  You should see a warning from GCC about this this flag being set, for confirmation.

    I am using GCC with these steps, and successfully printing them during run time:

  • Hi,

    that is exactly what I did. However to print diferent params of heaps structs I was accessing them directly and then printing using `arch_printf()` eg `arch_printf("%d", heap_usage_env.max_used)`. Are you using different API ? I guess that should not matter? I will double check my configuration again.

    Thanks,
    Michal

  • void print_heap_stats(void)
    {
            arch_printf("HEAP_INFO: ENV: max used: %d used: %d max_used_other: %d used_other: %d \r\n",
                    heap_usage_env.max_used_sz,
                    heap_usage_env.used_sz,
                    heap_usage_env.max_used_other_sz,
                    heap_usage_env.used_other_sz);
            arch_printf("HEAP_INFO: DB: max used: %d used: %d max_used_other: %d used_other: %d \r\n",
                            heap_usage_db.max_used_sz,
                            heap_usage_db.used_sz,
                            heap_usage_db.max_used_other_sz,
                            heap_usage_db.used_other_sz);
            arch_printf("HEAP_INFO: MSG: max used: %d used: %d max_used_other: %d used_other: %d \r\n",
                            heap_usage_msg.max_used_sz,
                            heap_usage_msg.used_sz,
                            heap_usage_msg.max_used_other_sz,
                            heap_usage_msg.used_other_sz);
            arch_printf("HEAP_INFO: NON RET: max used: %d used: %d max_used_other: %d used_other: %d \r\n\r\n",
                            heap_usage_nonRet.max_used_sz,
                            heap_usage_nonRet.used_sz,
                            heap_usage_nonRet.max_used_other_sz,
                            heap_usage_nonRet.used_other_sz);
    }