| OLD | NEW |
| 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 """Methods for converting model objects to human-readable formats.""" | 4 """Methods for converting model objects to human-readable formats.""" |
| 5 | 5 |
| 6 import datetime | 6 import datetime |
| 7 import itertools | 7 import itertools |
| 8 import time | 8 import time |
| 9 | 9 |
| 10 import models | 10 import models |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 self.verbose = verbose | 55 self.verbose = verbose |
| 56 self.recursive = recursive | 56 self.recursive = recursive |
| 57 | 57 |
| 58 def _DescribeSectionSizes(self, section_sizes): | 58 def _DescribeSectionSizes(self, section_sizes): |
| 59 relevant_names = models.SECTION_TO_SECTION_NAME.values() | 59 relevant_names = models.SECTION_TO_SECTION_NAME.values() |
| 60 section_names = sorted(k for k in section_sizes.iterkeys() | 60 section_names = sorted(k for k in section_sizes.iterkeys() |
| 61 if k in relevant_names or k.startswith('.data')) | 61 if k in relevant_names or k.startswith('.data')) |
| 62 total_bytes = sum(v for k, v in section_sizes.iteritems() | 62 total_bytes = sum(v for k, v in section_sizes.iteritems() |
| 63 if k in section_names and k != '.bss') | 63 if k in section_names and k != '.bss') |
| 64 yield '' | 64 yield '' |
| 65 yield 'Section Sizes (Total={:,} bytes):'.format(total_bytes) | 65 yield 'Section Sizes (Total={} ({} bytes)):'.format( |
| 66 _PrettySize(total_bytes), total_bytes) |
| 66 for name in section_names: | 67 for name in section_names: |
| 67 size = section_sizes[name] | 68 size = section_sizes[name] |
| 68 if name == '.bss': | 69 if name == '.bss': |
| 69 yield ' {}: {:,} bytes (not included in totals)'.format(name, size) | 70 yield ' {}: {} ({} bytes) (not included in totals)'.format( |
| 71 name, _PrettySize(size), size) |
| 70 else: | 72 else: |
| 71 percent = float(size) / total_bytes if total_bytes else 0 | 73 percent = float(size) / total_bytes if total_bytes else 0 |
| 72 yield ' {}: {:,} bytes ({:.1%})'.format(name, size, percent) | 74 yield ' {}: {} ({} bytes) ({:.1%})'.format( |
| 75 name, _PrettySize(size), size, percent) |
| 73 | 76 |
| 74 if self.verbose: | 77 if self.verbose: |
| 75 yield '' | 78 yield '' |
| 76 yield 'Other section sizes:' | 79 yield 'Other section sizes:' |
| 77 section_names = sorted(k for k in section_sizes.iterkeys() | 80 section_names = sorted(k for k in section_sizes.iterkeys() |
| 78 if k not in section_names) | 81 if k not in section_names) |
| 79 for name in section_names: | 82 for name in section_names: |
| 80 yield ' {}: {:,} bytes'.format(name, section_sizes[name]) | 83 yield ' {}: {} ({} bytes)'.format( |
| 84 name, _PrettySize(section_sizes[name]), section_sizes[name]) |
| 81 | 85 |
| 82 def _DescribeSymbol(self, sym, single_line=False): | 86 def _DescribeSymbol(self, sym, single_line=False): |
| 83 if sym.IsGroup(): | 87 if sym.IsGroup(): |
| 84 address = 'Group' | 88 address = 'Group' |
| 85 else: | 89 else: |
| 86 address = hex(sym.address) | 90 address = hex(sym.address) |
| 87 if self.verbose: | 91 if self.verbose: |
| 88 count_part = ' count=%d' % len(sym) if sym.IsGroup() else '' | 92 count_part = ' count=%d' % len(sym) if sym.IsGroup() else '' |
| 89 yield '{}@{:<9s} pss={} padding={} size_without_padding={}{}'.format( | 93 yield '{}@{:<9s} pss={} padding={} size_without_padding={}{}'.format( |
| 90 sym.section, address, _FormatPss(sym.pss), sym.padding, | 94 sym.section, address, _FormatPss(sym.pss), sym.padding, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 _FormatPss(running_total), '({:.1%})'.format(running_percent), l) | 139 _FormatPss(running_total), '({:.1%})'.format(running_percent), l) |
| 136 | 140 |
| 137 if self.recursive and s.IsGroup(): | 141 if self.recursive and s.IsGroup(): |
| 138 for l in self._DescribeSymbolGroupChildren(s, indent=indent + 1): | 142 for l in self._DescribeSymbolGroupChildren(s, indent=indent + 1): |
| 139 yield l | 143 yield l |
| 140 | 144 |
| 141 def _DescribeSymbolGroup(self, group): | 145 def _DescribeSymbolGroup(self, group): |
| 142 total_size = group.pss | 146 total_size = group.pss |
| 143 code_size = 0 | 147 code_size = 0 |
| 144 ro_size = 0 | 148 ro_size = 0 |
| 149 data_size = 0 |
| 150 bss_size = 0 |
| 145 unique_paths = set() | 151 unique_paths = set() |
| 146 for s in group.IterLeafSymbols(): | 152 for s in group.IterLeafSymbols(): |
| 147 if s.section == 't': | 153 if s.section == 't': |
| 148 code_size += s.pss | 154 code_size += s.pss |
| 149 elif s.section == 'r': | 155 elif s.section == 'r': |
| 150 ro_size += s.pss | 156 ro_size += s.pss |
| 157 elif s.section == 'd': |
| 158 data_size += s.pss |
| 159 elif s.section == 'b': |
| 160 bss_size += s.pss |
| 151 unique_paths.add(s.object_path) | 161 unique_paths.add(s.object_path) |
| 152 header_desc = [ | 162 header_desc = [ |
| 153 'Showing {:,} symbols ({:,} unique) with total pss: {} bytes'.format( | 163 'Showing {:,} symbols ({:,} unique) with total pss: {} bytes'.format( |
| 154 len(group), group.CountUniqueSymbols(), int(total_size)), | 164 len(group), group.CountUniqueSymbols(), int(total_size)), |
| 155 '.text={:<10} .rodata={:<10} other={:<10} total={}'.format( | 165 '.text={:<10} .rodata={:<10} .data*={:<10} .bss={:<10} total={}'.format( |
| 156 _PrettySize(int(code_size)), _PrettySize(int(ro_size)), | 166 _PrettySize(int(code_size)), _PrettySize(int(ro_size)), |
| 157 _PrettySize(int(total_size - code_size - ro_size)), | 167 _PrettySize(int(data_size)), _PrettySize(int(bss_size)), |
| 158 _PrettySize(int(total_size))), | 168 _PrettySize(int(total_size))), |
| 159 'Number of object files: {}'.format(len(unique_paths)), | 169 'Number of object files: {}'.format(len(unique_paths)), |
| 160 '', | 170 '', |
| 161 'Index, Running Total, Section@Address, PSS', | 171 'Index, Running Total, Section@Address, PSS', |
| 162 '-' * 60 | 172 '-' * 60 |
| 163 ] | 173 ] |
| 164 children_desc = self._DescribeSymbolGroupChildren(group) | 174 children_desc = self._DescribeSymbolGroupChildren(group) |
| 165 return itertools.chain(header_desc, children_desc) | 175 return itertools.chain(header_desc, children_desc) |
| 166 | 176 |
| 167 def _DescribeSymbolDiff(self, diff): | 177 def _DescribeSymbolDiff(self, diff): |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 328 |
| 319 def GenerateLines(obj, verbose=False, recursive=False): | 329 def GenerateLines(obj, verbose=False, recursive=False): |
| 320 """Returns an iterable of lines (without \n) that describes |obj|.""" | 330 """Returns an iterable of lines (without \n) that describes |obj|.""" |
| 321 return Describer(verbose=verbose, recursive=recursive).GenerateLines(obj) | 331 return Describer(verbose=verbose, recursive=recursive).GenerateLines(obj) |
| 322 | 332 |
| 323 | 333 |
| 324 def WriteLines(lines, func): | 334 def WriteLines(lines, func): |
| 325 for l in lines: | 335 for l in lines: |
| 326 func(l) | 336 func(l) |
| 327 func('\n') | 337 func('\n') |
| OLD | NEW |