blob: b21e520cfb7fbb11a3e9c429e2b43615cc44d451 [file] [log] [blame]
Wyatt Heplerf9fb90f2020-09-30 18:59:33 -07001.. _module-pw_bloat:
Alexei Frolov3fde6b12019-12-18 16:13:38 -08002
Wyatt Heplerb82f9952019-11-25 13:56:31 -08003--------
4pw_bloat
5--------
Alexei Frolov4c035b02019-11-14 16:36:15 -08006The bloat module provides tools to generate size report cards for output
Alexei Frolovfa34a822020-02-28 14:25:04 -08007binaries using `Bloaty McBloatface <https://github.com/google/bloaty>`_ and
8Pigweed's GN build system.
9
10Bloat report cards allow tracking the memory usage of a system over time as code
11changes are made and provide a breakdown of which parts of the code have the
12largest size impact.
Alexei Frolov4c035b02019-11-14 16:36:15 -080013
Alexei Frolov3fde6b12019-12-18 16:13:38 -080014.. _bloat-howto:
15
16Defining size reports
17=====================
Alexei Frolovfa34a822020-02-28 14:25:04 -080018Size reports are defined using the GN template ``pw_size_report``. The template
19requires at least two executable targets on which to perform a size diff. The
20base for the size diff can be specified either globally through the top-level
21``base`` argument, or individually per-binary within the ``binaries`` list.
Alexei Frolov3fde6b12019-12-18 16:13:38 -080022
Alexei Frolovfa34a822020-02-28 14:25:04 -080023**Arguments**
24
25* ``title``: Title for the report card.
26* ``base``: Optional default base target for all listed binaries.
27* ``binaries``: List of binaries to size diff. Each binary specifies a target,
28 a label for the diff, and optionally a base target that overrides the default
29 base.
30* ``source_filter``: Optional regex to filter labels in the diff output.
31* ``full_report``: Boolean flag indicating whether to output a full report of
32 all symbols in the binary, or a summary of the segment size changes. Default
33 false.
34
35.. code::
36
37 import("$dir_pw_bloat/bloat.gni")
38
39 executable("empty_base") {
40 sources = [ "empty_main.cc" ]
41 }
42
43 exectuable("hello_world_printf") {
44 sources = [ "hello_printf.cc" ]
45 }
46
47 exectuable("hello_world_iostream") {
48 sources = [ "hello_iostream.cc" ]
49 }
50
51 pw_size_report("my_size_report") {
52 title = "Hello world program using printf vs. iostream"
53 base = ":empty_base"
54 binaries = [
55 {
56 target = ":hello_world_printf"
57 label = "Hello world using printf"
58 },
59 {
60 target = ":hello_world_iostream"
61 label = "Hello world using iostream"
62 },
63 ]
64 }
65
Wyatt Hepler6230fa12021-05-11 18:41:51 -070066Size reports are typically included in ReST documentation, as described in
67`Documentation integration`_. Size reports may also be printed in the build
68output if desired. To enable this in the GN build, set the
69``pw_bloat_SHOW_SIZE_REPORTS`` build arg to ``true``.
Alexei Frolov4c035b02019-11-14 16:36:15 -080070
71Documentation integration
72=========================
Alexei Frolov09447842019-11-15 15:09:05 -080073Bloat reports are easy to add to documentation files. All ``pw_size_report``
Alexei Frolov725b85b2020-03-19 13:37:10 -070074targets output a file containing a tabular report card. This file can be
75imported directly into a ReST documentation file using the ``include``
Alexei Frolov4c035b02019-11-14 16:36:15 -080076directive.
77
Alexei Frolov3fde6b12019-12-18 16:13:38 -080078For example, the ``simple_bloat_loop`` and ``simple_bloat_function`` size
79reports under ``//pw_bloat/examples`` are imported into this file as follows:
Alexei Frolov4c035b02019-11-14 16:36:15 -080080
81.. code:: rst
82
Alexei Frolov3fde6b12019-12-18 16:13:38 -080083 Simple bloat loop example
84 ^^^^^^^^^^^^^^^^^^^^^^^^^
Alexei Frolov725b85b2020-03-19 13:37:10 -070085 .. include:: examples/simple_bloat_loop
Alexei Frolov3fde6b12019-12-18 16:13:38 -080086
87 Simple bloat function example
88 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexei Frolov725b85b2020-03-19 13:37:10 -070089 .. include:: examples/simple_bloat_function
Alexei Frolov4c035b02019-11-14 16:36:15 -080090
91Resulting in this output:
92
Alexei Frolov3fde6b12019-12-18 16:13:38 -080093Simple bloat loop example
94^^^^^^^^^^^^^^^^^^^^^^^^^
Alexei Frolov725b85b2020-03-19 13:37:10 -070095.. include:: examples/simple_bloat_loop
Alexei Frolov3fde6b12019-12-18 16:13:38 -080096
97Simple bloat function example
98^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexei Frolov725b85b2020-03-19 13:37:10 -070099.. include:: examples/simple_bloat_function