Skip to content

Commit

Permalink
Merge branch 'tools/move_idf_size_out' into 'master'
Browse files Browse the repository at this point in the history
tools: Move out idf_size.py in favour of using the esp-idf-size package

Closes IDF-6540

See merge request espressif/esp-idf!22038
  • Loading branch information
dobairoland committed Mar 28, 2023
2 parents da6041e + 3e0f612 commit 891f9a9
Show file tree
Hide file tree
Showing 41 changed files with 20 additions and 549,665 deletions.
1 change: 0 additions & 1 deletion .gitlab/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -187,7 +187,6 @@
/tools/ci/ @esp-idf-codeowners/ci
/tools/cmake/ @esp-idf-codeowners/build-config
/tools/esp_prov/ @esp-idf-codeowners/app-utilities
/tools/idf_size_yaml/ @esp-idf-codeowners/peripherals
/tools/kconfig*/ @esp-idf-codeowners/build-config
/tools/ldgen/ @esp-idf-codeowners/build-config
/tools/mass_mfg/ @esp-idf-codeowners/app-utilities
Expand Down
12 changes: 0 additions & 12 deletions .gitlab/ci/host-test.yml
Expand Up @@ -109,18 +109,6 @@ test_certificate_bundle_on_host:
- ./test_gen_crt_bundle.py


test_idf_size:
extends: .host_test_template
artifacts:
when: on_failure
paths:
- tools/test_idf_size/output
- tools/test_idf_size/.coverage
expire_in: 1 week
script:
- cd ${IDF_PATH}/tools/test_idf_size
- ./test.sh

test_idf_py:
extends: .host_test_template
variables:
Expand Down
2 changes: 0 additions & 2 deletions .gitlab/ci/rules.yml
Expand Up @@ -139,8 +139,6 @@
- "tools/test_idf_py/**/*"

- "tools/idf_size.py"
- "tools/idf_size_yaml/*"
- "tools/test_idf_size/**/*"

- "tools/tools.json"
- "tools/tools_schema.json"
Expand Down
20 changes: 10 additions & 10 deletions docs/en/api-guides/performance/size.rst
Expand Up @@ -191,17 +191,17 @@ Comparing Two Binaries

If making some changes that affect binary size, it's possible to use an ESP-IDF tool to break down the exact differences in size.

This operation isn't part of ``idf.py``, it's necessary to run the ``idf_size.py`` Python tool directly.
This operation isn't part of ``idf.py``, it's necessary to run the `esp_idf_size <https://github.com/espressif/esp-idf-size>`_ Python tool directly.

To do so, first locate the linker map file in the build directory. It will have the name ``PROJECTNAME.map``. The ``idf_size.py`` tool performs its analysis based on the output of the linker map file.
To do so, first locate the linker map file in the build directory. It will have the name ``PROJECTNAME.map``. The ``esp_idf_size`` tool performs its analysis based on the output of the linker map file.

To compare with another binary, you will also need its corresponding ``.map`` file saved from the build directory.

For example, to compare two builds: one with the default :ref:`CONFIG_COMPILER_OPTIMIZATION` setting "Debug (-Og)" configuration and one with "Optimize for size (-Os)":

.. code-block:: bash
$ $IDF_PATH/tools/idf_size.py --diff build_Og/https_request.map build_Os/https_request.map
$ python -m esp_idf_size --diff build_Og/https_request.map build_Os/https_request.map
<CURRENT> MAP file: build_Os/https_request.map
<REFERENCE> MAP file: build_Og/https_request.map
Difference is counted as <CURRENT> - <REFERENCE>, i.e. a positive number means that <CURRENT> is larger.
Expand All @@ -219,17 +219,17 @@ We can see from the "Difference" column that changing this one setting caused th
It's also possible to use the "diff" mode to output a table of component-level (static library archive) differences:

.. note::
To get the output in JSON or CSV format using ``idf_size.py`` it is possible to use the ``--format`` option.
To get the output in JSON or CSV format using ``esp_idf_size`` it is possible to use the ``--format`` option.

.. code-block:: bash
$IDF_PATH/tools/idf_size.py --archives --diff build_Og/https_request.map build_Oshttps_request.map
python -m esp_idf_size --archives --diff build_Og/https_request.map build_Oshttps_request.map
Also at the individual source file level:

.. code-block:: bash
$IDF_PATH/tools/idf_size.py --files --diff build_Og/https_request.map build_Oshttps_request.map
python -m esp_idf_size --files --diff build_Og/https_request.map build_Oshttps_request.map
Other options (like writing the output to a file) are available, pass ``--help`` to see the full list.

Expand All @@ -240,20 +240,20 @@ Showing Size When Linker Fails

If too much static memory is used, then the linker will fail with an error such as ``DRAM segment data does not fit``, ``region `iram0_0_seg' overflowed by 44 bytes``, or similar.

In these cases, ``idf.py size`` will not succeed either. However it is possible to run ``idf_size.py`` manually in order to view the *partial static memory usage* (the memory usage will miss the variables which could not be linked, so there still appears to be some free space.)
In these cases, ``idf.py size`` will not succeed either. However it is possible to run ``esp_idf_size`` manually in order to view the *partial static memory usage* (the memory usage will miss the variables which could not be linked, so there still appears to be some free space.)

The map file argument is ``<projectname>.map`` in the build directory

.. code-block:: bash
$IDF_PATH/tools/idf_size.py build/project_name.map
python -m esp_idf_size build/project_name.map
It is also possible to view the equivalent of ``size-components`` or ``size-files`` output:

.. code-block:: bash
$IDF_PATH/tools/idf_size.py --archives build/project_name.map
$IDF_PATH/tools/idf_size.py --files build/project_name.map
python -m esp_idf_size --archives build/project_name.map
python -m esp_idf_size --files build/project_name.map
.. _linker-map-file:

Expand Down
2 changes: 1 addition & 1 deletion tools/ci/ci_build_apps.py
Expand Up @@ -62,7 +62,7 @@ def get_pytest_apps(

default_size_json_path = 'size.json'
build_dir = 'build_@t_@w'
if target == 'linux': # no idf_size.py for linux target
if target == 'linux': # no esp_idf_size for linux target
default_size_json_path = None # type: ignore
# IDF-6644
# hard-coded in components/esp_partition/partition_linux.c
Expand Down
1 change: 0 additions & 1 deletion tools/ci/executable-list.txt
Expand Up @@ -112,7 +112,6 @@ tools/set-submodules-to-github.sh
tools/test_apps/system/no_embedded_paths/check_for_file_paths.py
tools/test_idf_py/test_hints.py
tools/test_idf_py/test_idf_py.py
tools/test_idf_size/test.sh
tools/test_idf_tools/test_idf_tools.py
tools/test_mkdfu/test_mkdfu.py
tools/test_mkuf2/test_mkuf2.py
Expand Down
8 changes: 4 additions & 4 deletions tools/cmake/project.cmake
Expand Up @@ -501,7 +501,7 @@ macro(project project_name)
set(project_elf ${CMAKE_PROJECT_NAME}.elf)

# Create a dummy file to work around CMake requirement of having a source file while adding an
# executable. This is also used by idf_size.py to detect the target
# executable. This is also used by esp_idf_size to detect the target
set(project_elf_src ${CMAKE_BINARY_DIR}/project_elf_src_${IDF_TARGET}.c)
add_custom_command(OUTPUT ${project_elf_src}
COMMAND ${CMAKE_COMMAND} -E touch ${project_elf_src}
Expand Down Expand Up @@ -566,7 +566,7 @@ macro(project project_name)
string(TOUPPER ${idf_target} idf_target)
# Add cross-reference table to the map file
target_link_options(${project_elf} PRIVATE "-Wl,--cref")
# Add this symbol as a hint for idf_size.py to guess the target name
# Add this symbol as a hint for esp_idf_size to guess the target name
target_link_options(${project_elf} PRIVATE "-Wl,--defsym=IDF_TARGET_${idf_target}=0")
# Enable map file output
target_link_options(${project_elf} PRIVATE "-Wl,--Map=${mapfile}")
Expand All @@ -589,9 +589,9 @@ macro(project project_name)
idf_build_get_property(idf_path IDF_PATH)
idf_build_get_property(python PYTHON)

set(idf_size ${python} ${idf_path}/tools/idf_size.py)
set(idf_size ${python} -m esp_idf_size)

# Add size targets, depend on map file, run idf_size.py
# Add size targets, depend on map file, run esp_idf_size
# OUTPUT_JSON is passed for compatibility reasons, SIZE_OUTPUT_FORMAT
# environment variable is recommended and has higher priority
add_custom_target(size
Expand Down

0 comments on commit 891f9a9

Please sign in to comment.