1、编译valgrind程序及相关库
cd <aosp>/external/valgrind/
mm
注:如果后续使用出现未识别操作时,需要下载valgrind高版本源码重新编译
- http://www.valgrind.org/downloads/valgrind-3.14.0.tar.bz2
- andorid-ndk-r12b-linux-x64
tar -jxvf valgrind-3.14.0.tar.bz2
cd valgrind-3.14.0
export NDKROOT=/home/renyun/android-ndk-r12b
export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar
export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld
export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
./autogen.sh
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-19/arch-arm" \
CFLAGS="--sysroot=$NDKROOT/platforms/android-19/arch-arm" \
./configure --prefix=/data/local/Inst \
--host=armv7-unknown-linux --target=armv7-unknown-linux \
--with-tmpdir=/sdcard
make -j32
make -j32 install DESTDIR=/home/renyun/Inst/
2、push valgrind及相关库到android设备
adb push out/target/product/xxx/system/bin/valgrind /system/bin/
adb push out/target/product/xxx/system/lib/valgrind /system/lib/
3、设置权限
chmod 777 /system/bin/valgrind
chmod 777 /system/lib/valgrind/*
4、设置默认日志输出路径权限
chmod 777 /data/local/tmp
5、设置属性,用于检查Service或者Activity
setprop wrap.<包名> "logwrapper valgrind -v --error-limit=no --trace-children=yes"
for example:
[wrap.com.ysten.sjiptv]: [logwrapper valgrind -v --error-limit=no --trace-children=yes]
6、设置环境变量
export VALGRIND_LIB=/system/lib/valgrind
7、执行logcat 查看valgrind打印日志
logcat -vtime -s valgrind
8、另开一个终端,重新启动app
am start -n xxxx/yyyy
参考
1、valgrind 内存泄露 监测工具 2、移植Valgrind检测Android JNI内存泄漏 3、valgrind: Unrecognised instruction at address 4、NDK下载
|