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

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

Issue 1645843004: [BinarySize] Filter duplicate lines in nm output. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also add an OWNERS file Created 4 years, 10 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/OWNERS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 """Common utilities for tools that deal with binary size information. 5 """Common utilities for tools that deal with binary size information.
6 """ 6 """
7 7
8 import logging 8 import logging
9 import re 9 import re
10 10
(...skipping 17 matching lines...) Expand all
28 '(.) ' # symbol type, one character 28 '(.) ' # symbol type, one character
29 '([^\t]+)' # symbol name, separated from next by tab 29 '([^\t]+)' # symbol name, separated from next by tab
30 '(?:\t(.*):[\d\?]+)?.*$') # location 30 '(?:\t(.*):[\d\?]+)?.*$') # location
31 # Match lines with addr but no size. 31 # Match lines with addr but no size.
32 addr_re = re.compile(r'^[0-9a-f]{8,} (.) ([^\t]+)(?:\t.*)?$') 32 addr_re = re.compile(r'^[0-9a-f]{8,} (.) ([^\t]+)(?:\t.*)?$')
33 # Match lines that don't have an address at all -- typically external symbols. 33 # Match lines that don't have an address at all -- typically external symbols.
34 noaddr_re = re.compile(r'^ {8,} (.) (.*)$') 34 noaddr_re = re.compile(r'^ {8,} (.) (.*)$')
35 # Match lines with no symbol name, only addr and type 35 # Match lines with no symbol name, only addr and type
36 addr_only_re = re.compile(r'^[0-9a-f]{8,} (.)$') 36 addr_only_re = re.compile(r'^[0-9a-f]{8,} (.)$')
37 37
38 seen_lines = set()
38 for line in nm_lines: 39 for line in nm_lines:
39 line = line.rstrip() 40 line = line.rstrip()
41 if line in seen_lines:
42 # nm outputs identical lines at times. We don't want to treat
43 # those as distinct symbols because that would make no sense.
44 continue
45 seen_lines.add(line)
40 match = sym_re.match(line) 46 match = sym_re.match(line)
41 if match: 47 if match:
42 address, size, sym_type, sym = match.groups()[0:4] 48 address, size, sym_type, sym = match.groups()[0:4]
43 size = int(size, 16) 49 size = int(size, 16)
44 if sym_type in ('B', 'b'): 50 if sym_type in ('B', 'b'):
45 continue # skip all BSS for now. 51 continue # skip all BSS for now.
46 path = match.group(5) 52 path = match.group(5)
47 yield sym, sym_type, size, path, address 53 yield sym, sym_type, size, path, address
48 continue 54 continue
49 match = addr_re.match(line) 55 match = addr_re.match(line)
50 if match: 56 if match:
51 # sym_type, sym = match.groups()[0:2] 57 # sym_type, sym = match.groups()[0:2]
52 continue # No size == we don't care. 58 continue # No size == we don't care.
53 match = noaddr_re.match(line) 59 match = noaddr_re.match(line)
54 if match: 60 if match:
55 sym_type, sym = match.groups() 61 sym_type, sym = match.groups()
56 if sym_type in ('U', 'w'): 62 if sym_type in ('U', 'w'):
57 continue # external or weak symbol 63 continue # external or weak symbol
58 match = addr_only_re.match(line) 64 match = addr_only_re.match(line)
59 if match: 65 if match:
60 continue # Nothing to do. 66 continue # Nothing to do.
61 67
62 68
63 # If we reach this part of the loop, there was something in the 69 # If we reach this part of the loop, there was something in the
64 # line that we didn't expect or recognize. 70 # line that we didn't expect or recognize.
65 logging.warning('nm output parser failed to parse: %s', repr(line)) 71 logging.warning('nm output parser failed to parse: %s', repr(line))
OLDNEW
« no previous file with comments | « tools/binary_size/OWNERS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698