How to use gprof

gprof test
1. See http://www.cs.utah.edu/dept/old/texinfo/as/gprof_toc.html

2.Write a test program fork.c and do test

$ gcc -g fork.c -pg

$ ./a.out
I am the child.
1 1 2 6 24 120 720 5040 40320 362880
I am the parent. My PID is 9663. My child's PID is 9664, Waiting for child ... ...
1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352

$ ls
a.out  fork.c  gmon.out

$ gprof a.out | less
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total          
 time   seconds   seconds    calls  ms/call  ms/call  name   
100.00      0.47     0.47       35    13.43    13.43  sub1

... ...
 Call graph (explanation follows)


granularity: each sample hit covers 4 byte(s) for 2.13% of 0.47 seconds

index % time    self  children    called     name
                             78176264             sub1 [1]
                0.47    0.00      35/35          main [2]
[1]    100.0    0.47    0.00      35+78176264 sub1 [1]
                             78176264             sub1 [1]

... ...

$ gprof -p | less //only output Flat profile

$ gprof -q | less //only output Call graph

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值