| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 """Deals with loading & saving .size files.""" | 5 """Deals with loading & saving .size files.""" |
| 6 | 6 |
| 7 import cStringIO | 7 import cStringIO |
| 8 import calendar | 8 import calendar |
| 9 import collections | 9 import collections |
| 10 import datetime | 10 import datetime |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 write_numeric(lambda s: s.size_without_padding) | 77 write_numeric(lambda s: s.size_without_padding) |
| 78 _LogSize(file_obj, 'sizes') # For libchrome, adds 300kb | 78 _LogSize(file_obj, 'sizes') # For libchrome, adds 300kb |
| 79 write_numeric(lambda s: path_tuples[(s.object_path, s.source_path)], | 79 write_numeric(lambda s: path_tuples[(s.object_path, s.source_path)], |
| 80 delta=True) | 80 delta=True) |
| 81 _LogSize(file_obj, 'path indices') # For libchrome: adds 125kb. | 81 _LogSize(file_obj, 'path indices') # For libchrome: adds 125kb. |
| 82 | 82 |
| 83 for group in by_section: | 83 for group in by_section: |
| 84 for symbol in group: | 84 for symbol in group: |
| 85 # Do not write name when full_name exists. It will be derived on load. | 85 # Do not write name when full_name exists. It will be derived on load. |
| 86 file_obj.write(symbol.full_name or symbol.name) | 86 file_obj.write(symbol.full_name or symbol.name) |
| 87 if symbol.is_anonymous: | 87 if symbol.flags: |
| 88 file_obj.write('\t1') | 88 file_obj.write('\t%x' % symbol.flags) |
| 89 file_obj.write('\n') | 89 file_obj.write('\n') |
| 90 _LogSize(file_obj, 'names (final)') # For libchrome: adds 3.5mb. | 90 _LogSize(file_obj, 'names (final)') # For libchrome: adds 3.5mb. |
| 91 | 91 |
| 92 | 92 |
| 93 def _LoadSizeInfoFromFile(file_obj): | 93 def _LoadSizeInfoFromFile(file_obj): |
| 94 """Loads a size_info from the given file.""" | 94 """Loads a size_info from the given file.""" |
| 95 lines = iter(file_obj) | 95 lines = iter(file_obj) |
| 96 next(lines) # Comment line. | 96 next(lines) # Comment line. |
| 97 actual_version = next(lines)[:-1] | 97 actual_version = next(lines)[:-1] |
| 98 assert actual_version == _SERIALIZATION_VERSION, ( | 98 assert actual_version == _SERIALIZATION_VERSION, ( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 127 | 127 |
| 128 addresses = read_numeric(delta=True) | 128 addresses = read_numeric(delta=True) |
| 129 sizes = read_numeric(delta=False) | 129 sizes = read_numeric(delta=False) |
| 130 path_indices = read_numeric(delta=True) | 130 path_indices = read_numeric(delta=True) |
| 131 | 131 |
| 132 raw_symbols = [None] * sum(section_counts) | 132 raw_symbols = [None] * sum(section_counts) |
| 133 symbol_idx = 0 | 133 symbol_idx = 0 |
| 134 for section_index, cur_section_name in enumerate(section_names): | 134 for section_index, cur_section_name in enumerate(section_names): |
| 135 for i in xrange(section_counts[section_index]): | 135 for i in xrange(section_counts[section_index]): |
| 136 line = next(lines)[:-1] | 136 line = next(lines)[:-1] |
| 137 is_anonymous = line.endswith('\t1') | 137 name = line |
| 138 name = line[:-2] if is_anonymous else line | 138 flags = 0 |
| 139 last_tab_idx = line.find('\t', -3) # Allows for two digits of flags. |
| 140 if last_tab_idx != -1: |
| 141 flags = int(line[last_tab_idx + 1:], 16) |
| 142 name = line[:last_tab_idx] |
| 139 | 143 |
| 140 new_sym = models.Symbol.__new__(models.Symbol) | 144 new_sym = models.Symbol.__new__(models.Symbol) |
| 141 new_sym.section_name = cur_section_name | 145 new_sym.section_name = cur_section_name |
| 142 new_sym.address = addresses[section_index][i] | 146 new_sym.address = addresses[section_index][i] |
| 143 new_sym.size = sizes[section_index][i] | 147 new_sym.size = sizes[section_index][i] |
| 144 new_sym.name = name | 148 new_sym.name = name |
| 145 paths = path_tuples[path_indices[section_index][i]] | 149 paths = path_tuples[path_indices[section_index][i]] |
| 146 new_sym.object_path = paths[0] | 150 new_sym.object_path = paths[0] |
| 147 new_sym.source_path = paths[1] | 151 new_sym.source_path = paths[1] |
| 148 new_sym.is_anonymous = is_anonymous | 152 new_sym.flags = flags |
| 149 new_sym.padding = 0 # Derived | 153 new_sym.padding = 0 # Derived |
| 150 new_sym.full_name = None # Derived | 154 new_sym.full_name = None # Derived |
| 151 raw_symbols[symbol_idx] = new_sym | 155 raw_symbols[symbol_idx] = new_sym |
| 152 symbol_idx += 1 | 156 symbol_idx += 1 |
| 153 | 157 |
| 154 return models.SizeInfo(section_sizes, raw_symbols, metadata=metadata) | 158 return models.SizeInfo(section_sizes, raw_symbols, metadata=metadata) |
| 155 | 159 |
| 156 | 160 |
| 157 def SaveSizeInfo(size_info, path): | 161 def SaveSizeInfo(size_info, path): |
| 158 """Saves |size_info| to |path}.""" | 162 """Saves |size_info| to |path}.""" |
| 159 if os.environ.get('MEASURE_GZIP') == '1': | 163 if os.environ.get('MEASURE_GZIP') == '1': |
| 160 with gzip.open(path, 'wb') as f: | 164 with gzip.open(path, 'wb') as f: |
| 161 _SaveSizeInfoToFile(size_info, f) | 165 _SaveSizeInfoToFile(size_info, f) |
| 162 else: | 166 else: |
| 163 # It is seconds faster to do gzip in a separate step. 6s -> 3.5s. | 167 # It is seconds faster to do gzip in a separate step. 6s -> 3.5s. |
| 164 stringio = cStringIO.StringIO() | 168 stringio = cStringIO.StringIO() |
| 165 _SaveSizeInfoToFile(size_info, stringio) | 169 _SaveSizeInfoToFile(size_info, stringio) |
| 166 | 170 |
| 167 logging.debug('Serialization complete. Gzipping...') | 171 logging.debug('Serialization complete. Gzipping...') |
| 168 stringio.seek(0) | 172 stringio.seek(0) |
| 169 with gzip.open(path, 'wb') as f: | 173 with gzip.open(path, 'wb') as f: |
| 170 shutil.copyfileobj(stringio, f) | 174 shutil.copyfileobj(stringio, f) |
| 171 | 175 |
| 172 | 176 |
| 173 def LoadSizeInfo(path): | 177 def LoadSizeInfo(path): |
| 174 """Returns a SizeInfo loaded from |path|.""" | 178 """Returns a SizeInfo loaded from |path|.""" |
| 175 with gzip.open(path) as f: | 179 with gzip.open(path) as f: |
| 176 return _LoadSizeInfoFromFile(f) | 180 return _LoadSizeInfoFromFile(f) |
| OLD | NEW |