Sumit Garg | 444bd73 | 2019-04-09 18:40:02 +0530 | [diff] [blame] | 1 | .. _ftrace: |
| 2 | |
| 3 | Ftrace |
| 4 | ###### |
| 5 | This section describes how to generate function call graph for user Trusted |
| 6 | Applications using ``ftrace``. |
| 7 | |
Sumit Garg | ba868fd | 2019-10-21 18:49:41 +0530 | [diff] [blame] | 8 | The configuration option ``CFG_FTRACE_SUPPORT=y`` enables OP-TEE to collect |
Sumit Garg | 444bd73 | 2019-04-09 18:40:02 +0530 | [diff] [blame] | 9 | function graph information from Trusted Applications running in user mode and |
| 10 | compiled with ``-pg``. Once collected, the function graph data is formatted |
| 11 | in the ``ftrace.out`` format and sent to ``tee-supplicant`` via RPC, so they |
| 12 | can be saved to disk, later processed and displayed using helper script called |
| 13 | ``symbolize.py`` present as part of ``optee_os`` repo. |
| 14 | |
Sumit Garg | ba868fd | 2019-10-21 18:49:41 +0530 | [diff] [blame] | 15 | Another configuration option ``CFG_SYSCALL_FTRACE=y`` in addition to |
| 16 | ``CFG_FTRACE_SUPPORT=y`` enables OP-TEE to collect function graph information |
| 17 | for syscalls as well while running in kernel mode on behalf of Trusted |
| 18 | Applications. |
| 19 | |
Sumit Garg | 444bd73 | 2019-04-09 18:40:02 +0530 | [diff] [blame] | 20 | Usage |
| 21 | ***** |
| 22 | |
Sumit Garg | ba868fd | 2019-10-21 18:49:41 +0530 | [diff] [blame] | 23 | - Build OP-TEE OS and OP-TEE Client with ``CFG_FTRACE_SUPPORT=y``. You |
Sumit Garg | 444bd73 | 2019-04-09 18:40:02 +0530 | [diff] [blame] | 24 | may also set ``CFG_ULIBS_MCOUNT=y`` in OP-TEE OS to instrument the |
Jerome Forissier | 2a22411 | 2020-05-27 11:45:25 +0200 | [diff] [blame] | 25 | user TA libraries contained in ``optee_os`` (such as ``libutee`` and |
| 26 | ``libutils``). |
Sumit Garg | 444bd73 | 2019-04-09 18:40:02 +0530 | [diff] [blame] | 27 | |
Sumit Garg | ba868fd | 2019-10-21 18:49:41 +0530 | [diff] [blame] | 28 | - Optionally build OP-TEE OS with ``CFG_SYSCALL_FTRACE=y`` to dump |
| 29 | additional syscall function graph information. |
| 30 | |
Sumit Garg | 444bd73 | 2019-04-09 18:40:02 +0530 | [diff] [blame] | 31 | - 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 Garg | ba868fd | 2019-10-21 18:49:41 +0530 | [diff] [blame] | 47 | ./optee_os/scripts/symbolize.py -d <ta_uuid>.elf -d tee.elf`` |
Sumit Garg | 5a34726 | 2019-09-05 12:25:59 +0530 | [diff] [blame] | 48 | |
| 49 | Typical 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 | |
| 72 | The duration (function's time of execution) is displayed on the closing bracket |
| 73 | line of a function or on the same line in case the function is the leaf one. |
| 74 | In other words, duration is displayed whenever an instrumented function returns. |
| 75 | It comprises the time spent executing the function and any of its callees. The |
| 76 | Counter-timer Physical Count register (CNTPCT) and the Counter-timer Frequency |
| 77 | register (CNTFRQ) are used to compute durations. Time spent servicing foreign |
| 78 | interrupts is subtracted. |