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

Side by Side Diff: tools/binary_size/libsupersize/file_format.py

Issue 2936033002: Supersize diff rewrite + tweaks (Closed)
Patch Set: review comnts Created 3 years, 6 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
OLDNEW
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 file_obj.write(symbol.full_name) 86 file_obj.write(symbol.full_name)
87 if symbol.aliases and symbol.aliases is not prev_aliases: 87 if symbol.aliases and symbol.aliases is not prev_aliases:
88 file_obj.write('\t0%x' % symbol.num_aliases) 88 file_obj.write('\t0%x' % symbol.num_aliases)
89 prev_aliases = symbol.aliases 89 prev_aliases = symbol.aliases
90 if symbol.flags: 90 if symbol.flags:
91 file_obj.write('\t%x' % symbol.flags) 91 file_obj.write('\t%x' % symbol.flags)
92 file_obj.write('\n') 92 file_obj.write('\n')
93 _LogSize(file_obj, 'names (final)') # For libchrome: adds 3.5mb. 93 _LogSize(file_obj, 'names (final)') # For libchrome: adds 3.5mb.
94 94
95 95
96 def _LoadSizeInfoFromFile(file_obj): 96 def _LoadSizeInfoFromFile(file_obj, size_path):
97 """Loads a size_info from the given file.""" 97 """Loads a size_info from the given file."""
98 lines = iter(file_obj) 98 lines = iter(file_obj)
99 next(lines) # Comment line. 99 next(lines) # Comment line.
100 actual_version = next(lines)[:-1] 100 actual_version = next(lines)[:-1]
101 assert actual_version == _SERIALIZATION_VERSION, ( 101 assert actual_version == _SERIALIZATION_VERSION, (
102 'Version mismatch. Need to write some upgrade code.') 102 'Version mismatch. Need to write some upgrade code.')
103 json_len = int(next(lines)) 103 json_len = int(next(lines))
104 json_str = file_obj.read(json_len) 104 json_str = file_obj.read(json_len)
105 headers = json.loads(json_str) 105 headers = json.loads(json_str)
106 section_sizes = headers['section_sizes'] 106 section_sizes = headers['section_sizes']
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 elif alias_counter > 0: 174 elif alias_counter > 0:
175 new_sym.aliases = raw_symbols[symbol_idx - 1].aliases 175 new_sym.aliases = raw_symbols[symbol_idx - 1].aliases
176 new_sym.aliases.append(new_sym) 176 new_sym.aliases.append(new_sym)
177 alias_counter -= 1 177 alias_counter -= 1
178 else: 178 else:
179 new_sym.aliases = None 179 new_sym.aliases = None
180 180
181 raw_symbols[symbol_idx] = new_sym 181 raw_symbols[symbol_idx] = new_sym
182 symbol_idx += 1 182 symbol_idx += 1
183 183
184 return models.SizeInfo(section_sizes, raw_symbols, metadata=metadata) 184 return models.SizeInfo(section_sizes, raw_symbols, metadata=metadata,
185 size_path=size_path)
185 186
186 187
187 def SaveSizeInfo(size_info, path): 188 def SaveSizeInfo(size_info, path):
188 """Saves |size_info| to |path}.""" 189 """Saves |size_info| to |path}."""
189 if os.environ.get('SUPERSIZE_MEASURE_GZIP') == '1': 190 if os.environ.get('SUPERSIZE_MEASURE_GZIP') == '1':
190 with gzip.open(path, 'wb') as f: 191 with gzip.open(path, 'wb') as f:
191 _SaveSizeInfoToFile(size_info, f) 192 _SaveSizeInfoToFile(size_info, f)
192 else: 193 else:
193 # It is seconds faster to do gzip in a separate step. 6s -> 3.5s. 194 # It is seconds faster to do gzip in a separate step. 6s -> 3.5s.
194 stringio = cStringIO.StringIO() 195 stringio = cStringIO.StringIO()
195 _SaveSizeInfoToFile(size_info, stringio) 196 _SaveSizeInfoToFile(size_info, stringio)
196 197
197 logging.debug('Serialization complete. Gzipping...') 198 logging.debug('Serialization complete. Gzipping...')
198 stringio.seek(0) 199 stringio.seek(0)
199 with gzip.open(path, 'wb') as f: 200 with gzip.open(path, 'wb') as f:
200 shutil.copyfileobj(stringio, f) 201 shutil.copyfileobj(stringio, f)
201 202
202 203
203 def LoadSizeInfo(path): 204 def LoadSizeInfo(path):
204 """Returns a SizeInfo loaded from |path|.""" 205 """Returns a SizeInfo loaded from |path|."""
205 with gzip.open(path) as f: 206 with gzip.open(path) as f:
206 return _LoadSizeInfoFromFile(f) 207 return _LoadSizeInfoFromFile(f, path)
OLDNEW
« no previous file with comments | « tools/binary_size/libsupersize/diff.py ('k') | tools/binary_size/libsupersize/integration_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698