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

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

Issue 2802293002: //tools/binary_size: Add object file count to Print() (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « tools/binary_size/describe.py ('k') | tools/binary_size/integration_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 """Loads a size_info from the given file.""" 92 """Loads a size_info from the given file."""
93 lines = iter(file_obj) 93 lines = iter(file_obj)
94 next(lines) # Comment line. 94 next(lines) # Comment line.
95 actual_version = next(lines)[:-1] 95 actual_version = next(lines)[:-1]
96 assert actual_version == _SERIALIZATION_VERSION, ( 96 assert actual_version == _SERIALIZATION_VERSION, (
97 'Version mismatch. Need to write some upgrade code.') 97 'Version mismatch. Need to write some upgrade code.')
98 json_len = int(next(lines)) 98 json_len = int(next(lines))
99 json_str = file_obj.read(json_len) 99 json_str = file_obj.read(json_len)
100 headers = json.loads(json_str) 100 headers = json.loads(json_str)
101 section_sizes = headers['section_sizes'] 101 section_sizes = headers['section_sizes']
102 metadata = headers['metadata'] 102 metadata = headers.get('metadata')
103 lines = iter(file_obj) 103 lines = iter(file_obj)
104 next(lines) # newline after closing } of json. 104 next(lines) # newline after closing } of json.
105 105
106 num_path_tuples = int(next(lines)) 106 num_path_tuples = int(next(lines))
107 path_tuples = [None] * num_path_tuples 107 path_tuples = [None] * num_path_tuples
108 for i in xrange(num_path_tuples): 108 for i in xrange(num_path_tuples):
109 path_tuples[i] = next(lines)[:-1].split('\t') 109 path_tuples[i] = next(lines)[:-1].split('\t')
110 110
111 section_names = next(lines)[:-1].split('\t') 111 section_names = next(lines)[:-1].split('\t')
112 section_counts = [int(c) for c in next(lines)[:-1].split('\t')] 112 section_counts = [int(c) for c in next(lines)[:-1].split('\t')]
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 logging.debug('Serialization complete. Gzipping...') 166 logging.debug('Serialization complete. Gzipping...')
167 stringio.seek(0) 167 stringio.seek(0)
168 with gzip.open(path, 'wb') as f: 168 with gzip.open(path, 'wb') as f:
169 shutil.copyfileobj(stringio, f) 169 shutil.copyfileobj(stringio, f)
170 170
171 171
172 def LoadSizeInfo(path): 172 def LoadSizeInfo(path):
173 """Returns a SizeInfo loaded from |path|.""" 173 """Returns a SizeInfo loaded from |path|."""
174 with gzip.open(path) as f: 174 with gzip.open(path) as f:
175 return _LoadSizeInfoFromFile(f) 175 return _LoadSizeInfoFromFile(f)
OLDNEW
« no previous file with comments | « tools/binary_size/describe.py ('k') | tools/binary_size/integration_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698