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

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

Issue 2854173003: supersize: Don't cluster by default. Make Diff() accept only SizeInfo. (Closed)
Patch Set: Created 3 years, 7 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 """Methods for converting model objects to human-readable formats.""" 4 """Methods for converting model objects to human-readable formats."""
5 5
6 import datetime 6 import datetime
7 import itertools 7 import itertools
8 import time 8 import time
9 9
10 import models 10 import models
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 return self._DescribeSymbolDiff(obj) 213 return self._DescribeSymbolDiff(obj)
214 if isinstance(obj, models.SymbolGroup): 214 if isinstance(obj, models.SymbolGroup):
215 return self._DescribeSymbolGroup(obj) 215 return self._DescribeSymbolGroup(obj)
216 if isinstance(obj, models.Symbol): 216 if isinstance(obj, models.Symbol):
217 return self._DescribeSymbol(obj) 217 return self._DescribeSymbol(obj)
218 return (repr(obj),) 218 return (repr(obj),)
219 219
220 220
221 def DescribeSizeInfoCoverage(size_info): 221 def DescribeSizeInfoCoverage(size_info):
222 """Yields lines describing how accurate |size_info| is.""" 222 """Yields lines describing how accurate |size_info| is."""
223 symbols = models.SymbolGroup(size_info.raw_symbols)
224 for section in models.SECTION_TO_SECTION_NAME: 223 for section in models.SECTION_TO_SECTION_NAME:
225 if section == 'd': 224 if section == 'd':
226 expected_size = sum(v for k, v in size_info.section_sizes.iteritems() 225 expected_size = sum(v for k, v in size_info.section_sizes.iteritems()
227 if k.startswith('.data')) 226 if k.startswith('.data'))
228 else: 227 else:
229 expected_size = size_info.section_sizes[ 228 expected_size = size_info.section_sizes[
230 models.SECTION_TO_SECTION_NAME[section]] 229 models.SECTION_TO_SECTION_NAME[section]]
231 230
232 def one_stat(group): 231 def one_stat(group):
233 template = ('Section {}: has {:.1%} of {} bytes accounted for from ' 232 template = ('Section {}: has {:.1%} of {} bytes accounted for from '
234 '{} symbols. {} bytes are unaccounted for.') 233 '{} symbols. {} bytes are unaccounted for.')
235 actual_size = group.size 234 actual_size = group.size
236 size_percent = float(actual_size) / expected_size 235 size_percent = float(actual_size) / expected_size
237 return template.format(section, size_percent, actual_size, len(group), 236 return template.format(section, size_percent, actual_size, len(group),
238 expected_size - actual_size) 237 expected_size - actual_size)
239 238
240 in_section = symbols.WhereInSection(section) 239 in_section = size_info.symbols.WhereInSection(section)
241 yield one_stat(in_section) 240 yield one_stat(in_section)
242 yield '* Padding accounts for {} bytes ({:.1%})'.format( 241 yield '* Padding accounts for {} bytes ({:.1%})'.format(
243 in_section.padding, float(in_section.padding) / in_section.size) 242 in_section.padding, float(in_section.padding) / in_section.size)
244 243
245 aliased_symbols = in_section.Filter(lambda s: s.aliases) 244 aliased_symbols = in_section.Filter(lambda s: s.aliases)
246 if len(aliased_symbols): 245 if len(aliased_symbols):
247 uniques = sum(1 for s in aliased_symbols.IterUniqueSymbols()) 246 uniques = sum(1 for s in aliased_symbols.IterUniqueSymbols())
248 yield '* Contains {} aliases, mapped to {} addresses ({} bytes)'.format( 247 yield '* Contains {} aliases, mapped to {} addresses ({} bytes)'.format(
249 len(aliased_symbols), uniques, aliased_symbols.size) 248 len(aliased_symbols), uniques, aliased_symbols.size)
250 else: 249 else:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 291
293 def GenerateLines(obj, verbose=False, recursive=False): 292 def GenerateLines(obj, verbose=False, recursive=False):
294 """Returns an iterable of lines (without \n) that describes |obj|.""" 293 """Returns an iterable of lines (without \n) that describes |obj|."""
295 return Describer(verbose=verbose, recursive=recursive).GenerateLines(obj) 294 return Describer(verbose=verbose, recursive=recursive).GenerateLines(obj)
296 295
297 296
298 def WriteLines(lines, func): 297 def WriteLines(lines, func):
299 for l in lines: 298 for l in lines:
300 func(l) 299 func(l)
301 func('\n') 300 func('\n')
OLDNEW
« no previous file with comments | « tools/binary_size/libsupersize/cluster_symbols.py ('k') | tools/binary_size/libsupersize/diff.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698