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