Thread: Can gprof go into each self-defined function?

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    159

    Can gprof go into each self-defined function?

    Hi,
    I am trying to use gnu profiler gprof to find out which operations cost most of the time, for example, I heard that exp can be very time expensive. However all I can get from gprof analysis is only the count of each self-defined function, but not the count for each operations inside each self-defined function. I guess gprof probably could do this, and was wondering how to get this infomation?
    Thanks in advance!

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by lehe View Post
    Hi,
    I am trying to use gnu profiler gprof to find out which operations cost most of the time, for example, I heard that exp can be very time expensive. However all I can get from gprof analysis is only the count of each self-defined function, but not the count for each operations inside each self-defined function. I guess gprof probably could do this, and was wondering how to get this infomation?
    Thanks in advance!
    Compile your code with full debug information (-g -pg) and use the -l (the letter ell, in case your font doesn't make it obvious) argument when you invoke gprof to get line-by-line profile information.

    Obviously, you are not able to "look inside" functions from the C library itself, such as exp(), unless you have a profile build of the C library. But you should be able to see the total time spent in that function.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    159
    Thanks brewbuck!
    I was wondering if -g is needed, since I saw on page 77 in "An Introduction to GCC", there is no -g specified.
    I guess if adding -g, gprof will count in the operations in the source code as it is written; If not,, the optimized operations will be counted?
    Seems like with -g it is easier to find out which operation costs most. But If I eventually need to use the optimized executable, would it be better to not include -g in compilation?

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by lehe View Post
    Thanks brewbuck!
    I was wondering if -g is needed, since I saw on page 77 in "An Introduction to GCC", there is no -g specified.
    I guess if adding -g, gprof will count in the operations in the source code as it is written; If not,, the optimized operations will be counted?
    Seems like with -g it is easier to find out which operation costs most. But If I eventually need to use the optimized executable, would it be better to not include -g in compilation?
    You only need "-g" if you want line-by-line profiling. Otherwise gprof does not have enough information to determine the specific line numbers.

    To profile an optimized executable, use both "-g -pg" and "-O". In some cases you may want to use "-fno-inline" to get more accurate results on a per-function basis, but these results don't translate to a fully optimized scenario since inlining should improve performance.

    Note that "-g" does not impact optimization. Debugging information and optimization are fully compatible. It just makes debugging harder because code can be re-ordered and variables optimized into nothingness.

    EDIT: Also, optimization will most likely cause some confusion about the exact line numbers, again, because code gets moved around. It's better than nothing, though.
    Last edited by brewbuck; 03-26-2009 at 10:33 PM.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM