tools: Add CSV support to idf_size.py

This adds CSV support to idf_size.py and idf.py size actions and using the --format argument which accepts 'text', 'json' or 'csv' as input.

idf_size.py --json argument is deprecated but left to avoid a breaking change.

For idf.py size actions OUTPUT_JSON environment variable set at configuration time is overriden at target build time if --format is used.

Additionally, this commit refactors big parts of code, unified usage of json_dict and manually generated dictionaries for textual output and improves code quality in many parts.
This commit is contained in:
Djordje Nedic
2022-07-14 13:39:53 +02:00
parent 5c1044d84d
commit 5ee663d592
10 changed files with 3223 additions and 507 deletions

View File

@@ -16,6 +16,9 @@ To optimize both firmware binary size and memory usage it's necessary to measure
Using the :ref:`idf.py` sub-commands ``size``, ``size-components`` and ``size-files`` provides a summary of memory used by the project:
.. note::
It is possible to add ``-DOUTPUT_FORMAT=csv`` or ``-DOUTPUT_FORMAT=json`` to get the output in CSV or JSON format.
Size Summary (idf.py size)
^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -188,9 +191,9 @@ 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 ``idf_size.py`` 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 ``idf_size.py`` 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.
@@ -215,6 +218,9 @@ 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.
.. code-block:: bash
$IDF_PATH/tools/idf_size.py --archives --diff build_Og/https_request.map build_Oshttps_request.map