blob: e5aa9bc8c015219ddd7cf719f554e161ef352810 [file] [log] [blame]
Sumit Garg444bd732019-04-09 18:40:02 +05301.. _ftrace:
2
3Ftrace
4######
5This section describes how to generate function call graph for user Trusted
6Applications using ``ftrace``.
7
Sumit Gargba868fd2019-10-21 18:49:41 +05308The configuration option ``CFG_FTRACE_SUPPORT=y`` enables OP-TEE to collect
Sumit Garg444bd732019-04-09 18:40:02 +05309function graph information from Trusted Applications running in user mode and
10compiled with ``-pg``. Once collected, the function graph data is formatted
11in the ``ftrace.out`` format and sent to ``tee-supplicant`` via RPC, so they
12can be saved to disk, later processed and displayed using helper script called
13``symbolize.py`` present as part of ``optee_os`` repo.
14
Sumit Gargba868fd2019-10-21 18:49:41 +053015Another configuration option ``CFG_SYSCALL_FTRACE=y`` in addition to
16``CFG_FTRACE_SUPPORT=y`` enables OP-TEE to collect function graph information
17for syscalls as well while running in kernel mode on behalf of Trusted
18Applications.
19
Sumit Garg444bd732019-04-09 18:40:02 +053020Usage
21*****
22
Sumit Gargba868fd2019-10-21 18:49:41 +053023 - Build OP-TEE OS and OP-TEE Client with ``CFG_FTRACE_SUPPORT=y``. You
Sumit Garg444bd732019-04-09 18:40:02 +053024 may also set ``CFG_ULIBS_MCOUNT=y`` in OP-TEE OS to instrument the
25 user TA libraries (libutee, libutils, libmpa).
26
Sumit Gargba868fd2019-10-21 18:49:41 +053027 - Optionally build OP-TEE OS with ``CFG_SYSCALL_FTRACE=y`` to dump
28 additional syscall function graph information.
29
Sumit Garg444bd732019-04-09 18:40:02 +053030 - Build user TAs with ``-pg``, for instance enable ``CFG_TA_MCOUNT=y`` to
31 instrument whole TA. Also, in case user wants to set ``-pg`` for a
32 particular file, following should go in corresponding sub.mk:
33 ``cflags-<file-name>-y+=-pg``. Note that instrumented TAs have a larger
34 ``.bss`` section. The memory overhead depends on ``CFG_FTRACE_BUF_SIZE``
35 macro which can be configured specific to user TAs using config:
36 ``CFG_FTRACE_BUF_SIZE=4096`` (default value: 2048, refer to the TA linker
37 script for details: ``ta/arch/arm/ta.ld.S``).
38
39 - Run the application normally. When the current session exits or there is
40 any abort during TA execution, ``tee-supplicant`` will write function
41 graph data to ``/tmp/ftrace-<ta_uuid>.out``. If the file already exists,
42 a number is appended, such as: ``ftrace-<ta_uuid>.1.out``.
43
44 - Run helper script called ``symbolize.py`` to translate the function graph
45 addresses into function names: ``cat ftrace-<ta_uuid>.out |
Sumit Gargba868fd2019-10-21 18:49:41 +053046 ./optee_os/scripts/symbolize.py -d <ta_uuid>.elf -d tee.elf``
Sumit Garg5a347262019-09-05 12:25:59 +053047
48Typical output
49**************
50
51.. code-block:: bash
52
53 | __ta_entry() {
54 | __utee_entry() {
55 1.664 us | ta_header_get_session();
56 11.264 us | from_utee_params();
57 .896 us | memcpy();
58 | TA_InvokeCommandEntryPoint() {
59 | TEE_GenerateRandom() {
60 163.360 us | utee_cryp_random_number_generate();
61 186.848 us | }
62 214.288 us | }
63 19.088 us | to_utee_params();
64 | ta_header_save_params() {
65 .736 us | memset();
66 2.832 us | }
67 304.880 us | }
68 307.168 us | }
69
70
71The duration (function's time of execution) is displayed on the closing bracket
72line of a function or on the same line in case the function is the leaf one.
73In other words, duration is displayed whenever an instrumented function returns.
74It comprises the time spent executing the function and any of its callees. The
75Counter-timer Physical Count register (CNTPCT) and the Counter-timer Frequency
76register (CNTFRQ) are used to compute durations. Time spent servicing foreign
77interrupts is subtracted.