gprof - reg

Nick Clifton
Tue May 10 15:38:00 GMT 2011

Hi Santosh,

> To determine the execution time of a function,
> gprof uses sampling method by collecting samples
> of program counter at regular intervals of time.
> It provides a statistical approximation of execution time.
> Other method is to measure the lapsed time between function
> entry and function exit. This method is simple and will
> provide exact timings.
> Why the first method is used in spite of its overhead?

1) It is less intrusive than the second method.  In fact it can be 
implemented without any compiler support at all.  The second method 
requires compiler support to add the hooks for function entry and exit, 
and it may even prevent the use of some compiler optimizations (eg 
tailcalls and function inlining).

2) It does not require as much memory to hold the profiling data.  With 
the second method you need to maintain a stack of function entry times, 
and you prably need special code to handle setjmp/longjmp and exceptions.

Please note that gprof is not the only profiling tool available.  You 
might also want to look at gcov and oprofile.  Plus for a some 
architectures using a simulator can provide very helpful profiling 


More information about the Binutils mailing list