public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* gprof - reg
@ 2011-05-01 11:54 santosh tatoju
  2011-05-10 15:38 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: santosh tatoju @ 2011-05-01 11:54 UTC (permalink / raw)
  To: binutils

Hi all,

I am currently working on gprof utility. I need a clarification on the following. 

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? why the second method is not adopted for evaluating function execution time? What are the advantages of using the first method over the second?

Pls do respond, Thanks in advance.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: gprof - reg
  2011-05-01 11:54 gprof - reg santosh tatoju
@ 2011-05-10 15:38 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2011-05-10 15:38 UTC (permalink / raw)
  To: santosh tatoju; +Cc: binutils

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 
information.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-05-10 15:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-01 11:54 gprof - reg santosh tatoju
2011-05-10 15:38 ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).