OLD | NEW |
---|---|
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 logging | 5 import logging |
6 import os | 6 import os |
7 import shutil | 7 import shutil |
8 import sys | 8 import sys |
9 import tempfile | 9 import tempfile |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... | |
26 VIDEO_FILENAME = 'video.mp4' | 26 VIDEO_FILENAME = 'video.mp4' |
27 WPR_LOG_FILENAME = 'wpr.log' | 27 WPR_LOG_FILENAME = 'wpr.log' |
28 | 28 |
29 # Memory dump category used to get memory metrics. | 29 # Memory dump category used to get memory metrics. |
30 MEMORY_DUMP_CATEGORY = 'disabled-by-default-memory-infra' | 30 MEMORY_DUMP_CATEGORY = 'disabled-by-default-memory-infra' |
31 | 31 |
32 # Devtools timeout of 1 minute to avoid websocket timeout on slow | 32 # Devtools timeout of 1 minute to avoid websocket timeout on slow |
33 # network condition. | 33 # network condition. |
34 _DEVTOOLS_TIMEOUT = 60 | 34 _DEVTOOLS_TIMEOUT = 60 |
35 | 35 |
36 # Categories to enable or disable for all traces collected. Disabled categories | |
37 # are prefixed with '-'. | |
38 _TRACING_CATEGORIES = [ | |
39 'blink', | |
40 'blink.net', | |
41 'blink.user_timing', | |
42 'devtools.timeline', | |
43 'java', | |
44 'toplevel', | |
45 'v8', | |
46 '-cc', # A lot of unnecessary events are enabled by default in "cc". | |
47 ] | |
gabadie
2016/06/06 16:17:30
We might probably be able to get rid of devtools.t
pasko
2016/06/06 17:30:52
If we remove toplevel, we would not be able to rea
gabadie
2016/06/06 17:37:10
Nice.
| |
36 | 48 |
37 def _CleanArtefactsFromPastRuns(output_directories_path): | 49 def _CleanArtefactsFromPastRuns(output_directories_path): |
38 """Cleans artifacts generated from past run in the output directory. | 50 """Cleans artifacts generated from past run in the output directory. |
39 | 51 |
40 Args: | 52 Args: |
41 output_directories_path: The output directory path where to clean the | 53 output_directories_path: The output directory path where to clean the |
42 previous traces. | 54 previous traces. |
43 """ | 55 """ |
44 for dirname in os.listdir(output_directories_path): | 56 for dirname in os.listdir(output_directories_path): |
45 directory_path = os.path.join(output_directories_path, dirname) | 57 directory_path = os.path.join(output_directories_path, dirname) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 run_id: Id of the run in the output directory. If it is None, then no | 151 run_id: Id of the run in the output directory. If it is None, then no |
140 trace or video will be saved. | 152 trace or video will be saved. |
141 """ | 153 """ |
142 run_path = None | 154 run_path = None |
143 if self.output_dir is not None and run_id is not None: | 155 if self.output_dir is not None and run_id is not None: |
144 run_path = os.path.join(self.output_dir, str(run_id)) | 156 run_path = os.path.join(self.output_dir, str(run_id)) |
145 if not os.path.isdir(run_path): | 157 if not os.path.isdir(run_path): |
146 os.makedirs(run_path) | 158 os.makedirs(run_path) |
147 self._chrome_ctl.SetNetworkEmulation( | 159 self._chrome_ctl.SetNetworkEmulation( |
148 self._GetEmulatorNetworkCondition('browser')) | 160 self._GetEmulatorNetworkCondition('browser')) |
149 additional_categories = [] | 161 categories = _TRACING_CATEGORIES |
150 if self.record_memory_dumps: | 162 if self.record_memory_dumps: |
151 additional_categories = [MEMORY_DUMP_CATEGORY] | 163 categories += [MEMORY_DUMP_CATEGORY] |
152 # TODO(gabadie): add a way to avoid recording a trace. | 164 # TODO(gabadie): add a way to avoid recording a trace. |
153 with self._chrome_ctl.Open() as connection: | 165 with self._chrome_ctl.Open() as connection: |
154 if clear_cache: | 166 if clear_cache: |
155 connection.ClearCache() | 167 connection.ClearCache() |
168 | |
169 # Binds all parameters of RecordUrlNavigation() to avoid repetition. | |
170 def RecordTrace(): | |
171 return loading_trace.LoadingTrace.RecordUrlNavigation( | |
172 url=self.url, | |
173 connection=connection, | |
174 chrome_metadata=self._chrome_ctl.ChromeMetadata(), | |
175 categories=categories, | |
176 timeout_seconds=_DEVTOOLS_TIMEOUT) | |
177 | |
156 if run_path is not None and self.record_video: | 178 if run_path is not None and self.record_video: |
157 device = self._chrome_ctl.GetDevice() | 179 device = self._chrome_ctl.GetDevice() |
158 if device is None: | 180 if device is None: |
159 raise RuntimeError('Can only record video on a remote device.') | 181 raise RuntimeError('Can only record video on a remote device.') |
160 video_recording_path = os.path.join(run_path, VIDEO_FILENAME) | 182 video_recording_path = os.path.join(run_path, VIDEO_FILENAME) |
161 with device_setup.RemoteSpeedIndexRecorder(device, connection, | 183 with device_setup.RemoteSpeedIndexRecorder(device, connection, |
162 video_recording_path): | 184 video_recording_path): |
163 trace = loading_trace.LoadingTrace.RecordUrlNavigation( | 185 trace = RecordTrace() |
164 url=self.url, | |
165 connection=connection, | |
166 chrome_metadata=self._chrome_ctl.ChromeMetadata(), | |
167 additional_categories=additional_categories, | |
168 timeout_seconds=_DEVTOOLS_TIMEOUT) | |
169 else: | 186 else: |
170 trace = loading_trace.LoadingTrace.RecordUrlNavigation( | 187 trace = RecordTrace() |
171 url=self.url, | |
172 connection=connection, | |
173 chrome_metadata=self._chrome_ctl.ChromeMetadata(), | |
174 additional_categories=additional_categories, | |
175 timeout_seconds=_DEVTOOLS_TIMEOUT) | |
176 if run_path is not None: | 188 if run_path is not None: |
177 trace_path = os.path.join(run_path, TRACE_FILENAME) | 189 trace_path = os.path.join(run_path, TRACE_FILENAME) |
178 trace.ToJsonFile(trace_path) | 190 trace.ToJsonFile(trace_path) |
179 | 191 |
180 def _RunUrl(self, run_id): | 192 def _RunUrl(self, run_id): |
181 for attempt_id in xrange(self._ATTEMPT_COUNT): | 193 for attempt_id in xrange(self._ATTEMPT_COUNT): |
182 try: | 194 try: |
183 self._chrome_ctl.ResetBrowserState() | 195 self._chrome_ctl.ResetBrowserState() |
184 clear_cache = False | 196 clear_cache = False |
185 if self.cache_operation == CacheOperation.CLEAR: | 197 if self.cache_operation == CacheOperation.CLEAR: |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 if not os.path.isdir(repeat_dir): | 280 if not os.path.isdir(repeat_dir): |
269 continue | 281 continue |
270 try: | 282 try: |
271 repeat_id = int(node_name) | 283 repeat_id = int(node_name) |
272 except ValueError: | 284 except ValueError: |
273 continue | 285 continue |
274 yield repeat_id, repeat_dir | 286 yield repeat_id, repeat_dir |
275 repeated_run_count += 1 | 287 repeated_run_count += 1 |
276 assert repeated_run_count > 0, ('Error: not a sandwich runner output ' | 288 assert repeated_run_count > 0, ('Error: not a sandwich runner output ' |
277 'directory: {}').format(runner_output_dir) | 289 'directory: {}').format(runner_output_dir) |
OLD | NEW |