Use gperftools' heap profiler to profile libc malloc

1k Views Asked by At

I am trying to profile an application to compare its performance using different allocation strategies.

I have no trouble profiling it when using tcmalloc but how to profile it using libc's allocation functions ? Indeed, enabling gperftool's heap profiler requires to use -ltcmalloc flag¹ but this results as tcmalloc being used as allocation strategy.

1

There are 1 best solutions below

0
On BEST ANSWER

how to profile it using libc's allocation functions?

Note: this requirement is a bit strange: it's not like your application will suddenly start using more or less heap memory, or change its allocation pattern or sites when you switch from tcmalloc to GLIBC malloc.

From https://gperftools.github.io/gperftools/heapprofile.html:

Heap profiling requires the use of libtcmalloc. This requirement may be removed in a future version of the heap profiler, and the heap profiler separated out into its own library.

So you can

  • wait for Google developers to remove this requirement (this may be a wait of a few days, or a few years -- I have no idea. Actually, it looks like above github.io page hasn't been updated since 2012, so I wouldn't hold my breath here), or
  • contribute the code required for separation yourself, or
  • find an equivalent way to do this with GLIBC (and possibly contribute that code to GLIBC).

I am not aware of any existing GLIBC equivalents that work today.