blob: add23e255865609a441706ec59193d3022f85376 [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 Shen9b4ba112022-01-19 14:57:04 +080027 sudo apt-get install python3-dev libmysqlclient-dev libncursesw6 libncurses6
28 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
Jianliang Shen9b4ba112022-01-19 14:57:04 +080039**********************
40Code size analyze tool
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
47 python3 code_size_analyze.py [-h] [-i MAP_FILE_INPUT] [-u]
48 <--gnuarm|--armcc>
49 [-a] [-s] [-l] [-o] [-f] [-d]
50 [--dump_section SECTION_NAME]
51 [--dump_library LIBRARY_NAME]
52 [--dump_obj OBJ_NAME]
53 [--dump_function DUMP_FUNCTION_NAME]
54 [--dump_data DUMP_DATA_NAME]
55 [--search_func FUNCTION_NAME]
56 [--search_data DATA_NAME]
57
58 options:
59 -h, --help show this help message and exit
60 -i MAP_FILE_INPUT map file path <path>/tfm_s.map
61 -u, --ui show UI
62 --gnuarm gnuarm map file input
63 --armcc armclang map file input
64 -a, --all show total
65 -s, --list_section list section
66 -l, --list_library list library
67 -o, --list_obj list object file
68 -f, --list_function list function
69 -d, --list_data list data
70 --dump_section SECTION_NAME dump section
71 --dump_library LIBRARY_NAME dump library
72 --dump_obj OBJ_NAME dump object file
73 --dump_function DUMP_FUNCTION_NAME dump function
74 --dump_data DUMP_DATA_NAME dump data
75 --search_func FUNCTION_NAME search function
76 --search_data DATA_NAME search data
77
78Create database
79===============
80
81It is required to input map file path for the script before show the UI. One of
82the options like ``--gnuarm`` or ``--armcc`` is required. Keep the compiler
83option same from the beginning to the end.
84
85.. code-block:: bash
86
87 python3 code_size_analyze.py -i MAP_FILE_INPUT <--gnuarm|--armcc>
88
89Show the UI
90===========
Jianliang Shenabf00412021-11-12 10:58:52 +080091
92The script ui.py supplies a menu to choose what developers may be interested.
Jianliang Shen9b4ba112022-01-19 14:57:04 +080093
94.. code-block:: bash
95
96 python3 code_size_analyze.py -u <--gnuarm|--armcc>
97
98There are several keys to use UI.
Jianliang Shenabf00412021-11-12 10:58:52 +080099
100* UP: Move UP, mouse scrolling up is same.
101* DOWN: Move down, mouse scrolling down is same.
102* RIGHT: Move right.
103* LEFT: Move left.
104* Enter: Move to next page if it can be unfolded.
105* ``Q`` or ``q``: Escape to previous page or close script if it in top menu.
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800106* ``s`` or ``S``: Enter output file name to save the content of current page.
107* ``:`` : Start search and enter the function or data name.
Jianliang Shenabf00412021-11-12 10:58:52 +0800108
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800109Dump detail information
110=======================
Jianliang Shenabf00412021-11-12 10:58:52 +0800111
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800112You can get the list of all sections, libraries, object files, functions or
113data. You can also dump the specific symbol with the name.
Jianliang Shenabf00412021-11-12 10:58:52 +0800114
Jianliang Shenabf00412021-11-12 10:58:52 +0800115.. code-block:: bash
116
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800117 python3 code_size_analyze.py <--gnuarm|--armcc> -s
118 python3 code_size_analyze.py <--gnuarm|--armcc> --dump_section SECTION_NAME
Jianliang Shenabf00412021-11-12 10:58:52 +0800119
Jianliang Shenabf00412021-11-12 10:58:52 +0800120
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800121Search specific function or data
122================================
Jianliang Shenabf00412021-11-12 10:58:52 +0800123
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800124You can search the target with keyword in command line. For example:
Jianliang Shenabf00412021-11-12 10:58:52 +0800125
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800126.. code-block:: bash
127
128 python3 code_size_analyze.py <--gnuarm|--armcc> --search_func FUNCTION_NAME
129 python3 code_size_analyze.py <--gnuarm|--armcc> --search_data DATA_NAME
130
131*******************
132Code size diff tool
133*******************
Jianliang Shenabf00412021-11-12 10:58:52 +0800134
135Use ``code_size_diff.py`` to diff two diffrent build results with same compiler.
136Firstly, use ``code_size_analyze.py`` to prepare two different databases. For
137example:
138
139.. code-block:: bash
140
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800141 usage: code_size_diff.py [-h] -i [input_dbs [input_dbs ...]]
142 [-a] [-f] [-d] [-o] [-l]
Jianliang Shenabf00412021-11-12 10:58:52 +0800143
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800144 optional arguments:
145 -h, --help show this help message and exit
146 -i [input_dbs [input_dbs ...]], --input [input_dbs [input_dbs ...]]
147 Input two different data base files
148 -a, --diff_all diff summary
149 -f, --diff_function diff function
150 -d, --diff_data diff data
151 -o, --diff_obj diff object file
152 -l, --diff_lib diff library
Jianliang Shenabf00412021-11-12 10:58:52 +0800153
154Then compare two database with the diff tool, the branch1 is base.
155
156.. code-block:: bash
157
158 python3 code_size_diff.py -i output/branch1.db output/branch2.db -a
159 Code size: +++ 48928 B 47.78 KB
160 RO data: +++ 29440 B 28.75 KB
161 RW data: --- 64 B 0.06 KB
162 ZI data: --- 500 B 0.49 KB
163 Flash size: +++ 78304 B 76.47 KB
164 RAM size: --- 564 B 0.55 KB
165
166The summary information change will be printed. Enter ``-h`` to get more usages
167of diff tool.
168
169--------------
170
Jianliang Shen9b4ba112022-01-19 14:57:04 +0800171*Copyright (c) 2021-2022, Arm Limited. All rights reserved.*