Xavier Lamorlette
Notes sur Valgrind, issuees d'une formation de Julian Seward, et de mon expérience.
Le site de Valgrind est valgrind.org.
Sommaire :
Memcheck (+ Valkyrie UI): memory error detector:
Recommended compiling options:
-g
(to see line numbers)-O
(avoid -O2
and above)-fno-inline-functions
(maybe)Run Memcheck:
valgrind --tool=memcheck --xml=yes --leak-check=full --show-reachable=yes --xml-file=results.xml program [with its arguments]
Options:
--num-callers=[x]
: to see more frames in errors stack traces--track-origins=yes
: to find the sources of undefinedness (slower)--suppressions=[filename]
(--gen-suppressions=yes/all
to start)--trace-children=yes
, --child-silent-after-fork=yes
,
--log-file=logfile%p.txt
, --trace-children-skip=patt1,patt2
Make requests from code:
#include <memcheck/memcheck.h>
Callgrind (+ KCachegrind UI): low level time profiler and function-call profiler, simulating CPU caches.
Recommended compiling options:
-g
(to see line numbers)-march=native
-fno-inline-functions
: disable inlining to get clearer resultsRun 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:
--instr-atstart=no
callgrind_control -i on [pid]
callgrind_control -i off [pid]
callgrind_control -d [pid]
callgrind_control -z [pid]
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: 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
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:
--x=[x]
: graph number of columns--y=[y]
: graph number of rowsTool similar to Massif: DHAT.
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.