asan/gpreftools内存调试简明用法

 

启用高版本gcc

yum install centos-release-scl yum install devtoolset-11-gcc yum install devtoolset-11-gcc-c++ yum install devtoolset-11-libasan-devel

source /opt/rh/devtoolset-11/enable

参考:https://www.cnblogs.com/hugetong/p/8303160.html

 

libasan编译选项

make EXTRA_CFLAGS="-O0 -g -fsanitize=address -fsanitize-recover=address -fno-omit-frame-pointer -static-libasan -DBUILD_DEBUG -UDPDK_MALLOC -DRTE_MALLOC_ASAN"

 

gpreftools编译选项

make EXTRA_CFLAGS="-O0 -g -fno-omit-frame-pointer -DBUILD_DEBUG -UDPDK_MALLOC -rdynamic -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free"

 

greftools运行时

设置环境变量,下文是systemd里的环境变量配置格式。按需选择,不需要都配

Environment="LD_PRELOAD=/usr/lib64/libtcmalloc.so.4.1.2"
Environment="HEAPPROFILE=/var/Logs/app_heapprof.log"
Environment="HEAPCHECK=normal"
Environment="HEAP_PROFILE_ALLOCATION_INTERVAL=1024"
Environment="HEAP_PROFILE_INUSE_INTERVAL=1024"
Environment="HEAP_PROFILE_TIME_INTERVAL=10"
Environment="HEAPPROFILESIGNAL=31"

/usr/bin/my_app

 

 查看分析结果

pprof --text --base=/tmp/heap/heapprof/heapprof.XXX.heap ./build/app /tmp/heap/heapprof/heapprof.XXX.heap

pprof --text /root/caotong1/app4 /export/Logs/jstack/app_heapprof.lg.0001.heap

如果打在rpm包里,二进制文件会被strap,导致pprof出来的栈信息是错的。参数可以直接给map信息文件。如下:

 pprof --text /usr/lib/debug/usr/bin/app.debug /var/Logs/app_heapprof.log.0060.heap 

 

libasan运行时

设置环境变量,下文是systemd里的环境变量配置格式

Environment="ASAN_OPTIONS=allow_addr2line=true:halt_on_error=true:help=0:log_path=/var/Logs/app_asan.log"

/usr/bin/my_app

 

libasan在线打印输出的接口

__lsan_do_recoverable_leak_check();

 

 

posted on 2024-04-18 12:27  toong  阅读(61)  评论(0编辑  收藏  举报