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

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

Issue 2797163006: Android: update static initializer checks in resource_sizes.py. (Closed)
Patch Set: Add back GetStaticInitializers comment Created 3 years, 8 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 | no next file » | 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 # Matches [ 2] .hash HASH 00000000006681f0 0001f0 003154 04 A 3 0 8 153 # Matches [ 2] .hash HASH 00000000006681f0 0001f0 003154 04 A 3 0 8
154 for match in re.finditer(r'\[[\s\d]+\] (\..*)$', stdout, re.MULTILINE): 154 for match in re.finditer(r'\[[\s\d]+\] (\..*)$', stdout, re.MULTILINE):
155 items = match.group(1).split() 155 items = match.group(1).split()
156 section_sizes[items[0]] = int(items[4], 16) 156 section_sizes[items[0]] = int(items[4], 16)
157 157
158 return section_sizes 158 return section_sizes
159 159
160 160
161 def _ParseLibBuildId(so_path, tools_prefix): 161 def _ParseLibBuildId(so_path, tools_prefix):
162 """Returns the Build ID of the given native library.""" 162 """Returns the Build ID of the given native library."""
163 stdout = _RunReadelf(so_path, ['n'], tools_prefix) 163 stdout = _RunReadelf(so_path, ['-n'], tools_prefix)
164 match = re.search(r'Build ID: (\w+)', stdout) 164 match = re.search(r'Build ID: (\w+)', stdout)
165 return match.group(1) if match else None 165 return match.group(1) if match else None
166 166
167 167
168 def CountStaticInitializers(so_path, tools_prefix): 168 def CountStaticInitializers(so_path, tools_prefix):
169 # Static initializers expected in official builds. Note that this list is 169 # Static initializers expected in official builds. Note that this list is
170 # built using 'nm' on libchrome.so which results from a GCC official build 170 # built using 'nm' on libchrome.so which results from a GCC official build
171 # (i.e. Clang is not supported currently). 171 # (i.e. Clang is not supported currently).
172 def get_elf_section_size(readelf_stdout, section_name): 172 def get_elf_section_size(readelf_stdout, section_name):
173 # Matches: .ctors PROGBITS 000000000516add0 5169dd0 000010 00 WA 0 0 8 173 # Matches: .ctors PROGBITS 000000000516add0 5169dd0 000010 00 WA 0 0 8
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 if i in id_name_map and name != id_name_map[i]: 587 if i in id_name_map and name != id_name_map[i]:
588 print 'WARNING: Resource ID conflict %s (%s vs %s)' % ( 588 print 'WARNING: Resource ID conflict %s (%s vs %s)' % (
589 i, id_name_map[i], name) 589 i, id_name_map[i], name)
590 id_name_map[i] = name 590 id_name_map[i] = name
591 id_header_map[i] = os.path.relpath(header, out_dir) 591 id_header_map[i] = os.path.relpath(header, out_dir)
592 return id_name_map, id_header_map 592 return id_name_map, id_header_map
593 593
594 594
595 def _PrintStaticInitializersCountFromApk(apk_filename, tools_prefix, 595 def _PrintStaticInitializersCountFromApk(apk_filename, tools_prefix,
596 chartjson=None): 596 chartjson=None):
597 print 'Finding static initializers (can take a minute)'
598 with zipfile.ZipFile(apk_filename) as z: 597 with zipfile.ZipFile(apk_filename) as z:
599 infolist = z.infolist() 598 so_files = [f for f in z.infolist()
599 if f.filename.endswith('.so') and f.file_size > 0]
600 # Skip checking static initializers for 32 bit .so files when 64 bit .so files
601 # are present since the 32 bit versions will be checked by bots that only
602 # build the 32 bit version. This avoids the complexity of finding 32 bit .so
603 # files in the output directory in 64 bit builds.
604 has_64 = any('64' in f.filename for f in so_files)
605 files_to_check = [f for f in so_files if not has_64 or '64' in f.filename]
600 out_dir = constants.GetOutDirectory() 606 out_dir = constants.GetOutDirectory()
601 si_count = 0 607 si_count = 0
602 for zip_info in infolist: 608 for so_info in files_to_check:
603 # Check file size to account for placeholder libraries. 609 lib_name = os.path.basename(so_info.filename).replace('crazy.', '')
604 if zip_info.filename.endswith('.so') and zip_info.file_size > 0: 610 unstripped_path = os.path.join(out_dir, 'lib.unstripped', lib_name)
605 lib_name = os.path.basename(zip_info.filename).replace('crazy.', '') 611 if os.path.exists(unstripped_path):
606 unstripped_path = os.path.join(out_dir, 'lib.unstripped', lib_name) 612 si_count += _PrintStaticInitializersCount(
607 if os.path.exists(unstripped_path): 613 apk_filename, so_info.filename, unstripped_path, tools_prefix)
608 si_count += _PrintStaticInitializersCount( 614 else:
609 apk_filename, zip_info.filename, unstripped_path, tools_prefix) 615 raise Exception('Unstripped .so not found. Looked here: %s',
610 else: 616 unstripped_path)
611 raise Exception('Unstripped .so not found. Looked here: %s',
612 unstripped_path)
613 ReportPerfResult(chartjson, 'StaticInitializersCount', 'count', si_count, 617 ReportPerfResult(chartjson, 'StaticInitializersCount', 'count', si_count,
614 'count') 618 'count')
615 619
616 620
617 def _PrintStaticInitializersCount(apk_path, apk_so_name, so_with_symbols_path, 621 def _PrintStaticInitializersCount(apk_path, apk_so_name, so_with_symbols_path,
618 tools_prefix): 622 tools_prefix):
619 """Counts the number of static initializers in the given shared library. 623 """Counts the number of static initializers in the given shared library.
620 Additionally, files for which static initializers were found are printed 624 Additionally, files for which static initializers were found are printed
621 on the standard output. 625 on the standard output.
622 626
623 Args: 627 Args:
624 apk_path: Path to the apk. 628 apk_path: Path to the apk.
625 apk_so_name: Name of the so. 629 apk_so_name: Name of the so.
626 so_with_symbols_path: Path to the unstripped libchrome.so file. 630 so_with_symbols_path: Path to the unstripped libchrome.so file.
627 tools_prefix: Prefix for arch-specific version of binary utility tools. 631 tools_prefix: Prefix for arch-specific version of binary utility tools.
628 Returns: 632 Returns:
629 The number of static initializers found. 633 The number of static initializers found.
630 """ 634 """
631 # GetStaticInitializers uses get-static-initializers.py to get a list of all 635 # GetStaticInitializers uses get-static-initializers.py to get a list of all
632 # static initializers. This does not work on all archs (particularly arm). 636 # static initializers. This does not work on all archs (particularly arm).
633 # TODO(rnephew): Get rid of warning when crbug.com/585588 is fixed. 637 # This mostly copies infra/scripts/legacy/scripts/slave/chromium/sizes.py.
638 print 'Finding static initializers in %s (can take a minute)' % apk_so_name
634 with Unzip(apk_path, filename=apk_so_name) as unzipped_so: 639 with Unzip(apk_path, filename=apk_so_name) as unzipped_so:
635 _VerifyLibBuildIdsMatch(tools_prefix, unzipped_so, so_with_symbols_path) 640 _VerifyLibBuildIdsMatch(tools_prefix, unzipped_so, so_with_symbols_path)
636 readelf_si_count = CountStaticInitializers(unzipped_so, tools_prefix) 641 readelf_si_count = CountStaticInitializers(unzipped_so, tools_prefix)
637 sis, dump_si_count = GetStaticInitializers( 642 sis, dump_si_count = GetStaticInitializers(so_with_symbols_path, tools_prefix)
638 so_with_symbols_path, tools_prefix) 643 print ('Found %s files with static initializers using readelf\n'
639 if readelf_si_count != dump_si_count: 644 'Found %s files with static initializers using '
640 print ('There are %d files with static initializers, but ' 645 'dump-static-initializers') % (readelf_si_count, dump_si_count)
641 'dump-static-initializers found %d: files' %
642 (readelf_si_count, dump_si_count))
643 else:
644 print '%s - Found %d files with static initializers:' % (
645 os.path.basename(so_with_symbols_path), dump_si_count)
646 print '\n'.join(sis) 646 print '\n'.join(sis)
647 647
648 return readelf_si_count 648 return readelf_si_count
649 649
650 def _FormatBytes(byts): 650 def _FormatBytes(byts):
651 """Pretty-print a number of bytes.""" 651 """Pretty-print a number of bytes."""
652 if byts > 2**20.0: 652 if byts > 2**20.0:
653 byts /= 2**20.0 653 byts /= 2**20.0
654 return '%.2fm' % byts 654 return '%.2fm' % byts
655 if byts > 2**10.0: 655 if byts > 2**10.0:
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 args.apk, tools_prefix, chartjson=chartjson) 782 args.apk, tools_prefix, chartjson=chartjson)
783 if chartjson: 783 if chartjson:
784 results_path = os.path.join(args.output_dir, 'results-chart.json') 784 results_path = os.path.join(args.output_dir, 'results-chart.json')
785 logging.critical('Dumping json to %s', results_path) 785 logging.critical('Dumping json to %s', results_path)
786 with open(results_path, 'w') as json_file: 786 with open(results_path, 'w') as json_file:
787 json.dump(chartjson, json_file) 787 json.dump(chartjson, json_file)
788 788
789 789
790 if __name__ == '__main__': 790 if __name__ == '__main__':
791 sys.exit(main()) 791 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698