valgrind之callgrind性能优化

1.callgrind概述

  它主要用来检查程序中函数调用过程中各个函数的CPU消耗,以便开发者分析程序中各个函数的CPU使用情况,方便优化提供程序的运行效率。

2 安装valgrind

$sudo apt install valgrind

3 编译

  编译程序时使用–g –O0,即编译调试版,不优化程序性能。如:gcc -g -O0 sample.c –o sample

4 调试运行

$valgrind --tool=callgrind ./svpushlnx

  程序运行结束后,会在当前目录下生成callgrind.out.($pid)分析日志

5 分析CPU消耗

1.4.1 安装kcachegrind

$sudo apt install kcachegrind

1.4.2 分析callgrind.out.($pid)日志文件

$kcachegrind callgrind.out.24034

valgrind之callgrind性能优化

如上图所示,lr为执行指令占程序运行过程中总指令的百分率。lr越高的函数,则说明其消耗的CPU资源越高。优化的空间就越大。当用户选中左边方框的函数后右下角会出现该函数的子调用过程(调用栈)已及各个子过程的ir,用户可以双击子过程进入子过程的调用栈。而右上角则显示,有哪些函数可能会调用被选中的函数。

相关推荐