内存诊断工程搭建及demo测试

第三章 内存诊断工具 19
3.1mtrace工具 19
3.1.1工具背景 19
3.1.2环境搭建 19
3.1.3demo测试 19
3.2memwatch工具 20
3.2.1工具背景 20
3.2.2环境搭建 21
3.2.3demo模拟 21
3.3memleak工具 23
3.3.1工具背景 23
3.3.2环境搭建 23
3.2.3demo模拟 23
3.4valgrind工具 24
3.4.1工具背景 24
3.4.2环境搭建 25
3.4.3模拟测试 26
3.4.4实践项目 28

第三章 内存诊断工具
3.1mtrace工具
3.1.1工具背景
应用环境:Linux GLIBC
  编程语言:C
  使用方法:包含头文件mcheck.h,定义环境变量MALLOC_TRACE为输出文件名,程序开始时调用mtrace()即可。
  结果输出:用户指定的文件
  设计思路:为malloc,realloc,free函数添加钩子函数,记录每一对malloc-free的执行
优缺点:只能检查使用malloc/realloc/free造成的的内存泄露

3.1.2环境搭建
1.在demo里面添加相关头文件#include<mcheck.h>,这个头文件是库里有的
2.在main函数里面添加测试内存泄漏的函数mtrace();
3.用交叉工具链编译,正常编译test.c文件即可
4.导入盒子,最后测试输出日志需要自己定义路径和文件名
例如:export MALLOC_TRACE=/mnt/data/result.log

3.1.3demo测试
1.导入执行程序,设置环境变量如图所示,最后用env,查看环境变量是否设置成功。
在这里插入图片描述在这里插入图片描述
图3-1 设置环境变量

2.测试内存泄漏的demo,最后生成result.log日志。如图所示
在这里插入图片描述
图3-2 生成检测日志

3.查看生成的检测日志,由于都是地址类型的,网上没有相关的教程,也不知道具体是什么意思,打印的日志显示问题不明显,但是18C就是396字节,猜测前面是地址,后面就是在这个地址漏了396字节,漏掉了两次。
在这里插入图片描述
图3-3 日志分析

总结:本工具可以测试malloc,free相关的内存泄漏,指针多次释放,指针释放被用等问题,但是日志显示不明显,需要通过地址去找,且需要添加头文件和测试函数接口,设置环境变量,不独立于项目,不适合项目使用。

3.2memwatch工具
3.2.1工具背景
应用环境:Linux
  编程语言:C
  使用方法:加入memwatch.h,编译时加上-DMEMWATCH -DMW_STDIO及 memwatch.c
  结果输出:输出文件名称为memwatch.log,在程序执行期间,错误提示都会显示在stdout 上
  设计思路:将malloc/realloc/calloc/strdup/free等重定义为mwMalloc(sz, FILE, LINE)等,内部维护一个操作链表
优缺点&#x

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The Advanced Volume Sensor Project is one element of the ONR Advanced Damage Countermeasures FNC program. The Volume Sensor Project is developing new methods for remote situational awareness and damage control event detection using conventional video cameras and other techniques. The Spectral-Based Volume Sensor (SBVS) Testbed uses a suite of single-element optical detectors operating outside the visible region. Event detection algorithms were developed to make use of the data generated by the SBVS Testbed. These algorithms detect flaming and smoldering sources both within and outside the SBVS Testbed’s field of view (FOV). A positive nuisance classification algorithm was also developed for arc welding and similar nuisance events, which detected all welding events with extremely few false alarms. The developed algorithms were tested against data collected during the Volume Sensor Test Series 2, July to November 2003. Comparable performance to COTS OFDs was achieved for FOV flaming sources, and superior performance was demonstrated for partially or completely obscured flaming sources. Unclassified Unclassified Unclassified UL 83 Jeffrey C. Owrutsky (202) 404-6352 Fire detection; Optical flame detection; Volume sensor; Remote sensing; Smoke detection; Arc welding detection; Damage control; Damage countermeasures Memorandum NRL/MR/6110--05-8856 Approved for public release; distribution is unlimited. *Nova Research, Inc., Alexandria, VA 22308 †Hughes Associates, Inc., Baltimore, MD 21227 ‡NRL Code 6180 Accompanying CD (on the inside back cover) contains this Memorandum Report and the supporting material referenced in the text.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值