http://www.cs.duke.edu/~ola/courses/programming/gprof.html
How to Use GProf in 5 Easy Steps.
1. Get your program working!! gprof is not a debugger. Use it once
you have a working program to optimize that program.
2. Compile and link with the -pg option. If you use an Owen
Astrachan patented makefile this simply means changing the CFLAGS
variable.
3. Run your program normally; that is, pretend you didn't do
anything to it and do what you would normally do (checking difficult,
slow, or fast cases, of course).
4. Type gprof exec > out where exec is replaced by your
executable's name and out by some meaningful name for the profiling
information. For instance, if your executable were "foo" on the third
run compiled with the -O2 option then you might type:
gprof foo > run3.withO2.stats
5. Look over the output and learn what it means. Hint, go to the
second table. The first is pretty useless. To get there, search for
"granularity" twice from the top of the file (in emacs, use C-s; in
less or more use /).