Google Perftools

As Oprofile has been removed from Debian, I needed to find alternative. perf was the most natural one but it currently does not support dwarf CFI stack unwinding. On amd64 Linux distro, it means that the application to be profiled and all libraries must be rebuilt with -fno-fomit-frame-pointer. A patch to enable CFI stack unwinding as been submitted but not accepted. Without it, it’s not possible to have a hierarchical and cumulative view. It make perf almost unusable for application profiling.

There I tried Google perftools. It doesn’t use hardware register like oprofile or perf but as explained in the documentation it is nice for sample based CPU profiling. An executable built with -g -O2 can be profiled without any modifications. The profiling output can even be browsed in kcachegrind.

Here are some python lines taken from there that I use to profile a C++ library providing a python binding:

#! /usr/bin/env python
import ctypes.util
google_profiler = ctypes.util.find_library('profiler')
libprofiler = ctypes.CDLL(google_profiler)
libprofiler.ProfilerStart("pprof.prof")
#your code to be profiled

#ctypes, #oprofile, #perf, #perftools