Can I make a template function noinline or else force it to appear in the profiler?

789 Views Asked by At

I'm trying to profile with perf on Ubuntu 20.04, but the problem is that many functions do not appear in it (likely because they are inlined), or only their addresses appear (without names etc.). I'm using CMake's RelWithDebInfo build. But there are some template functions that I don't know how to bring to the profiler results. I think marking them noinline may help if this is legal in C++ for template functions, but this screws up the codebase and needs to be done per-function. Any suggestions how to make all functions noinline at once?

2

There are 2 best solutions below

2
Xoozee On BEST ANSWER

You could add -fno-inline to CMAKE_CXX_FLAGS.

From GCC man page:

-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
Кое Кто On

you need to instantiate the templates where you want them to be instantiated

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

And maybe also mark methods __declspec(noinline) or something.