ProAnswers.org

How to profile C++ code in Linux?

You can use valgrind with the following options

[b]valgrind --tool=callgrind ./(Your binary)[/b]

It will generate a file called callgrind.out.x. You can then use kcachegrind tool to read this file. It will give you a graphical analysis of things with results like which lines cost how much.

You can use gprof.

make sure you compile code with -pg option

> cc -o hello hello1.c hello2.c -g -pg

There are other tools also, you can try like Valgrind, Intel VTune, Sun DTrace.