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?
Per the comment by @user6556709 , the loader and dynamic linking are what show in my graph output above. The referenced example does not indicate how to find your main, but it can be found in the 'Flat Profile' section of the GUI:
It took some digging to find -- it can be grouped by source to show only .c/.h files, or use the Location heading to sort by location name and search for main.