Profiling root/C++ with valgrind

From Etp
Jump to: navigation, search

By profiling root or other C/C++ programs with valgrind you can quite easily find out in which progam part or function calls your program spends its time.

These are the basic steps:

  • execute your program or root macro with valgrind, such as:
valgrind  --tool=callgrind root.exe -splash -l "runD3PDSelectorLocalFL.C(\"t.xrootd_list.2\")"

Please note that you need to specify root.exe (C++ binary) and not just root (wrapper script)

valgrind slows down the xecution of your program by some factor 30, so just run over a small data sample.

  • start kcachegrind . This is a graphical viewer which takes the file callgrind.out.XXXX (produced by previous valgrind run) as input. By default you see on the left a view of the functions sorted basically by inclusive CPU usage time. You can use different criteria to sort, produce callgraph, etc, see screenshot.

Kcachegrind.png

For more information see kcachegrind.sourceforge.net