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

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

Issue 2969123002: Add deduplication logic to .pak files (Closed)
Patch Set: fix resource_sizes computation Created 3 years, 5 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 | « no previous file | tools/grit/grit/format/data_pack.py » ('j') | tools/grit/grit/format/data_pack.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 chartjson=chartjson) 837 chartjson=chartjson)
833 if chartjson: 838 if chartjson:
834 results_path = os.path.join(args.output_dir, 'results-chart.json') 839 results_path = os.path.join(args.output_dir, 'results-chart.json')
835 logging.critical('Dumping json to %s', results_path) 840 logging.critical('Dumping json to %s', results_path)
836 with open(results_path, 'w') as json_file: 841 with open(results_path, 'w') as json_file:
837 json.dump(chartjson, json_file) 842 json.dump(chartjson, json_file)
838 843
839 844
840 if __name__ == '__main__': 845 if __name__ == '__main__':
841 sys.exit(main()) 846 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | tools/grit/grit/format/data_pack.py » ('j') | tools/grit/grit/format/data_pack.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698