Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kcachegrind. Show only functions from my code

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:

enter image description here

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[])
like image 897
Kenenbek Arzymatov Avatar asked Oct 28 '16 12:10

Kenenbek Arzymatov


People also ask

How does callgrind work?

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.

How to use call grind?

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.

How do I start KCacheGrind?

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.


3 Answers

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.

like image 184
milianw Avatar answered Oct 07 '22 22:10

milianw


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.

like image 20
Manthan Tilva Avatar answered Oct 07 '22 23:10

Manthan Tilva


when you are on os x you can try profilingviewer, it can hide system functions based on customizable presets.

enter image description here

like image 42
user24525 Avatar answered Oct 08 '22 00:10

user24525