I want to profile my code. So I do:
valgrind --tool=callgrind my_program [programm arguments]
kcachegrind callgrind.out.x
Now I have kcachegrind
window like this:
There is a lot of core and library functions, but how can I set up valgrind
or kcachegrind
to trace only functions are in my code (which, of course, call library functions)?
The expected output is something like that:
time number of calls function_name()
4,52% 569854 CSim2Sim my_function1(int argc, char* argv[])
3,52% 452158 CSim2Sim my_function2(int argc, char* argv[])
3,52% 36569 CSim2Sim my_function3(int argc, char* argv[])
1,52% 1258 CSim2Sim my_function4(int argc, char* argv[])
Callgrind is a profiling tool that records the call history among functions in a program's run as a call-graph. By default, the collected data consists of the number of instructions executed, their relationship to source lines, the caller/callee relationship between functions, and the numbers of such calls.
To use Callgrind, you must specify --tool=callgrind on the Valgrind command line or use the supplied script callgrind . Callgrind's cache simulation is based on the Cachegrind tool of the Valgrind package.
You can launch KCacheGrind using command line or in the program menu if your system installed it here. Then, you have to open your profile file. The first view present a list of all the profiled functions. You can see the inclusive and the self cost of each function and the location of each one.
Go to View -> Grouping and select ELF Object. In the corresponding toolview pick your application/library ELF object and it will show only functions within them.
You won't be able to get the desired output though. You cannot measure time with Valgrind, it only counts instructions and can estimate cycle counts and cache misses. And callgrind also does not show you the full function signature, it will always drop the arguments and only displays the function name.
Valgrind
provide facility to suppress particular error or error from particular object file or from some library. Check this link.
As per this instruction you can prepare you suppresion file (like a.supp) and pass it to valgrind
valgrind --tool=callgrind --suppressions=/path/to/a.supp my_program [programm arguments]
I haven't use kcachegrind, but I am sure it must provide some facility to change command-line option of valgrind.
when you are on os x you can try profilingviewer, it can hide system functions based on customizable presets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With