====== Valgrind ====== ===== General options ===== Syntax: **''valgrind [options] ''** * **''--db-attach=yes''** : to automatically attach gdb on errors * **''--error-limit=no''** : to display all errors even if there are a lot of them * **''--num-callers=50''** : to increase the maximum backtrace displayed ===== Tools ===== ==== Memcheck ==== Memory checker (default tool). Syntax: **''valgrind [--tool=memcheck] [options] ''** * **''--leak-check=full''** : to completely analyse memory leaks * **''--show-reachable=yes''**: to show the detail of reachable memory * **''--track-origins=yes''** : to display where was allocated the "uninitialized value" ==== Massif ==== Memory profiling. Syntax: **''valgrind --tool=massif [options] ; ms_print massif.''** * **''--time-unit=B''** : display results in bytes ==== Callgrind ==== Performance profiling, to find time taken in functions and number of calls of functions. Syntax: **''valgrind --tool=callgrind ; kcachegrind callgrind.out.xxxx ; calgrind_control''** ==== Cachegrind ==== CPU cache profiling, to find cache misses. Syntax: **''valgrind --tool=cachegrind ''** Always do profiling with optimization options of compiler, or you could optimize things that the compiler already automatically does.