Opt-level >= 2 removes debug symbols needed in perf profiling

I think you might be a new victim of the frame pointer omission optimization.

For a couple of years now, compilers have systematically enabled by default, at their highest optimization levels, an optimization which breaks profilers' call graphs. GCC calls it "omit-frame-pointer" , other compilers may call it differently.

Disabling this optimization may be hard on some compilers, and even if you manage, you will quickly realize that every library on your system is built with this optimization enabled and will also break your profile if you call it. Unless you are ready to effectively rebuild your whole Linux distribution with "-fno-omit-frame-pointer", it is a lost battle.

For sufficiently recent versions of perf, the best workaround is to use --call-graph=dwarf. DWARF-based call graphs have much higher overhead than frame pointer based ones, so you will want to tune down the sampling rate a bit. But they only need debugging symbols to work reliably.

Oh, and if you know people who are in the business of building compilers, please tell them that frame pointer omission optimization was only necessary on register-starved 32-bit x86 and has much less effect on modern AMD64 systems. It causes a lot more harm than it does good, and should not be enabled by default.

11 Likes