内存检测工具valgrind
valgrind --tool=memcheck --leak-check=full --error-limit=no --trace-children=yes ./server
valgrind --tool=massif --trace-children=yes --time-unit=B --max-snapshots=100 --pages-as-heap=yes --detailed-freq=1000 --massif-out-file=a.out.massif.out.%p ./$server 2>>massif.log 1>&2
valgrind --tool=massif --trace-children=yes --time-unit=B --max-snapshots=100 --massif-out-file=a.out.massif.out.%p ./$server 2>>massif.log 1>&2
ms_print massif.2222
Valgrind包括如下一些工具:
Memcheck。这是valgrind应用最广泛的工具,一个重量级的内存检查器,能够发现开发中绝大多数内存错误使用情况,比如:使用未初始化的内存,使用已经释放了的内存,内存访问越界等。这也是本文将重点介绍的部分。
Callgrind。它主要用来检查程序中函数调用过程中出现的问题。
Cachegrind。它主要用来检查程序中缓存使用出现的问题。
Helgrind。它主要用来检查多线程程序中出现的竞争问题。
Massif。它主要用来检查程序中堆栈使用中出现的问题。
Extension。可以利用core提供的功能,自己编写特定的内存调试工具。
Memcheck 能够检测出内存问题,关键在于其建立了两个全局表。
Valid-Value 表:
对于进程的整个地址空间中的每一个字节(byte),都有与之对应的 8 个 bits;对于 CPU 的每个寄存器,也有一个与之对应的 bit 向量。这些 bits 负责记录该字节或者寄存器值是否具有有效的、已初始化的值。
Valid-Address 表
对于进程整个地址空间中的每一个字节(byte),还有与之对应的 1 个 bit,负责记录该地址是否能够被读写。
检测原理:
当要读写内存中某个字节时,首先检查这个字节对应的 A bit。如果该A bit显示该位置是无效位置,memcheck 则报告读写错误。
内核(core)类似于一个虚拟的 CPU 环境,这样当内存中的某个字节被加载到真实的 CPU 中时,该字节对应的 V bit 也被加载到虚拟的 CPU 环境中。一旦寄存器中的值,被用来产生内存地址,或者该值能够影响程序输出,则 memcheck 会检查对应的V bits,如果该值尚未初始化,则会报告使用未初始化内存错误。
Here’s the command line I used:
valgrind --smc-check=all --trace-children=yes --tool=massif --pages-as-heap=yes \ --detailed-freq=1000000 optg64/dist/bin/firefox -P cad20 -no-remote
Here’s what that means:
--smc-check=all
tells Valgrind that the program may use self-modifying code (or, in Firefox’s case, overwrite dynamically generated code).--trace-children
tells Valgrind to trace into child processes exec’d by the program. This is necessary because optg64/dist/bin/firefox is a wrapper script.--tool=massif
tells Valgrind to run Massif.--pages-as-heap=yes
tells Massif to profile allocations of all memory at the page level, rather than just profiling the heap (ie. memory allocated via malloc/new). This is important because the heap is less than half of Firefox’s memory consumption.--detailed-freq=1000000
tells Massif to do detailed snapshots (which are more informative but more costly) only every 1,000,000th snapshot, which is less often than the default of every 10th snapshot. This makes it run a bit faster. This is fine because Massif always takes a detailed snapshot at the peak memory consumption point, and that’s the one I’m interested in.optg64/
is the name of my build directory.-P cad20
tells Firefox to use a particular profile that I set up appropriately.-no-remote
tells Firefox to start a new instance; this is necessary because I had a Firefox 3.6 process already running.
Massif produced a number of files, one per invoked process. They have names like massif.out.22722
, where the number is the process ID. I worked out which one was the main Firefox executable; this is not hard because the output file has the invoked command on its second line. I then viewed it in two ways. The first was with Massif’s ms_print script
, using this command:
图形
http://sourceforge.net/projects/precompiledbin/?source=typ_redirect
KCacheGrind windows 系統下的代替方案
WinCacheGrind
可分析由xdebug產出的cachegrind.xxx檔,簡易版的kcachegrind。
windows port of kcachegrind
由原linux的kcachegrind,重新編譯在windows上可執行版,功能與linux kcachegrind相同。
Webgrind
網頁版的callgrind,搭配xdebug可做即時線上做php script profile。
内存检测工具valgrind的更多相关文章
- 【调试】Linux下超强内存检测工具Valgrind
[调试]Linux下超强内存检测工具Valgrind 内容简介 Valgrind是什么? Valgrind的使用 Valgrind详细教程 1. Valgrind是什么? Valgrind是一套Lin ...
- C/C++内存检测工具Valgrind
内存检测Valgrind简介 Valgrind是运行在Linux上一套基于仿真技术的程序调试和分析工具,作者是获得过Google-O'Reilly开源大奖的Julian Seward, 它包含一个内核 ...
- c程序内存检测工具 - Valgrind
常用C程序内存泄露检测工具 https://blog.csdn.net/u012662731/article/details/78652651
- Yosimite10.10(Mac os)安装c/c++内存检测工具valgrind
1.下载支持包m4-1.4.13.tar.gz $ curl -O http://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz 2. 解压m4-1.4.13.t ...
- 内存检测工具valgrind的安装和简单使用
1. 安装 .tar.bz2 cd valgrind- sudo ./configure sudo make sudo make install 2. 简单使用 #include <stdio. ...
- valgrind内存检测工具
valgrind 那点事 ---------------------------------------内存检测工具 valgrind要使用此工具,可以使用--tool=memcheck 在Valgr ...
- linux下内存泄露检测工具Valgrind介绍
目前在linux开发一个分析实时路况的应用程序,在联合测试中发现程序存在内存泄露的情况. 这下着急了,马上就要上线了,还好发现了一款Valgrind工具,完美的解决了内存泄露的问题. 推荐大家可以使用 ...
- linux下内存检测工具的使用和对比
linux背后隐藏着各种丰富的工具,学会这些工具,让这些工具更好地服务于我们的项目开发,不仅可以提高工作的效率,而且可以增强个人技术力. 参考:http://blog.chinaunix.net/ui ...
- Android 内存泄露总结(附内存检测工具)
https://segmentfault.com/a/1190000006852540 主要是分三块: 静态储存区:编译时就分配好,在程序整个运行期间都存在.它主要存放静态数据和常量. 栈区:当方法执 ...
随机推荐
- 一篇SSM框架整合友好的文章(二)
上一篇讲述了DAO 层,mybatis实现数据库的连接,DAO层接口设计,以及mybtis和spring的整合.DAO层采用接口设计方式实现,接口和SQL实现的分离,方便维护.DAO层所负责的仅仅是接 ...
- javascript入门笔记4-数组
1.数组 var arr=new Array(); var myarray= new Array(8); //创建数组,存储8个数据. 注意: 1.创建的新数组是空数组,没有值,如输出,则显示unde ...
- 永久免费开源的卫星地形图地图下载工具更新Somap2.13版本功能更新 更新时间2019年2月22日13:59:05
一.下载地址 最新版本下载地址:SoMap2.13点击此处下载 二.系统自主开发特色功能展示 1.上百种地图随意下载 高德.百度.arcgis.谷歌.bing.海图.腾讯.Openstreet.天地 ...
- 树梅派(Raspberry Pi 3b)安装kali linux 2.0
最近终于入手了一枚树梅派3B,忘记是什么时候到手了,买回来,也没有激动无比,也没有心情澎湃,也就扔到床头,并没有像以前超想拥有的感觉,像是失去了对这些东西都兴趣,没有以前那么强烈了,对于这些对信仰有些 ...
- CSU1216: 异或最大值(01Trie树)
Description 给定一些数,求这些数中两个数的异或值最大的那个值 Input 多组数据.第一行为数字个数n,1 <= n <= 10 ^ 5.接下来n行每行一个32位有符号非负整数 ...
- 使用docker搭建“企业级镜像仓库”Harbor
一.前沿 docker的官方镜像仓库registry,功能比较单一,不太好用,特别是删除镜像操作,不够友好. Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,通过添加一 ...
- python中字符串编码方式小结
Python2中字符串的类型有两种:str和unicode,其中unicode是统一编码方式,它使得字符跟二进制是一一对应的,因此所有其他编码的encode都从unicode开始,而其他编码方式按照相 ...
- Centos7安装Mysql5.7并修改初始密码
1.CentOS 的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件. wget https://dev.mysql.com/get/mysql57-community-r ...
- 生产-消费模式的synchronized和lock实现(十)
lock: package com.net.thread.lock; import java.util.concurrent.locks.Condition; import java.util.con ...
- 学习python第十二天,函数4 生成器generator和迭代器Iterator
在Python中,这种一边循环一边计算的机制,称为生成器:generator 要创建一个generator,有很多种方法.第一种方法很简单,只要把一个列表生成式的[]改成(),就创建了一个genera ...