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

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

Issue 2801663003: //tools/binary_size: Add Disassemble() to console.py. Tweak metadata. (Closed)
Patch Set: Created 3 years, 8 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 """Classes that comprise the data model for binary size analysis.""" 4 """Classes that comprise the data model for binary size analysis.
5
6 The primary classes are Symbol, and SymbolGroup.
7
8 Some notes on common propertis:
9 * address: The start address of the symbol.
10 May be 0 (e.g. for .bss or for SymbolGroups).
11 * size: The number of bytes this symbol takes up, including padding that comes
12 before |address|.
13 * padding: The number of bytes of padding before |address| due to this symbol.
14 * name: Symbol names with parameter list removed.
15 Never None, but will be '' for anonymous symbols.
16 * full_name: Symbols names with parameter list left in.
17 Never None, but will be '' for anonymous symbols, and for symbols that do
18 not contain a parameter list.
19 * is_anonymous: True when the symbol exists in an anonymous namespace (which
20 are removed from both full_name and name during normalization).
21 * section_name: E.g. ".text", ".rodata", ".data.rel.local"
22 * section: The second character of |section_name|. E.g. "t", "r", "d".
23 P---A------S
estevenson 2017/04/06 14:14:01 ?
agrieve 2017/04/06 14:53:54 Whoops :P. Removed.
24
25 """
5 26
6 import collections 27 import collections
7 import copy 28 import copy
8 import os 29 import os
9 import re 30 import re
10 31
11 import match_util 32 import match_util
12 33
13 34
35 METADATA_GIT_REVISION = 'git_revision'
36 METADATA_MAP_FILENAME = 'map_file_name'
37 METADATA_ELF_FILENAME = 'elf_file_name'
38 METADATA_ELF_MTIME = 'elf_mtime' # int timestamp in utc.
39 METADATA_ELF_BUILD_ID = 'elf_build_id'
40
14 SECTION_TO_SECTION_NAME = { 41 SECTION_TO_SECTION_NAME = {
15 'b': '.bss', 42 'b': '.bss',
16 'd': '.data', 43 'd': '.data',
17 'r': '.rodata', 44 'r': '.rodata',
18 't': '.text', 45 't': '.text',
19 } 46 }
20 47
21 48
22 class SizeInfo(object): 49 class SizeInfo(object):
23 """Represents all size information for a single binary. 50 """Represents all size information for a single binary.
24 51
25 Fields: 52 Fields:
26 section_sizes: A dict of section_name -> size. 53 section_sizes: A dict of section_name -> size.
27 symbols: A SymbolGroup (or SymbolDiff) with all symbols in it. 54 symbols: A SymbolGroup (or SymbolDiff) with all symbols in it.
55 metadata: A dict.
28 """ 56 """
29 __slots__ = ( 57 __slots__ = (
30 'section_sizes', 58 'section_sizes',
31 'symbols', 59 'symbols',
32 'tag', 60 'metadata',
33 'timestamp',
34 ) 61 )
35 62
36 """Root size information.""" 63 """Root size information."""
37 def __init__(self, section_sizes, symbols, timestamp=None, tag=''): 64 def __init__(self, section_sizes, symbols, metadata=None):
38 self.section_sizes = section_sizes # E.g. {'.text': 0} 65 self.section_sizes = section_sizes # E.g. {'.text': 0}
39 self.symbols = symbols # List of symbols sorted by address per-section. 66 self.symbols = symbols # List of symbols sorted by address per-section.
40 self.timestamp = timestamp # UTC datetime object. 67 self.metadata = metadata or {}
41 self.tag = tag # E.g. git revision.
42 assert not tag or '\n' not in tag # Simplifies file format.
43 68
44 69
45 class BaseSymbol(object): 70 class BaseSymbol(object):
46 """Base class for Symbol and SymbolGroup.""" 71 """Base class for Symbol and SymbolGroup.
72
73 Refer to module docs for field descriptions.
74 """
47 __slots__ = () 75 __slots__ = ()
48 76
49 @property 77 @property
50 def section(self): 78 def section(self):
51 """Returns the one-letter section. 79 """Returns the one-letter section.
52 80
53 E.g. If section_name == '.rodata', then section == 'r'. 81 E.g. If section_name == '.rodata', then section == 'r'.
54 """ 82 """
55 return self.section_name[1] 83 return self.section_name[1]
56 84
(...skipping 19 matching lines...) Expand all
76 def _Key(self): 104 def _Key(self):
77 """Returns a tuple that can be used to see if two Symbol are the same. 105 """Returns a tuple that can be used to see if two Symbol are the same.
78 106
79 Keys are not guaranteed to be unique within a SymbolGroup. For example, it 107 Keys are not guaranteed to be unique within a SymbolGroup. For example, it
80 is common to have multiple "** merge strings" symbols, which will have a 108 is common to have multiple "** merge strings" symbols, which will have a
81 common key.""" 109 common key."""
82 return (self.section_name, self.full_name or self.name) 110 return (self.section_name, self.full_name or self.name)
83 111
84 112
85 class Symbol(BaseSymbol): 113 class Symbol(BaseSymbol):
86 """Represents a single symbol within a binary.""" 114 """Represents a single symbol within a binary.
115
116 Refer to module docs for field descriptions.
117 """
87 118
88 __slots__ = ( 119 __slots__ = (
89 'address', 120 'address',
90 'full_name', 121 'full_name',
91 'is_anonymous', 122 'is_anonymous',
92 'object_path', 123 'object_path',
93 'name', 124 'name',
94 'padding', 125 'padding',
95 'section_name', 126 'section_name',
96 'source_path', 127 'source_path',
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 610
580 def _ExtractPrefixBeforeSeparator(string, separator, count=1): 611 def _ExtractPrefixBeforeSeparator(string, separator, count=1):
581 idx = -len(separator) 612 idx = -len(separator)
582 prev_idx = None 613 prev_idx = None
583 for _ in xrange(count): 614 for _ in xrange(count):
584 idx = string.find(separator, idx + len(separator)) 615 idx = string.find(separator, idx + len(separator))
585 if idx < 0: 616 if idx < 0:
586 break 617 break
587 prev_idx = idx 618 prev_idx = idx
588 return string[:prev_idx] 619 return string[:prev_idx]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698