Xavier Lamorlette

Valgrind

Notes sur Valgrind, issuees d'une formation de Julian Seward, et de mon expérience.

Le site de Valgrind est valgrind.org.

Saint George and the Dragon - Valgrind

Memcheck

Run Memcheck:

valgrind --tool=memcheck --xml=yes --leak-check=full --show-reachable=yes --xml-file=results.xml program [with its arguments]

Make requests from code:

#include <memcheck/memcheck.h>

Callgrind

Callgrind (+ KCachegrind UI): low level time profiler and function-call profiler, simulating CPU caches.

Run Callgrind:

valgrind --tool=callgrind --simulate-cache=yes --branch-sim=yes --cacheuse=yes \
--callgrind-out-file=callgrind.out program [with its arguments]
callgrind_annotate callgrind.out [source files to annotate] | grep -v callgrind_annotate

Manual selective profiling:

Automatic selective profiling:

valgrind --tool=callgrind --simulate-cache=yes \
--toggle-collect="*MyClass::MyMethod*" \
--dump-after="MyClass::MyMethod(arguments)" \
program [with its arguments]
To get the exact signature of a function:
nm -l -C libdll.so | grep MyMethod

One file per thread: --separate-threads=yes.

Cachegrind

Cachegrind: simpler than Callgrind. Does branch predictions.

Run Cachegrind:

valgrind --tool=cachegrind –-branch-sim=yes -–cache-sim=yes program [with its arguments]
cg_annotate cachegrind.out.[pid] [source files to annotate]  # or --auto=yes

Other other profiling tools

Massif

Massif: heap memory space profiler. Takes periodic snapshots of heap.

Run Massif:

valgrind --tool=massif program [with its arguments]

Display Massif data:

ms_print massif.out.valgrind.[pid]

ms_print options:

Tool similar to Massif: DHAT.

Helgrind

Helgrind: thread error detector.

Similar tool: DRD.

La dernière mise à jour de cette page date d'avril 2019.

Le contenu de ce site est, en tant qu'œuvre originale de l'esprit, protégé par le droit d'auteur.
Pour tout commentaire, vous pouvez m'écrire à xavier.lamorlette@gmail.com.