Chinaunix首页 | 论坛 | 博客
  • 博客访问: 93622
  • 博文数量: 121
  • 博客积分: 1422
  • 博客等级: 上尉
  • 技术积分: 1235
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-05 13:10
文章分类

全部博文(121)

文章存档

2012年(9)

2011年(2)

2010年(110)

分类:

2010-04-13 16:29:20

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)

阅读(598) | 评论(0) | 转发(0) |
0

上一篇:useful linux admin commands

下一篇:valgrind

给主人留下些什么吧!~~