-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pw_bloat: Simple
pw bloat
CLI command
This adds a command to the Pigweed CLI which can be used to run size reports on binaries without having to go through the GN build. The command initially supports single binary size reports on ELF files which are linked using pw_bloat memory region symbols. Additional data sources can be specified to be displayed hierarchically under the root memoryregions. Example usage (no child data sources): $ pw bloat out/docs/obj/pw_result/size_report/bin/ladder_and_then.elf ▒█████▄ █▓ ▄███▒ ▒█ ▒█ ░▓████▒ ░▓████▒ ▒▓████▄ ▒█░ █░ ░█▒ ██▒ ▀█▒ ▒█░ █ ▒█ ▒█ ▀ ▒█ ▀ ▒█ ▀█▌ ▒█▄▄▄█░ ░█▒ █▓░ ▄▄░ ▒█░ █ ▒█ ▒███ ▒███ ░█ █▌ ▒█▀ ░█░ ▓█ █▓ ░█░ █ ▒█ ▒█ ▄ ▒█ ▄ ░█ ▄█▌ ▒█ ░█░ ░▓███▀ ▒█▓▀▓█░ ░▓████▒ ░▓████▒ ▒▓████▀ +----------------------+---------+ | memoryregions | sizes | +======================+=========+ |FLASH |1,048,064| |RAM | 196,608| |VECTOR_TABLE | 512| +======================+=========+ |Total |1,245,184| +----------------------+---------+ Change-Id: Icc34a085cc62ce3fcf0697f04aaed50c6d559024 Requires: pigweed-internal:32580 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/112314 Reviewed-by: Armando Montanez <[email protected]> Reviewed-by: Ewout van Bekkum <[email protected]> Commit-Queue: Alexei Frolov <[email protected]>
- Loading branch information
Showing
8 changed files
with
149 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright 2022 The Pigweed Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
"""Size reporting utilities.""" | ||
|
||
import argparse | ||
import logging | ||
from pathlib import Path | ||
import sys | ||
|
||
from pw_bloat import bloat | ||
from pw_bloat.label import DataSourceMap | ||
from pw_bloat.label_output import BloatTableOutput | ||
import pw_cli.log | ||
|
||
_LOG = logging.getLogger(__name__) | ||
|
||
|
||
def _parse_args() -> argparse.Namespace: | ||
parser = argparse.ArgumentParser(description=__doc__) | ||
|
||
parser.add_argument('binary', | ||
help='Path to the ELF file to analyze', | ||
type=Path) | ||
parser.add_argument( | ||
'-d', | ||
'--data-sources', | ||
help='Comma-separated list of additional Bloaty data sources to report', | ||
type=lambda s: s.split(','), | ||
default=()) | ||
parser.add_argument('-v', | ||
'--verbose', | ||
help=('Print all log messages ' | ||
'(only errors are printed by default)'), | ||
action='store_true') | ||
|
||
return parser.parse_args() | ||
|
||
|
||
def main() -> int: | ||
"""Run binary size reports.""" | ||
|
||
args = _parse_args() | ||
|
||
if not args.verbose: | ||
pw_cli.log.set_all_loggers_minimum_level(logging.ERROR) | ||
|
||
try: | ||
bloaty_tsv = bloat.memory_regions_size_report( | ||
args.binary, | ||
additional_data_sources=args.data_sources, | ||
extra_args=('--tsv', )) | ||
except bloat.NoMemoryRegions: | ||
_LOG.error('Executable %s does not define any bloat memory regions', | ||
args.binary) | ||
_LOG.error( | ||
'Refer to https://pigweed.dev/pw_bloat/#memoryregions-data-source') | ||
_LOG.error('for information on how to configure them.') | ||
return 1 | ||
|
||
data_source_map = DataSourceMap.from_bloaty_tsv(bloaty_tsv) | ||
|
||
print(BloatTableOutput(data_source_map).create_table()) | ||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters