| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 # Using an OrderedDict makes the indices more repetitive (better compression). | 46 # Using an OrderedDict makes the indices more repetitive (better compression). |
| 47 path_tuples = collections.OrderedDict.fromkeys( | 47 path_tuples = collections.OrderedDict.fromkeys( |
| 48 (s.object_path, s.source_path) for s in size_info.symbols) | 48 (s.object_path, s.source_path) for s in size_info.symbols) |
| 49 for i, key in enumerate(path_tuples): | 49 for i, key in enumerate(path_tuples): |
| 50 path_tuples[key] = i | 50 path_tuples[key] = i |
| 51 file_obj.write('%d\n' % len(path_tuples)) | 51 file_obj.write('%d\n' % len(path_tuples)) |
| 52 file_obj.writelines('%s\t%s\n' % pair for pair in path_tuples) | 52 file_obj.writelines('%s\t%s\n' % pair for pair in path_tuples) |
| 53 _LogSize(file_obj, 'paths') # For libchrome, adds 200kb. | 53 _LogSize(file_obj, 'paths') # For libchrome, adds 200kb. |
| 54 | 54 |
| 55 # Symbol counts by section. | 55 # Symbol counts by section. |
| 56 by_section = models.SymbolGroup(size_info.symbols) | 56 by_section = size_info.symbols.GroupBySectionName().Sorted( |
| 57 by_section = by_section.GroupBySectionName().SortedByName() | 57 key=lambda s:(s[0].IsBss(), s[0].address, s.name)) |
| 58 file_obj.write('%s\n' % '\t'.join(g.name for g in by_section)) | 58 file_obj.write('%s\n' % '\t'.join(g.name for g in by_section)) |
| 59 file_obj.write('%s\n' % '\t'.join(str(len(g)) for g in by_section)) | 59 file_obj.write('%s\n' % '\t'.join(str(len(g)) for g in by_section)) |
| 60 | 60 |
| 61 def write_numeric(func, delta=False): | 61 def write_numeric(func, delta=False): |
| 62 for group in by_section: | 62 for group in by_section: |
| 63 prev_value = 0 | 63 prev_value = 0 |
| 64 last_sym = group[-1] | 64 last_sym = group[-1] |
| 65 for symbol in group: | 65 for symbol in group: |
| 66 value = func(symbol) | 66 value = func(symbol) |
| 67 if delta: | 67 if delta: |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 logging.debug('Serialization complete. Gzipping...') | 198 logging.debug('Serialization complete. Gzipping...') |
| 199 stringio.seek(0) | 199 stringio.seek(0) |
| 200 with gzip.open(path, 'wb') as f: | 200 with gzip.open(path, 'wb') as f: |
| 201 shutil.copyfileobj(stringio, f) | 201 shutil.copyfileobj(stringio, f) |
| 202 | 202 |
| 203 | 203 |
| 204 def LoadSizeInfo(path): | 204 def LoadSizeInfo(path): |
| 205 """Returns a SizeInfo loaded from |path|.""" | 205 """Returns a SizeInfo loaded from |path|.""" |
| 206 with gzip.open(path) as f: | 206 with gzip.open(path) as f: |
| 207 return _LoadSizeInfoFromFile(f) | 207 return _LoadSizeInfoFromFile(f) |
| OLD | NEW |