1,下载gperftools
2,编译gperftools
./autogen.sh
./configure --with-sysroot=/opt/xxx/sysroots --build=x86_64-xxx-linux --host=aarch64-xxx-linux --prefix=/opt/xxx/sysroots/x86_64-xxx-linux/usr/
make
make install
3,编译代码
官方文档:
If you want the CPU profiler, heap profiler, and heap leak-checker to
all be available for your application, you can do:
gcc -o myapp ... -lprofiler -ltcmalloc
However, if you have a reason to use the static versions of the
library, this two-library linking won't work:
gcc -o myapp ... /usr/lib/libprofiler.a /usr/lib/libtcmalloc.a # errors!
Instead, use the special libtcmalloc_and_profiler library, which we
make for just this purpose:
gcc -o myapp ... /usr/lib/libtcmalloc_and_profiler.a
另外,heap profiler和heap leak-checker可以不用重新编译代码,按照如下官方文档说明操作即可:
You can also use LD_PRELOAD to heap-check an executable that you
didn't compile.
4,把gperftools的.so以及.a(位置/opt/xxx/sysroots/x86_64-xxx-linux/usr/)拷贝到盒子上/usr/lib中
5,把编译好的程序放入盒子中
6,执行程序
CPU PROFILER
CPUPROFILE=/tmp/prof.out <path/to/binary> [binary args]
HEAP CHECKER
HEAPCHECK=1 <path/to/binary> [binary args]
7,使用pprof解析生成的文件