[Ilugc] Profiling a C program.

  • From: logulinux@xxxxxxx (Logu)
  • Date: Thu Mar 13 17:59:37 2008

I compiled and linked the program with -pg option. But when I run the 
gprof
I only get this output

 %   cumulative   self         self     total
time   seconds   seconds    calls   Ts/call  Ts/call  name
 0.00      0.00     0.00        5        0.00     0.00    pmesg

Could someone point me what I am missing here. I need to find the time
spent on each function calls.


I barely remember using gprof.

I have found the simple shell command time(1) to be far more easier to
use and helpful.


We have a product which hit some performance issues in some scenarios and I 
would like to trobleshoot the performance. Since I didnt get the correct 
gprof output, I wrote a simple program to see if profiling works. I dont 
think time(1) will help here.

I remember gprof reporting huge amounts of data. How did you get just
one line?

I just posted  the relevant output :)

There are plenty of profiling/monitoring tools in linux.

Why don't you try the other ones?

lsof(1), fstat(1) and so on.

I think you can simply

$ time ./a.out

for your immediate need.


I have not used fstat and I dont think lsof will help for my requirement. 
And I am now more focused why gprof is not giving the time spent data.


As to why gprof results weird results, the answer might be far deeper
than what meets the eye.

As someone suggested you can try a few iterations.

My simple program has a function which spends atleast 2 seconds. Initially I 
have used sleep and replaced them with "for" loops containg simple 
calculations to ensure that they atleast spend two seconds.

Some of the internet documents mentioned about linking with libc_p instead 
of libc, but I could not find such library.


Thank you so much for your reply.
-logu







Other related posts: