I have a program which I try to clock, or profile. When I compile with -O flags some functions disappears from the out put from gprof. Is there an explanation to this..?
Thanks!
I have a program which I try to clock, or profile. When I compile with -O flags some functions disappears from the out put from gprof. Is there an explanation to this..?
Thanks!
The compiler might have inlined them.
Kurt
In fact, one common effect of using -O style of options is to increase likelihood of certain types of functions being inlined.
Another explanation is that the "function" is actually a macro. Macros work by modifying code before the compiler sees it, so will never appear explicitly in the executable, let alone be recognised by a debugger or profiler.
Or, if you have functions which produce identical assembly, the linker may optimise the resuling assembly to only have one copy of the function.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
-O applies optimisations, as stated above.
If you want to profile, profile your WORST case, i.e. your debug build with no optimisation. Then you know where the bottlenecks are and optimisation by the compiler can only make things better. If you have a build with enough debug information in it to profile, then you're not really having the best code you can anyway - just the profiling code itself can be a source of slowdown, and the debug symbols etc. that need to be included will impact any caching etc. that you might benefit from anyway.
So DELIBERATELY make your profiled code as bad as possible (i.e. no optimisation, debug symbols, etc.), re-code as necessary to improve it, and you know that your WORST case will never be that bad in your actual production code.
- Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
- A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
- The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.