2

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.

station
  • 6,715
  • 14
  • 55
  • 89
  • Is there some other way I can do it? "have to " means I have to profile it I doesn't neccessarily mean using gprof. – station Jul 25 '11 at 14:23
  • Well, when I have the objective of locating code to optimize so the app is as fast as possible (as opposed to just measuring how long it takes), [this is how I do it](http://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux/378024#378024). I've been doing this an awful long time, and I'm still mystified that it's not simply considered obvious. – Mike Dunlavey Jul 25 '11 at 14:41

1 Answers1

2

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.

caf
  • 233,326
  • 40
  • 323
  • 462