应用 Valgrind 发现 Linux 程序的内存问题

一,安装:

 

1、 到www.valgrind.org下载最新版valgrind-3.2.3.tar.bz2
2、 解压安装包:tar –jxvf valgrind-3.2.3.tar.bz2
3、 解压后生成目录valgrind-3.2.3 
4、 cd valgrind-3.2.3
5、 ./configure --prefix=/data/home/nemo/tools/valgrind
6、 Make;make install

 


二。使用

1  valgrind不能attach到已经在运行的进程上(到目前为止在网上木有找到方法)

2  最基本的用法,在启动脚本加上  valgrind --tool=memcheck --leak-check=full --show-reachable=yes --log-file=$LOGFILE ./$pname $RUN_OPTIONS

3  --log-file是加上输出日志文件

4  如果日志太多,可查找“Invalid“ "ERROR SUMMARY"


进入到 tools/valgrind/bin 目录下(如果安装是默认的话就在/usr/local/bin)

执行 ./valgrind ls -l
如果显示:
==17343== Memcheck, a memory error detector
==17343== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==17343== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
==17343== Command: ls -l
==17343== 
total 220
-rwxr-xr-x 1 nemo users 40959 2010-08-31 15:11 callgrind_annotate
-rwxr-xr-x 1 nemo users 13662 2010-08-31 15:11 callgrind_control
-rwxr-xr-x 1 nemo users 32064 2010-08-31 15:11 cg_annotate
-rwxr-xr-x 1 nemo users 43514 2010-08-31 15:11 cg_merge
-rwxr-xr-x 1 nemo users 24211 2010-08-31 15:11 ms_print
-rwxr-xr-x 1 nemo users  8715 2010-08-31 15:11 no_op_client_for_valgrind
-rwxr-xr-x 1 nemo users 30703 2010-08-31 15:11 valgrind
-rwxr-xr-x 1 nemo users 19175 2010-08-31 15:11 valgrind-listener
==17343== 
==17343== HEAP SUMMARY:
==17343==     in use at exit: 12,539 bytes in 37 blocks
==17343==   total heap usage: 320 allocs, 283 frees, 35,761 bytes allocated
==17343== 
==17343== LEAK SUMMARY:
==17343==    definitely lost: 72 bytes in 2 blocks
==17343==    indirectly lost: 240 bytes in 20 blocks
==17343==      possibly lost: 0 bytes in 0 blocks
==17343==    still reachable: 12,227 bytes in 15 blocks
==17343==         suppressed: 0 bytes in 0 blocks
==17343== Rerun with --leak-check=full to see details of leaked memory
==17343== 
==17343== For counts of detected and suppressed errors, rerun with: -v
==17343== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 3 from 3)

表示安装ok了.

 

使用:http://www.ibm.com/developerworks/cn/linux/l-cn-valgrind/

http://baoer31.blog.163.com/blog/static/66036536200852665733158/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值