Re: profilers

Barry Martin <>
10 Dec 1997 00:40:54 -0500

          From comp.compilers

Related articles
profilers (Waverly Edwards) (1997-12-05)
Re: profilers (William A. Barath) (1997-12-07)
Re: profilers (1997-12-10)
Re: profilers (Barry Martin) (1997-12-10)
Re: profilers (Tony DeWitt) (1997-12-10)
Re: profilers debray@CS.Arizona.EDU (1997-12-12)
Re: profilers (Chris F Clark) (1997-12-12)
Re: profilers (William A. Barath) (1997-12-12)
| List of all articles for this month |

From: Barry Martin <>
Newsgroups: comp.compilers
Date: 10 Dec 1997 00:40:54 -0500
Organization: Compilers Central
References: 97-12-017 97-12-046
Keywords: performance

On 5 Dec 1997, Waverly Edwards wrote:
>|Can anyone tell me where to find resources for making an execution profiler.
>|Books, Websites, source code and just about anything else is welcome.

"William A. Barath" <> writes
>The most efficient way I can imagine to do it is this: compile into
>each function a small code fragment at the entry and exit points which
>read a global variable containing the seed of a high-resolution timer
>and add the difference between the two reads to a table entry for that
>function. Easy, little overhead, little bloat, and accurate even if
>the timer is only good for milliseconds (due to the averaging effect
>of repeated updates.) I've never done it, but it seems quite

It is not quite that simple - execution of a function can be suspended
for a number of reasons, including awaiting a non-deterministic event,
such as a key-press, and hence the timer must be stopped and restarted
before and after calls to such functions. This is can be done
reasonably simply in languages such as C, where you can use the pre-
processor to remap standard library functions to your own standard
library shell, which stops the timer, calls the standard libary
function, and then re-starts the timer. You do have the problem of
knowing which function the standard library function was called from;
this will be simple when C9X compilers appear, using __func__, but
until then you will have to write you own C parser. As John has
commented, using the -p option on UNIX cc is easier and probably more
accurate. This counts the number of executions of each function
rather than timing each function and hence you do not encounter the
problems described above or any loading effects on
multi-user/multi-tasking operating systems (which is virtually
everything except MS-DOS).
Barry Martin

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.