third_party.pigweed.src/pw_bloat/docs.rst

103 lines
3.0 KiB
ReStructuredText
Raw Normal View History

.. default-domain:: cpp
.. highlight:: sh
pw_toolchain_size_report template This change adds a GN template which creates a size report card across a set of different toolchains. The toolchains are defined in a build variable, each with an optional linker script and Bloaty config. The size report template builds a base and diff executable with each of the toolchains and compares the size difference of each. Example output for the host target: simple_bloat_toolchain ────────────────────── ┌───────────┬─────────┬────────┬───────┬───────┐ │ Label │ Segment │ Before │ Delta │ After │ ├═══════════┼═════════┼════════┼═══════┼═══════┤ │ gcc -Og │ CODE │ 413 │ +32 │ 445 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ gcc -Os │ CODE │ 429 │ +16 │ 445 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ gcc -O2 │ CODE │ 429 │ +32 │ 461 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -Og │ CODE │ 448 │ +32 │ 480 │ │ │ RAM │ 113 │ +15 │ 128 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -Os │ CODE │ 432 │ +16 │ 448 │ │ │ RAM │ 113 │ +15 │ 128 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -O2 │ CODE │ 448 │ +80 │ 528 │ │ │ RAM │ 113 │ +15 │ 128 │ └───────────┴─────────┴────────┴───────┴───────┘ Change-Id: I2c65f4d4f61354b9779628f207297eacd04470b9
2019-12-19 00:13:38 +00:00
.. _chapter-bloat:
--------
pw_bloat
--------
The bloat module provides tools to generate size report cards for output
binaries using `Bloaty McBloatface <https://github.com/google/bloaty>`_ and
Pigweed's GN build system.
Bloat report cards allow tracking the memory usage of a system over time as code
changes are made and provide a breakdown of which parts of the code have the
largest size impact.
pw_toolchain_size_report template This change adds a GN template which creates a size report card across a set of different toolchains. The toolchains are defined in a build variable, each with an optional linker script and Bloaty config. The size report template builds a base and diff executable with each of the toolchains and compares the size difference of each. Example output for the host target: simple_bloat_toolchain ────────────────────── ┌───────────┬─────────┬────────┬───────┬───────┐ │ Label │ Segment │ Before │ Delta │ After │ ├═══════════┼═════════┼════════┼═══════┼═══════┤ │ gcc -Og │ CODE │ 413 │ +32 │ 445 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ gcc -Os │ CODE │ 429 │ +16 │ 445 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ gcc -O2 │ CODE │ 429 │ +32 │ 461 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -Og │ CODE │ 448 │ +32 │ 480 │ │ │ RAM │ 113 │ +15 │ 128 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -Os │ CODE │ 432 │ +16 │ 448 │ │ │ RAM │ 113 │ +15 │ 128 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -O2 │ CODE │ 448 │ +80 │ 528 │ │ │ RAM │ 113 │ +15 │ 128 │ └───────────┴─────────┴────────┴───────┴───────┘ Change-Id: I2c65f4d4f61354b9779628f207297eacd04470b9
2019-12-19 00:13:38 +00:00
.. _bloat-howto:
Defining size reports
=====================
Size reports are defined using the GN template ``pw_size_report``. The template
requires at least two executable targets on which to perform a size diff. The
base for the size diff can be specified either globally through the top-level
``base`` argument, or individually per-binary within the ``binaries`` list.
**Arguments**
* ``title``: Title for the report card.
* ``base``: Optional default base target for all listed binaries.
* ``binaries``: List of binaries to size diff. Each binary specifies a target,
a label for the diff, and optionally a base target that overrides the default
base.
* ``source_filter``: Optional regex to filter labels in the diff output.
* ``full_report``: Boolean flag indicating whether to output a full report of
all symbols in the binary, or a summary of the segment size changes. Default
false.
.. code::
import("$dir_pw_bloat/bloat.gni")
executable("empty_base") {
sources = [ "empty_main.cc" ]
}
exectuable("hello_world_printf") {
sources = [ "hello_printf.cc" ]
}
exectuable("hello_world_iostream") {
sources = [ "hello_iostream.cc" ]
}
pw_size_report("my_size_report") {
title = "Hello world program using printf vs. iostream"
base = ":empty_base"
binaries = [
{
target = ":hello_world_printf"
label = "Hello world using printf"
},
{
target = ":hello_world_iostream"
label = "Hello world using iostream"
},
]
}
pw_toolchain_size_report template This change adds a GN template which creates a size report card across a set of different toolchains. The toolchains are defined in a build variable, each with an optional linker script and Bloaty config. The size report template builds a base and diff executable with each of the toolchains and compares the size difference of each. Example output for the host target: simple_bloat_toolchain ────────────────────── ┌───────────┬─────────┬────────┬───────┬───────┐ │ Label │ Segment │ Before │ Delta │ After │ ├═══════════┼═════════┼════════┼═══════┼═══════┤ │ gcc -Og │ CODE │ 413 │ +32 │ 445 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ gcc -Os │ CODE │ 429 │ +16 │ 445 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ gcc -O2 │ CODE │ 429 │ +32 │ 461 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -Og │ CODE │ 448 │ +32 │ 480 │ │ │ RAM │ 113 │ +15 │ 128 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -Os │ CODE │ 432 │ +16 │ 448 │ │ │ RAM │ 113 │ +15 │ 128 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -O2 │ CODE │ 448 │ +80 │ 528 │ │ │ RAM │ 113 │ +15 │ 128 │ └───────────┴─────────┴────────┴───────┴───────┘ Change-Id: I2c65f4d4f61354b9779628f207297eacd04470b9
2019-12-19 00:13:38 +00:00
When the size report target runs, it will print its report card to stdout.
Additionally, size report targets also generate ReST output, which is described
below.
Documentation integration
=========================
Bloat reports are easy to add to documentation files. All ``pw_size_report``
targets output a ``.rst`` file containing a tabular report card. This file
can be imported directly into a documentation file using the ``include``
directive.
pw_toolchain_size_report template This change adds a GN template which creates a size report card across a set of different toolchains. The toolchains are defined in a build variable, each with an optional linker script and Bloaty config. The size report template builds a base and diff executable with each of the toolchains and compares the size difference of each. Example output for the host target: simple_bloat_toolchain ────────────────────── ┌───────────┬─────────┬────────┬───────┬───────┐ │ Label │ Segment │ Before │ Delta │ After │ ├═══════════┼═════════┼════════┼═══════┼═══════┤ │ gcc -Og │ CODE │ 413 │ +32 │ 445 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ gcc -Os │ CODE │ 429 │ +16 │ 445 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ gcc -O2 │ CODE │ 429 │ +32 │ 461 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -Og │ CODE │ 448 │ +32 │ 480 │ │ │ RAM │ 113 │ +15 │ 128 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -Os │ CODE │ 432 │ +16 │ 448 │ │ │ RAM │ 113 │ +15 │ 128 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -O2 │ CODE │ 448 │ +80 │ 528 │ │ │ RAM │ 113 │ +15 │ 128 │ └───────────┴─────────┴────────┴───────┴───────┘ Change-Id: I2c65f4d4f61354b9779628f207297eacd04470b9
2019-12-19 00:13:38 +00:00
For example, the ``simple_bloat_loop`` and ``simple_bloat_function`` size
reports under ``//pw_bloat/examples`` are imported into this file as follows:
.. code:: rst
pw_toolchain_size_report template This change adds a GN template which creates a size report card across a set of different toolchains. The toolchains are defined in a build variable, each with an optional linker script and Bloaty config. The size report template builds a base and diff executable with each of the toolchains and compares the size difference of each. Example output for the host target: simple_bloat_toolchain ────────────────────── ┌───────────┬─────────┬────────┬───────┬───────┐ │ Label │ Segment │ Before │ Delta │ After │ ├═══════════┼═════════┼════════┼═══════┼═══════┤ │ gcc -Og │ CODE │ 413 │ +32 │ 445 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ gcc -Os │ CODE │ 429 │ +16 │ 445 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ gcc -O2 │ CODE │ 429 │ +32 │ 461 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -Og │ CODE │ 448 │ +32 │ 480 │ │ │ RAM │ 113 │ +15 │ 128 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -Os │ CODE │ 432 │ +16 │ 448 │ │ │ RAM │ 113 │ +15 │ 128 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -O2 │ CODE │ 448 │ +80 │ 528 │ │ │ RAM │ 113 │ +15 │ 128 │ └───────────┴─────────┴────────┴───────┴───────┘ Change-Id: I2c65f4d4f61354b9779628f207297eacd04470b9
2019-12-19 00:13:38 +00:00
Simple bloat loop example
^^^^^^^^^^^^^^^^^^^^^^^^^
.. include:: examples/simple_bloat_loop.rst
Simple bloat function example
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. include:: examples/simple_bloat_function.rst
Resulting in this output:
pw_toolchain_size_report template This change adds a GN template which creates a size report card across a set of different toolchains. The toolchains are defined in a build variable, each with an optional linker script and Bloaty config. The size report template builds a base and diff executable with each of the toolchains and compares the size difference of each. Example output for the host target: simple_bloat_toolchain ────────────────────── ┌───────────┬─────────┬────────┬───────┬───────┐ │ Label │ Segment │ Before │ Delta │ After │ ├═══════════┼═════════┼════════┼═══════┼═══════┤ │ gcc -Og │ CODE │ 413 │ +32 │ 445 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ gcc -Os │ CODE │ 429 │ +16 │ 445 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ gcc -O2 │ CODE │ 429 │ +32 │ 461 │ │ │ RAM │ 576 │ +8 │ 584 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -Og │ CODE │ 448 │ +32 │ 480 │ │ │ RAM │ 113 │ +15 │ 128 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -Os │ CODE │ 432 │ +16 │ 448 │ │ │ RAM │ 113 │ +15 │ 128 │ ├───────────┼─────────┼────────┼───────┼───────┤ │ clang -O2 │ CODE │ 448 │ +80 │ 528 │ │ │ RAM │ 113 │ +15 │ 128 │ └───────────┴─────────┴────────┴───────┴───────┘ Change-Id: I2c65f4d4f61354b9779628f207297eacd04470b9
2019-12-19 00:13:38 +00:00
Simple bloat loop example
^^^^^^^^^^^^^^^^^^^^^^^^^
.. include:: examples/simple_bloat_loop.rst
Simple bloat function example
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. include:: examples/simple_bloat_function.rst