OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 | 4 |
5 import json | 5 import json |
| 6 import optparse |
6 import os | 7 import os |
7 import py_utils | 8 import py_utils |
8 import re | 9 import re |
9 | 10 |
10 from devil.android import device_errors | 11 from devil.android import device_errors |
11 from devil.android.sdk import intent | 12 from devil.android.sdk import intent |
12 | 13 |
13 from systrace import trace_result | 14 from systrace import trace_result |
14 from systrace import tracing_agents | 15 from systrace import tracing_agents |
15 | 16 |
16 | 17 |
| 18 _DEFAULT_CHROME_CATEGORIES = '_DEFAULT_CHROME_CATEGORIES' |
17 _HEAP_PROFILE_MMAP_PROPERTY = 'heapprof.mmap' | 19 _HEAP_PROFILE_MMAP_PROPERTY = 'heapprof.mmap' |
18 | 20 |
19 | 21 |
20 class ChromeTracingAgent(tracing_agents.TracingAgent): | 22 class ChromeTracingAgent(tracing_agents.TracingAgent): |
21 def __init__(self, device, package_info, | 23 def __init__(self, device, package_info, ring_buffer, trace_memory=False): |
22 categories, ring_buffer, trace_memory=False): | |
23 tracing_agents.TracingAgent.__init__(self) | 24 tracing_agents.TracingAgent.__init__(self) |
24 self._device = device | 25 self._device = device |
25 self._package_info = package_info | 26 self._package_info = package_info |
26 self._categories = categories | |
27 self._ring_buffer = ring_buffer | 27 self._ring_buffer = ring_buffer |
28 self._logcat_monitor = self._device.GetLogcatMonitor() | 28 self._logcat_monitor = self._device.GetLogcatMonitor() |
29 self._trace_file = None | 29 self._trace_file = None |
30 self._trace_memory = trace_memory | 30 self._trace_memory = trace_memory |
31 self._is_tracing = False | 31 self._is_tracing = False |
32 self._trace_start_re = \ | 32 self._trace_start_re = \ |
33 re.compile(r'Logging performance trace to file') | 33 re.compile(r'Logging performance trace to file') |
34 self._trace_finish_re = \ | 34 self._trace_finish_re = \ |
35 re.compile(r'Profiler finished[.] Results are in (.*)[.]') | 35 re.compile(r'Profiler finished[.] Results are in (.*)[.]') |
| 36 self._categories = None |
36 | 37 |
37 def __repr__(self): | 38 def __repr__(self): |
38 return 'chrome trace' | 39 return 'chrome trace' |
39 | 40 |
40 @staticmethod | 41 @staticmethod |
41 def GetCategories(device, package_info): | 42 def GetCategories(device, package_info): |
42 with device.GetLogcatMonitor() as logmon: | 43 with device.GetLogcatMonitor() as logmon: |
43 device.BroadcastIntent(intent.Intent( | 44 device.BroadcastIntent(intent.Intent( |
44 action='%s.GPU_PROFILER_LIST_CATEGORIES' % package_info.package)) | 45 action='%s.GPU_PROFILER_LIST_CATEGORIES' % package_info.package)) |
45 try: | 46 try: |
46 json_category_list = logmon.WaitFor( | 47 json_category_list = logmon.WaitFor( |
47 re.compile(r'{"traceCategoriesList(.*)'), timeout=5).group(0) | 48 re.compile(r'{"traceCategoriesList(.*)'), timeout=5).group(0) |
48 except device_errors.CommandTimeoutError: | 49 except device_errors.CommandTimeoutError: |
49 raise RuntimeError('Performance trace category list marker not found. ' | 50 raise RuntimeError('Performance trace category list marker not found. ' |
50 'Is the correct version of the browser running?') | 51 'Is the correct version of the browser running?') |
51 | 52 |
52 record_categories = set() | 53 record_categories = set() |
53 disabled_by_default_categories = set() | 54 disabled_by_default_categories = set() |
54 json_data = json.loads(json_category_list)['traceCategoriesList'] | 55 json_data = json.loads(json_category_list)['traceCategoriesList'] |
55 for item in json_data: | 56 for item in json_data: |
56 for category in item.split(','): | 57 for category in item.split(','): |
57 if category.startswith('disabled-by-default'): | 58 if category.startswith('disabled-by-default'): |
58 disabled_by_default_categories.add(category) | 59 disabled_by_default_categories.add(category) |
59 else: | 60 else: |
60 record_categories.add(category) | 61 record_categories.add(category) |
61 | 62 |
62 return list(record_categories), list(disabled_by_default_categories) | 63 return list(record_categories), list(disabled_by_default_categories) |
63 | 64 |
64 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) | 65 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) |
65 def StartAgentTracing(self, options, categories, timeout=None): | 66 def StartAgentTracing(self, config, timeout=None): |
| 67 self._categories = _ComputeChromeCategories(config) |
66 self._logcat_monitor.Start() | 68 self._logcat_monitor.Start() |
67 start_extras = {'categories': ','.join(self._categories)} | 69 start_extras = {'categories': ','.join(self._categories)} |
68 if self._ring_buffer: | 70 if self._ring_buffer: |
69 start_extras['continuous'] = None | 71 start_extras['continuous'] = None |
70 self._device.BroadcastIntent(intent.Intent( | 72 self._device.BroadcastIntent(intent.Intent( |
71 action='%s.GPU_PROFILER_START' % self._package_info.package, | 73 action='%s.GPU_PROFILER_START' % self._package_info.package, |
72 extras=start_extras)) | 74 extras=start_extras)) |
73 | 75 |
74 if self._trace_memory: | 76 if self._trace_memory: |
75 self._device.EnableRoot() | 77 self._device.EnableRoot() |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 'the browser? (Android Settings -> Apps -> [the browser app] -> ' | 120 'the browser? (Android Settings -> Apps -> [the browser app] -> ' |
119 'Permissions -> Storage)') | 121 'Permissions -> Storage)') |
120 return host_file | 122 return host_file |
121 | 123 |
122 def SupportsExplicitClockSync(self): | 124 def SupportsExplicitClockSync(self): |
123 return False | 125 return False |
124 | 126 |
125 def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback): | 127 def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback): |
126 assert self.SupportsExplicitClockSync(), ('Clock sync marker cannot be ' | 128 assert self.SupportsExplicitClockSync(), ('Clock sync marker cannot be ' |
127 'recorded since explicit clock sync is not supported.') | 129 'recorded since explicit clock sync is not supported.') |
| 130 |
| 131 |
| 132 class ChromeConfig(tracing_agents.TracingConfig): |
| 133 def __init__(self, chrome_categories, trace_cc, trace_frame_viewer, |
| 134 trace_ubercompositor, trace_gpu, trace_flow, trace_memory, |
| 135 trace_scheduler): |
| 136 tracing_agents.TracingConfig.__init__(self) |
| 137 self.chrome_categories = chrome_categories |
| 138 self.trace_cc = trace_cc |
| 139 self.trace_frame_viewer = trace_frame_viewer |
| 140 self.trace_ubercompositor = trace_ubercompositor |
| 141 self.trace_gpu = trace_gpu |
| 142 self.trace_flow = trace_flow |
| 143 self.trace_memory = trace_memory |
| 144 self.trace_scheduler = trace_scheduler |
| 145 |
| 146 |
| 147 def add_options(parser): |
| 148 chrome_opts = optparse.OptionGroup(parser, 'Chrome tracing options') |
| 149 chrome_opts.add_option('-c', '--categories', help='Select Chrome tracing ' |
| 150 'categories with comma-delimited wildcards, ' |
| 151 'e.g., "*", "cat1*,-cat1a". Omit this option to trace ' |
| 152 'Chrome\'s default categories. Chrome tracing can be ' |
| 153 'disabled with "--categories=\'\'". Use "list" to ' |
| 154 'see the available categories.', |
| 155 metavar='CHROME_CATEGORIES', dest='chrome_categories', |
| 156 default=_DEFAULT_CHROME_CATEGORIES) |
| 157 chrome_opts.add_option('--trace-cc', |
| 158 help='Deprecated, use --trace-frame-viewer.', |
| 159 action='store_true') |
| 160 chrome_opts.add_option('--trace-frame-viewer', |
| 161 help='Enable enough trace categories for ' |
| 162 'compositor frame viewing.', action='store_true') |
| 163 chrome_opts.add_option('--trace-ubercompositor', |
| 164 help='Enable enough trace categories for ' |
| 165 'ubercompositor frame data.', action='store_true') |
| 166 chrome_opts.add_option('--trace-gpu', help='Enable extra trace categories ' |
| 167 'for GPU data.', action='store_true') |
| 168 chrome_opts.add_option('--trace-flow', help='Enable extra trace categories ' |
| 169 'for IPC message flows.', action='store_true') |
| 170 chrome_opts.add_option('--trace-memory', help='Enable extra trace categories ' |
| 171 'for memory profile. (tcmalloc required)', |
| 172 action='store_true') |
| 173 chrome_opts.add_option('--trace-scheduler', help='Enable extra trace ' |
| 174 'categories for scheduler state', |
| 175 action='store_true') |
| 176 return chrome_opts |
| 177 |
| 178 def get_config(options): |
| 179 return ChromeConfig(options.chrome_categories, options.trace_cc, |
| 180 options.trace_frame_viewer, options.trace_ubercompositor, |
| 181 options.trace_gpu, options.trace_flow, |
| 182 options.trace_memory, options.trace_scheduler) |
| 183 |
| 184 def _ComputeChromeCategories(config): |
| 185 categories = [] |
| 186 if config.trace_frame_viewer: |
| 187 categories.append('disabled-by-default-cc.debug') |
| 188 if config.trace_ubercompositor: |
| 189 categories.append('disabled-by-default-cc.debug*') |
| 190 if config.trace_gpu: |
| 191 categories.append('disabled-by-default-gpu.debug*') |
| 192 if config.trace_flow: |
| 193 categories.append('disabled-by-default-toplevel.flow') |
| 194 if config.trace_memory: |
| 195 categories.append('disabled-by-default-memory') |
| 196 if config.trace_scheduler: |
| 197 categories.append('disabled-by-default-blink.scheduler') |
| 198 categories.append('disabled-by-default-cc.debug.scheduler') |
| 199 categories.append('disabled-by-default-renderer.scheduler') |
| 200 if config.chrome_categories: |
| 201 categories += config.chrome_categories.split(',') |
| 202 return categories |
OLD | NEW |