C++ 内存检查和性能分析工具 valgrind
source link: https://zhiqiang.org/coding/cpp-profiler-valgrind.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
C++ 内存检查和性能分析工具 valgrind
一个好用的 C++性能分析工具需满足几个条件:
- 配置简单,不需要改动原程序和重新编译。
- 可以跟踪到动态链接库内部。
- 有结果的图形界面,可以分层追踪最耗时的片段。
目前我唯一知道满足这些条件的是visual stdio
以及valgrind
。前者是 windows 平台微软的作品,后者是 linux 上的开源软件。
valgrind
可通过apt-get
安装,并会自动安装所有子工具:
sudo apt-get install valgrind
除此之外,还需安装图形界面工具KCachegrind
:
sudo apt-get install kcachegrind
kcachegrind
依赖的包比较多,下载安装时间较长。
valgrind 是一系列软件,它最初的功能是检查程序的内存状况。效率检查是子工具callgrind
。
valgrind --tool=callgrind -v [callgrind options] your-program [program options]
此处-v
可进入动态链接库。它会在当前目录下生成一个callgrind.out.918
或类似的文件。
查看结果:
kcachegrind callgrind.out.918
Q. E. D.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK