Thread: how to use gprof

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    19

    how to use gprof

    hi, i have written my own malloc and now I want to test it with a test program and use gprof to measure the performance.
    my to programs are: malloc.c and tstmalloc.c.

    how do i do this? I think it has something to do with -pg flag right?

    thanks in advance

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    And how did you get as far as "thinking it's -pg"?

    In the many minutes that have passed, did you try it to see what would happen?
    Profiling with GProf
    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.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    19
    in the many minutes that have passed i have learned how to use it on a single program but not how to do it with my 2 programs. (where in the command to put it) any ideas for how to do that?

    the command i use without the -pg is home> gcc -o tstmalloc -g -Wall -DSTRATEGY=1 malloc.c tstmalloc.c (strategy is only there to make my malloc use first-fit)

    thanks again for helping me

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    So just add -pg and it should compile ALL the source files on that command line with profiling enabled.

    Or have you already tried that, and found that it didn't work (in which case, you should have said so).
    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.

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    19
    i have tried that and it didnt work. sorry for not saying so. if i put -pg in the end nothing happens (I get a new prompt but nothing more) and if I put it right after tstmalloc I get lots of errors about multiple definitions. so where should I add it?

    thanks for helping me!

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    The following should work.

    Code:
    gcc -pg -o tstmalloc tstmalloc.c malloc.c
    ./tstmalloc
    gprof gmon.out > profile.txt
    vi profile.txt
    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. Profiling other than gprof
    By Kempelen in forum C Programming
    Replies: 1
    Last Post: 06-02-2011, 11:13 AM
  2. Question about Gprof
    By PetrolMan in forum C++ Programming
    Replies: 1
    Last Post: 03-23-2009, 10:18 AM
  3. compiling using gprof
    By shuo in forum C++ Programming
    Replies: 5
    Last Post: 05-27-2008, 07:47 AM
  4. Gprof under windows
    By Kempelen in forum C Programming
    Replies: 7
    Last Post: 05-23-2008, 05:49 PM
  5. Profiling with GPROF
    By RoshanX in forum C Programming
    Replies: 2
    Last Post: 03-30-2007, 02:38 PM