blob: bbbbb48576421db44976ec4e40444225bc84902f [file] [log] [blame]
Alexei Frolov4c035b02019-11-14 16:36:15 -08001.. default-domain:: cpp
2
3.. highlight:: sh
4
Alexei Frolov3fde6b12019-12-18 16:13:38 -08005.. _chapter-bloat:
6
Wyatt Heplerb82f9952019-11-25 13:56:31 -08007--------
8pw_bloat
9--------
Alexei Frolov4c035b02019-11-14 16:36:15 -080010The bloat module provides tools to generate size report cards for output
Alexei Frolovfa34a822020-02-28 14:25:04 -080011binaries using `Bloaty McBloatface <https://github.com/google/bloaty>`_ and
12Pigweed's GN build system.
13
14Bloat report cards allow tracking the memory usage of a system over time as code
15changes are made and provide a breakdown of which parts of the code have the
16largest size impact.
Alexei Frolov4c035b02019-11-14 16:36:15 -080017
Alexei Frolov3fde6b12019-12-18 16:13:38 -080018.. _bloat-howto:
19
20Defining size reports
21=====================
Alexei Frolovfa34a822020-02-28 14:25:04 -080022Size reports are defined using the GN template ``pw_size_report``. The template
23requires at least two executable targets on which to perform a size diff. The
24base for the size diff can be specified either globally through the top-level
25``base`` argument, or individually per-binary within the ``binaries`` list.
Alexei Frolov3fde6b12019-12-18 16:13:38 -080026
Alexei Frolovfa34a822020-02-28 14:25:04 -080027**Arguments**
28
29* ``title``: Title for the report card.
30* ``base``: Optional default base target for all listed binaries.
31* ``binaries``: List of binaries to size diff. Each binary specifies a target,
32 a label for the diff, and optionally a base target that overrides the default
33 base.
34* ``source_filter``: Optional regex to filter labels in the diff output.
35* ``full_report``: Boolean flag indicating whether to output a full report of
36 all symbols in the binary, or a summary of the segment size changes. Default
37 false.
38
39.. code::
40
41 import("$dir_pw_bloat/bloat.gni")
42
43 executable("empty_base") {
44 sources = [ "empty_main.cc" ]
45 }
46
47 exectuable("hello_world_printf") {
48 sources = [ "hello_printf.cc" ]
49 }
50
51 exectuable("hello_world_iostream") {
52 sources = [ "hello_iostream.cc" ]
53 }
54
55 pw_size_report("my_size_report") {
56 title = "Hello world program using printf vs. iostream"
57 base = ":empty_base"
58 binaries = [
59 {
60 target = ":hello_world_printf"
61 label = "Hello world using printf"
62 },
63 {
64 target = ":hello_world_iostream"
65 label = "Hello world using iostream"
66 },
67 ]
68 }
69
70When the size report target runs, it will print its report card to stdout.
71Additionally, size report targets also generate ReST output, which is described
72below.
Alexei Frolov4c035b02019-11-14 16:36:15 -080073
74Documentation integration
75=========================
Alexei Frolov09447842019-11-15 15:09:05 -080076Bloat reports are easy to add to documentation files. All ``pw_size_report``
Alexei Frolov725b85b2020-03-19 13:37:10 -070077targets output a file containing a tabular report card. This file can be
78imported directly into a ReST documentation file using the ``include``
Alexei Frolov4c035b02019-11-14 16:36:15 -080079directive.
80
Alexei Frolov3fde6b12019-12-18 16:13:38 -080081For example, the ``simple_bloat_loop`` and ``simple_bloat_function`` size
82reports under ``//pw_bloat/examples`` are imported into this file as follows:
Alexei Frolov4c035b02019-11-14 16:36:15 -080083
84.. code:: rst
85
Alexei Frolov3fde6b12019-12-18 16:13:38 -080086 Simple bloat loop example
87 ^^^^^^^^^^^^^^^^^^^^^^^^^
Alexei Frolov725b85b2020-03-19 13:37:10 -070088 .. include:: examples/simple_bloat_loop
Alexei Frolov3fde6b12019-12-18 16:13:38 -080089
90 Simple bloat function example
91 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexei Frolov725b85b2020-03-19 13:37:10 -070092 .. include:: examples/simple_bloat_function
Alexei Frolov4c035b02019-11-14 16:36:15 -080093
94Resulting in this output:
95
Alexei Frolov3fde6b12019-12-18 16:13:38 -080096Simple bloat loop example
97^^^^^^^^^^^^^^^^^^^^^^^^^
Alexei Frolov725b85b2020-03-19 13:37:10 -070098.. include:: examples/simple_bloat_loop
Alexei Frolov3fde6b12019-12-18 16:13:38 -080099
100Simple bloat function example
101^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexei Frolov725b85b2020-03-19 13:37:10 -0700102.. include:: examples/simple_bloat_function