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

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

Issue 2404253003: Reland #2 of Fix monochrome not booting issue (Closed)
Patch Set: Change default back to loading locales from disk 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
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'\.dex$', YES), 187 FileGroup('Java code', r'\.dex$', YES),
188 FileGroup('Native resources (no l10n)', r'\.pak$', NO), 188 FileGroup('Native resources (no l10n)',
189 r'^assets/.*(resources|percent)\.pak$', NO),
189 # For locale paks, assume only english paks are extracted. 190 # For locale paks, assume only english paks are extracted.
190 FileGroup('Native resources (l10n)', r'\.lpak$', lambda f: 'en_' in f), 191 # Handles locale paks as bother resources or assets (.lpak or .pak).
191 FileGroup('ICU (i18n library) data', r'assets/icudtl\.dat$', NO), 192 FileGroup('Native resources (l10n)',
192 FileGroup('V8 Snapshots', r'\.bin$', NO), 193 r'\.lpak$|^assets/.*(?!resources|percent)\.pak$',
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),
193 FileGroup('PNG drawables', r'\.png$', NO), 197 FileGroup('PNG drawables', r'\.png$', NO),
194 FileGroup('Non-compiled Android resources', r'^res/', NO), 198 FileGroup('Non-compiled Android resources', r'^res/', NO),
195 FileGroup('Compiled Android resources', r'\.arsc$', NO), 199 FileGroup('Compiled Android resources', r'\.arsc$', NO),
196 FileGroup('Package metadata', r'^(META-INF/|AndroidManifest\.xml$)', NO), 200 FileGroup('Package metadata', r'^(META-INF/|AndroidManifest\.xml$)', NO),
197 FileGroup('Unknown files', r'.', NO), 201 FileGroup('Unknown files', r'.', NO),
198 ) 202 )
199 203
200 apk = zipfile.ZipFile(apk_filename, 'r') 204 apk = zipfile.ZipFile(apk_filename, 'r')
201 try: 205 try:
202 apk_contents = apk.infolist() 206 apk_contents = apk.infolist()
(...skipping 11 matching lines...) Expand all
214 for group in FILE_GROUPS: 218 for group in FILE_GROUPS:
215 if re.search(group.regex, member.filename): 219 if re.search(group.regex, member.filename):
216 found_files[group].append(member) 220 found_files[group].append(member)
217 break 221 break
218 else: 222 else:
219 raise KeyError('No group found for file "%s"' % member.filename) 223 raise KeyError('No group found for file "%s"' % member.filename)
220 224
221 total_install_size = total_apk_size 225 total_install_size = total_apk_size
222 226
223 for group in FILE_GROUPS: 227 for group in FILE_GROUPS:
224 uncompressed_size = sum(member.file_size for member in found_files[group]) 228 uncompressed_size = 0
225 packed_size = sum(member.compress_size for member in found_files[group]) 229 packed_size = 0
226 install_size = packed_size 230 extracted_size = 0
227 install_bytes = sum(member.file_size for member in found_files[group] 231 for member in found_files[group]:
228 if group.extracted(member.filename)) 232 uncompressed_size += member.file_size
229 install_size += install_bytes 233 packed_size += member.compress_size
230 total_install_size += install_bytes 234 # Assume that if a file is not compressed, then it is not extracted.
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
231 240
232 ReportPerfResult(chartjson, apk_basename + '_Breakdown', 241 ReportPerfResult(chartjson, apk_basename + '_Breakdown',
233 group.name + ' size', packed_size, 'bytes') 242 group.name + ' size', packed_size, 'bytes')
234 ReportPerfResult(chartjson, apk_basename + '_InstallBreakdown', 243 ReportPerfResult(chartjson, apk_basename + '_InstallBreakdown',
235 group.name + ' size', install_size, 'bytes') 244 group.name + ' size', install_size, 'bytes')
236 ReportPerfResult(chartjson, apk_basename + '_Uncompressed', 245 ReportPerfResult(chartjson, apk_basename + '_Uncompressed',
237 group.name + ' size', uncompressed_size, 'bytes') 246 group.name + ' size', uncompressed_size, 'bytes')
238 247
239 transfer_size = _CalculateCompressedSize(apk_filename) 248 transfer_size = _CalculateCompressedSize(apk_filename)
240 ReportPerfResult(chartjson, apk_basename + '_InstallSize', 249 ReportPerfResult(chartjson, apk_basename + '_InstallSize',
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 509
501 if chartjson: 510 if chartjson:
502 results_path = os.path.join(options.output_dir, 'results-chart.json') 511 results_path = os.path.join(options.output_dir, 'results-chart.json')
503 logging.critical('Dumping json to %s', results_path) 512 logging.critical('Dumping json to %s', results_path)
504 with open(results_path, 'w') as json_file: 513 with open(results_path, 'w') as json_file:
505 json.dump(chartjson, json_file) 514 json.dump(chartjson, json_file)
506 515
507 516
508 if __name__ == '__main__': 517 if __name__ == '__main__':
509 sys.exit(main(sys.argv)) 518 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