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.