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?
Can I make a template function noinline or else force it to appear in the profiler?
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.
Relevant: How can I tell gcc not to inline a function? (it might be not wanted to avoid inlining of all functions). –
Jeffryjeffy
You don't need to gimp all your functions, just
__attribute__((noipa))
or __attribute__((noinline,noclone))
one the one function you want to block. (Unless it's defined in a standard header so you can't easily add attributes to it). Of course, not inlining a small template function will often significantly hurt optimization of that one spot. Oh, but the question is asking how to globally disable inlining, not on a per-function basis. –
Maidy 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.
© 2022 - 2025 — McMap. All rights reserved.
-O
option? If so, remove it. – Centring-O2
or-O3
, just no functions inlined. Otherwise, the profiler results would be too far from reality. – Erdeitemplate <typename T> class Array { ... };
...template class Array<int>;
template class Array<float>;
– Myronmyrrh