www.delorie.com/gnu/docs/binutils/gprof_22.html   search  
Buy GNU books!

GNU gprof

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7. Answers to Common Questions

How do I find which lines in my program were executed the most times?

Compile your program with basic-block counting enabled, run it, then use the following pipeline:

gprof -l -C objfile | sort -k 3 -n -r

This listing will show you the lines in your code executed most often, but not necessarily those that consumed the most time.

How do I find which lines in my program called a particular function?

Use `gprof -l' and lookup the function in the call graph. The callers will be broken down by function and line number.

How do I analyze a program that runs for less than a second?

Try using a shell script like this one:

for i in `seq 1 100`; do
  mv gmon.out gmon.out.$i

gprof -s fastprog gmon.out.*

gprof fastprog gmon.sum

If your program is completely deterministic, all the call counts will be simple multiples of 100 (i.e. a function called once in each run will appear with a call count of 100).

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003