Which options should I pass to gcc when compiling for profiling?
Options which are essential to produce output suitable are:
* -pg : generate profiling instrumentation code (only for gprof)
* -g : produce debugging information
* -fno-omit-frame-pointer : use the frame pointer (frame pointer usage is disabled by default in some architectures like x86_64 and for some optimization levels; it is impossible to walk the call stack without it)
You want the code you are profiling to be as close as possible as the code that you will be releasing. So you should include all options that you use in your release code, typically:
* -O2 : optimizations that do not involve a space-speed tradeoff
* -DNDEBUG : disable debugging code in the standard library (such as the assert macro)
However, due to the profiling mechanism used by gprof (and other profilers), many of the optimizations performed by gcc interfere with the accuracy/granularity of the profiling. You should pass these options to disable those particular optimizations:
* -fno-inline-functions : do not inline functions into their parents (otherwise the time spent on these functions will be attributed to the caller)
* -fno-inline-functions-called-once : similar to above
* -fno-optimize-sibling-calls : do not optimize sibling and tail recursive calls (otherwise tail calls may be attributed to the parent function)
阅读(611) | 评论(0) | 转发(0) |