https://gperftools.github.io/gperftools/heap_checker.html 安装google-perftools: apt-get install libunwind-dev apt-get install google-perftools
git clone https://github.com/libunwind/libunwind.git cd libunwind sh ./autogen.sh ./configure make sudo make install git clone https://github.com/gperftools/gperftools.git sh autogen.sh ./configure make sudo make install
sudo apt install kcachegrind
g++ -g -o -ltcmalloc xxx
You can run the heap checker on applications you didn't compile yourself, by using LD_PRELOAD: $ LD_PRELOAD="/usr/lib/libtcmalloc.so" HEAPCHECK=normal We don't necessarily recommend this mode of usage.
export LD_PRELOAD="/usr/local/lib/libtcmalloc.so" export PPROF_PATH="/usr/local/bin/pprof" export HEAPCHECK="normal" ./main
pprof ./hello "/tmp/hello.1536222._main_-end.heap" --inuse_objects --lines --heapcheck --edgefraction=1e-10 --nodefraction=1e-10 --svg >> analize.svg