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 | |
567 resource_overhead_bytes = 6 | 565 resource_overhead_bytes = 6 |
568 for pak in paks: | 566 for pak in paks: |
569 for k, v in pak.resources.iteritems(): | 567 for r in pak.resources: |
570 resource_count_map[k] += 1 | 568 resource_count_map[r] += 1 |
571 if id(v) not in seen_data_ids: | 569 resource_size_map[r] += len(pak.resources[r]) + resource_overhead_bytes |
572 seen_data_ids.add(id(v)) | 570 |
573 resource_size_map[k] += resource_overhead_bytes + len(v) | |
574 else: | |
575 resource_size_map[k] += alias_overhead_bytes | |
576 # Output the overall resource summary. | 571 # Output the overall resource summary. |
577 total_resource_size = sum(resource_size_map.values()) | 572 total_resource_size = sum(resource_size_map.values()) |
578 total_resource_count = len(resource_count_map) | 573 total_resource_count = len(resource_count_map) |
579 assert total_resource_size <= total_file_size | 574 assert total_resource_size <= total_file_size |
580 print 'Total pak resources: %s' % total_resource_count | 575 print 'Total pak resources: %s' % total_resource_count |
581 print 'Total uncompressed resource size: %s' % _FormatBytes( | 576 print 'Total uncompressed resource size: %s' % _FormatBytes( |
582 total_resource_size) | 577 total_resource_size) |
583 print | 578 print |
584 | 579 |
585 resource_id_name_map, resources_id_header_map = _AnnotatePakResources() | 580 resource_id_name_map, resources_id_header_map = _AnnotatePakResources() |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 chartjson=chartjson) | 827 chartjson=chartjson) |
833 if chartjson: | 828 if chartjson: |
834 results_path = os.path.join(args.output_dir, 'results-chart.json') | 829 results_path = os.path.join(args.output_dir, 'results-chart.json') |
835 logging.critical('Dumping json to %s', results_path) | 830 logging.critical('Dumping json to %s', results_path) |
836 with open(results_path, 'w') as json_file: | 831 with open(results_path, 'w') as json_file: |
837 json.dump(chartjson, json_file) | 832 json.dump(chartjson, json_file) |
838 | 833 |
839 | 834 |
840 if __name__ == '__main__': | 835 if __name__ == '__main__': |
841 sys.exit(main()) | 836 sys.exit(main()) |
OLD | NEW |