develop/optimizations/tools.html · develop/optimizations/tools.rst 공식 원문 ↗

Zephyr 3.7.0 · Develop · Optimizations · Tools

최적화 도구

Build target을 실행해 RAM·ROM·worst-case stack과 structure padding을 실제 symbol 단위로 추적합니다.

Official pathdevelop/optimizations/tools.html
Source filedevelop/optimizations/tools.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

ram_report와 rom_report의 symbol tree, Puncover web 분석, CONFIG_STACK_USAGE, Pahole의 structure hole 출력을 실제 명령과 함께 설명합니다.

Image

ram_report · rom_report

Stack

Puncover · worst case

Struct

Pahole · padding holes

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 6ACCDF6BB56851FB6D3587FBA99E2A949AD80063235F9186B65F2616B3D29D59
.. _optimization_tools:

Optimization Tools
##################

The available optimization tools let you analyse :ref:`footprint_tools`
and :ref:`data_structure_tools` using different build system targets.

.. _footprint_tools:

Footprint and Memory Usage
**************************

The build system offers 3 targets to view and analyse RAM, ROM and stack usage
in generated images. The tools run on the final image and give information
about size of symbols and code being used in both RAM and ROM. Additionally,
with features available through the compiler, we can also generate worst-case
stack usage analysis.

Some of the tools mentioned in this section are organizing their output based
on the physical organization of the symbols. As some symbols might be external
to the project's tree structure, or might lack metadata needed to display them
by name, the following top-level containers are used to group such symbols:

* Hidden - The RAM and ROM reports list all processing symbols with no matching
  mapped files in the Hidden category.

  This means that the file for the listed symbol was not added to the metadata file,
  was empty, or was undefined. The tool was unable to get the name
  of the function for the given symbol nor identify where it comes from.

* No paths - The RAM and ROM reports list all processing symbols with relative paths
  in the No paths category.

  This means that the listed symbols cannot be placed in the tree structure
  of the report at an absolute path under one specific file. The tool was able
  to get the name of the function, but it was unable to identify where it comes from.

  .. note::

     You can have multiple cases of the same function, and the No paths category
     will list the sum of these in one entry.


Build Target: ram_report
========================

List all compiled objects and their RAM usage in a tabular form with bytes
per symbol and the percentage it uses. The data is grouped based on the file
system location of the object in the tree and the file containing the symbol.

Use the ``ram_report`` target with your board, as in the following example.

.. zephyr-app-commands::
    :tool: all
    :app: samples/hello_world
    :board: reel_board
    :goals: ram_report

These commands will generate something similar to the output below::

    Path                                                           Size    %      Address
    ========================================================================================
    Root                                                           4637 100.00%  -
    ├── (hidden)                                                      4   0.09%  -
    ├── (no paths)                                                 2748  59.26%  -
    │   ├── _cpus_active                                              4   0.09%  0x20000314
    │   ├── _kernel                                                  32   0.69%  0x20000318
    │   ├── _sw_isr_table                                           384   8.28%  0x00006474
    │   ├── cli.1                                                    16   0.35%  0x20000254
    │   ├── on.2                                                      4   0.09%  0x20000264
    │   ├── poll_out_lock.0                                           4   0.09%  0x200002d4
    │   ├── z_idle_threads                                          128   2.76%  0x20000120
    │   ├── z_interrupt_stacks                                     2048  44.17%  0x20000360
    │   └── z_main_thread                                           128   2.76%  0x200001a0
    ├── WORKSPACE                                                   184   3.97%  -
    │   └── modules                                                 184   3.97%  -
    │       └── hal                                                 184   3.97%  -
    │           └── nordic                                          184   3.97%  -
    │               └── nrfx                                        184   3.97%  -
    │                   └── drivers                                 184   3.97%  -
    │                       └── src                                 184   3.97%  -
    │                           ├── nrfx_clock.c                      8   0.17%  -
    │                           │   └── m_clock_cb                    8   0.17%  0x200002e4
    │                           ├── nrfx_gpiote.c                   132   2.85%  -
    │                           │   └── m_cb                        132   2.85%  0x20000060
    │                           ├── nrfx_ppi.c                        4   0.09%  -
    │                           │   └── m_channels_allocated          4   0.09%  0x200000e4
    │                           └── nrfx_twim.c                      40   0.86%  -
    │                               └── m_cb                         40   0.86%  0x200002ec
    └── ZEPHYR_BASE                                                1701  36.68%  -
        ├── arch                                                      5   0.11%  -
        │   └── arm                                                   5   0.11%  -
        │       └── core                                              5   0.11%  -
        │           ├── mpu                                           1   0.02%  -
        │           │   └── arm_mpu.c                                 1   0.02%  -
        │           │       └── static_regions_num                    1   0.02%  0x20000348
        │           └── tls.c                                         4   0.09%  -
        │               └── z_arm_tls_ptr                             4   0.09%  0x20000240
        ├── drivers                                                 258   5.56%  -
        │   ├── ...                                                 ...    ...%
    ========================================================================================
                                                                   4637


Build Target: rom_report
========================

List all compiled objects and their ROM usage in a tabular form with bytes
per symbol and the percentage it uses. The data is grouped based on the file
system location of the object in the tree and the file containing the symbol.

Use the ``rom_report`` target with your board, as in the following example.

.. zephyr-app-commands::
    :tool: all
    :app: samples/hello_world
    :board: reel_board
    :goals: rom_report

These commands will generate something similar to the output below::

    Path                                                           Size    %      Address
    ========================================================================================
    Root                                                          27828 100.00%  -
    ├── ...                                                         ...    ...%
    └── ZEPHYR_BASE                                               13558  48.72%  -
        ├── arch                                                   1766   6.35%  -
        │   └── arm                                                1766   6.35%  -
        │       └── core                                           1766   6.35%  -
        │           ├── cortex_m                                   1020   3.67%  -
        │           │   ├── fault.c                                 620   2.23%  -
        │           │   │   ├── bus_fault.constprop.0               108   0.39%  0x00000749
        │           │   │   ├── mem_manage_fault.constprop.0        120   0.43%  0x000007b5
        │           │   │   ├── usage_fault.constprop.0              84   0.30%  0x000006f5
        │           │   │   ├── z_arm_fault                         292   1.05%  0x0000082d
        │           │   │   └── z_arm_fault_init                     16   0.06%  0x00000951
        │           │   ├── ...                                     ...    ...%
        ├── boards                                                   32   0.11%  -
        │   └── arm                                                  32   0.11%  -
        │       └── reel_board                                       32   0.11%  -
        │           └── board.c                                      32   0.11%  -
        │               ├── __init_board_reel_board_init              8   0.03%  0x000063e4
        │               └── board_reel_board_init                    24   0.09%  0x00000ed5
        ├── build                                                   194   0.70%  -
        │   └── zephyr                                              194   0.70%  -
        │       ├── isr_tables.c                                    192   0.69%  -
        │       │   └── _irq_vector_table                           192   0.69%  0x00000040
        │       └── misc                                              2   0.01%  -
        │           └── generated                                     2   0.01%  -
        │               └── configs.c                                 2   0.01%  -
        │                   └── _ConfigAbsSyms                        2   0.01%  0x00005945
        ├── drivers                                                6282  22.57%  -
        │   ├── ...                                                 ...    ...%
    ========================================================================================
                                                                  21652

Build Target: puncover
======================

This target uses a third-party tool called puncover which can be found at
https://github.com/HBehrens/puncover. When this target is built, it will
launch a local web server which will allow you to open a web client and browse
the files and view their ROM, RAM, and stack usage.

Before you can use this
target, install the puncover Python module::

    pip3 install git+https://github.com/HBehrens/puncover --user

.. warning::

   This is a third-party tool that might or might not be working at any given
   time. Please check the GitHub issues, and report new problems to the
   project maintainer.

After you installed the Python module, use ``puncover`` target with your board,
as in the following example.

.. zephyr-app-commands::
    :tool: all
    :app: samples/hello_world
    :board: reel_board
    :goals: puncover


To view worst-case stack usage analysis, build this with the
:kconfig:option:`CONFIG_STACK_USAGE` enabled.

.. zephyr-app-commands::
    :tool: all
    :app: samples/hello_world
    :board: reel_board
    :goals: puncover
    :gen-args: -DCONFIG_STACK_USAGE=y


.. _data_structure_tools:

Data Structures
****************


Build Target: pahole
=====================

Poke-a-hole (pahole) is an object-file analysis tool to find the size of
the data structures, and the holes caused due to aligning the data
elements to the word-size of the CPU by the compiler.

Poke-a-hole (pahole) must be installed prior to using this target. It can be
obtained from https://git.kernel.org/pub/scm/devel/pahole/pahole.git and is
available in the dwarves package in both fedora and ubuntu::

    sudo apt-get install dwarves

Alternatively, you can get it from fedora::

    sudo dnf install dwarves

After you installed the package, use ``pahole`` target with your board,
as in the following example.

.. zephyr-app-commands::
    :tool: all
    :app: samples/hello_world
    :board: reel_board
    :goals: pahole

Pahole will generate something similar to the output below in the console::

    /* Used at: [...]/build/zephyr/kobject_hash.c */
    /* <375> [...]/zephyr/include/zephyr/sys/dlist.h:37 */
    union {
            struct _dnode *            head;               /*     0     4 */
            struct _dnode *            next;               /*     0     4 */
    };
    /* Used at: [...]/build/zephyr/kobject_hash.c */
    /* <397> [...]/zephyr/include/zephyr/sys/dlist.h:36 */
    struct _dnode {
            union {
                    struct _dnode *    head;                 /*     0     4 */
                    struct _dnode *    next;                 /*     0     4 */
            };                                               /*     0     4 */
            union {
                    struct _dnode *    tail;                 /*     4     4 */
                    struct _dnode *    prev;                 /*     4     4 */
            };                                               /*     4     4 */

            /* size: 8, cachelines: 1, members: 2 */
            /* last cacheline: 8 bytes */
    };
    /* Used at: [...]/build/zephyr/kobject_hash.c */
    /* <3b7> [...]/zephyr/include/zephyr/sys/dlist.h:41 */
    union {
            struct _dnode *            tail;               /*     0     4 */
            struct _dnode *            prev;               /*     0     4 */
    };
    ...
    ...

Part 3

한국어 전문 번역

최적화 도구

사용 가능한 최적화 도구는 여러 build system target을 사용해 footprint와 data structure를 분석합니다.

Footprint와 memory 사용량

Build system은 생성 image의 RAM, ROM, stack 사용량을 보고 분석하는 target 세 개를 제공합니다. 도구는 최종 image에서 실행되어 RAM과 ROM에서 사용하는 symbol과 code의 크기를 보여 줍니다. Compiler 기능을 사용하면 worst-case stack usage 분석도 생성할 수 있습니다.

이 절의 일부 도구는 symbol의 물리적 구성에 따라 출력을 정리합니다. Project tree 밖에 있거나 이름 표시에 필요한 metadata가 없는 symbol은 다음 top-level container에 묶습니다.

  • Hidden: RAM·ROM report에서 matching mapped file이 없는 모든 처리 symbol을 나열합니다. 해당 symbol file이 metadata file에 추가되지 않았거나 비어 있거나 정의되지 않았음을 뜻합니다. 도구가 symbol의 function name과 출처를 모두 알아내지 못했습니다.
  • No paths: RAM·ROM report에서 relative path가 있는 모든 처리 symbol을 나열합니다. 하나의 특정 file 아래 absolute path로 report tree에 배치할 수 없음을 뜻합니다. Function name은 찾았지만 출처를 식별하지 못했습니다.

Build target: ram_report

Compile된 모든 object와 RAM 사용량을 symbol별 byte와 비율로 표 형식으로 나열합니다. Object의 file system 위치와 symbol이 들어 있는 file을 기준으로 data를 묶습니다.

ram_report target을 board와 함께 사용합니다.

west build -b reel_board samples/hello_world
west build -t ram_report
# Use cmake to configure a Ninja-based buildsystem:
cmake -Bbuild -GNinja -DBOARD=reel_board samples/hello_world

# Now run the build tool on the generated build system:
ninja -Cbuild ram_report

명령은 다음과 비슷한 출력을 생성합니다.

Path                                                           Size    %      Address
========================================================================================
Root                                                           4637 100.00%  -
├── (hidden)                                                      4   0.09%  -
├── (no paths)                                                 2748  59.26%  -
│   ├── _cpus_active                                              4   0.09%  0x20000314
│   ├── _kernel                                                  32   0.69%  0x20000318
│   ├── _sw_isr_table                                           384   8.28%  0x00006474
│   ├── cli.1                                                    16   0.35%  0x20000254
│   ├── on.2                                                      4   0.09%  0x20000264
│   ├── poll_out_lock.0                                           4   0.09%  0x200002d4
│   ├── z_idle_threads                                          128   2.76%  0x20000120
│   ├── z_interrupt_stacks                                     2048  44.17%  0x20000360
│   └── z_main_thread                                           128   2.76%  0x200001a0
├── WORKSPACE                                                   184   3.97%  -
│   └── modules                                                 184   3.97%  -
│       └── hal                                                 184   3.97%  -
│           └── nordic                                          184   3.97%  -
│               └── nrfx                                        184   3.97%  -
│                   └── drivers                                 184   3.97%  -
│                       └── src                                 184   3.97%  -
│                           ├── nrfx_clock.c                      8   0.17%  -
│                           │   └── m_clock_cb                    8   0.17%  0x200002e4
│                           ├── nrfx_gpiote.c                   132   2.85%  -
│                           │   └── m_cb                        132   2.85%  0x20000060
│                           ├── nrfx_ppi.c                        4   0.09%  -
│                           │   └── m_channels_allocated          4   0.09%  0x200000e4
│                           └── nrfx_twim.c                      40   0.86%  -
│                               └── m_cb                         40   0.86%  0x200002ec
└── ZEPHYR_BASE                                                1701  36.68%  -
    ├── arch                                                      5   0.11%  -
    │   └── arm                                                   5   0.11%  -
    │       └── core                                              5   0.11%  -
    │           ├── mpu                                           1   0.02%  -
    │           │   └── arm_mpu.c                                 1   0.02%  -
    │           │       └── static_regions_num                    1   0.02%  0x20000348
    │           └── tls.c                                         4   0.09%  -
    │               └── z_arm_tls_ptr                             4   0.09%  0x20000240
    ├── drivers                                                 258   5.56%  -
    │   ├── ...                                                 ...    ...%
========================================================================================
                                                               4637

Build target: rom_report

Compile된 모든 object와 ROM 사용량을 symbol별 byte와 비율로 표 형식으로 나열합니다. Object의 file system 위치와 symbol이 들어 있는 file을 기준으로 data를 묶습니다.

rom_report target을 board와 함께 사용합니다.

west build -b reel_board samples/hello_world
west build -t rom_report
# Use cmake to configure a Ninja-based buildsystem:
cmake -Bbuild -GNinja -DBOARD=reel_board samples/hello_world

# Now run the build tool on the generated build system:
ninja -Cbuild rom_report

명령은 다음과 비슷한 출력을 생성합니다.

Path                                                           Size    %      Address
========================================================================================
Root                                                          27828 100.00%  -
├── ...                                                         ...    ...%
└── ZEPHYR_BASE                                               13558  48.72%  -
    ├── arch                                                   1766   6.35%  -
    │   └── arm                                                1766   6.35%  -
    │       └── core                                           1766   6.35%  -
    │           ├── cortex_m                                   1020   3.67%  -
    │           │   ├── fault.c                                 620   2.23%  -
    │           │   │   ├── bus_fault.constprop.0               108   0.39%  0x00000749
    │           │   │   ├── mem_manage_fault.constprop.0        120   0.43%  0x000007b5
    │           │   │   ├── usage_fault.constprop.0              84   0.30%  0x000006f5
    │           │   │   ├── z_arm_fault                         292   1.05%  0x0000082d
    │           │   │   └── z_arm_fault_init                     16   0.06%  0x00000951
    │           │   ├── ...                                     ...    ...%
    ├── boards                                                   32   0.11%  -
    │   └── arm                                                  32   0.11%  -
    │       └── reel_board                                       32   0.11%  -
    │           └── board.c                                      32   0.11%  -
    │               ├── __init_board_reel_board_init              8   0.03%  0x000063e4
    │               └── board_reel_board_init                    24   0.09%  0x00000ed5
    ├── build                                                   194   0.70%  -
    │   └── zephyr                                              194   0.70%  -
    │       ├── isr_tables.c                                    192   0.69%  -
    │       │   └── _irq_vector_table                           192   0.69%  0x00000040
    │       └── misc                                              2   0.01%  -
    │           └── generated                                     2   0.01%  -
    │               └── configs.c                                 2   0.01%  -
    │                   └── _ConfigAbsSyms                        2   0.01%  0x00005945
    ├── drivers                                                6282  22.57%  -
    │   ├── ...                                                 ...    ...%
========================================================================================
                                                              21652

Build target: puncover

이 target은 Puncover라는 third-party tool을 사용합니다. Target을 build하면 local web server를 실행하며, web client에서 file을 탐색하고 ROM, RAM, stack 사용량을 볼 수 있습니다.

Target을 사용하기 전에 Puncover Python module을 설치합니다.

pip3 install git+https://github.com/HBehrens/puncover --user

puncover target을 board와 함께 사용합니다.

west build -b reel_board samples/hello_world
west build -t puncover
# Use cmake to configure a Ninja-based buildsystem:
cmake -Bbuild -GNinja -DBOARD=reel_board samples/hello_world

# Now run the build tool on the generated build system:
ninja -Cbuild puncover

Worst-case stack usage 분석을 보려면 CONFIG_STACK_USAGE를 활성화해 build합니다.

west build -b reel_board samples/hello_world -- -DCONFIG_STACK_USAGE=y
west build -t puncover
# Use cmake to configure a Ninja-based buildsystem:
cmake -Bbuild -GNinja -DBOARD=reel_board -DCONFIG_STACK_USAGE=y samples/hello_world

# Now run the build tool on the generated build system:
ninja -Cbuild puncover

Data structure

Build target: pahole

Poke-a-hole(Pahole)은 data structure 크기와 compiler가 data element를 CPU word size에 맞춰 정렬하면서 생긴 hole을 찾는 object-file 분석 도구입니다.

이 target을 사용하기 전에 Pahole을 설치해야 합니다. Fedora와 Ubuntu에서는 dwarves package로 제공합니다.

sudo apt-get install dwarves

Fedora에서는 다음 명령으로 설치할 수도 있습니다.

sudo dnf install dwarves

pahole target을 board와 함께 사용합니다.

west build -b reel_board samples/hello_world
west build -t pahole
# Use cmake to configure a Ninja-based buildsystem:
cmake -Bbuild -GNinja -DBOARD=reel_board samples/hello_world

# Now run the build tool on the generated build system:
ninja -Cbuild pahole

Pahole은 console에 다음과 비슷한 출력을 생성합니다.

/* Used at: [...]/build/zephyr/kobject_hash.c */
/* <375> [...]/zephyr/include/zephyr/sys/dlist.h:37 */
union {
        struct _dnode *            head;               /*     0     4 */
        struct _dnode *            next;               /*     0     4 */
};
/* Used at: [...]/build/zephyr/kobject_hash.c */
/* <397> [...]/zephyr/include/zephyr/sys/dlist.h:36 */
struct _dnode {
        union {
                struct _dnode *    head;                 /*     0     4 */
                struct _dnode *    next;                 /*     0     4 */
        };                                               /*     0     4 */
        union {
                struct _dnode *    tail;                 /*     4     4 */
                struct _dnode *    prev;                 /*     4     4 */
        };                                               /*     4     4 */

        /* size: 8, cachelines: 1, members: 2 */
        /* last cacheline: 8 bytes */
};
/* Used at: [...]/build/zephyr/kobject_hash.c */
/* <3b7> [...]/zephyr/include/zephyr/sys/dlist.h:41 */
union {
        struct _dnode *            tail;               /*     0     4 */
        struct _dnode *            prev;               /*     0     4 */
};
...
...

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.