Re: Instrumenting code for profiling.

tmk@netvision.net.il (Michael Tiomkin)
20 Nov 2004 21:30:26 -0500

          From comp.compilers

Related articles
Instrumenting code for profiling. par_ianth@yahoo.com (2004-11-14)
Re: Instrumenting code for profiling. gah@ugcs.caltech.edu (glen herrmannsfeldt) (2004-11-17)
Re: Instrumenting code for profiling. s.bosscher@student.tudelft.nl (2004-11-17)
Re: Instrumenting code for profiling. nmm1@cus.cam.ac.uk (2004-11-19)
Re: Instrumenting code for profiling. diablovision@yahoo.com (2004-11-20)
Re: Instrumenting code for profiling. idbaxter@semdesigns.com (Ira Baxter) (2004-11-20)
Re: Instrumenting code for profiling. tmk@netvision.net.il (2004-11-20)
Re: Instrumenting code for profiling. nmm1@cus.cam.ac.uk (2004-11-26)
| List of all articles for this month |

From: tmk@netvision.net.il (Michael Tiomkin)
Newsgroups: comp.compilers
Date: 20 Nov 2004 21:30:26 -0500
Organization: http://groups.google.com
References: 04-11-043 04-11-051 04-11-065
Keywords: performance, debug
Posted-Date: 20 Nov 2004 21:30:26 EST

nmm1@cus.cam.ac.uk (Nick Maclaren) wrote
> glen herrmannsfeldt <gah@ugcs.caltech.edu> writes:
> |>
> |> FETE would read in a Fortran 66 program and then write out a new
> |> Fortran program that would count the number of times each statement
> |> was executed. ...
>
> Yes. There were other, similar ones, too.
>
> |> Presumably a similar system could be done for other languages.
>
> If you can't, it would be pretty hard to compile! With Fortran or
> BCPL, you could take short cuts and not do a full parsing job; with C
> or Algol 68, you would have to do a full parse, and would find it
> easiest to hack a compiler.


    Well, with some natural assumptions, you don't need to do full
parsing for C profiling. You can use the line info in the executable
to find the images of the "statements" (BTW, the line num/file name
can be used as an ID for a statement). In C, the only problem can be
jump tables in switch statements, but you can find the pattern that
your compiler uses and update the jump tables as well.


    For a function with one entry (the case of C), it's not very
complicated to make a copy of the function extended with
instrumentation. You even don't neeed to analyze the executable: a
good disassembler can help in this task, and then you can easily
insert profiling instructions.


    The question is if you really need to do profiling by yourself. Most
compilers would happily do this for you, and there are other tools
that do profiling for executables, like Vtune of Intel did for Win/x86
platform.


    Michael


Post a followup to this message

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