Antonio Ragagnin
Antonio Ragagnin

Reputation: 2327

Valgrind cache profiling of two different parts of a function

I have a C program, which I compiled with the -g options, and then runned with:

valgrind --tool=cachegrind --branch-sim=yes ./myexecutable

This let me know which function contains a bottleneck. However this is a pretty long function and it is not clear to me from which part of the function I get most of the cache missings. I cannot (do not want to) divide it in two different parts.

Is there a way (maybe including a valgrind.h or with some magical #pragma stuff), to instruct Valgrind to make different statistics for different parts of a function?

Upvotes: 0

Views: 75

Answers (1)

K-J
K-J

Reputation: 586

To check function-by-function values, you have probably used cg_annotate like this:

cg_annotate cachegrind.out.1234

If you add the "--auto=yes" flag to that command, the values will be displayed for each line:

cg_annotate --auto=yes cachegrind.out.1234

You can print the result into a file so that you can search for your function. Note that only lines and functions that have a major performance impact will be displayed, so if you can't find certain lines they likely have a negligible impact on the execution.

Upvotes: 1

Related Questions