how to use gprof in Linux?

帅比萌擦擦* 提交于 2019-12-11 04:27:38

问题


I have a C code in a file test.c .I have to profile it using grof.I have used the following commands to do so.

gcc -p -o result test.c
./result
gprof result

A section of the output looks as follows:

`Flat profile: Each sample counts as 0.01 seconds. no time accumulated

% cumulative self self total
time seconds seconds calls Ts/call Ts/call name`

The problem is no matter what complex or easy program I use each sample count doesn't change from 0.01 seconds.Why is that and no time is being accumulated and displayed under the various coloumns.


回答1:


You are using the wrong command-line option to gcc. -p is for a different, older profiler - for gprof, you need -pg.

If you still see no time acculmulated, it just means that your program didn't consume enough CPU time to register - gprof uses sample-based profiling, and it didn't run long enough for any samples to be taken.



来源:https://stackoverflow.com/questions/6816274/how-to-use-gprof-in-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!