Thanks Vedant, and my apologies for the delay getting back to you - work got "busy".
I wasn't aware of the '-fprofile-generate' option, so thanks for point this out. I have tried running it and I can see the instrumentation hooks that it generates - I assume that there is a library I have to implement to support this, can you let me know where the source for this library is?
This approach uses the C++ ctor initialisation support which is generally fine. However, in many cases in our embedded target programmers often forbid using static objects so that they can eliminate the start-up overhead of their initialisation; but that's another issue.
So the reason we cannot simply exclude source files from instrumentation, is that the majority of the real code involved tends to reside in the headers in the source for massively inlined template classes, and it is the instrumentation of these that is creating the real problem. And we do want to profile our own functions in the source file itself. For instance, a simple accessor function such as:
// From 'header.h'
struct X {
int k;
int getK() const { return k; }
...
};
// In 'source.cpp'
#include "header.h"
...
X anX;
...
int check = anX.getK();
Now the tiny accessor function which is usually trivially eliminated during inlining, is unnecessarily instrumented with the '__cyg_profile_func_enter' and '__cyg_profile_func_exit' calls, as well as the calling function.
Magnify this by the expansion and inlining of many hundreds of such functions, and the overhead becomes very large. And unfortunately, it also hides the true cost of the component that the programmer actually wants to measure. This is why I was wondering was there a '#pragma' that might allow me to write (contrived '#pragma' syntax):
// In 'source.cpp'
#pragma push profile instrumentation
#pragma disable profile instrumentation
#include "header.h"
#pragma pop profile instrumentation
...
X anX;
...
int check = anX.getK();
or an alternative mechanism. The GCC compiler has the options '-finstrument-functions-exclude-file-list' and '-finstrument-functions-exclude-function-list' for this purpose, but these are not available in CLang/LLVM.
I will experiment with the '-mllvm -disable-preinline' option, thanks for telling me about this too.
All the best,
MartinO