| 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 CATEGORIES = [ |
| 31 # Need blink network trace events for prefetch_view.PrefetchSimulationView |
| 32 'blink.net', |
| 33 |
| 34 # Need to get mark trace events for _GetWebPageTrackedEvents() |
| 35 'blink.user_timing', |
| 36 |
| 37 # Need to memory dump trace event for _GetBrowserDumpEvents() |
| 38 'disabled-by-default-memory-infra'] |
| 39 |
| 26 _JOB_SEARCH_PATH = 'sandwich_jobs' | 40 _JOB_SEARCH_PATH = 'sandwich_jobs' |
| 27 | 41 |
| 28 # Devtools timeout of 1 minute to avoid websocket timeout on slow | 42 # Devtools timeout of 1 minute to avoid websocket timeout on slow |
| 29 # network condition. | 43 # network condition. |
| 30 _DEVTOOLS_TIMEOUT = 60 | 44 _DEVTOOLS_TIMEOUT = 60 |
| 31 | 45 |
| 32 | 46 |
| 33 def _ReadUrlsFromJobDescription(job_name): | 47 def _ReadUrlsFromJobDescription(job_name): |
| 34 """Retrieves the list of URLs associated with the job name.""" | 48 """Retrieves the list of URLs associated with the job name.""" |
| 35 try: | 49 try: |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 os.makedirs(run_path) | 204 os.makedirs(run_path) |
| 191 self._chrome_ctl.SetNetworkEmulation( | 205 self._chrome_ctl.SetNetworkEmulation( |
| 192 self._GetEmulatorNetworkCondition('browser')) | 206 self._GetEmulatorNetworkCondition('browser')) |
| 193 # TODO(gabadie): add a way to avoid recording a trace. | 207 # TODO(gabadie): add a way to avoid recording a trace. |
| 194 with self._chrome_ctl.Open() as connection: | 208 with self._chrome_ctl.Open() as connection: |
| 195 if clear_cache: | 209 if clear_cache: |
| 196 connection.ClearCache() | 210 connection.ClearCache() |
| 197 if run_path is not None and self.record_video: | 211 if run_path is not None and self.record_video: |
| 198 device = self._chrome_ctl.GetDevice() | 212 device = self._chrome_ctl.GetDevice() |
| 199 assert device, 'Can only record video on a remote device.' | 213 assert device, 'Can only record video on a remote device.' |
| 200 video_recording_path = os.path.join(run_path, 'video.mp4') | 214 video_recording_path = os.path.join(run_path, VIDEO_FILENAME) |
| 201 with device_setup.RemoteSpeedIndexRecorder(device, connection, | 215 with device_setup.RemoteSpeedIndexRecorder(device, connection, |
| 202 video_recording_path): | 216 video_recording_path): |
| 203 trace = loading_trace.LoadingTrace.RecordUrlNavigation( | 217 trace = loading_trace.LoadingTrace.RecordUrlNavigation( |
| 204 url=url, | 218 url=url, |
| 205 connection=connection, | 219 connection=connection, |
| 206 chrome_metadata=self._chrome_ctl.ChromeMetadata(), | 220 chrome_metadata=self._chrome_ctl.ChromeMetadata(), |
| 207 categories=sandwich_metrics.CATEGORIES, | 221 categories=CATEGORIES, |
| 208 timeout_seconds=_DEVTOOLS_TIMEOUT) | 222 timeout_seconds=_DEVTOOLS_TIMEOUT) |
| 209 else: | 223 else: |
| 210 trace = loading_trace.LoadingTrace.RecordUrlNavigation( | 224 trace = loading_trace.LoadingTrace.RecordUrlNavigation( |
| 211 url=url, | 225 url=url, |
| 212 connection=connection, | 226 connection=connection, |
| 213 chrome_metadata=self._chrome_ctl.ChromeMetadata(), | 227 chrome_metadata=self._chrome_ctl.ChromeMetadata(), |
| 214 categories=sandwich_metrics.CATEGORIES, | 228 categories=CATEGORIES, |
| 215 timeout_seconds=_DEVTOOLS_TIMEOUT) | 229 timeout_seconds=_DEVTOOLS_TIMEOUT) |
| 216 if run_path is not None: | 230 if run_path is not None: |
| 217 trace_path = os.path.join(run_path, 'trace.json') | 231 trace_path = os.path.join(run_path, TRACE_FILENAME) |
| 218 trace.ToJsonFile(trace_path) | 232 trace.ToJsonFile(trace_path) |
| 219 | 233 |
| 220 def _RunUrl(self, url, run_id): | 234 def _RunUrl(self, url, run_id): |
| 221 clear_cache = False | 235 clear_cache = False |
| 222 if self.cache_operation == 'clear': | 236 if self.cache_operation == 'clear': |
| 223 clear_cache = True | 237 clear_cache = True |
| 224 elif self.cache_operation == 'push': | 238 elif self.cache_operation == 'push': |
| 225 self._chrome_ctl.PushBrowserCache(self._local_cache_directory_path) | 239 self._chrome_ctl.PushBrowserCache(self._local_cache_directory_path) |
| 226 elif self.cache_operation == 'reload': | 240 elif self.cache_operation == 'reload': |
| 227 self._RunNavigation(url, clear_cache=True) | 241 self._RunNavigation(url, clear_cache=True) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 285 |
| 272 if self._local_cache_directory_path: | 286 if self._local_cache_directory_path: |
| 273 shutil.rmtree(self._local_cache_directory_path) | 287 shutil.rmtree(self._local_cache_directory_path) |
| 274 self._local_cache_directory_path = None | 288 self._local_cache_directory_path = None |
| 275 if self.cache_operation == 'save': | 289 if self.cache_operation == 'save': |
| 276 self._PullCacheFromDevice() | 290 self._PullCacheFromDevice() |
| 277 if self.trace_output_directory: | 291 if self.trace_output_directory: |
| 278 self._SaveRunInfos(ran_urls) | 292 self._SaveRunInfos(ran_urls) |
| 279 | 293 |
| 280 self._chrome_ctl = None | 294 self._chrome_ctl = None |
| OLD | NEW |