编译环境:Ubuntu x86_64(Linux root 2.6.32-45-generic #101-Ubuntu SMP Mon Dec 3 15:39:38 UTC 2012 x86_64 GNU/Linux)
运行环境:Android 4.0.4 (Linux kernel 3.0.21 OMAP4460)

一、下载NDK9和valgrind 3.8.1。

二、按照valgrind 3.8.1中的README.android进行编译,步骤如下:
1. 指定NDK根目录
export NDKROOT=/path/to/android-ndk-r9

2. 指定通用的安卓设备
export HWKIND=generic

3. 指定交叉工具链路径
export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar
export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld
export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc

4. 到valgrind目录下配置valgrind
cd /path/to/valgrind
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND"

CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm"

 ./configure --prefix=/data/local/valgrind --host=armv7-unknown-linux --target=armv7-unknown-linux  --with-tmpdir=/sdcard
注:配置这步经常报错,前面的路径等设置需要细心啊。

5. 编译并安装到指定路径
make -j2

make -j2 install DESTDIR=`pwd`/Inst
注:-j2表示利用双核提升编译速度,对速度不在乎的可以去掉。

三、安卓上运行
1. 拷贝Inst到安卓系统/data/local/valgrind中。
注:假如路径不是编译配置时的路径,这时需要重新设置一下,否则会报错。“valgrind: failed to start tool 'memcheck' for platform 'arm-linux': No such file or directory”
export VALGRIND_LIB=/data/local/valgrind/lib/valgrind/

2. 安卓4.0.4下(OMAP4460)执行Memcheck效果
127|shell@android:/data/local # /data/local/valgrind/bin/valgrind ls                  
==3509== Memcheck, a memory error detector

==3509== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.

==3509== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info

==3509== Command: ls

==3509==

--3509-- WARNING: Serious error when reading debug info

--3509-- When reading debug info from /data/local/valgrind/lib/valgrind/vgpreload_core-arm-linux.so:

--3509-- Can't make sense of .data section mapping

test

tmp

==3509==

==3509== HEAP SUMMARY:

==3509==     in use at exit: 4,096 bytes in 1 blocks

==3509==   total heap usage: 5 allocs, 4 frees, 8,337 bytes allocated

==3509==

==3509== LEAK SUMMARY:

==3509==    definitely lost: 0 bytes in 0 blocks

==3509==    indirectly lost: 0 bytes in 0 blocks

==3509==      possibly lost: 0 bytes in 0 blocks

==3509==    still reachable: 4,096 bytes in 1 blocks

==3509==         suppressed: 0 bytes in 0 blocks

==3509== Rerun with --leak-check=full to see details of leaked memory

==3509==

==3509== For counts of detected and suppressed errors, rerun with: -v

==3509== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

shell@android:/data/local # 

3. 安卓4.0.4下(OMAP4460)执行callgrind步骤
/data/local/valgrind/bin/valgrind --tool=callgrind ./test
执行完成后在目录下生成"callgrind.out.XXX"(XXX是进程ID号)是分析文件,可以直接利用:/data/local/valgrind/bin/callgrind_annotate callgrind.out.XXX 打印结果;
也可以在Ubuntu上使用:gprof2dot.py -f callgrind callgrind.out.XXX |dot -Tpng -o report.png 来生成图形化结果(需下载gprof2dot.py脚本,详见参考资料3)。
注:
1、使用callgrind时,./test程序运行时间短(<2s),运算量小的可以正常执行callgrind;而当test程序运行时间较长(>6S),运算量较大时,会导致安卓系统不稳定,无法正确执行下去,估计valgrind对安卓的兼容性较差吧。


参考资料:
1. http://blog.csdn.net/21cnbao/article/details/7399863    宋宝华 使用valgrind检测Android native程序的内存
2. http://blog.csdn.net/gxh9314/article/details/8447559    mips 交叉编译valgrind
3. http://blog.csdn.net/yanghao23/article/details/7514587 linux下利用valgrind工具进行内存泄露检测和性能分析

Ubuntu上交叉编译valgrind for Android 4.0.4的过程与注意事项的更多相关文章

  1. ubuntu 上使用valgrind

    Valgrind是一个GPL的软件,用于Linux(For x86, amd64 and ppc32)程序的内存调试和代码剖析.你可以在它的环境中运行你的程序来监视内存的使用情况,比如C 语言中的ma ...

  2. 在Ubuntu 14.04 TLS下openvas V8.0源代码安装过程

    [Qboy原创]详细记录源代码的安装过程 1.下载原代码 在http://www.openvas.org/install-source.html下载 Libraries 8.0.8 Scanner 5 ...

  3. 使用 VirtualBox 虚拟机在电脑上运行 Android 4.0 系统,让电脑瞬间变安卓平板

    Ref: http://www.iplaysoft.com/android-v4-ics-for-virtualbox.html 随着 Android 手机的各种软件应用越来越多,很多没有购买的朋友都 ...

  4. AppCompat v21 — Android 5.0之前版本设备的Material Design实现

    博客原文地址:http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html,要想打 ...

  5. Android 4.0 ICS SystemUI浅析——StatusBar结构分析

    Android 4.0 ICS SystemUI浅析——StatusBar结构分析 分类: Android2012-06-30 14:45 23687人阅读 评论(8) 收藏 举报 androidsi ...

  6. 《Thinking in Android 9.0 系统开发源码钻研录》

    最近打算把个人站点的博客文章同步到"博客园"! Thinking in Android -- "系统启动" [启动阶段] [相关文章] 状态 源码版本 init ...

  7. java项目 在 linux ubuntu 上的部署相关

    --------------------JDK在linux ubuntu上的安装------------------------------------------------------------ ...

  8. Android 5.0以上Material Design 沉浸式状态栏

    偶然在知乎上看到这个问题,Android 5.0 如何实现将布局的内容延伸到状态栏,之前也见过多个应用的这个功能,但是知乎上的答案却没有一个真正实现此功能的一类是把标题栏设置App主题颜色,一类是提取 ...

  9. Android 4.0 x86安装教程 附带联网参数详细设置

    Android 4.0 x86是一个可以支持在电脑上运行的Android 4.0系统.没有手机一样也可以体验Android 4.0.这对玩机爱好者们来说也算得上是一个不大不小的好消息.不过目前的And ...

随机推荐

  1. sql用法

    1:  SELECT `SCHEMA_NAME`  FROM `information_schema`.`SCHEMATA`;    查询sql中的数据库名 2:  select * from for ...

  2. [svc]ip地址划分

    网络界有2个计算题,一个是子网掩码,另一个就是三次握手,四次回收序列号计算了. 学会如何划分等长子网 学会如何合并网段 学会ip是否能分配 理解特殊的ip地址 ip头部 ip地址分类 现在的IP网络使 ...

  3. python 面向对象编程学习总结

    面向对象是个抽象的东西,概念比较多,下面会一一介绍. 一.类和实例 类(Class)和实例(Instance)是面向对象最重要的概念. 类是指抽象出的模板.实例则是根据类创建出来的具体的“对象”,每个 ...

  4. The adidas NMD Singapore is one of the brands top selling

    Like pointed out, we've two adidas NMD Singapore releases using the first arriving Blue and Black as ...

  5. Java实现最基本的集中排序

    排序是一个很重要的概念,现实生活中,我们需要为很多的东西排序.下面我们就介绍几种简单的排序的方法和最基本的思想. 1.冒泡排序:假设一个数组中有10个数字,从左边开始

  6. linux改变apt-get安装源

    最近自己装了个ubuntu kylin 在使用的过程中发现,系统的apt-get 的源有毛病,总是安装不了软件. 感觉应该是传说中的墙的原因,所以准备换到阿里云的源. 下面是步骤: 1.复制原文件备份 ...

  7. MySQL基准测试工具--sysbench

    我们需要知道的是sysbench并不是一个压力测试工具,是一个基准测试工具.linux自带的版本比较低,我们需要自己安装sysbench. [root@test2 ~]# sysbench --ver ...

  8. 前端学习笔记之CSS浮动浅析

    很早以前就接触过CSS,但对于浮动始终非常迷惑,可能是自身理解能力差,也可能是没能遇到一篇通俗的教程. 前些天小菜终于搞懂了浮动的基本原理,迫不及待的分享给大家. 写在前面的话: 由于CSS内容比较多 ...

  9. 文件读写网络IO简单了解,同步IO和异步IO

    在Linux中,对文件的读写其实就是IO. 与IO有关的名词:同步,异步,阻塞,非阻塞,甚至是同步阻塞,同步非阻塞,异步阻塞,异步非阻塞.别急,下面有举例IO分为两大种,同步和异步 同步IO:阻塞IO ...

  10. JavaScript 预编译(变量提升和函数提升的原理)

    本文部分内容转自https://www.cnblogs.com/CBDoctor/p/3745246.html 1.变量提升 console.log(global); // undefined var ...