help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gprof annotation not working with gcc-3.3.3


From: Dan Katz
Subject: gprof annotation not working with gcc-3.3.3
Date: Tue, 20 Apr 2004 18:08:06 -0400
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux)

I've been trying to profile a simple C program, but I can't seem to
get gprof and gcc to play nicely anymore -- particularly in the
context of the annotated listing.



To begin, my system is a Debian(unstable) system with the following:

    $ gcc --version
    gcc (GCC) 3.3.3 (Debian 20040401)
    [...]

    $ dkatz@fifi:~$ gprof --version
    GNU gprof 2.14.90.0.7
    [...]

    $ strings /lib/libc.so.6 | grep version
    [...]
    GNU C Library stable release version 2.3.2, by Roland McGrath et al.
    Compiled by GNU CC version 3.3.3 20031206 (prerelease) (Debian).
    [...]

    $ uname -a 
    Linux fifi 2.6.5-1-686 #1 Wed Apr 7 00:24:54 EST 2004 i686 GNU/Linux


I compile the following simple C program (called "junk.c" in my
world):

------------------------------------------------------------------------
int
main()
{
     long i;
     long j = 0;
     for (i = 0; i < 10000000; ++i)
     {
          if (0 == i % 2)
               j += 2;
          else
               j++;
     }
     j /= 10;
     return 0;
}
------------------------------------------------------------------------

with  the command

    $ gcc -Wall -ansi -O0 -g -pg -lc_p junk.c

I noticed that the gprof info pages maintained that I should also use
the '-a' option while compiling (a node entitled "The Annotated Source
Listing" states "Compiling with `gcc ... -g -pg -a' augments your
program..."), but that option seems to no longer exist in gcc 3.3.3.  

After compilation, I just run the program and then run gprof on the
resulting gmon.out:

    $ ./a.out
    $ gprof -A -l -x a.out gmon.out 
    *** File /home/dkatz/junk/junk.c:
                    int
                    main()
               1 -> {
                         long i;
               1 ->      long j = 0;
               1 ->      for (i = 0; i < 10000000; ++i)
                         {
               1 ->           if (0 == i % 2)
               1 ->                j += 2;
                              else
               1 ->                j++;
                         }
               1 ->      j /= 10;
               1 ->      return 0;
               1 -> }
 
 
    Top 10 Lines:
 
         Line      Count
 
            3          1
 
    Execution Summary:
   
            9   Executable lines in this file
            9   Lines executed
       100.00   Percent of the file executed
 
            1   Total number of line executions
         0.11   Average executions per line


Clearly, the counts within the for loop are not being kept.




So it seems that gcc-3.3.3 and gprof are not working nicely together
for annotation.  At the very least, the gprof documentation is out of
date.  But the more serious question is:  has gcc left gprof behind?
I notice that gcc comes with gcov now, which would seem to imply that
gcov is the preferred coverage tool.  But what about time profiling?
Is gprof still the standard tool for that?  And is it working
correctly with 3.3.3?


Dan Katz


-- 
Daniel P. Katz
Software Development
ProfitLogic - Helping Retailers Make More Money
25 First Street, Third Floor
Cambridge, MA 02141
http://www.profitlogic.com/  
 
Direct:  617.218.1979
Fax:     617.494.9787
Email:   dkatz@profitlogic.com
WWW:     http://www.profitlogic.com


reply via email to

[Prev in Thread] Current Thread [Next in Thread]