|Valgrind 3.3 - Advanced Debugging and Profiling for GNU/Linux applications|
by J. Seward, N. Nethercote, J. Weidendorfer and the Valgrind Development Team
Paperback (6"x9"), 164 pages
RRP £12.95 ($19.95)
First off, as for normal Valgrind use, you probably want to
compile with debugging info (the
‘-g’ flag). But by contrast with
normal Valgrind use, you probably
do want to turn
optimisation on, since you should profile your program as it will
be normally run.
The two steps are:
- Run your program with ‘valgrind --tool=cachegrind’ in front of the normal command line invocation. When the program finishes, Cachegrind will print summary cache statistics. It also collects line-by-line information in a file ‘cachegrind.out.<pid>’, where ‘<pid>’ is the program's process ID. Branch prediction statistics are not collected by default. To do so, add the flag ‘--branch-sim=yes’. This step should be done every time you want to collect information about a new program, a changed program, or about the same program with different input.
- Generate a function-by-function summary, and possibly annotate source files, using the supplied cg_annotate program. Source files to annotate can be specified manually, or manually on the command line, or “interesting” source files can be annotated automatically with the ‘--auto=yes’ option. You can annotate C/C++ files or assembly language files equally easily. This step can be performed as many times as you like for each Step 2. You may want to do multiple annotations showing different information each time.
As an optional intermediate step, you can use the supplied cg_merge program to sum together the outputs of multiple Cachegrind runs, into a single file which you then use as the input for cg_annotate.
These steps are described in detail in the following sections.
|ISBN 0954612051||Valgrind 3.3 - Advanced Debugging and Profiling for GNU/Linux applications||See the print edition|