| OLD | NEW |
| (Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Contains a set of Chrome-specific size queries.""" |
| 6 |
| 7 import logging |
| 8 import models |
| 9 |
| 10 |
| 11 class _Grouper(object): |
| 12 def __init__(self): |
| 13 self.groups = [] |
| 14 |
| 15 def Add(self, name, group): |
| 16 logging.debug('Computed %s', name) |
| 17 group.name = name |
| 18 self.groups.append(group) |
| 19 return group.Inverted() |
| 20 |
| 21 def Finalize(self, remaining): |
| 22 self.groups.sort(key=lambda s:(s.name.startswith('Other'), -s.pss)) |
| 23 if remaining: |
| 24 stars = remaining.Filter(lambda s: s.name.startswith('*')) |
| 25 if stars: |
| 26 remaining = stars.Inverted() |
| 27 stars.name = '** Merged Symbols' |
| 28 self.groups.append(stars) |
| 29 remaining.name = 'Other' |
| 30 self.groups.append(remaining) |
| 31 |
| 32 logging.debug('Finalized') |
| 33 return models.SymbolGroup(self.groups, is_sorted=True) |
| 34 |
| 35 |
| 36 def _CategorizeByChromeComponent(symbols): |
| 37 g = _Grouper() |
| 38 |
| 39 # Put things that filter out a lot of symbols at the beginning where possible |
| 40 # to optimize speed. |
| 41 symbols = g.Add('WebRTC', symbols.WhereMatches(r'(?i)webrtc')) |
| 42 symbols = g.Add('Skia', symbols.Filter(lambda s: 'skia/' in s.source_path)) |
| 43 symbols = g.Add('V8', symbols.Filter( |
| 44 lambda s: s.source_path.startswith('v8/'))) |
| 45 |
| 46 # Next, put non-regex queries, since they're a bit faster. |
| 47 symbols = g.Add('ICU', symbols.Filter(lambda s: '/icu/' in s.source_path)) |
| 48 symbols = g.Add('Prefetch', symbols.Filter( |
| 49 lambda s: 'resource_prefetch' in s.source_path)) |
| 50 symbols = g.Add('Password Manager', symbols.Filter( |
| 51 lambda s: 'password_manager' in s.source_path)) |
| 52 symbols = g.Add('Internals Pages', symbols.Filter( |
| 53 lambda s: '_internals' in s.source_path)) |
| 54 symbols = g.Add('Autofill', symbols.WhereSourcePathMatches(r'(?i)autofill')) |
| 55 symbols = g.Add('WebGL', symbols.WhereMatches(r'(?i)webgl')) |
| 56 symbols = g.Add('WebBluetooth', symbols.WhereMatches(r'(?i)bluetooth')) |
| 57 symbols = g.Add('WebUSB', symbols.WhereMatches(r'(?i)webusb|(\b|_)usb(\b|_)')) |
| 58 symbols = g.Add('WebVR', symbols.WhereMatches( |
| 59 r'{{_gvr_}}|{{_cwebvr_}}|{{_vr_}}')) |
| 60 symbols = g.Add('FileSystem', symbols.WhereSourcePathMatches( |
| 61 r'content/.*/fileapi|WebKit/.*/filesystem')) |
| 62 symbols = g.Add('WebCrypto', symbols.WhereMatches(r'(?i)webcrypto')) |
| 63 symbols = g.Add('Printing', symbols.WhereMatches(r'printing')) |
| 64 symbols = g.Add('Cast', symbols.WhereSourcePathMatches( |
| 65 r'(?i)(\b|_)cast(\b|_)')) |
| 66 symbols = g.Add('Media Source', symbols.WhereMatches( |
| 67 r'(?i)mediasource|blink::.*TrackDefault|blink::.*SourceBuffer')) |
| 68 |
| 69 # XSLT must come before libxml. |
| 70 symbols = g.Add('XSLT', symbols.WhereMatches(r'(?i)xslt')) |
| 71 symbols = g.Add('libxml', symbols.Filter( |
| 72 lambda s: 'libxml' in s.source_path)) |
| 73 |
| 74 # These have some overlap with above, so need to come afterwards. |
| 75 blink_syms = symbols.WhereSourcePathMatches(r'\b(blink|WebKit)\b') |
| 76 symbols = blink_syms.Inverted() |
| 77 blink_generated = blink_syms.WhereSourceIsGenerated() |
| 78 g.Add('Blink (generated)', blink_generated) |
| 79 g.Add('Blink (non-generated)', blink_generated.Inverted()) |
| 80 |
| 81 symbols = g.Add('Codecs', symbols.WhereSourcePathMatches( |
| 82 r'^third_party/(libweb[mp]|libpng|libjpeg_turbo|opus|ffmpeg|libvpx)/')) |
| 83 symbols = g.Add('Other Third-Party', symbols.Filter( |
| 84 lambda s: 'third_party' in s.source_path)) |
| 85 |
| 86 return g.Finalize(symbols) |
| 87 |
| 88 |
| 89 def _CategorizeGenerated(symbols): |
| 90 g = _Grouper() |
| 91 |
| 92 # JNI is generated into .h files then #included, so the symbols don't actaully |
| 93 # appear as "SourceIsGenerated". |
| 94 # Note: String literals within symbols like "kBaseRegisteredMethods" are not |
| 95 # being accounted for here because they end up within "** merge strings". |
| 96 # This could be fixed by assigning them all to proper variables rather |
| 97 # than having them be inline. |
| 98 symbols = g.Add('RegisterJNI', symbols.WhereFullNameMatches( |
| 99 r'Register.*JNIEnv\*\)|RegisteredMethods$')) |
| 100 |
| 101 symbols = symbols.WhereSourceIsGenerated() |
| 102 symbols = g.Add('Protocol Buffers', symbols.Filter(lambda s: ( |
| 103 '/protobuf/' in s.object_path or |
| 104 s.object_path.endswith('.pbzero.o') or |
| 105 s.object_path.endswith('.pb.o')))) |
| 106 symbols = g.Add('Mojo', symbols.Filter(lambda s: ( |
| 107 '.mojom' in s.source_path or # Blink uses .mojom-blink.cc |
| 108 s.source_path.startswith('mojo/') or |
| 109 s.name.startswith('mojo::')))) |
| 110 symbols = g.Add('DevTools', symbols.WhereSourcePathMatches( |
| 111 r'\b(?:protocol|devtools)\b')) |
| 112 symbols = g.Add('Blink (bindings)', symbols.Filter(lambda s: ( |
| 113 'blink/bindings' in s.source_path or |
| 114 ('WebKit/' in s.object_path and '/bindings/' in s.object_path)))) |
| 115 symbols = g.Add('Blink (IDL)', symbols.Filter(lambda s: ( |
| 116 'WebKit/Source/core' in s.object_path))) |
| 117 symbols = g.Add('Blink (Other)', symbols.Filter(lambda s: ( |
| 118 'WebKit' in s.object_path or 'blink/' in s.object_path))) |
| 119 |
| 120 return g.Finalize(symbols) |
| 121 |
| 122 |
| 123 class CannedQueries(object): |
| 124 """A set of pre-written queries.""" |
| 125 |
| 126 def __init__(self, size_infos): |
| 127 self._size_infos = size_infos |
| 128 |
| 129 def _SymbolsArg(self, arg): |
| 130 arg = arg if arg is not None else self._size_infos[-1] |
| 131 if isinstance(arg, models.SizeInfo): |
| 132 arg = arg.symbols |
| 133 return arg |
| 134 |
| 135 def CategorizeGenerated(self, symbols=None): |
| 136 """Categorizes symbols that come from generated source files.""" |
| 137 return _CategorizeGenerated(self._SymbolsArg(symbols)) |
| 138 |
| 139 def CategorizeByChromeComponent(self, symbols=None): |
| 140 """Groups symbols by component using predefined queries.""" |
| 141 return _CategorizeByChromeComponent(self._SymbolsArg(symbols)) |
| OLD | NEW |