OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2017 The Chromium Authors. All rights reserved. | 2 # Copyright 2017 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Tool for finding the cause of binary size bloat. | 6 """Tool for finding the cause of binary size bloat. |
7 | 7 |
8 See //tools/binary_size/README.md for example usage. | 8 See //tools/binary_size/README.md for example usage. |
9 | 9 |
10 Note: this tool will perform gclient sync/git checkout on your local repo if | 10 Note: this tool will perform gclient sync/git checkout on your local repo if |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 """Prepare a binary size diff with ready to print results.""" | 70 """Prepare a binary size diff with ready to print results.""" |
71 raise NotImplementedError() | 71 raise NotImplementedError() |
72 | 72 |
73 def RunDiff(self, logfile, before_dir, after_dir): | 73 def RunDiff(self, logfile, before_dir, after_dir): |
74 logging.info('Creating: %s', self.name) | 74 logging.info('Creating: %s', self.name) |
75 self.ProduceDiff(before_dir, after_dir) | 75 self.ProduceDiff(before_dir, after_dir) |
76 self.AppendResults(logfile) | 76 self.AppendResults(logfile) |
77 | 77 |
78 | 78 |
79 class NativeDiff(BaseDiff): | 79 class NativeDiff(BaseDiff): |
80 _RE_SUMMARY = re.compile( | 80 _RE_SUMMARY = re.compile(r'Section Sizes .*?\n\n.*?(?=\n\n)', flags=re.DOTALL) |
81 r'.*(Section Sizes .*? object files added, \d+ removed).*', | |
82 flags=re.DOTALL) | |
83 _RE_SUMMARY_STAT = re.compile( | 81 _RE_SUMMARY_STAT = re.compile( |
84 r'Section Sizes \(Total=(?P<value>\d+) (?P<units>\w+)\)') | 82 r'Section Sizes \(Total=(?P<value>\d+) (?P<units>\w+)\)') |
85 _SUMMARY_STAT_NAME = 'Native Library Delta' | 83 _SUMMARY_STAT_NAME = 'Native Library Delta' |
86 | 84 |
87 def __init__(self, size_name, supersize_path): | 85 def __init__(self, size_name, supersize_path): |
88 self._size_name = size_name | 86 self._size_name = size_name |
89 self._supersize_path = supersize_path | 87 self._supersize_path = supersize_path |
90 self._diff = [] | 88 self._diff = [] |
91 super(NativeDiff, self).__init__('Native Diff') | 89 super(NativeDiff, self).__init__('Native Diff') |
92 | 90 |
93 @property | 91 @property |
94 def summary_stat(self): | 92 def summary_stat(self): |
95 m = NativeDiff._RE_SUMMARY_STAT.search(self._diff) | 93 m = NativeDiff._RE_SUMMARY_STAT.search(self._diff) |
96 if m: | 94 if m: |
97 return _DiffResult( | 95 return _DiffResult( |
98 NativeDiff._SUMMARY_STAT_NAME, m.group('value'), m.group('units')) | 96 NativeDiff._SUMMARY_STAT_NAME, m.group('value'), m.group('units')) |
99 return None | 97 return None |
100 | 98 |
101 def DetailedResults(self): | 99 def DetailedResults(self): |
102 return self._diff.splitlines() | 100 return self._diff.splitlines() |
103 | 101 |
104 def Summary(self): | 102 def Summary(self): |
105 return NativeDiff._RE_SUMMARY.match(self._diff).group(1) | 103 return NativeDiff._RE_SUMMARY.search(self._diff).group() |
106 | 104 |
107 def ProduceDiff(self, before_dir, after_dir): | 105 def ProduceDiff(self, before_dir, after_dir): |
108 before_size = os.path.join(before_dir, self._size_name) | 106 before_size = os.path.join(before_dir, self._size_name) |
109 after_size = os.path.join(after_dir, self._size_name) | 107 after_size = os.path.join(after_dir, self._size_name) |
110 cmd = [self._supersize_path, 'diff', before_size, after_size] | 108 cmd = [self._supersize_path, 'diff', before_size, after_size] |
111 self._diff = _RunCmd(cmd)[0].replace('{', '{{').replace('}', '}}') | 109 self._diff = _RunCmd(cmd)[0].replace('{', '{{').replace('}', '}}') |
112 | 110 |
113 | 111 |
114 class ResourceSizesDiff(BaseDiff): | 112 class ResourceSizesDiff(BaseDiff): |
115 _RESOURCE_SIZES_PATH = os.path.join( | 113 _RESOURCE_SIZES_PATH = os.path.join( |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 | 804 |
807 if i != 0: | 805 if i != 0: |
808 diff_mngr.MaybeDiff(i - 1, i) | 806 diff_mngr.MaybeDiff(i - 1, i) |
809 | 807 |
810 diff_mngr.Summarize() | 808 diff_mngr.Summarize() |
811 | 809 |
812 | 810 |
813 if __name__ == '__main__': | 811 if __name__ == '__main__': |
814 sys.exit(main()) | 812 sys.exit(main()) |
815 | 813 |
OLD | NEW |