Open KushnerovMikhail opened 4 weeks ago
Hello @KushnerovMikhail, and thank you very much for your first pull request to the Zephyr project! Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary. If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊
Add profiling util based on periodic stack unwinding. Perf from Linux was taken as a reference.
Code is based on Sampling profiler (#29304) by @Jongy.
The operation of module is based on frame pointer usage and saving registers during interruption handling by zephyr.
General work description: The unwinding function stay in timer as expiry function so is called during interruption handling. Thus the function have access to saved registers (program counter and frame pointer in particular) of the current thread and use it to unwind the thread stack. Timer starting and results printing function are made as shell commands for conveniency. Obtained samples can be translated into flamegraph using stackcollapse.py script.
Flame graph example, generated from
echo_server
sample:Kconfig optioins:
CONFIG_PERF
enables perf subsystem in compilation.CONFIG_PERF_BUFFER_SIZE
specifies size of buffer, where samples are stored.Kconfig requirements:
CONFIG_THREAD_STACK_INFO=y
providesstart
andsize
thread stack values.CONFIG_SMP=n
SMP support is not implemented yet.CONFIG_OMIT_FRAME_POINTER=n
&&CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT=y
provide frame pointer.CONFIG_SHELL=y
needs because subsystem provides shell commands.CONFIG_RISCV=y
||CONFIG_X86_64=y
- subsystem implemented only for x86_64 and riscv yet.