7

C++ 内存检查和性能分析工具 valgrind

 3 years ago
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

作者: 张志强

, 发表于 2016-01-05

, 共 546 字 , 共阅读 617 次

一个好用的 C++性能分析工具需满足几个条件:

  1. 配置简单,不需要改动原程序和重新编译。
  2. 可以跟踪到动态链接库内部。
  3. 有结果的图形界面,可以分层追踪最耗时的片段。

目前我唯一知道满足这些条件的是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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK