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

问题描述 投票:0回答:2

我尝试在 Ubuntu 20.04 上使用

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

c++ cmake profiling perf debug-information
2个回答
3
投票

您可以将

-fno-inline
添加到
CMAKE_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.

0
投票

您需要在您希望实例化模板的地方实例化模板

template <typename T> class Array { ... };`
...
//cpp
template class Array<int>;
template class Array<float>;

也许还可以标记方法

__declspec(noinline)
之类的。

© www.soinside.com 2019 - 2024. All rights reserved.