gprof工具使用

来源:互联网 发布:投诉淘宝卖家电话多少 编辑:程序博客网 时间:2024/04/30 20:57

gprof会精确的给出函数被调用的时间和次数,给出函数调用关系


gprof使用:

1. 在编译和链接阶段加入-pg
2. 重新编译代码
3. 运行生成的可执行程序,在可执行程序当前目录下生成gmon.out

4. 用 gprof 工具分析 gmon.out 文件

gprof ./gwcap gmon.out -p

-p参数标识“flat profile”模式,在分析结果中不显示函数的调用关系,AIX平台默认此参数有效。
输出以下内容:
清单 2. flat profile 的结果
Flat profile:
Each sample counts as 0.01 seconds.
  %    cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 80.38    203.27   203.27    50000     4.07     4.07    b
 19.61    252.87    49.60    50000     0.99     0.99    a
  0.00    252.88     0.01                                  main

上面结果中各个列的含义如下:
%time       函数以及衍生函数(函数内部再次调用的子函数)所占的总运行时间的百分比 
cumulative seconds 函数累计执行的时间
self seconds  函数执行占用的时间
calls          函数的调用次数
self   ms/call   每一次调用函数花费的时间microseconds,不包括衍生函数的运行时间
total  ms/call    每一次调用函数花费的时间microseconds,包括衍生函数的运行时间
name           函数名称
列的含义,在gprof的输出结果中都有详细的说明。


Usage: gprof [-[abcDhilLsTvwxyz]] [-[ACeEfFJnNOpPqQZ][name]] [-I dirs]
        [-d[num]] [-k from/to] [-m min-count] [-t table-length]
        [--[no-]annotated-source[=name]] [--[no-]exec-counts[=name]]
        [--[no-]flat-profile[=name]] [--[no-]graph[=name]]
        [--[no-]time=name] [--all-lines] [--brief] [--debug[=level]]
        [--function-ordering] [--file-ordering]
        [--directory-path=dirs] [--display-unused-functions]
        [--file-format=name] [--file-info] [--help] [--line] [--min-count=n]
        [--no-static] [--print-path] [--separate-files]
        [--static-call-graph] [--sum] [--table-length=len] [--traditional]
        [--version] [--width=n] [--ignore-non-functions]
        [--demangle[=STYLE]] [--no-demangle] [@FILE]
        [image-file] [profile-file...]


0 0