我可以将模板函数设置为 noinline 或者强制它出现在分析器中吗?

Ser*_*tch 6 c++ profiling cmake debug-information perf

我试图perf在 Ubuntu 20.04 上进行配置,但问题是许多函数没有出现在其中(可能是因为它们是内联的),或者只出现它们的地址(没有名称等)。我正在使用 CMake 的RelWithDebInfo构建。但有一些模板函数我不知道如何将其引入分析器结果中。我认为noinline如果这在 C++ 中对于模板函数是合法的,那么标记它们可能会有所帮助,但这会破坏代码库并且需要针对每个函数完成。有什么建议如何noinline同时实现所有功能吗?

Xoo*_*zee 3

您可以添加-fno-inlineCMAKE_CXX_FLAGS.

来自GCC 手册页

-fno-inline
      Do not expand any functions inline apart from those marked
      with the "always_inline" attribute.  This is the default when
      not optimizing.

      Single functions can be exempted from inlining by marking
      them with the "noinline" attribute.
Run Code Online (Sandbox Code Playgroud)

  • 相关:[如何告诉 gcc 不要内联函数?](/sf/ask/103182131/)(可能不希望避免内联所有函数)。 (2认同)