GCC compiler specific question

Mar 17, 2006 9 Replies

Hi, I am looking for a builtin functionality of the GCC. Is there a way get an unambiguous number of each compiled/linked c-function? I want to use it as an index into a table for all functions of an embedded (cross GCC, M68k) executable. With the help of this index I would be able to define a table where I can store profiling information of my code e.g. by using timer values of a hardware timer, the function name (__func__) and so on. I didn't find something suitable in the GCC manual.



Thanks for you help.



What about the address of the function? It should be unique, and it is perfect for building function tables!

Regards,

Zara

Zara schrieb:

Good idea, but the problem is I have to implement a search algorithm to find out if the currently processed function is already present in the table or not. I wanted to avoid to do this way because of timing issues.

Here is a small code snippet to give a rough idea of what I intend:

void FunctionName(void) { # ifdef __PROF__ Prof_g[FunctionIndex].sFuncName = __func__; Prof_g[FunctionIndex].nNCalls++; Prof_g[FunctionIndex].nStartTime = CTM4_g.nMCSM11Counter; # endif /* __PROF__ */ ... FunctionBody ... # ifdef __PROF__ Prof_g[FunctionIndex].nStopTime = CTM4_g.nMCSM11Counter; Prof_g[FunctionIndex].nCurExecTime = Prof_g.nStopTime - Prof_g.nStartTime; # endif /* __PROF__ */ }

Binary search? Just 2log(N) iterations for N functions. 10000 functions take

14 iterations.

Meindert

I suppose you could do something like:

int global_function_number; ...

void FunctionName(void) { #ifdef __PROF__ static int FunctionIndex; extern int global_function_number; if(!FunctionIndex) { FunctionIndex = global_function_number++; } Prof_g[FunctionIndex].sFuncName = __func__; Prof_g[FunctionIndex].nNCalls++; Prof_g[FunctionIndex].nStartTime = CTM4_g.nMCSM11Counter; ...

John Devereux

Instead of adding explicit profiling code to the source, have you considered Monte Carlo profiling ? For counting function calls, you could use the gcc -p or -pg flag.

Its address.

Why? Do you want to re-invent the -pg option and gprof? And/or

-fprofile-arcs and gcov?

Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.

Hans-Bernhard Broeker schrieb:

No, I don't want to reinvent any GNU tools. But I cannot imagine that it is possible to get a real picture of an embedded software with asynchronous interrupts from the outside world with these tools. So I decided to follow the way I described.

Look for -finstrument-functions option. GCC will generate calls to the entry and exit profiling functions which you can implement as you wish.

Vadim

You may not have set out wanting to --- by you definitely appear to be doing exactly that.

The timer used by -pg is inside the target system, i.e. it'd be a timer of your embedded system. The builtin featur you're looking at

*is* -pg, and more to the point, the mcount() function used by it. Your best by far is going to be to change mcount() and/or the

-fprofile-arcs support machinery for your purpose. The tricky part will be to get the generated data off the embedded system and presentable for gprof, of course.

Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required