Leveraging Compiler Code Instrumentation for Zephyr Tracing & Profiling Tools - Gustavo Romero & Kevin Townsend, Linaro
Most profiling and tracing features in Zephyr today either depend on proprietary and expensive tooling, or have significant platform limitations. For instance, Segger's SystemView, which requires J-Link, or gprof, which only supports a few platforms -- often emulated -- like native_posix, and native_posix_64 platforms, with no timestamp data associated with events.
Clang and GCC compilers provide entry/exit instrumentation for functions via the -finstrumentation-functions flag. This flag allows for a specific function to be called on any function entry/exit event, which we can leverage to generate code tracing and profiling information.
In this presentation, the authors propose and demonstrate a platform, tooling, and arch-neutral subsystem based on compiler function instrumentation for Zephyr. Possible ways to display the collected data, like flame graphs, are also presented.
The new tool can be used for:
A) Tracing, meaning it can be used to generate an instrumented call graph, including timestamps, limited by the number of entry/exit events that can fit into a memory buffer.
B) Profiling, meaning it can be used to calculate the overall runtime spent in the top 'n' functions, plus the entry/exit counts for said functions, without much concern for a memory buffer overrun.