OLD | NEW |
1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Main Python API for analyzing binary size.""" | 5 """Main Python API for analyzing binary size.""" |
6 | 6 |
7 import argparse | 7 import argparse |
8 import calendar | 8 import calendar |
9 import collections | 9 import collections |
10 import datetime | 10 import datetime |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 # Convert ../../third_party/... -> third_party/... | 128 # Convert ../../third_party/... -> third_party/... |
129 return path[6:] | 129 return path[6:] |
130 return path | 130 return path |
131 | 131 |
132 | 132 |
133 def _ExtractSourcePaths(symbols, output_directory): | 133 def _ExtractSourcePaths(symbols, output_directory): |
134 """Fills in the .source_path attribute of all symbols. | 134 """Fills in the .source_path attribute of all symbols. |
135 | 135 |
136 Returns True if source paths were found. | 136 Returns True if source paths were found. |
137 """ | 137 """ |
138 all_found = True | |
139 mapper = ninja_parser.SourceFileMapper(output_directory) | 138 mapper = ninja_parser.SourceFileMapper(output_directory) |
| 139 not_found_paths = set() |
140 | 140 |
141 for symbol in symbols: | 141 for symbol in symbols: |
142 object_path = symbol.object_path | 142 object_path = symbol.object_path |
143 if symbol.source_path or not object_path: | 143 if symbol.source_path or not object_path: |
144 continue | 144 continue |
145 # We don't have source info for prebuilt .a files. | 145 # We don't have source info for prebuilt .a files. |
146 if not object_path.startswith('..'): | 146 if not os.path.isabs(object_path) and not object_path.startswith('..'): |
147 source_path = mapper.FindSourceForPath(object_path) | 147 source_path = mapper.FindSourceForPath(object_path) |
148 if source_path: | 148 if source_path: |
149 symbol.source_path = _NormalizeSourcePath(source_path) | 149 symbol.source_path = _NormalizeSourcePath(source_path) |
150 else: | 150 elif object_path not in not_found_paths: |
151 all_found = False | 151 not_found_paths.add(object_path) |
152 logging.warning('Could not find source path for %s', object_path) | 152 logging.warning('Could not find source path for %s', object_path) |
153 logging.debug('Parsed %d .ninja files.', mapper.GetParsedFileCount()) | 153 logging.debug('Parsed %d .ninja files.', mapper.GetParsedFileCount()) |
154 return all_found | 154 return len(not_found_paths) == 0 |
155 | 155 |
156 | 156 |
157 def _CalculatePadding(symbols): | 157 def _CalculatePadding(symbols): |
158 """Populates the |padding| field based on symbol addresses. | 158 """Populates the |padding| field based on symbol addresses. |
159 | 159 |
160 Symbols must already be sorted by |address|. | 160 Symbols must already be sorted by |address|. |
161 """ | 161 """ |
162 seen_sections = [] | 162 seen_sections = [] |
163 for i, symbol in enumerate(symbols[1:]): | 163 for i, symbol in enumerate(symbols[1:]): |
164 prev_symbol = symbols[i] | 164 prev_symbol = symbols[i] |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 lazy_paths.tool_prefix) | 467 lazy_paths.tool_prefix) |
468 for k, v in elf_section_sizes.iteritems(): | 468 for k, v in elf_section_sizes.iteritems(): |
469 assert v == size_info.section_sizes.get(k), ( | 469 assert v == size_info.section_sizes.get(k), ( |
470 'ELF file and .map file do not match.') | 470 'ELF file and .map file do not match.') |
471 | 471 |
472 logging.info('Recording metadata: \n %s', | 472 logging.info('Recording metadata: \n %s', |
473 '\n '.join(describe.DescribeMetadata(size_info.metadata))) | 473 '\n '.join(describe.DescribeMetadata(size_info.metadata))) |
474 logging.info('Saving result to %s', args.size_file) | 474 logging.info('Saving result to %s', args.size_file) |
475 file_format.SaveSizeInfo(size_info, args.size_file) | 475 file_format.SaveSizeInfo(size_info, args.size_file) |
476 logging.info('Done') | 476 logging.info('Done') |
OLD | NEW |