Valgrind basics is a tool that can find bugs in compiled code by running compiled executable and instrumenting it. According to docs works best on code compiled with Basic usage
valgrind ${prog-to-run} ${arg1} ${arg2} ...
Checking for memory access errors and memory leaks:
valgrind --tool=memcheck --leak-check=full --show-reachable=yes --num-callers=16 ${prog-to-run}
Profiling memory usage:
valgrind --tool=massif ${prog-to-run}
gv massif.${pid}.ps
most massif.${pid}.txt
Profiling CPU usage:
valgrind --tool=callgrind ${prog-to-run}
or:
valgrind --tool=callgrind --instr-atstart=no ${prog-to-run}
and then: callgrind_control -i on callgrind_control -i off It generates Profiling sections of the code
In other words, if your code looks like: #include <valgrind/callgrind.h> CALLGRIND_TOGGLE_COLLECT foo(); CALLGRIND_TOGGLE_COLLECT your program is profiled only when foo() function is running. There’s also an option |