libbpf-tools: Suport memleak trace third-part allocators
Memleak run failed when trace task who use jemalloc, and luckly i see it fixed in memleak.py: https://github.com/iovisor/bcc/pull/4812/files, so we can also support on c version.
compile jemalloc with "je_" prefix: ./configure --with-jemalloc-prefix=je_
jemalloc test case:
#include <stdio.h> #include <unistd.h> #include <time.h> #include <jemalloc/jemalloc.h>
#define malloc(size) je_malloc(size) #define free(ptr) je_free(ptr) int main(void) { for (int i = 0; i < 100; i++) { void *p = malloc(1000); sleep(1); } return 0; } gcc -o alloc alloc.c -ljemalloc
test result:
sudo ./memleak -p $(pidof alloc) -O /usr/local/lib/libjemalloc.so
libbpf: elf: ambiguous match for 'mmap@GLIBC_2.2.5', 'mmap' in '/usr/local/lib/libjemalloc.so' libbpf: elf: ambiguous match for 'mmap@GLIBC_2.2.5', 'mmap' in '/usr/local/lib/libjemalloc.so' libbpf: elf: ambiguous match for 'munmap@GLIBC_2.2.5', 'munmap' in '/usr/local/lib/libjemalloc.so' libbpf: elf: failed to find symbol 'pvalloc' in '/usr/local/lib/libjemalloc.so' libbpf: elf: failed to find symbol 'pvalloc' in '/usr/local/lib/libjemalloc.so' Tracing outstanding memory allocs... Hit Ctrl-C to end [15:12:34] Top 1 stacks with outstanding allocations: 5000 bytes in 5 allocations from stack 0 [<00005584f3217188>] main+0x1f 1 [<00007fe897617d90>] __libc_init_first+0x90 [15:12:39] Top 1 stacks with outstanding allocations: 10000 bytes in 10 allocations from stack 0 [<00005584f3217188>] main+0x1f 1 [<00007fe897617d90>] __libc_init_first+0x90