I'm trying to use kcachegrind to generate a callgraph, preferably with a clear indication of which blocks in the call graph correspond to my functions. I followed this answer as a test run, and got a different output. I don't understand what I need to do to repeat the results of this example. How do I get kcachegrind to display my function names on the call graph?
For convenience, here is the exact code I used:
int f2(int i) { return i + 2; }
int f1(int i) { return f2(2) + i + 1; }
int f0(int i) { return f1(1) + f2(2); }
int pointed(int i) { return i; }
int not_called(int i) { return 0; }
int main(int argc, char **argv) {
int (*f)(int);
f0(1);
f1(1);
f = pointed;
if (argc == 1)
f(1);
if (argc == 2)
not_called(1);
return 0;
}
This file (main.c) was compiled as such:
gcc -ggdb3 -O0 -std=c99 main.c -o main
and then I invoked valgrind:
valgrind --tool=callgrind ./main
which output the following:
==4770== Callgrind, a call-graph generating cache profiler
==4770== Copyright (C) 2002-2017, and GNU GPL'd, by Josef Weidendorfer et al.
==4770== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==4770== Command: ./main
==4770==
==4770== For interactive control, run 'callgrind_control -h'.
==4770==
==4770== Events : Ir
==4770== Collected : 121502
==4770==
==4770== I refs: 121,502
finally, I launched kcachegrind with the output file (callgrind.out.4789):
kcachegrind callgrind.out.4789
From the example I used, I expected the call graph to look like this:
Instead, I got something that looked like this:
What can I do to reveal my function names on the call graph?