blob: 4d6a1e23910b1620fe22e9530d762ca92f2ef57b [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
Jerome Forissier2a224112020-05-27 11:45:25 +020025 user TA libraries contained in ``optee_os`` (such as ``libutee`` and
26 ``libutils``).
Sumit Garg444bd732019-04-09 18:40:02 +053027
Sumit Gargba868fd2019-10-21 18:49:41 +053028 - Optionally build OP-TEE OS with ``CFG_SYSCALL_FTRACE=y`` to dump
29 additional syscall function graph information.
30
Sumit Garg444bd732019-04-09 18:40:02 +053031 - Build user TAs with ``-pg``, for instance enable ``CFG_TA_MCOUNT=y`` to
32 instrument whole TA. Also, in case user wants to set ``-pg`` for a
33 particular file, following should go in corresponding sub.mk:
34 ``cflags-<file-name>-y+=-pg``. Note that instrumented TAs have a larger
35 ``.bss`` section. The memory overhead depends on ``CFG_FTRACE_BUF_SIZE``
36 macro which can be configured specific to user TAs using config:
37 ``CFG_FTRACE_BUF_SIZE=4096`` (default value: 2048, refer to the TA linker
38 script for details: ``ta/arch/arm/ta.ld.S``).
39
40 - Run the application normally. When the current session exits or there is
41 any abort during TA execution, ``tee-supplicant`` will write function
42 graph data to ``/tmp/ftrace-<ta_uuid>.out``. If the file already exists,
43 a number is appended, such as: ``ftrace-<ta_uuid>.1.out``.
44
45 - Run helper script called ``symbolize.py`` to translate the function graph
46 addresses into function names: ``cat ftrace-<ta_uuid>.out |
Sumit Gargba868fd2019-10-21 18:49:41 +053047 ./optee_os/scripts/symbolize.py -d <ta_uuid>.elf -d tee.elf``
Sumit Garg5a347262019-09-05 12:25:59 +053048
49Typical output
50**************
51
52.. code-block:: bash
53
54 | __ta_entry() {
55 | __utee_entry() {
56 1.664 us | ta_header_get_session();
57 11.264 us | from_utee_params();
58 .896 us | memcpy();
59 | TA_InvokeCommandEntryPoint() {
60 | TEE_GenerateRandom() {
61 163.360 us | utee_cryp_random_number_generate();
62 186.848 us | }
63 214.288 us | }
64 19.088 us | to_utee_params();
65 | ta_header_save_params() {
66 .736 us | memset();
67 2.832 us | }
68 304.880 us | }
69 307.168 us | }
70
71
72The duration (function's time of execution) is displayed on the closing bracket
73line of a function or on the same line in case the function is the leaf one.
74In other words, duration is displayed whenever an instrumented function returns.
75It comprises the time spent executing the function and any of its callees. The
76Counter-timer Physical Count register (CNTPCT) and the Counter-timer Frequency
77register (CNTFRQ) are used to compute durations. Time spent servicing foreign
78interrupts is subtracted.