Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: build/android/resource_sizes.py

Issue 2406093002: Fix monochrome not booting issue (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/gyp/write_build_config.py ('k') | build/config/android/internal_rules.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Prints the size of each given file and optionally computes the size of 6 """Prints the size of each given file and optionally computes the size of
7 libchrome.so without the dependencies added for building with android NDK. 7 libchrome.so without the dependencies added for building with android NDK.
8 Also breaks down the contents of the APK to determine the installed size 8 Also breaks down the contents of the APK to determine the installed size
9 and assign size contributions to different classes of file. 9 and assign size contributions to different classes of file.
10 """ 10 """
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 # extracted from the apk at install/runtime. 177 # extracted from the apk at install/runtime.
178 FileGroup = collections.namedtuple('FileGroup', 178 FileGroup = collections.namedtuple('FileGroup',
179 ['name', 'regex', 'extracted']) 179 ['name', 'regex', 'extracted'])
180 180
181 # File groups are checked in sequence, so more specific regexes should be 181 # File groups are checked in sequence, so more specific regexes should be
182 # earlier in the list. 182 # earlier in the list.
183 YES = lambda _: True 183 YES = lambda _: True
184 NO = lambda _: False 184 NO = lambda _: False
185 FILE_GROUPS = ( 185 FILE_GROUPS = (
186 FileGroup('Native code', r'\.so$', lambda f: 'crazy' not in f), 186 FileGroup('Native code', r'\.so$', lambda f: 'crazy' not in f),
187 FileGroup('Java code', r'^classes.*\.dex$', YES), 187 FileGroup('Java code', r'\.dex$', YES),
188 FileGroup('Native resources (no l10n)', 188 FileGroup('Native resources (no l10n)', r'\.pak$', NO),
189 r'^assets/.*(resources|percent)\.pak$', NO),
190 # For locale paks, assume only english paks are extracted. 189 # For locale paks, assume only english paks are extracted.
191 # Handles locale paks as bother resources or assets (.lpak or .pak). 190 FileGroup('Native resources (l10n)', r'\.lpak$', lambda f: 'en_' in f),
192 FileGroup('Native resources (l10n)', 191 FileGroup('ICU (i18n library) data', r'assets/icudtl\.dat$', NO),
193 r'\.lpak$|^assets/.*(?!resources|percent)\.pak$', 192 FileGroup('V8 Snapshots', r'\.bin$', NO),
194 lambda f: 'en_' in f or 'en-' in f),
195 FileGroup('ICU (i18n library) data', r'^assets/icudtl\.dat$', NO),
196 FileGroup('V8 Snapshots', r'^assets/.*\.bin$', NO),
197 FileGroup('PNG drawables', r'\.png$', NO), 193 FileGroup('PNG drawables', r'\.png$', NO),
198 FileGroup('Non-compiled Android resources', r'^res/', NO), 194 FileGroup('Non-compiled Android resources', r'^res/', NO),
199 FileGroup('Compiled Android resources', r'\.arsc$', NO), 195 FileGroup('Compiled Android resources', r'\.arsc$', NO),
200 FileGroup('Package metadata', r'^(META-INF/|AndroidManifest\.xml$)', NO), 196 FileGroup('Package metadata', r'^(META-INF/|AndroidManifest\.xml$)', NO),
201 FileGroup('Unknown files', r'.', NO), 197 FileGroup('Unknown files', r'.', NO),
202 ) 198 )
203 199
204 apk = zipfile.ZipFile(apk_filename, 'r') 200 apk = zipfile.ZipFile(apk_filename, 'r')
205 try: 201 try:
206 apk_contents = apk.infolist() 202 apk_contents = apk.infolist()
(...skipping 11 matching lines...) Expand all
218 for group in FILE_GROUPS: 214 for group in FILE_GROUPS:
219 if re.search(group.regex, member.filename): 215 if re.search(group.regex, member.filename):
220 found_files[group].append(member) 216 found_files[group].append(member)
221 break 217 break
222 else: 218 else:
223 raise KeyError('No group found for file "%s"' % member.filename) 219 raise KeyError('No group found for file "%s"' % member.filename)
224 220
225 total_install_size = total_apk_size 221 total_install_size = total_apk_size
226 222
227 for group in FILE_GROUPS: 223 for group in FILE_GROUPS:
228 uncompressed_size = 0 224 uncompressed_size = sum(member.file_size for member in found_files[group])
229 packed_size = 0 225 packed_size = sum(member.compress_size for member in found_files[group])
230 extracted_size = 0 226 install_size = packed_size
231 for member in found_files[group]: 227 install_bytes = sum(member.file_size for member in found_files[group]
232 uncompressed_size += member.file_size 228 if group.extracted(member.filename))
233 packed_size += member.compress_size 229 install_size += install_bytes
234 # Assume that if a file is not compressed, then it is not extracted. 230 total_install_size += install_bytes
235 is_compressed = member.compress_type != zipfile.ZIP_STORED
236 if is_compressed and group.extracted(member.filename):
237 extracted_size += member.file_size
238 install_size = packed_size + extracted_size
239 total_install_size += extracted_size
240 231
241 ReportPerfResult(chartjson, apk_basename + '_Breakdown', 232 ReportPerfResult(chartjson, apk_basename + '_Breakdown',
242 group.name + ' size', packed_size, 'bytes') 233 group.name + ' size', packed_size, 'bytes')
243 ReportPerfResult(chartjson, apk_basename + '_InstallBreakdown', 234 ReportPerfResult(chartjson, apk_basename + '_InstallBreakdown',
244 group.name + ' size', install_size, 'bytes') 235 group.name + ' size', install_size, 'bytes')
245 ReportPerfResult(chartjson, apk_basename + '_Uncompressed', 236 ReportPerfResult(chartjson, apk_basename + '_Uncompressed',
246 group.name + ' size', uncompressed_size, 'bytes') 237 group.name + ' size', uncompressed_size, 'bytes')
247 238
248 transfer_size = _CalculateCompressedSize(apk_filename) 239 transfer_size = _CalculateCompressedSize(apk_filename)
249 ReportPerfResult(chartjson, apk_basename + '_InstallSize', 240 ReportPerfResult(chartjson, apk_basename + '_InstallSize',
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 500
510 if chartjson: 501 if chartjson:
511 results_path = os.path.join(options.output_dir, 'results-chart.json') 502 results_path = os.path.join(options.output_dir, 'results-chart.json')
512 logging.critical('Dumping json to %s', results_path) 503 logging.critical('Dumping json to %s', results_path)
513 with open(results_path, 'w') as json_file: 504 with open(results_path, 'w') as json_file:
514 json.dump(chartjson, json_file) 505 json.dump(chartjson, json_file)
515 506
516 507
517 if __name__ == '__main__': 508 if __name__ == '__main__':
518 sys.exit(main(sys.argv)) 509 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « build/android/gyp/write_build_config.py ('k') | build/config/android/internal_rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698