1

I am interested in testing speed of some function calls from the code written in C/C++. I searched and I was directed to use Valgrind platform with Callgrind tool.

I have briefly read the manual, but I am still wondering how I can utilize the functionality of the tool to evaluate the time of my function runtime speed.

I was wondering if I could get some pointers how I can achieve my goal.

Any help would be appreciated.

ElectroJunkie
  • 301
  • 5
  • 16

1 Answers1

2

Compile your program with debug symbols (e.g. GDB symbols works fine, which are activated with the "-ggdb" flag).

If you are executing your program like this:

./program

Then run it with Valgrind+Callgrind with this command:

valgrind --tool=callgrind ./program

Callgrind will then produce a file called callgrind.out.1234 (1234 is the process ID and will probably be different when you run). Open this file with:

cg_annotate callgrind.out.1234

You may want to use grep to extract your function name. In the left column the number of instructions used for that function is displayed. Functions that use a comparatively low amount of instructions will be ignored, though.

If you want to see the output some nice graphics, I would recommend you to install KCachegrind.

K-J
  • 548
  • 2
  • 16