Examining C/C++ Heap memory statistics in gdb

后端 未结 2 459
孤城傲影
孤城傲影 2020-12-13 18:56

I\'m trying to investigate the state of the C/C++ heap from within gdb on Linux amd64, is there a nice way to do this?

One approach I\'ve tried is to \"call mallinfo

相关标签:
2条回答
  • 2020-12-13 19:22

    If you can change the code:

    #include <malloc.h>
    #include <stdio.h>
    
    void dumpMallinfo(void) {
      struct mallinfo m = mallinfo();
      printf("uordblks = %d\nfordblks = %d\n", m.uordblks, m.fordblks);
    }
    

    In GDB, you can call dumpMallinfo().

    0 讨论(0)
  • 2020-12-13 19:23

    @fd - the RedHat bug had your answer.

    The mallinfo function has been deprecated, and won't be updated. A true query stats API is TDB. Today, you have malloc_stats and malloc_info. I can't find any documentation on either one, but here's what they give you.

    Is this close enough to what you need?

    (gdb) call malloc_stats()
    Arena 0:
    system bytes     =     135168
    in use bytes     =         96
    Total (incl. mmap):
    system bytes     =     135168
    in use bytes     =         96
    max mmap regions =          0
    max mmap bytes   =          0
    
    (gdb) call malloc_info(0, stdout)
    <malloc version="1">
    <heap nr="0">
    <sizes>
    <unsorted from="1228788" to="1229476" total="3917678" count="3221220448"/>
    </sizes>
    <total type="fast" count="0" size="0"/>
    <total type="rest" count="3221220448" size="3917678"/>
    <system type="current" size="135168"/>
    <system type="max" size="135168"/>
    <aspace type="total" size="135168"/>
    <aspace type="mprotect" size="135168"/>
    </heap>
    <total type="fast" count="0" size="0"/>
    <total type="rest" count="3221220448" size="3917678"/>
    <system type="current" size="135168
    />
    <system type="max" size="135168
    />
    <aspace type="total" size="135168"/>
    <aspace type="mprotect" size="135168"/>
    </malloc>
    
    0 讨论(0)
提交回复
热议问题