|
1 | 1 | .. _profiling-perf: |
2 | 2 |
|
3 | | - |
4 | 3 | Perf |
5 | 4 | #### |
6 | 5 |
|
| 6 | +Perf is a profiler tool based on stack tracing. It can be used for lightweight profiling |
| 7 | +with minimal code overhead. |
7 | 8 |
|
8 | | -Perf is a profiler tool, based on stack tracing. It can be used to light weight profiling |
9 | | -almost without any code overhead. |
10 | | - |
11 | | -Work principe |
12 | | -************* |
| 9 | +Work Principle |
| 10 | +************** |
13 | 11 |
|
14 | | -``perf record`` shell-command starts timer with perf tracer function. |
15 | | -Timers are driven by inerrupts, so perf tracer function is calling during interruption. |
16 | | -Zephyr core save return address and frame pointer in interrupt stack or ``callee_saved`` |
17 | | -struture before caling interrupt hundler. So perf trace function makes stack traces by |
18 | | -using return address and frame pointer. |
| 12 | +The ``perf record`` shell command starts a timer with the perf tracer function. |
| 13 | +Timers are driven by interrupts, so the perf tracer function is called during an interruption. |
| 14 | +The Zephyr core saves the return address and frame pointer in the interrupt stack or ``callee_saved`` |
| 15 | +structure before calling the interrupt handler. Thus, the perf trace function makes stack traces by |
| 16 | +using the return address and frame pointer. |
19 | 17 |
|
20 | | -Then stackcollapse.py script convert return addresses in stack trace to function names |
21 | | -by elf file and print them in required for FlameGraph format. |
| 18 | +The :zephyr_file:`scripts/profiling/stackcollapse.py` script can be used to convert return addresses |
| 19 | +in the stack trace to function names using symbols from the ELF file, and to prints them in the |
| 20 | +format expected by `FlameGraph`_. |
22 | 21 |
|
23 | 22 | Configuration |
24 | 23 | ************* |
25 | 24 |
|
26 | | -Configure this module using the following options. |
| 25 | +You can configure this module using the following options: |
27 | 26 |
|
28 | | -* :kconfig:option:`CONFIG_PROFILING_PERF`: enable the module. This opion add |
29 | | - perf command in shell. |
| 27 | +* :kconfig:option:`CONFIG_PROFILING_PERF`: Enables the module. This option adds |
| 28 | + the ``perf`` command to the shell. |
30 | 29 |
|
31 | | -* :kconfig:option:`CONFIG_PROFILING_PERF_BUFFER_SIZE`: sets size of perf buffer, |
| 30 | +* :kconfig:option:`CONFIG_PROFILING_PERF_BUFFER_SIZE`: Sets the size of the perf buffer |
32 | 31 | where samples are saved before printing. |
33 | 32 |
|
34 | 33 | Usage |
35 | 34 | ***** |
36 | 35 |
|
37 | | -More specific example can be found in :zephyr:code-sample:`profiling-perf`. |
38 | | - |
39 | | -#. Build with perf enabled and run. |
40 | | - |
41 | | -#. Begin perf sampling by shell-command |
42 | | - |
43 | | - .. code-block:: text |
44 | | -
|
45 | | - perf record <period> <frequency> |
46 | | -
|
47 | | - This command will start timer with perf sampler for *period* in seconds and |
48 | | - with *frequency* in hertz. |
49 | | - |
50 | | - Wait for the completion message ``perf done!`` or ``perf buf override!`` |
51 | | - (if perf buffer size is smaller than required). |
52 | | - |
53 | | -#. Print made by perf samles in terminal by shell-command |
54 | | - |
55 | | - .. code-block:: text |
56 | | -
|
57 | | - perf printbuf |
58 | | -
|
59 | | - Output exaple: |
60 | | - |
61 | | - .. code-block:: text |
62 | | -
|
63 | | - Perf buf length 1985 |
64 | | - 0000000000000004 |
65 | | - 0000000080004e58 |
66 | | - 00000000800071ca |
67 | | - 0000000080000964 |
68 | | - aaaaaaaaaaaaaaaa |
69 | | - 0000000000000002 |
70 | | - .... |
71 | | - 00000000800163e0 |
72 | | -
|
73 | | - Copy gotten output in some file, for example *perf_buf*. |
74 | | - |
75 | | -#. Translate perf samples by stackcollapse script to format, required by FlameGraph |
76 | | - |
77 | | - .. code-block:: bash |
78 | | -
|
79 | | - python zephyr/scripts/perf/stackcollapse.py perf_buf <build_dir>/zephyr/zephyr.elf > perf_buf.folded |
80 | | -
|
81 | | - And turn into .svg FlameGraph (for example *graph.svg*) |
82 | | - |
83 | | - .. code-block:: bash |
84 | | -
|
85 | | - ./FlameGraph/flamegraph.pl perf_buf.folded > graph.svg |
86 | | -
|
87 | | - All this step can be done by one command |
88 | | - |
89 | | - .. code-block:: bash |
| 36 | +Refer to the :zephyr:code-sample:`profiling-perf` sample for an example of how to use the perf tool. |
90 | 37 |
|
91 | | - python zephyr/scripts/perf/stackcollapse.py perf_buf <build_dir>/zephyr/zephyr.elf | ./FlameGraph/flamegraph.pl > graph.svg |
| 38 | + .. _FlameGraph: https://github.com/brendangregg/FlameGraph/ |
0 commit comments