Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 1 | ###################### |
| 2 | Code size analyze tool |
| 3 | ###################### |
| 4 | |
| 5 | .. contents:: Table of Contents |
| 6 | |
| 7 | These are scripts to dump ARMCLANG complie map file detail information and get |
| 8 | the 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 Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 17 | ****************** |
| 18 | Install dependency |
| 19 | ****************** |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 20 | |
| 21 | Linux |
| 22 | ===== |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 23 | Install curse and database. |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 24 | |
| 25 | .. code-block:: bash |
| 26 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 27 | sudo apt-get install python3-dev libmysqlclient-dev libncursesw6 libncurses6 |
| 28 | pip install mysqlclient XlsxWriter |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 29 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 30 | Windows |
| 31 | ======= |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 32 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 33 | In power shell, use pip to install packages. |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 34 | |
| 35 | .. code-block:: bash |
| 36 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 37 | pip install mysqlclient XlsxWriter windows-curses |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 38 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 39 | ********************** |
| 40 | Code size analyze tool |
| 41 | ********************** |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 42 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 43 | The 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 | |
| 78 | Create database |
| 79 | =============== |
| 80 | |
| 81 | It is required to input map file path for the script before show the UI. One of |
| 82 | the options like ``--gnuarm`` or ``--armcc`` is required. Keep the compiler |
| 83 | option 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 | |
| 89 | Show the UI |
| 90 | =========== |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 91 | |
| 92 | The script ui.py supplies a menu to choose what developers may be interested. |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 93 | |
| 94 | .. code-block:: bash |
| 95 | |
| 96 | python3 code_size_analyze.py -u <--gnuarm|--armcc> |
| 97 | |
| 98 | There are several keys to use UI. |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 99 | |
| 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 Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 106 | * ``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 Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 108 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 109 | Dump detail information |
| 110 | ======================= |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 111 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 112 | You can get the list of all sections, libraries, object files, functions or |
| 113 | data. You can also dump the specific symbol with the name. |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 114 | |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 115 | .. code-block:: bash |
| 116 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 117 | python3 code_size_analyze.py <--gnuarm|--armcc> -s |
| 118 | python3 code_size_analyze.py <--gnuarm|--armcc> --dump_section SECTION_NAME |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 119 | |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 120 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 121 | Search specific function or data |
| 122 | ================================ |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 123 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 124 | You can search the target with keyword in command line. For example: |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 125 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 126 | .. 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 | ******************* |
| 132 | Code size diff tool |
| 133 | ******************* |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 134 | |
| 135 | Use ``code_size_diff.py`` to diff two diffrent build results with same compiler. |
| 136 | Firstly, use ``code_size_analyze.py`` to prepare two different databases. For |
| 137 | example: |
| 138 | |
| 139 | .. code-block:: bash |
| 140 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 141 | usage: code_size_diff.py [-h] -i [input_dbs [input_dbs ...]] |
| 142 | [-a] [-f] [-d] [-o] [-l] |
Jianliang Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 143 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 144 | 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 Shen | abf0041 | 2021-11-12 10:58:52 +0800 | [diff] [blame] | 153 | |
| 154 | Then 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 | |
| 166 | The summary information change will be printed. Enter ``-h`` to get more usages |
| 167 | of diff tool. |
| 168 | |
| 169 | -------------- |
| 170 | |
Jianliang Shen | 9b4ba11 | 2022-01-19 14:57:04 +0800 | [diff] [blame^] | 171 | *Copyright (c) 2021-2022, Arm Limited. All rights reserved.* |