gprof官方文档注解

https://www.systutorials.com/docs/linux/man/1-gprof/

DESCRIPTION

gmon.out存储了函数调用信息,被调用函数计入调用函数的时间,cc是c complier,-pg会将生成profile的相应版本的库链接进来。

Gprof所做的工作就是将目标文件的符号表和函数调用统计信息关联起来,如果有多个则汇总。所以在生成报告的时候需要将二进制文件和gmon.out一起传给gprof,而且由于是编译器插入额外的代码(插桩)进行统计,所以一定要运行起来之后才可以得到运行期的统计信息。

“gprof” produces an execution profile of C, Pascal, or Fortran77 programs. The effect of called routines is incorporated in the profile of each caller. The profile data is taken from the call graph profile file (gmon.out default) which is created by programs that are compiled with the -pg option of “cc”, “pc”, and “f77”. The -pg option also links in versions of the library routines that are compiled for profiling. “Gprof” reads the given object file (the default is “a.out”) and establishes the relation between its symbol table and the call graph profile from gmon.out. If more than one profile file is specified, the “gprof” output shows the sum of the profile information in the given profile files.

routine就是函数例程,花费的时间会按照图传递(所以学好图算法是必须的),环被发现并且作为一个整体看待。

“Gprof” calculates the amount of time spent in each routine. Next, these times are propagated along the edges of the call graph. Cycles are discovered, and calls into a cycle are made to share the time of the cycle.

几种模式:flat模式直接告诉你每个函数所花的时间,call graph模式重点正对不必要的子函数调用,annotated版本则精确到行。

Several forms of output are available from the analysis.

The flat profile shows how much time your program spent in each function, and how many times that function was called. If you simply want to know which functions burn most of the cycles, it is stated concisely here.

The call graph shows, for each function, which functions called it, which other functions it called, and how many times. There is also an estimate of how much time was spent in the subroutines of each function. This can suggest places where you might try to eliminate function calls that use a lot of time.

The annotated source listing is a copy of the program’s source code, labeled with the number of times each line of the program was executed.

OPTIONS

默认的参数是-p,-q,只显示flat和call graph

Specifying any of these options overrides the default (-p -q), which prints a flat profile and call graph analysis for all functions.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值