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 json | 5 import json |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import shutil | 8 import shutil |
9 import sys | 9 import sys |
10 import tempfile | 10 import tempfile |
11 | 11 |
12 _SRC_DIR = os.path.abspath(os.path.join( | 12 _SRC_DIR = os.path.abspath(os.path.join( |
13 os.path.dirname(__file__), '..', '..', '..')) | 13 os.path.dirname(__file__), '..', '..', '..')) |
14 | 14 |
15 sys.path.append(os.path.join(_SRC_DIR, 'third_party', 'catapult', 'devil')) | 15 sys.path.append(os.path.join(_SRC_DIR, 'third_party', 'catapult', 'devil')) |
16 from devil.android import device_utils | 16 from devil.android import device_utils |
17 | 17 |
18 import chrome_cache | 18 import chrome_cache |
19 import controller | 19 import controller |
20 import devtools_monitor | 20 import devtools_monitor |
21 import device_setup | 21 import device_setup |
22 import loading_trace | 22 import loading_trace |
23 import sandwich_metrics | |
24 | 23 |
25 | 24 |
| 25 # Standard filenames in the sandwich runner's output directory. |
| 26 TRACE_FILENAME = 'trace.json' |
| 27 VIDEO_FILENAME = 'video.mp4' |
| 28 |
| 29 # List of selected trace event categories when running chrome. |
| 30 ADDITIONAL_CATEGORIES = ( |
| 31 'disabled-by-default-memory-infra',) # Used by _GetBrowserDumpEvents() |
| 32 |
26 _JOB_SEARCH_PATH = 'sandwich_jobs' | 33 _JOB_SEARCH_PATH = 'sandwich_jobs' |
27 | 34 |
28 # Devtools timeout of 1 minute to avoid websocket timeout on slow | 35 # Devtools timeout of 1 minute to avoid websocket timeout on slow |
29 # network condition. | 36 # network condition. |
30 _DEVTOOLS_TIMEOUT = 60 | 37 _DEVTOOLS_TIMEOUT = 60 |
31 | 38 |
32 | 39 |
33 def _ReadUrlsFromJobDescription(job_name): | 40 def _ReadUrlsFromJobDescription(job_name): |
34 """Retrieves the list of URLs associated with the job name.""" | 41 """Retrieves the list of URLs associated with the job name.""" |
35 try: | 42 try: |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 os.makedirs(run_path) | 197 os.makedirs(run_path) |
191 self._chrome_ctl.SetNetworkEmulation( | 198 self._chrome_ctl.SetNetworkEmulation( |
192 self._GetEmulatorNetworkCondition('browser')) | 199 self._GetEmulatorNetworkCondition('browser')) |
193 # TODO(gabadie): add a way to avoid recording a trace. | 200 # TODO(gabadie): add a way to avoid recording a trace. |
194 with self._chrome_ctl.Open() as connection: | 201 with self._chrome_ctl.Open() as connection: |
195 if clear_cache: | 202 if clear_cache: |
196 connection.ClearCache() | 203 connection.ClearCache() |
197 if run_path is not None and self.record_video: | 204 if run_path is not None and self.record_video: |
198 device = self._chrome_ctl.GetDevice() | 205 device = self._chrome_ctl.GetDevice() |
199 assert device, 'Can only record video on a remote device.' | 206 assert device, 'Can only record video on a remote device.' |
200 video_recording_path = os.path.join(run_path, 'video.mp4') | 207 video_recording_path = os.path.join(run_path, VIDEO_FILENAME) |
201 with device_setup.RemoteSpeedIndexRecorder(device, connection, | 208 with device_setup.RemoteSpeedIndexRecorder(device, connection, |
202 video_recording_path): | 209 video_recording_path): |
203 trace = loading_trace.LoadingTrace.RecordUrlNavigation( | 210 trace = loading_trace.LoadingTrace.RecordUrlNavigation( |
204 url=url, | 211 url=url, |
205 connection=connection, | 212 connection=connection, |
206 chrome_metadata=self._chrome_ctl.ChromeMetadata(), | 213 chrome_metadata=self._chrome_ctl.ChromeMetadata(), |
207 additional_categories=sandwich_metrics.ADDITIONAL_CATEGORIES, | 214 additional_categories=ADDITIONAL_CATEGORIES, |
208 timeout_seconds=_DEVTOOLS_TIMEOUT) | 215 timeout_seconds=_DEVTOOLS_TIMEOUT) |
209 else: | 216 else: |
210 trace = loading_trace.LoadingTrace.RecordUrlNavigation( | 217 trace = loading_trace.LoadingTrace.RecordUrlNavigation( |
211 url=url, | 218 url=url, |
212 connection=connection, | 219 connection=connection, |
213 chrome_metadata=self._chrome_ctl.ChromeMetadata(), | 220 chrome_metadata=self._chrome_ctl.ChromeMetadata(), |
214 additional_categories=sandwich_metrics.ADDITIONAL_CATEGORIES, | 221 additional_categories=ADDITIONAL_CATEGORIES, |
215 timeout_seconds=_DEVTOOLS_TIMEOUT) | 222 timeout_seconds=_DEVTOOLS_TIMEOUT) |
216 if run_path is not None: | 223 if run_path is not None: |
217 trace_path = os.path.join(run_path, 'trace.json') | 224 trace_path = os.path.join(run_path, TRACE_FILENAME) |
218 trace.ToJsonFile(trace_path) | 225 trace.ToJsonFile(trace_path) |
219 | 226 |
220 def _RunUrl(self, url, run_id): | 227 def _RunUrl(self, url, run_id): |
221 clear_cache = False | 228 clear_cache = False |
222 if self.cache_operation == 'clear': | 229 if self.cache_operation == 'clear': |
223 clear_cache = True | 230 clear_cache = True |
224 elif self.cache_operation == 'push': | 231 elif self.cache_operation == 'push': |
225 self._chrome_ctl.PushBrowserCache(self._local_cache_directory_path) | 232 self._chrome_ctl.PushBrowserCache(self._local_cache_directory_path) |
226 elif self.cache_operation == 'reload': | 233 elif self.cache_operation == 'reload': |
227 self._RunNavigation(url, clear_cache=True) | 234 self._RunNavigation(url, clear_cache=True) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 278 |
272 if self._local_cache_directory_path: | 279 if self._local_cache_directory_path: |
273 shutil.rmtree(self._local_cache_directory_path) | 280 shutil.rmtree(self._local_cache_directory_path) |
274 self._local_cache_directory_path = None | 281 self._local_cache_directory_path = None |
275 if self.cache_operation == 'save': | 282 if self.cache_operation == 'save': |
276 self._PullCacheFromDevice() | 283 self._PullCacheFromDevice() |
277 if self.trace_output_directory: | 284 if self.trace_output_directory: |
278 self._SaveRunInfos(ran_urls) | 285 self._SaveRunInfos(ran_urls) |
279 | 286 |
280 self._chrome_ctl = None | 287 self._chrome_ctl = None |
OLD | NEW |