yum -y install valgrind
Ubuntu20.04安装valgrind_ubuntu安装valgrind-CSDN博客
sudo apt-get install automake
sudo apt-get install autoconf
cd valgrind-3.19.0
./autogen.sh
./configure
make -j4
sudo make install
valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./sample
valgrind检测内存泄漏、越界访问、野指针访问实验_野指针检测-CSDN博客
valgrind_valgrind --tool=massif-CSDN博客
valgrind massif内存分析工具_valgrind分析内存占用top-CSDN博客
massif工具使用
sudo apt install massif-visualizer
运行: massif-visualizer {massiflog}
之后会生成一个很炫酷的图片
valgrind -v --tool=massif --time-unit=ms --detailed-freq=1 --massif-out-file={massif_log_path} {run_exec_cmd}
valgrind -v --tool=massif --time-unit=B --detailed-freq=1 --massif-out-file=/xxx/xxx.log ./xxxx
Valgrind 介绍_git valgrind-CSDN博客
【C/C++ 集成内存调试、内存泄漏检测和性能分析的工具 Valgrind 】Linux 下 Valgrind 工具的全面使用指南 - 知乎 (zhihu.com)
valgrind --tool=massif --pages-as-heap=yes your_program [your_program_arguments]
使用 --pages-as-heap
选项
这个选项会让 Massif 把所有的内存页都当作堆来处理,这可以让你看到所有的内存分配,而不仅仅是通过 malloc
、new
等函数分配的内存:
如何在windows使用valgrind_如何在windows下使用f2py_weixin_39621870的博客-CSDN博客
分享一个Redis自带的压测工具:redis-benchmark - 知乎
https://www.cnblogs.com/zengkefu/p/5642991.html
valgrind是开源的性能分析利器。 根据它的文档,可以用它来检查内存泄漏等问题,还可以用来生成函数的调用图,就这两个功能就足够有吸引力了。
本文主要是介绍如何使用valgrind的callgrind工具进行性能分析。
分析过程
使用callgrind工具生成性能分析数据
命令格式如下:
valgrind --tool=callgrind ./exproxy
其中 ./exproxy就是我们要分析的程序。执行完毕后,就会在当前目录下生成一个文件。文件名为“callgrind.out.进程号”。如,callgrind.out.31113。注意,对于daemon进程的调试,不要通过kill -9方式停止。
如果你调试的程序是多线程,你也可以在命令行中加一个参数 -separate-threads=yes。这样就会为每个线程单独生成一个性能分析文件。如下:
valgrind --tool=callgrind --separate-threads=yes ./exproxy
生成的文件除了callgrind.out.31113外,还会多出一些子线程的文件。文件名如下:
callgrind.out.31113-01 callgrind.out.31113-02 callgrind.out.31113-03
使用valgrind --tool=callgrind ./exproxy
把callgrind生成的性能数据转换成dot格式数据
下载
tar zxvf gprof2dot-2022.7.29.tar.gz
sudo ln -s gprof2dot-2022.7.29/gprof2dot.py /usr/bin/gprof2dot.py
gprof2dot.py -f callgrind callgrind.out.921224 |dot -Tpng -o callgrind_report.png
gprof2dot.py -f callgrind -s callgrind.out.974015 > valgrind.dot
查看 valgrind.dot
dot -Tpng valgrind.dot -o valgrind.png
dot -Tsvg xxxxx.dot -o output.svg
生成图片
参数解释:
https://github.com/jrfonseca/gprof2dot?tab=readme-ov-file
-s, --strip strip function parameters, template parameters, and
const modifiers from demangled C++ function names
从杂乱无章的c++函数名中去掉函数形参、模板形参和const修饰符
-n PERCENTAGE, --node-thres=PERCENTAGE
eliminate nodes below this threshold [default: 0.5]
排除低于该阈值的节点[默认值:0.5]
-e PERCENTAGE, --edge-thres=PERCENTAGE
eliminate edges below this threshold [default: 0.1]
消除低于该阈值的边缘[默认值:0.1]
valgrind_gprof2dot ubuntu_ubuntu中gprof2dot.py-CSDN博客
下面方法不用
可以使用gprof2dot.py脚本,把callgrind生成的性能分析数据转换成dot格式的数据。方便使用dot把分析数据图形化。
wget http://www.bo56.com/download/gprof2dot.tar.gz
tar xvf gprof2dot.tar.gz
sudo apt install python2
脚本可以 点此下载 。脚本使用方式如下:
python2 gprof2dot.py -f callgrind -n10 -s callgrind.out.31113 > valgrind.dot
使用dot把数据生成图片
命令格式如下:
dot -Tpng valgrind.dot -o valgrind.png
生成的图片示例
通过图形,我们可以很直观的知道那段程序执行慢,并且了解相关调用关系
QNX下Valgrind 内存泄漏分析 - 知乎 (zhihu.com)
(663条消息) 内存泄漏动态检测(valgrind)_whcz的博客-CSDN博客
内存泄漏检测
valgrind --leak-check=full --show-reachable=yes --trace-children=yes --log-file=result ./ndreverter
其中--leak-check=full 指的是完全检查内存泄漏,--show-reachable=yes是显示内存泄漏的地点,--trace-children=yes是跟入子进程。当程 序正常退出的时候valgrind自然会输出内存泄漏的信息。
valgrind Illegal instruction (core dumped)
valgrind运行程序core dump问题-CSDN论坛
利用Valgrind和gperftools解决内存问题
利用Valgrind和gperftools解决内存问题 - 简书
pclint 内存泄漏
PC-lint Plus 学习笔记
https://blog.csdn.net/qq_43045569/article/details/105920649
PC-Lint使用_tongxiaomo的博客-CSDN博客_pc-lint
内存检测工具Dr. Memory的使用
内存检测工具Dr. Memory的使用_网络资源是无限的-CSDN博客_dr memory 使用
Dr. Memory是一个内存调试工具,它是一个开源免费的内存检测工具,它能够及时发现内存相关的编程错误,比如未初始化访问、内存非法访问、数组越界读/写、以及内存泄露等。它可以在Linux、Windows、Mac OS和Android操作系统上使用。关于Dr. Memory的更多说明可以参考其主页:Home
下面简单说下其在Windows7上的使用过程:
https://github.com/fengbingchun/Messy_Test
Linux内存使用以及内存泄露 - 知乎 (zhihu.com)
C/C++
1. Valgrind: Debugging and profiling Linux programs, aiming at programs written in C and C++
2. ccmalloc: Linux和Solaris下对C和C++程序的简单的使用内存泄漏和malloc调试库
3. LeakTracer: Linux、Solaris和HP-UX下跟踪和分析C++程序中的内存泄漏
4. Electric Fence: Linux分发版中由Bruce Perens编写的malloc()调试库
5. Leaky: Linux下检测内存泄漏的程序
6. Dmalloc: Debug Malloc Library
7. MEMWATCH: 由Johan Lindh编写,是一个开放源代码C语言内存错误检测工具,主要是通过gcc的precessor来进行
8. KCachegrind: A visualization tool for the profiling data generated by Cachegrind and Calltree