Chromium Code Reviews

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

Issue 258633003: Graphical version of the run_binary_size_analysis tool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Using the python addr2line wrapper. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 """Common utilities for tools that deal with binary size information.
6 """
7
8 import re
9 import sys
10
Primiano Tucci (use gerrit) 2014/05/20 15:22:57 Nit: add an extra newline here
Daniel Bratell 2014/05/21 08:42:13 Done.
11 def ParseNm(input):
12 """Parse nm output.
13
14 Argument: an iterable over lines of nm output.
Primiano Tucci (use gerrit) 2014/05/20 15:22:57 Nit: the format should look like: this Parse nm o
Daniel Bratell 2014/05/21 08:42:13 Done.
Primiano Tucci (use gerrit) 2014/05/21 10:05:59 Ehm, I think the first line of the docstring shoul
15
16 Yields: (symbol name, symbol type, symbol size, source file path).
17 Path may be None if nm couldn't figure out the source file.
18 """
19
20 # Match lines with size, symbol, optional location, optional discriminator
21 sym_re = re.compile(r'^[0-9a-f]{8,} ' # address (8+ hex digits)
22 '([0-9a-f]{8,}) ' # size (8+ hex digits)
23 '(.) ' # symbol type, one character
24 '([^\t]+)' # symbol name, separated from next by tab
25 '(?:\t(.*):[\d\?]+)?.*$') # location
26 # Match lines with addr but no size.
27 addr_re = re.compile(r'^[0-9a-f]{8,} (.) ([^\t]+)(?:\t.*)?$')
Primiano Tucci (use gerrit) 2014/05/20 15:22:57 Hmm what is the sense of the last non capturing gr
Daniel Bratell 2014/05/21 08:42:13 I suspect it is to document the format and reject
Primiano Tucci (use gerrit) 2014/05/21 10:05:59 I tend to not overengineer regex, especially with
28 # Match lines that don't have an address at all -- typically external symbols.
29 noaddr_re = re.compile(r'^ {8,} (.) (.*)$')
30 # Match lines with no symbol name, only addr and type
31 addr_only_re = re.compile(r'^[0-9a-f]{8,} (.)$')
32
33 for line in input:
34 line = line.rstrip()
35 match = sym_re.match(line)
36 if match:
37 size, type, sym = match.groups()[0:3]
38 size = int(size, 16)
39 if type.lower() == 'b':
40 continue # skip all BSS for now
41 path = match.group(4)
42 yield sym, type, size, path
43 continue
44 match = addr_re.match(line)
45 if match:
46 type, sym = match.groups()[0:2]
Primiano Tucci (use gerrit) 2014/05/20 15:22:57 Uhm I'm missing something? why you get type and sy
Daniel Bratell 2014/05/21 08:42:13 For documentation I guess. I'm making it a comment
47 # No size == we don't care.
48 continue
49 match = noaddr_re.match(line)
50 if match:
51 type, sym = match.groups()
52 if type in ('U', 'w'):
53 # external or weak symbol
Primiano Tucci (use gerrit) 2014/05/20 15:22:57 continue # external or weak symbol (save one line
54 continue
55 match = addr_only_re.match(line)
56 if match:
57 # Nothing to do.
58 continue
59
60 print >>sys.stderr, 'unparsed:', repr(line)
Primiano Tucci (use gerrit) 2014/05/20 15:22:57 What about using logging.error()? Most of the cod
OLDNEW

Powered by Google App Engine