Updated over 3 years ago by Knödlseder Jürgen
Valgrid is a very useful tool for finding bottle necks in the execution of code and to identify where actually the type is spent.
valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes gsrvy (args)
Mark the code zone using some macros
#include <valgrind/callgrind.h>
int main()
{
foo1();
CALLGRIND_START_INSTRUMENTATION;
CALLGRIND_TOGGLE_COLLECT;
bar1();
CALLGRIND_TOGGLE_COLLECT;
CALLGRIND_STOP_INSTRUMENTATION;
foo2();
foo3();
}
valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes --collect-atstart=no --instr-atstart=no gsrvy (args)
If the callgrind.out.*
file is empty call
callgrind_control -d [hint [PID/Name]]where hint is an arbitrary string you can optionally specify to later be able to distinguish profile dumps.
Check whether instrumentation is turned on using
callgrind_control -b
You can also decide to switch instrumentation on using
callgrind_control -i on(and switching off again by specifying “off” instead of “on”).
Use the kcachegrind
GUI to visualise the results.