Complile C++ for Profiling

I would use RelWithDebInfo. I think it is usually -O2 rather than -O3, but it keeps debugging information. For profiling, you’ll need to manually add other flags like -fprofile-arcs and (probably) other compiler-specific flags (for gprof). perf and callgrind generally work with a plain RelWithDebInfo build (at least that’s how I use them).

1 Like