Ian Lance Taylor wrote:
It's really a lot easier to do this as a source code modification than
as a compiler change. Unless you already have a lot of experience
with the compiler, I think you'd be lucky or very good to get it done
in two weeks.
I have already done it as source code modification, once. It has its limitations
which may be overcome in the compiler (e.g. using a specialized ABI to
call the profiler functions).
For the prologue changes look at FUNCTION_PROFILER and friends in the
internal documentation. There is currently no support for profiling
support in the epilogue. It could be added along the same lines as
FUNCTION_PROFILER.
Thanks for the pointer. I have now read this documentation, but I am not
sure it suits my needs:

* No support for an epilogue. Isn't there some support for finalize
through other means? My epilogue should be called even when
exceptions are thrown.
* I need a static variable per function (not a counter but a pointer
to a struct or a struct) I hope that the proposed
fprintf(f,"LP%d", labelno) is sufficient.
* I need something more portable than assembler code. I'd like to
define the profiler in C or even in a *portable* lower level language.
* The documentation repeatedly mentions 'mcount', is it just an
example for the most common profiling function, or is it a must? I
would like to define something different, which does a completely
different stuff.

If I were you I wouldn't bother with __FUNCTION__ and would just deal
with PC addresses. Use a post-processing pass to convert those back
into function names, using, e.g., addr2line
That's not a perfect solution.

* I am not sure if there is a portable way to extract PC from stack.
For now I can do this for Linux/x86 but its not perfect (also, how
can this be done? With -fomit-frame-pointer and with
-fno-omit-frame-pointer?)
* Inline functions won't be profiled (I'd like to be able to
selectively profile some of the inline functions using
__attribute__((profile)) or some such).
* There are many great features that are more difficult to implement
if the PC is used instead of a string.

Thanks
Michael

--
Michael Veksler
http:///tx.technion.ac.il/~mveksler


Reply via email to