| OLD | NEW |
| 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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 | 513 |
| 514 # Output the overall resource summary. | 514 # Output the overall resource summary. |
| 515 total_resource_size = sum(resource_size_map.values()) | 515 total_resource_size = sum(resource_size_map.values()) |
| 516 total_resource_count = len(resource_count_map) | 516 total_resource_count = len(resource_count_map) |
| 517 assert total_resource_size <= total_file_size | 517 assert total_resource_size <= total_file_size |
| 518 print 'Total pak resources: %s' % total_resource_count | 518 print 'Total pak resources: %s' % total_resource_count |
| 519 print 'Total uncompressed resource size: %s' % _FormatBytes( | 519 print 'Total uncompressed resource size: %s' % _FormatBytes( |
| 520 total_resource_size) | 520 total_resource_size) |
| 521 print | 521 print |
| 522 | 522 |
| 523 resource_id_name_map = _GetResourceIdNameMap() | 523 resource_id_name_map, resources_id_header_map = _AnnotatePakResources() |
| 524 | 524 |
| 525 # Output the table of details about all resources across pak files. | 525 # Output the table of details about all resources across pak files. |
| 526 print | 526 print |
| 527 print '%56s %5s %17s' % ('RESOURCE', 'COUNT', 'UNCOMPRESSED SIZE') | 527 print '%56s %5s %17s' % ('RESOURCE', 'COUNT', 'UNCOMPRESSED SIZE') |
| 528 for i in sorted(resource_size_map, key=resource_size_map.get, | 528 for i in sorted(resource_size_map, key=resource_size_map.get, |
| 529 reverse=True): | 529 reverse=True): |
| 530 if resource_size_map[i] >= min_pak_resource_size: | 530 if resource_size_map[i] < min_pak_resource_size: |
| 531 print '%56s %5s %9s %6.2f%%' % ( | 531 break |
| 532 resource_id_name_map.get(i, i), | 532 |
| 533 resource_count_map[i], | 533 print '%56s %5s %9s %6.2f%%' % ( |
| 534 _FormatBytes(resource_size_map[i]), | 534 resource_id_name_map.get(i, i), |
| 535 100.0 * resource_size_map[i] / total_resource_size) | 535 resource_count_map[i], |
| 536 _FormatBytes(resource_size_map[i]), |
| 537 100.0 * resource_size_map[i] / total_resource_size) |
| 538 |
| 539 # Print breakdown on a per-grd file basis. |
| 540 size_by_header = collections.defaultdict(int) |
| 541 for resid, size in resource_size_map.iteritems(): |
| 542 size_by_header[resources_id_header_map.get(resid, 'unknown')] += size |
| 543 |
| 544 print |
| 545 print '%80s %17s' % ('HEADER', 'UNCOMPRESSED SIZE') |
| 546 for header in sorted(size_by_header, key=size_by_header.get, reverse=True): |
| 547 if size_by_header[header] < min_pak_resource_size: |
| 548 break |
| 549 |
| 550 print '%80s %9s %6.2f%%' % ( |
| 551 header, |
| 552 _FormatBytes(size_by_header[header]), |
| 553 100.0 * size_by_header[header] / total_resource_size) |
| 536 | 554 |
| 537 | 555 |
| 538 def _GetResourceIdNameMap(): | 556 def _AnnotatePakResources(): |
| 539 """Returns a map of {resource_id: resource_name}.""" | 557 """Returns a pair of maps: id_name_map, id_header_map.""" |
| 540 out_dir = constants.GetOutDirectory() | 558 out_dir = constants.GetOutDirectory() |
| 541 assert os.path.isdir(out_dir), 'Failed to locate out dir at %s' % out_dir | 559 assert os.path.isdir(out_dir), 'Failed to locate out dir at %s' % out_dir |
| 542 print 'Looking at resources in: %s' % out_dir | 560 print 'Looking at resources in: %s' % out_dir |
| 543 | 561 |
| 544 grit_headers = [] | 562 grit_headers = [] |
| 545 for root, _, files in os.walk(out_dir): | 563 for root, _, files in os.walk(out_dir): |
| 546 if root.endswith('grit'): | 564 if root.endswith('grit'): |
| 547 grit_headers += [os.path.join(root, f) for f in files if f.endswith('.h')] | 565 grit_headers += [os.path.join(root, f) for f in files if f.endswith('.h')] |
| 548 assert grit_headers, 'Failed to find grit headers in %s' % out_dir | 566 assert grit_headers, 'Failed to find grit headers in %s' % out_dir |
| 549 | 567 |
| 550 id_name_map = {} | 568 id_name_map = {} |
| 569 id_header_map = {} |
| 551 for header in grit_headers: | 570 for header in grit_headers: |
| 552 with open(header, 'r') as f: | 571 with open(header, 'r') as f: |
| 553 for line in f.readlines(): | 572 for line in f.readlines(): |
| 554 m = _RC_HEADER_RE.match(line.strip()) | 573 m = _RC_HEADER_RE.match(line.strip()) |
| 555 if m: | 574 if m: |
| 556 i = int(m.group('id')) | 575 i = int(m.group('id')) |
| 557 name = m.group('name') | 576 name = m.group('name') |
| 558 if i in id_name_map and name != id_name_map[i]: | 577 if i in id_name_map and name != id_name_map[i]: |
| 559 print 'WARNING: Resource ID conflict %s (%s vs %s)' % ( | 578 print 'WARNING: Resource ID conflict %s (%s vs %s)' % ( |
| 560 i, id_name_map[i], name) | 579 i, id_name_map[i], name) |
| 561 id_name_map[i] = name | 580 id_name_map[i] = name |
| 562 return id_name_map | 581 id_header_map[i] = os.path.relpath(header, out_dir) |
| 582 return id_name_map, id_header_map |
| 563 | 583 |
| 564 | 584 |
| 565 def _PrintStaticInitializersCountFromApk(apk_filename, chartjson=None): | 585 def _PrintStaticInitializersCountFromApk(apk_filename, chartjson=None): |
| 566 print 'Finding static initializers (can take a minute)' | 586 print 'Finding static initializers (can take a minute)' |
| 567 with zipfile.ZipFile(apk_filename) as z: | 587 with zipfile.ZipFile(apk_filename) as z: |
| 568 infolist = z.infolist() | 588 infolist = z.infolist() |
| 569 out_dir = constants.GetOutDirectory() | 589 out_dir = constants.GetOutDirectory() |
| 570 si_count = 0 | 590 si_count = 0 |
| 571 for zip_info in infolist: | 591 for zip_info in infolist: |
| 572 # Check file size to account for placeholder libraries. | 592 # Check file size to account for placeholder libraries. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 | 730 |
| 711 if chartjson: | 731 if chartjson: |
| 712 results_path = os.path.join(options.output_dir, 'results-chart.json') | 732 results_path = os.path.join(options.output_dir, 'results-chart.json') |
| 713 logging.critical('Dumping json to %s', results_path) | 733 logging.critical('Dumping json to %s', results_path) |
| 714 with open(results_path, 'w') as json_file: | 734 with open(results_path, 'w') as json_file: |
| 715 json.dump(chartjson, json_file) | 735 json.dump(chartjson, json_file) |
| 716 | 736 |
| 717 | 737 |
| 718 if __name__ == '__main__': | 738 if __name__ == '__main__': |
| 719 sys.exit(main(sys.argv)) | 739 sys.exit(main(sys.argv)) |
| OLD | NEW |