Skip to content

Profiling

Gprof was the tool to use normally, but the last time i encountered a lot of problems:

  • c++ give ridiculously large stack frames like in gdb
  • all numbers seemed to be 0.0
  • a completely incomprehensible gprof output

perf

Take a look at this first, perf is a standard tool for profiling the kernel, but it can be used for your own programs as well.

visit

Install like this :

perf installation
1
2
3
sudo apt install linux-tools-common
sudo apt install linux-oem-5.6-tools-common
sudo apt-get install linux-tools-5.8.0-55-generic

Of course your kernel version may vary. But this worked on laptop. Now start your program no instrumentation is needed :

run with gdb
1
2
3
gdb ./debug/backend
pidof backend
xxxxx

You could remember the pid, but it is easier to just run this oneliner :

oneliner
perf top -p `pidof backend` -K

Now you wait until you get a screen like this :

output
4.33%  libc-2.31.so           [.] _IO_setb
3.95%  libssl.so.1.1          [.] 0x0000000000064d89
3.31%  backend                [.] osrm::engine::routing_algorithms::ch::relaxOutgoingEdges[visit](false)
3.25%  libc-2.31.so           [.] _int_malloc
3.12%  backend                [.] free@plt
3.10%  backend                [.] osrm::engine::routing_algorithms::directShortestPathSearch<osrm::engi
3.02%  libfcgi.so.0.0.0       [.] FCGX_GetParam
2.82%  libcrypto.so.1.1       [.] HMAC_Init_ex
2.78%  backend                [.] osrm::engine::guidance::assembleGeometry
2.65%  backend                [.] osrm::engine::routing_algorithms::ch::routingStep[visit](true, true)
2.47%  libgssapi_krb5.so.2.2  [.] 0x000000000000ca30

This is rather like gprof, the one that works. Also it gets updated while you go active on your program. It really seems to wait until you do something in the backend.

Kcachegrind

visit

It is an option to valgrind and you can use it simply like this on the normal executable (no -pg compilation needed)

kcachegrind
1
2
3
4
valgrind --tool=cachegrind ./test/test
# or ..
valgrind --tool=cachegrind ./debug/backend
kcachegrind callgrind.out.xxx # the one generated !

This will get you a nice visual layout still not completely clear but way better than gprof.