OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import logging | 5 import logging |
6 import optparse | 6 import optparse |
7 import os | 7 import os |
8 import re | 8 import re |
9 | 9 |
10 from lib.bucket import BucketSet | 10 from lib.bucket import BucketSet |
(...skipping 13 matching lines...) Expand all Loading... |
24 """Subclasses are a subcommand for this executable. | 24 """Subclasses are a subcommand for this executable. |
25 | 25 |
26 See COMMANDS in main() in dmprof.py. | 26 See COMMANDS in main() in dmprof.py. |
27 """ | 27 """ |
28 _DEVICE_BINDIRS = ['/data/data/', '/data/app-lib/', '/data/local/tmp'] | 28 _DEVICE_BINDIRS = ['/data/data/', '/data/app-lib/', '/data/local/tmp'] |
29 | 29 |
30 def __init__(self, usage): | 30 def __init__(self, usage): |
31 self._parser = optparse.OptionParser(usage) | 31 self._parser = optparse.OptionParser(usage) |
32 | 32 |
33 @staticmethod | 33 @staticmethod |
34 def load_basic_files( | 34 def load_basic_files(dump_path, multiple, alternative_dirs=None): |
35 dump_path, multiple, no_dump=False, alternative_dirs=None): | |
36 prefix = SubCommand._find_prefix(dump_path) | 35 prefix = SubCommand._find_prefix(dump_path) |
37 # If the target process is estimated to be working on Android, converts | 36 # If the target process is estimated to be working on Android, converts |
38 # a path in the Android device to a path estimated to be corresponding in | 37 # a path in the Android device to a path estimated to be corresponding in |
39 # the host. Use --alternative-dirs to specify the conversion manually. | 38 # the host. Use --alternative-dirs to specify the conversion manually. |
40 if not alternative_dirs: | 39 if not alternative_dirs: |
41 alternative_dirs = SubCommand._estimate_alternative_dirs(prefix) | 40 alternative_dirs = SubCommand._estimate_alternative_dirs(prefix) |
42 if alternative_dirs: | 41 if alternative_dirs: |
43 for device, host in alternative_dirs.iteritems(): | 42 for device, host in alternative_dirs.iteritems(): |
44 LOGGER.info('Assuming %s on device as %s on host' % (device, host)) | 43 LOGGER.info('Assuming %s on device as %s on host' % (device, host)) |
45 symbol_data_sources = SymbolDataSources(prefix, alternative_dirs) | 44 symbol_data_sources = SymbolDataSources(prefix, alternative_dirs) |
46 symbol_data_sources.prepare() | 45 symbol_data_sources.prepare() |
47 bucket_set = BucketSet() | 46 bucket_set = BucketSet() |
48 bucket_set.load(prefix) | 47 bucket_set.load(prefix) |
49 if not no_dump: | 48 if multiple: |
50 if multiple: | 49 dump_list = DumpList.load(SubCommand._find_all_dumps(dump_path)) |
51 dump_list = DumpList.load(SubCommand._find_all_dumps(dump_path)) | 50 else: |
52 else: | 51 dump = Dump.load(dump_path) |
53 dump = Dump.load(dump_path) | |
54 symbol_mapping_cache = SymbolMappingCache() | 52 symbol_mapping_cache = SymbolMappingCache() |
55 with open(prefix + '.cache.function', 'a+') as cache_f: | 53 with open(prefix + '.cache.function', 'a+') as cache_f: |
56 symbol_mapping_cache.update( | 54 symbol_mapping_cache.update( |
57 FUNCTION_SYMBOLS, bucket_set, | 55 FUNCTION_SYMBOLS, bucket_set, |
58 SymbolFinder(FUNCTION_SYMBOLS, symbol_data_sources), cache_f) | 56 SymbolFinder(FUNCTION_SYMBOLS, symbol_data_sources), cache_f) |
59 with open(prefix + '.cache.typeinfo', 'a+') as cache_f: | 57 with open(prefix + '.cache.typeinfo', 'a+') as cache_f: |
60 symbol_mapping_cache.update( | 58 symbol_mapping_cache.update( |
61 TYPEINFO_SYMBOLS, bucket_set, | 59 TYPEINFO_SYMBOLS, bucket_set, |
62 SymbolFinder(TYPEINFO_SYMBOLS, symbol_data_sources), cache_f) | 60 SymbolFinder(TYPEINFO_SYMBOLS, symbol_data_sources), cache_f) |
63 with open(prefix + '.cache.sourcefile', 'a+') as cache_f: | 61 with open(prefix + '.cache.sourcefile', 'a+') as cache_f: |
64 symbol_mapping_cache.update( | 62 symbol_mapping_cache.update( |
65 SOURCEFILE_SYMBOLS, bucket_set, | 63 SOURCEFILE_SYMBOLS, bucket_set, |
66 SymbolFinder(SOURCEFILE_SYMBOLS, symbol_data_sources), cache_f) | 64 SymbolFinder(SOURCEFILE_SYMBOLS, symbol_data_sources), cache_f) |
67 bucket_set.symbolize(symbol_mapping_cache) | 65 bucket_set.symbolize(symbol_mapping_cache) |
68 if no_dump: | 66 if multiple: |
69 return bucket_set | |
70 elif multiple: | |
71 return (bucket_set, dump_list) | 67 return (bucket_set, dump_list) |
72 else: | 68 else: |
73 return (bucket_set, dump) | 69 return (bucket_set, dump) |
74 | 70 |
75 @staticmethod | 71 @staticmethod |
76 def _find_prefix(path): | 72 def _find_prefix(path): |
77 return re.sub('\.[0-9][0-9][0-9][0-9]\.heap', '', path) | 73 return re.sub('\.[0-9][0-9][0-9][0-9]\.heap', '', path) |
78 | 74 |
79 @staticmethod | 75 @staticmethod |
80 def _estimate_alternative_dirs(prefix): | 76 def _estimate_alternative_dirs(prefix): |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 self._parser.error('needs %d argument(s).\n' % required) | 147 self._parser.error('needs %d argument(s).\n' % required) |
152 return None | 148 return None |
153 return (options, args) | 149 return (options, args) |
154 | 150 |
155 @staticmethod | 151 @staticmethod |
156 def _parse_policy_list(options_policy): | 152 def _parse_policy_list(options_policy): |
157 if options_policy: | 153 if options_policy: |
158 return options_policy.split(',') | 154 return options_policy.split(',') |
159 else: | 155 else: |
160 return None | 156 return None |
OLD | NEW |