OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env 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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 100.0 * pak.compress_size / total_compress_size, | 555 100.0 * pak.compress_size / total_compress_size, |
556 _FormatBytes(pak.file_size), | 556 _FormatBytes(pak.file_size), |
557 100.0 * pak.file_size / total_file_size) | 557 100.0 * pak.file_size / total_file_size) |
558 | 558 |
559 print | 559 print |
560 print 'Analyzing pak resources in %s...' % apk_filename | 560 print 'Analyzing pak resources in %s...' % apk_filename |
561 | 561 |
562 # Calculate aggregate stats about resources across pak files. | 562 # Calculate aggregate stats about resources across pak files. |
563 resource_count_map = collections.defaultdict(int) | 563 resource_count_map = collections.defaultdict(int) |
564 resource_size_map = collections.defaultdict(int) | 564 resource_size_map = collections.defaultdict(int) |
| 565 seen_data_ids = set() |
| 566 alias_overhead_bytes = 4 |
565 resource_overhead_bytes = 6 | 567 resource_overhead_bytes = 6 |
566 for pak in paks: | 568 for pak in paks: |
567 for r in pak.resources: | 569 for k, v in pak.resources.iteritems(): |
568 resource_count_map[r] += 1 | 570 resource_count_map[k] += 1 |
569 resource_size_map[r] += len(pak.resources[r]) + resource_overhead_bytes | 571 if id(v) not in seen_data_ids: |
570 | 572 seen_data_ids.add(id(v)) |
| 573 resource_size_map[k] += resource_overhead_bytes + len(v) |
| 574 else: |
| 575 resource_size_map[k] += alias_overhead_bytes |
571 # Output the overall resource summary. | 576 # Output the overall resource summary. |
572 total_resource_size = sum(resource_size_map.values()) | 577 total_resource_size = sum(resource_size_map.values()) |
573 total_resource_count = len(resource_count_map) | 578 total_resource_count = len(resource_count_map) |
574 assert total_resource_size <= total_file_size | 579 assert total_resource_size <= total_file_size |
575 print 'Total pak resources: %s' % total_resource_count | 580 print 'Total pak resources: %s' % total_resource_count |
576 print 'Total uncompressed resource size: %s' % _FormatBytes( | 581 print 'Total uncompressed resource size: %s' % _FormatBytes( |
577 total_resource_size) | 582 total_resource_size) |
578 print | 583 print |
579 | 584 |
580 resource_id_name_map, resources_id_header_map = _AnnotatePakResources() | 585 resource_id_name_map, resources_id_header_map = _AnnotatePakResources() |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 chartjson=chartjson) | 832 chartjson=chartjson) |
828 if chartjson: | 833 if chartjson: |
829 results_path = os.path.join(args.output_dir, 'results-chart.json') | 834 results_path = os.path.join(args.output_dir, 'results-chart.json') |
830 logging.critical('Dumping json to %s', results_path) | 835 logging.critical('Dumping json to %s', results_path) |
831 with open(results_path, 'w') as json_file: | 836 with open(results_path, 'w') as json_file: |
832 json.dump(chartjson, json_file) | 837 json.dump(chartjson, json_file) |
833 | 838 |
834 | 839 |
835 if __name__ == '__main__': | 840 if __name__ == '__main__': |
836 sys.exit(main()) | 841 sys.exit(main()) |
OLD | NEW |