Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
binary_size_utils.py
Go to the documentation of this file.
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"""Common utilities for tools that deal with binary size information.
5"""
6
7import logging
8import re
9
10
11def ParseNm(nm_lines):
12 """Parse nm output, returning data for all relevant (to binary size)
13 symbols and ignoring the rest.
14
15 Args:
16 nm_lines: an iterable over lines of nm output.
17
18 Yields:
19 (symbol name, symbol type, symbol size, source file path).
20
21 Path may be None if nm couldn't figure out the source file.
22 """
23
24 # Match lines with size, symbol, optional location, optional discriminator
25 sym_re = re.compile(r'^([0-9a-f]{8,}) ' # address (8+ hex digits)
26 '([0-9a-f]{8,}) ' # size (8+ hex digits)
27 '(.) ' # symbol type, one character
28 '([^\t]+)' # symbol name, separated from next by tab
29 '(?:\t(.*):[\d\?]+)?.*$') # location
30 # Match lines with addr but no size.
31 addr_re = re.compile(r'^[0-9a-f]{8,} (.) ([^\t]+)(?:\t.*)?$')
32 # Match lines that don't have an address at all -- typically external symbols.
33 noaddr_re = re.compile(r'^ {8,} (.) (.*)$')
34 # Match lines with no symbol name, only addr and type
35 addr_only_re = re.compile(r'^[0-9a-f]{8,} (.)$')
36
37 seen_lines = set()
38 for line in nm_lines:
39 line = line.rstrip()
40 if line in seen_lines:
41 # nm outputs identical lines at times. We don't want to treat
42 # those as distinct symbols because that would make no sense.
43 continue
44 seen_lines.add(line)
45 match = sym_re.match(line)
46 if match:
47 address, size, sym_type, sym = match.groups()[0:4]
48 size = int(size, 16)
49 if sym_type in ('B', 'b'):
50 continue # skip all BSS for now.
51 path = match.group(5)
52 yield sym, sym_type, size, path, address
53 continue
54 match = addr_re.match(line)
55 if match:
56 # sym_type, sym = match.groups()[0:2]
57 continue # No size == we don't care.
58 match = noaddr_re.match(line)
59 if match:
60 sym_type, sym = match.groups()
61 if sym_type in ('U', 'w'):
62 continue # external or weak symbol
63 match = addr_only_re.match(line)
64 if match:
65 continue # Nothing to do.
66
67 # If we reach this part of the loop, there was something in the
68 # line that we didn't expect or recognize.
69 logging.warning('nm output parser failed to parse: %s', repr(line))
Type::kYUV Type::kRGBA() int(0.7 *637)