OLD | NEW |
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 """ |
11 | 11 |
12 import collections | 12 import collections |
13 import json | 13 import json |
14 import operator | 14 import operator |
15 import optparse | 15 import optparse |
16 import os | 16 import os |
17 import re | 17 import re |
18 import sys | 18 import sys |
19 import tempfile | 19 import tempfile |
20 import zipfile | 20 import zipfile |
21 import zlib | 21 import zlib |
22 | 22 |
| 23 import devil_chromium |
23 from devil.utils import cmd_helper | 24 from devil.utils import cmd_helper |
24 from pylib import constants | 25 from pylib.constants import host_paths |
25 | 26 |
26 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'tools', 'grit')) | 27 _GRIT_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'tools', 'grit') |
27 from grit.format import data_pack # pylint: disable=import-error | 28 |
28 sys.path.append(os.path.join( | 29 with host_paths.SysPath(_GRIT_PATH): |
29 constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', 'common')) | 30 from grit.format import data_pack # pylint: disable=import-error |
30 import perf_tests_results_helper # pylint: disable=import-error | 31 |
| 32 with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): |
| 33 import perf_tests_results_helper # pylint: disable=import-error |
31 | 34 |
32 | 35 |
33 # Static initializers expected in official builds. Note that this list is built | 36 # Static initializers expected in official builds. Note that this list is built |
34 # using 'nm' on libchrome.so which results from a GCC official build (i.e. | 37 # using 'nm' on libchrome.so which results from a GCC official build (i.e. |
35 # Clang is not supported currently). | 38 # Clang is not supported currently). |
36 | 39 |
37 STATIC_INITIALIZER_SYMBOL_PREFIX = '_GLOBAL__I_' | 40 STATIC_INITIALIZER_SYMBOL_PREFIX = '_GLOBAL__I_' |
38 | 41 |
39 EXPECTED_STATIC_INITIALIZERS = frozenset([ | 42 EXPECTED_STATIC_INITIALIZERS = frozenset([ |
40 'allocators.cpp', | 43 'allocators.cpp', |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 if resource_size_map[i] >= min_pak_resource_size: | 267 if resource_size_map[i] >= min_pak_resource_size: |
265 print '%56s %5s %9s %6.2f%%' % ( | 268 print '%56s %5s %9s %6.2f%%' % ( |
266 resource_id_name_map.get(i, i), | 269 resource_id_name_map.get(i, i), |
267 resource_count_map[i], | 270 resource_count_map[i], |
268 _FormatBytes(resource_size_map[i]), | 271 _FormatBytes(resource_size_map[i]), |
269 100.0 * resource_size_map[i] / total_resource_size) | 272 100.0 * resource_size_map[i] / total_resource_size) |
270 | 273 |
271 | 274 |
272 def _GetResourceIdNameMap(build_type): | 275 def _GetResourceIdNameMap(build_type): |
273 """Returns a map of {resource_id: resource_name}.""" | 276 """Returns a map of {resource_id: resource_name}.""" |
274 out_dir = os.path.join(constants.DIR_SOURCE_ROOT, 'out', build_type) | 277 out_dir = os.path.join(host_paths.DIR_SOURCE_ROOT, 'out', build_type) |
275 assert os.path.isdir(out_dir), 'Failed to locate out dir at %s' % out_dir | 278 assert os.path.isdir(out_dir), 'Failed to locate out dir at %s' % out_dir |
276 print 'Looking at resources in: %s' % out_dir | 279 print 'Looking at resources in: %s' % out_dir |
277 | 280 |
278 grit_headers = [] | 281 grit_headers = [] |
279 for root, _, files in os.walk(out_dir): | 282 for root, _, files in os.walk(out_dir): |
280 if root.endswith('grit'): | 283 if root.endswith('grit'): |
281 grit_headers += [os.path.join(root, f) for f in files if f.endswith('.h')] | 284 grit_headers += [os.path.join(root, f) for f in files if f.endswith('.h')] |
282 assert grit_headers, 'Failed to find grit headers in %s' % out_dir | 285 assert grit_headers, 'Failed to find grit headers in %s' % out_dir |
283 | 286 |
284 id_name_map = {} | 287 id_name_map = {} |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 | 363 |
361 # For backward compatibilty with buildbot scripts, treat --so-path as just | 364 # For backward compatibilty with buildbot scripts, treat --so-path as just |
362 # another file to print the size of. We don't need it for anything special any | 365 # another file to print the size of. We don't need it for anything special any |
363 # more. | 366 # more. |
364 if options.so_path: | 367 if options.so_path: |
365 files.append(options.so_path) | 368 files.append(options.so_path) |
366 | 369 |
367 if not files: | 370 if not files: |
368 option_parser.error('Must specify a file') | 371 option_parser.error('Must specify a file') |
369 | 372 |
| 373 devil_chromium.Initialize() |
| 374 |
370 if options.so_with_symbols_path: | 375 if options.so_with_symbols_path: |
371 PrintStaticInitializersCount( | 376 PrintStaticInitializersCount( |
372 options.so_with_symbols_path, chartjson=chartjson) | 377 options.so_with_symbols_path, chartjson=chartjson) |
373 | 378 |
374 PrintResourceSizes(files, chartjson=chartjson) | 379 PrintResourceSizes(files, chartjson=chartjson) |
375 | 380 |
376 for f in files: | 381 for f in files: |
377 if f.endswith('.apk'): | 382 if f.endswith('.apk'): |
378 PrintApkAnalysis(f, chartjson=chartjson) | 383 PrintApkAnalysis(f, chartjson=chartjson) |
379 PrintPakAnalysis(f, options.min_pak_resource_size, options.build_type) | 384 PrintPakAnalysis(f, options.min_pak_resource_size, options.build_type) |
380 | 385 |
381 if chartjson: | 386 if chartjson: |
382 results_path = os.path.join(options.outpur_dir, 'results-chart.json') | 387 results_path = os.path.join(options.outpur_dir, 'results-chart.json') |
383 with open(results_path, 'w') as json_file: | 388 with open(results_path, 'w') as json_file: |
384 json.dump(chartjson, json_file) | 389 json.dump(chartjson, json_file) |
385 | 390 |
386 | 391 |
387 if __name__ == '__main__': | 392 if __name__ == '__main__': |
388 sys.exit(main(sys.argv)) | 393 sys.exit(main(sys.argv)) |
OLD | NEW |