古人学问无遗力,少壮功夫老始成。 纸上得来终觉浅,绝知此事要躬行。

【原创】gprof使用方法补遗

上一篇 / 下一篇  2009-09-24 10:41:06 / 个人分类:测试工具

原创于cnerlang.blogspot.com 2009年3月5日,现将其迁移至此:

       前段时间在做一个项目测试时用到了gprof,由于以前没用过,只好google一次,不过网上的资料都是千篇一律……

       以下是我看过英文文档和gprof自带的帮助总结出来的一些内容,希望能对大家有所帮助!

       在分析后,我们可以看到一共输出了两张table: Flat Profile 和 Call Graph

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.

我们先来看一下Flat Profile:

% time
This is the percentage of the total execution time your program spent in this function. These should all add up to 100%.

cumulative seconds
This is the cumulative total number of seconds the computer spent executing this functions, plus the time spent in all the functions above this one in this table.

self seconds
This is the number of seconds accounted for by this function alone. The flat profile listing is sorted first by this number.

calls
This is the total number of times the function was called. If the function was never called, or the number of times it was called cannot be determined (probably because the function was not compiled with profiling enabled), the calls field is blank.

self ms/call
This represents the average number of milliseconds spent in this function per call, if this function is profiled. Otherwise, this field is blank for this function.

total ms/call
This represents the average number of milliseconds spent in this function and its descendants per call, if this function is profiled. Otherwise, this field is blank for this function.

name
This is the name of the function. The flat profile is sorted by this field alphabetically after the self seconds field is sorted.



再来看一下call graph:

index 
Entries are numbered with consecutive integers. Each function therefore has an index number, which appears at the beginning of its primary line.
Each cross-reference to a function, as a caller or subroutine of another, gives its index number as well as its name. The index number guides you if you wish to look for the entry for that function.
% time
This is the percentage of the total time that was spent in this function, including time spent in subroutines called from this function.
The time spent in this function is counted again for the callers of this function. Therefore, adding up these percentages is meaningless.
self
This is the total amount of time spent in this function. This should be identical to the number printed in the seconds field for this function in the flat profile.
children
This is the total amount of time spent in the subroutine calls made by this function. This should be equal to the sum of all the self and children entries of the children listed directly below this function.
called
This is the number of times the function was called.
If the function called itself recursively, there are two numbers, separated by a `+'. The first number counts non-recursive calls, and the second counts recursive calls. separated by a `/'.The first number counts the number of times the function called this child,and the second counts the total number of times the child was called.
name
This is the name of the current function. The index number is repeated after it.

TAG:

 

评分:0

我来说两句

Open Toolbar