Chromium Code Reviews| Index: tools/binary_size/explain_binary_size_delta.py |
| diff --git a/tools/binary_size/explain_binary_size_delta.py b/tools/binary_size/explain_binary_size_delta.py |
| index cb99fe6cc93981b3bec3ecff66e8ea0cb1a9fa07..75b6aea17f3bf4758a563be01d152c0ddbb216e6 100755 |
| --- a/tools/binary_size/explain_binary_size_delta.py |
| +++ b/tools/binary_size/explain_binary_size_delta.py |
| @@ -38,6 +38,8 @@ dumps. Example: |
| """ |
| import collections |
| +from collections import Counter |
| +from math import ceil |
| import operator |
| import optparse |
| import os |
| @@ -46,6 +48,19 @@ import sys |
| import binary_size_utils |
| +def CalculateSharedAddresses(symbols): |
| + """Checks how many symbols share the same memory space.""" |
|
Andrew Hayden (chromium.org)
2015/02/16 12:47:38
Please document the return type.
Daniel Bratell
2015/02/18 13:31:53
Done.
|
| + count = Counter() |
| + for _, _, _, _, address in symbols: |
| + count[address] += 1 |
| + |
| + # metacount = Counter() |
|
Andrew Hayden (chromium.org)
2015/02/16 12:47:38
Please remove the commented lines 57-61 or uncomme
Daniel Bratell
2015/02/18 13:31:53
Done.
|
| + # for share_count in count.itervalues(): |
| + # metacount[share_count] += 1 |
| + # for (key, value) in metacount.items(): |
| + # print("%d symbols were shared %d times" % ((value * key), key)) |
| + return count |
| + |
| def Compare(symbols1, symbols2): |
| """Executes a comparison of the symbols in symbols1 and symbols2. |
| @@ -59,19 +74,28 @@ def Compare(symbols1, symbols2): |
| cache1 = {} |
| cache2 = {} |
| - # Make a map of (file, symbol_type) : (symbol_name, symbol_size) |
| - for cache, symbols in ((cache1, symbols1), (cache2, symbols2)): |
| - for symbol_name, symbol_type, symbol_size, file_path in symbols: |
| + # Make a map of (file, symbol_type) : (symbol_name, effective_symbol_size) |
| + share_count1 = CalculateSharedAddresses(symbols1) |
| + share_count2 = CalculateSharedAddresses(symbols2) |
| + for cache, symbols, share_count in ((cache1, symbols1, share_count1), |
| + (cache2, symbols2, share_count2)): |
| + for symbol_name, symbol_type, symbol_size, file_path, address in symbols: |
| if 'vtable for ' in symbol_name: |
| symbol_type = '@' # hack to categorize these separately |
| if file_path: |
| file_path = os.path.normpath(file_path) |
| else: |
| file_path = '(No Path)' |
| + shared_count = share_count[address] |
| + if shared_count == 1: |
| + effective_symbol_size = symbol_size |
| + else: |
| + assert shared_count > 1 |
| + effective_symbol_size = int(ceil(symbol_size / float(shared_count))) |
|
Andrew Hayden (chromium.org)
2015/02/16 12:47:38
For clarity, I'd prefer that we turn this line int
Daniel Bratell
2015/02/18 13:31:53
Done.
|
| key = (file_path, symbol_type) |
| bucket = cache.setdefault(key, {}) |
| size_list = bucket.setdefault(symbol_name, []) |
| - size_list.append(symbol_size) |
| + size_list.append(effective_symbol_size) |
| # Now diff them. We iterate over the elements in cache1. For each symbol |
| # that we find in cache2, we record whether it was deleted, changed, or |
| @@ -177,6 +201,7 @@ def CrunchStats(added, removed, changed, unchanged, showsources, showsymbols): |
| sections = [new_symbols, removed_symbols, grown_symbols, shrunk_symbols] |
| for section in sections: |
| for file_path, symbol_type, symbol_name, size1, size2 in section.symbols: |
| + assert not '&' in file_path, "File path: " + file_path |
|
Andrew Hayden (chromium.org)
2015/02/16 12:47:38
Is there some context for this being added?
Daniel Bratell
2015/02/18 13:31:53
I really can't remember. Probably remains from som
|
| section.sources.add(file_path) |
| if size1 is not None: |
| section.before_size += size1 |