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

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

Issue 2691123002: Android: fix resource_sizes.py strings normalization. (Closed)
Patch Set: Created 3 years, 10 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 si_count = max(si_count, 0) 182 si_count = max(si_count, 0)
183 return si_count 183 return si_count
184 184
185 185
186 def GetStaticInitializers(so_path): 186 def GetStaticInitializers(so_path):
187 output = cmd_helper.GetCmdOutput([_DUMP_STATIC_INITIALIZERS_PATH, '-d', 187 output = cmd_helper.GetCmdOutput([_DUMP_STATIC_INITIALIZERS_PATH, '-d',
188 so_path]) 188 so_path])
189 return output.splitlines() 189 return output.splitlines()
190 190
191 191
192 def _NormalizeResourcesArsc(apk_path, num_supported_configs): 192 def _NormalizeResourcesArsc(apk_path):
193 """Estimates the expected overhead of untranslated strings in resources.arsc. 193 """Estimates the expected overhead of untranslated strings in resources.arsc.
194 194
195 See http://crbug.com/677966 for why this is necessary. 195 See http://crbug.com/677966 for why this is necessary.
196 """ 196 """
197 aapt_output = _RunAaptDumpResources(apk_path) 197 aapt_output = _RunAaptDumpResources(apk_path)
198 198
199 # en-rUS is in the default config and may be cluttered with non-translatable 199 # en-rUS is in the default config and may be cluttered with non-translatable
200 # strings, so en-rGB is a better baseline for finding missing translations. 200 # strings, so en-rGB is a better baseline for finding missing translations.
201 en_strings = _CreateResourceIdValueMap(aapt_output, 'en-rGB') 201 en_strings = _CreateResourceIdValueMap(aapt_output, 'en-rGB')
202 fr_strings = _CreateResourceIdValueMap(aapt_output, 'fr') 202 fr_strings = _CreateResourceIdValueMap(aapt_output, 'fr')
203 203
204 # en-US and en-GB configs will never be translated. 204 # Chrome supports 44 locales (en-US and en-GB will never be translated).
205 config_count = num_supported_configs - 2 205 # This can be changed to |translations.GetNumEntries()| when Chrome and
206 # WebView support the same set of locales (http://crbug.com/369218).
207 config_count = 42
206 208
207 size = 0 209 size = 0
208 for res_id, string_val in en_strings.iteritems(): 210 for res_id, string_val in en_strings.iteritems():
209 if string_val == fr_strings[res_id]: 211 if string_val == fr_strings[res_id]:
210 string_size = len(string_val) 212 string_size = len(string_val)
211 # 7 bytes is the per-entry overhead (not specific to any string). See 213 # 7 bytes is the per-entry overhead (not specific to any string). See
212 # https://android.googlesource.com/platform/frameworks/base.git/+/android- 4.2.2_r1/tools/aapt/StringPool.cpp#414. 214 # https://android.googlesource.com/platform/frameworks/base.git/+/android- 4.2.2_r1/tools/aapt/StringPool.cpp#414.
213 # The 1.5 factor was determined experimentally and is meant to account for 215 # The 1.5 factor was determined experimentally and is meant to account for
214 # other languages generally having longer strings than english. 216 # other languages generally having longer strings than english.
215 size += config_count * (7 + string_size * 1.5) 217 size += config_count * (7 + string_size * 1.5)
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 # Avoid noise caused when strings change and translations haven't yet been 430 # Avoid noise caused when strings change and translations haven't yet been
429 # updated. 431 # updated.
430 english_pak = translations.FindByPattern(r'.*/en[-_][Uu][Ss]\.l?pak') 432 english_pak = translations.FindByPattern(r'.*/en[-_][Uu][Ss]\.l?pak')
431 num_translations = translations.GetNumEntries() 433 num_translations = translations.GetNumEntries()
432 if english_pak and num_translations > 1: 434 if english_pak and num_translations > 1:
433 normalized_apk_size -= translations.ComputeZippedSize() 435 normalized_apk_size -= translations.ComputeZippedSize()
434 # 1.17 found by looking at Chrome.apk and seeing how much smaller en-US.pak 436 # 1.17 found by looking at Chrome.apk and seeing how much smaller en-US.pak
435 # is relative to the average locale .pak. 437 # is relative to the average locale .pak.
436 normalized_apk_size += int( 438 normalized_apk_size += int(
437 english_pak.compress_size * num_translations * 1.17) 439 english_pak.compress_size * num_translations * 1.17)
438 normalized_apk_size += int( 440 normalized_apk_size += int(_NormalizeResourcesArsc(apk_filename))
439 _NormalizeResourcesArsc(apk_filename, num_translations))
440 441
441 ReportPerfResult(chartjson, apk_basename + '_Specifics', 442 ReportPerfResult(chartjson, apk_basename + '_Specifics',
442 'normalized apk size', normalized_apk_size, 'bytes') 443 'normalized apk size', normalized_apk_size, 'bytes')
443 444
444 ReportPerfResult(chartjson, apk_basename + '_Specifics', 445 ReportPerfResult(chartjson, apk_basename + '_Specifics',
445 'file count', len(apk_contents), 'zip entries') 446 'file count', len(apk_contents), 'zip entries')
446 447
447 for info in unknown.AllEntries(): 448 for info in unknown.AllEntries():
448 print 'Unknown entry:', info.filename, info.compress_size 449 print 'Unknown entry:', info.filename, info.compress_size
449 450
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 711
711 if chartjson: 712 if chartjson:
712 results_path = os.path.join(options.output_dir, 'results-chart.json') 713 results_path = os.path.join(options.output_dir, 'results-chart.json')
713 logging.critical('Dumping json to %s', results_path) 714 logging.critical('Dumping json to %s', results_path)
714 with open(results_path, 'w') as json_file: 715 with open(results_path, 'w') as json_file:
715 json.dump(chartjson, json_file) 716 json.dump(chartjson, json_file)
716 717
717 718
718 if __name__ == '__main__': 719 if __name__ == '__main__':
719 sys.exit(main(sys.argv)) 720 sys.exit(main(sys.argv))
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