blob: c556962ea528b3121da3611e5c5abcbaeafc4f6f [file] [log] [blame]
Jianliang Shenabf00412021-11-12 10:58:52 +08001######################
2Code size analyze tool
3######################
4
5.. contents:: Table of Contents
6
7These are scripts to dump ARMCLANG complie map file detail information and get
8the change between two different build results. The features are:
9
10* Get a database to implement data tables from ARMCLANG or GNUARM map file.
11* Supply an UI for developers to scan sorted information of sections, libraries,
12 object files, functions and data. It can help analyze the biggest or smallest
13 targets in certain image. It can also help search functions or data to locate
14 their address and detail information.
15* Diff two databases to see the code size increasement or decreasement.
16
Jianliang Shen9b4ba112022-01-19 14:57:04 +080017******************
18Install dependency
19******************
Jianliang Shenabf00412021-11-12 10:58:52 +080020
21Linux
22=====
Jianliang Shen9b4ba112022-01-19 14:57:04 +080023Install curse and database.
Jianliang Shenabf00412021-11-12 10:58:52 +080024
25.. code-block:: bash
26
Jianliang Shen28cce572022-05-02 21:44:03 +080027 sudo apt-get install python3-dev libmysqlclient-dev libncursesw6 libncurses6 libsqlite3-dev
Jianliang Shen9b4ba112022-01-19 14:57:04 +080028 pip install mysqlclient XlsxWriter
Jianliang Shenabf00412021-11-12 10:58:52 +080029
Jianliang Shen9b4ba112022-01-19 14:57:04 +080030Windows
31=======
Jianliang Shenabf00412021-11-12 10:58:52 +080032
Jianliang Shen9b4ba112022-01-19 14:57:04 +080033In power shell, use pip to install packages.
Jianliang Shenabf00412021-11-12 10:58:52 +080034
35.. code-block:: bash
36
Jianliang Shen9b4ba112022-01-19 14:57:04 +080037 pip install mysqlclient XlsxWriter windows-curses
Jianliang Shenabf00412021-11-12 10:58:52 +080038
Elena Uziunaiteb90a3402023-11-13 16:24:28 +000039*****
40Usage
41*****
Jianliang Shenabf00412021-11-12 10:58:52 +080042
Jianliang Shen9b4ba112022-01-19 14:57:04 +080043The commands of code size analyze tool usage are:
44
45.. code-block:: bash
46
Jianliang Shen28cce572022-05-02 21:44:03 +080047 usage: code_size_analyze.py [-h] [--gnuarm | --armcc] [--db-name <data.db>]
48 [-u | -S | -s | -l | -o | -f | -d |
49 --dump-sec <sec> | --dump-lib <lib> |
50 --dump-obj <obj> | --dump-func <func> |
51 --dump-data <data> | --search-func <func> |
52 --search-data <data>]
53 [--sort-by-size | --sort-by-name |
54 --sort-by-obj | --sort-by-lib |
55 --sort-by-sec] [--desc | --asc]
56 file_input
Jianliang Shen9b4ba112022-01-19 14:57:04 +080057
Jianliang Shen28cce572022-05-02 21:44:03 +080058 positional arguments:
59 file_input map or database file
60
61 optional arguments:
62 -h, --help show this help message and exit
63 --gnuarm GNUARM model
64 --armcc ARMCLANG model
65 --db-name <data.db> database name to save
66 -u, --ui start UI to analyze
67 -S, --Summary show summary message
68 -s, --list-section list section
69 -l, --list-library list library
70 -o, --list-obj list object file
71 -f, --list-function list function
72 -d, --list-data list data
73 --dump-sec <sec> dump section
74 --dump-lib <lib> dump library
75 --dump-obj <obj> dump object file
76 --dump-func <func> dump function
77 --dump-data <data> dump data
78 --search-func <func> search function
79 --search-data <data> search data
80 --sort-by-size list by size order
81 --sort-by-name list by name order
82 --sort-by-obj list by object file name order
83 --sort-by-lib list by library file name order
84 --sort-by-sec list by section name order
85 --desc sort with desc order
86 --asc sort with asc order
Jianliang Shen9b4ba112022-01-19 14:57:04 +080087
88Create database
89===============
90
91It is required to input map file path for the script before show the UI. One of
Jianliang Shen28cce572022-05-02 21:44:03 +080092the options like ``--gnuarm`` or ``--armcc`` is required.
93
94The default database name created is ``data.db``. Use ``--db-name`` to name the
95output file if necessary. For example, saving two different databases to compare
96later.
Jianliang Shen9b4ba112022-01-19 14:57:04 +080097
98.. code-block:: bash
99
Jianliang Shen28cce572022-05-02 21:44:03 +0800100 $: python code_size_analyze.py tfm_s.map <--gnuarm|--armcc> --db-name tfm_s.db
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800101
Jianliang Shen28cce572022-05-02 21:44:03 +0800102UI mode
103=======
Jianliang Shenabf00412021-11-12 10:58:52 +0800104
105The script ui.py supplies a menu to choose what developers may be interested.
Jianliang Shen28cce572022-05-02 21:44:03 +0800106You can enter UI mode by analyzing map file directly or by importing database
107file path. The latter way is suggested as it runs more quickly.
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800108
109.. code-block:: bash
110
Jianliang Shen28cce572022-05-02 21:44:03 +0800111 $: python code_size_analyze.py tfm_s.map <--gnuarm|--armcc> -u
112 $: python code_size_analyze.py tfm_s.db -u
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800113
114There are several keys to use UI.
Jianliang Shenabf00412021-11-12 10:58:52 +0800115
116* UP: Move UP, mouse scrolling up is same.
117* DOWN: Move down, mouse scrolling down is same.
118* RIGHT: Move right.
119* LEFT: Move left.
120* Enter: Move to next page if it can be unfolded.
121* ``Q`` or ``q``: Escape to previous page or close script if it in top menu.
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800122* ``s`` or ``S``: Enter output file name to save the content of current page.
123* ``:`` : Start search and enter the function or data name.
Jianliang Shenabf00412021-11-12 10:58:52 +0800124
Jianliang Shen28cce572022-05-02 21:44:03 +0800125Terminal mode
126=============
127
128In terminal mode, it is better to analyze database file rather than map file.
129
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800130Dump detail information
Jianliang Shen28cce572022-05-02 21:44:03 +0800131-----------------------
Jianliang Shenabf00412021-11-12 10:58:52 +0800132
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800133You can get the list of all sections, libraries, object files, functions or
134data. You can also dump the specific symbol with the name.
Jianliang Shenabf00412021-11-12 10:58:52 +0800135
Jianliang Shenabf00412021-11-12 10:58:52 +0800136.. code-block:: bash
137
Jianliang Shen28cce572022-05-02 21:44:03 +0800138 $: python code_size_analyze.py tfm_s.map --armcc --db-name test.db -S
139 ───────────────────────────────────────────────
140 Code size : 56676 55.35 KB
141 -----------------------------------------------
142 RO data : 3732 3.64 KB
143 RW data : 204 0.20 KB
144 ZI data : 24588 24.01 KB
145 Flash size : 60612 59.19 KB = Code + RO + RW
146 RAM size : 24792 24.21 KB = RW + ZI
147 ───────────────────────────────────────────────
Jianliang Shenabf00412021-11-12 10:58:52 +0800148
Jianliang Shen28cce572022-05-02 21:44:03 +0800149 $: python code_size_analyze.py tfm_s.db -s
150 $: python code_size_analyze.py tfm_s.db --dump-sec <sec>
Jianliang Shenabf00412021-11-12 10:58:52 +0800151
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800152Search specific function or data
Jianliang Shen28cce572022-05-02 21:44:03 +0800153--------------------------------
Jianliang Shenabf00412021-11-12 10:58:52 +0800154
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800155You can search the target with keyword in command line. For example:
Jianliang Shenabf00412021-11-12 10:58:52 +0800156
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800157.. code-block:: bash
158
Jianliang Shen28cce572022-05-02 21:44:03 +0800159 $: python code_size_analyze.py tfm_s.db --search-func <func>
160 $: python code_size_analyze.py tfm_s.db --search-data <data>
161
162Sort Table
163----------
164
165You can sort the messages in terminal mode. The script supplies five options and
166two orders. For example:
167
168.. code-block:: bash
169
170 $: python code_size_analyze.py tfm_s.db -l --sort-by-size --asc
171 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
172 Name Flash size RAM size Code RO data RW data ZI data Inc. data Debug
173 --------------------------------------------------------------------------------------------------------------------------------------------------
174 libtfm_qcbor_s.a 758 0 758 0 0 0 4 17046
175 libtfm_sprt.a 1016 0 1016 0 0 0 0 41004
176 c_w.l 1248 96 1248 0 0 96 86 1892
177 libtfm_psa_rot_partition_attestation.a 2497 557 2492 5 0 557 68 51865
178 libtfm_spm.a 4112 657 3932 136 44 613 168 52958
179 libtfm_psa_rot_partition_its.a 5090 116 5030 32 28 88 28 49804
180 libtfm_psa_rot_partition_crypto.a 6062 3232 6062 0 0 3232 36 92472
181 libplatform_s.a 6486 316 5582 780 124 192 404 94887
182 libmbedcrypto.a 28408 2292 26138 2262 8 2284 1066 226489
183 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
184
185Not all symbols support to be sorted by the whole five options, refer to the
186table to get more information.
187
188+----------------+---------+---------+--------------+----------+------+
189| Options | Section | Library | Object files | Function | Data |
190+================+=========+=========+==============+==========+======+
191| --sort-by-size | | | | | |
192+----------------+---------+---------+--------------+----------+------+
193| --sort-by-name | | | | | |
194+----------------+---------+---------+--------------+----------+------+
195| --sort-by-sec | | | | | |
196+----------------+---------+---------+--------------+----------+------+
197| --sort-by-lib | | | | | |
198+----------------+---------+---------+--------------+----------+------+
199| --sort-by-obj | | | | | |
200+----------------+---------+---------+--------------+----------+------+
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800201
202*******************
203Code size diff tool
204*******************
Jianliang Shenabf00412021-11-12 10:58:52 +0800205
206Use ``code_size_diff.py`` to diff two diffrent build results with same compiler.
Jianliang Shenabf00412021-11-12 10:58:52 +0800207
208.. code-block:: bash
209
Jianliang Shen28cce572022-05-02 21:44:03 +0800210 usage: code_size_diff.py [-h] (-S | -f | -d | -o | -l) based_db compared_db
211
212 positional arguments:
213 based_db based databse
214 compared_db compared databse
Jianliang Shenabf00412021-11-12 10:58:52 +0800215
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800216 optional arguments:
Jianliang Shen28cce572022-05-02 21:44:03 +0800217 -h, --help show this help message and exit
218 -S, --diff-Summary diff summary
219 -f, --diff-function diff function
220 -d, --diff-data diff data
221 -o, --diff-obj diff object file
222 -l, --diff-lib diff library
Jianliang Shenabf00412021-11-12 10:58:52 +0800223
Jianliang Shen28cce572022-05-02 21:44:03 +0800224Firstly, use ``code_size_analyze.py`` to prepare two different databases. Then
225compare two database with the diff tool, the branch1 is base.
Jianliang Shenabf00412021-11-12 10:58:52 +0800226
227.. code-block:: bash
228
Jianliang Shen28cce572022-05-02 21:44:03 +0800229 $: python code_size_diff.py output/branch1.db output/branch2.db -S
Jianliang Shenabf00412021-11-12 10:58:52 +0800230 Code size: +++ 48928 B 47.78 KB
231 RO data: +++ 29440 B 28.75 KB
232 RW data: --- 64 B 0.06 KB
233 ZI data: --- 500 B 0.49 KB
234 Flash size: +++ 78304 B 76.47 KB
235 RAM size: --- 564 B 0.55 KB
236
Jianliang Shenabf00412021-11-12 10:58:52 +0800237--------------
238
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800239*Copyright (c) 2021-2022, Arm Limited. All rights reserved.*