您的位置:首页 > 其它

How to use gprof

2009-04-23 15:17 190 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: