Thread: Functions 'disappears' while profiling.

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    110

    Functions 'disappears' while profiling.

    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!

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    The compiler might have inlined them.
    Kurt

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by ZuK View Post
    The compiler might have inlined them.
    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.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    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"

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Quote Originally Posted by überfuzz View Post
    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!
    Of course, this would be a lot easier if you posted an actual short example showing us exactly what you're seeing.
    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.

  6. #6
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    -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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. texture disappears!
    By ne-coco in forum C++ Programming
    Replies: 0
    Last Post: 03-13-2012, 06:51 AM
  2. Profiling
    By MK27 in forum Tech Board
    Replies: 1
    Last Post: 06-04-2010, 12:26 PM
  3. profiling
    By zaac in forum C++ Programming
    Replies: 3
    Last Post: 01-30-2009, 10:06 AM
  4. Profiling
    By moi in forum C Programming
    Replies: 2
    Last Post: 03-02-2006, 07:29 AM
  5. compiler disappears
    By spveer in forum C Programming
    Replies: 5
    Last Post: 07-07-2005, 10:38 AM