Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: tools/android/loading/sandwich_runner.py

Issue 1925803003: sandwich: Make speed-index and memory measurement optional from run-all (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses Egor's nit Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23
24 24
25 # Standard filenames in the sandwich runner's output directory. 25 # Standard filenames in the sandwich runner's output directory.
26 TRACE_FILENAME = 'trace.json' 26 TRACE_FILENAME = 'trace.json'
27 VIDEO_FILENAME = 'video.mp4' 27 VIDEO_FILENAME = 'video.mp4'
28 28
29 # List of selected trace event categories when running chrome. 29 # Memory dump category used to get memory metrics.
30 ADDITIONAL_CATEGORIES = ( 30 MEMORY_DUMP_CATEGORY = 'disabled-by-default-memory-infra'
31 'disabled-by-default-memory-infra',) # Used by _GetBrowserDumpEvents()
32 31
33 _JOB_SEARCH_PATH = 'sandwich_jobs' 32 _JOB_SEARCH_PATH = 'sandwich_jobs'
34 33
35 # Devtools timeout of 1 minute to avoid websocket timeout on slow 34 # Devtools timeout of 1 minute to avoid websocket timeout on slow
36 # network condition. 35 # network condition.
37 _DEVTOOLS_TIMEOUT = 60 36 _DEVTOOLS_TIMEOUT = 60
38 37
39 38
40 def _ReadUrlsFromJobDescription(job_name): 39 def _ReadUrlsFromJobDescription(job_name):
41 """Retrieves the list of URLs associated with the job name.""" 40 """Retrieves the list of URLs associated with the job name."""
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 116
118 # Output directory where to save the traces. Is str or None. 117 # Output directory where to save the traces. Is str or None.
119 self.trace_output_directory = None 118 self.trace_output_directory = None
120 119
121 # List of urls to run. 120 # List of urls to run.
122 self.urls = [] 121 self.urls = []
123 122
124 # Configures whether to record speed-index video. 123 # Configures whether to record speed-index video.
125 self.record_video = False 124 self.record_video = False
126 125
126 # Configures whether to record memory dumps.
127 self.record_memory_dumps = False
128
127 # Path to the WPR archive to load or save. Is str or None. 129 # Path to the WPR archive to load or save. Is str or None.
128 self.wpr_archive_path = None 130 self.wpr_archive_path = None
129 131
130 # Configures whether the WPR archive should be read or generated. 132 # Configures whether the WPR archive should be read or generated.
131 self.wpr_record = False 133 self.wpr_record = False
132 134
133 # The android DeviceUtils to run sandwich on or None to run it locally. 135 # The android DeviceUtils to run sandwich on or None to run it locally.
134 self.android_device = None 136 self.android_device = None
135 137
136 self._chrome_ctl = None 138 self._chrome_ctl = None
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 run_id: Id of the run in the output directory. If it is None, then no 184 run_id: Id of the run in the output directory. If it is None, then no
183 trace or video will be saved. 185 trace or video will be saved.
184 """ 186 """
185 run_path = None 187 run_path = None
186 if self.trace_output_directory is not None and run_id is not None: 188 if self.trace_output_directory is not None and run_id is not None:
187 run_path = os.path.join(self.trace_output_directory, str(run_id)) 189 run_path = os.path.join(self.trace_output_directory, str(run_id))
188 if not os.path.isdir(run_path): 190 if not os.path.isdir(run_path):
189 os.makedirs(run_path) 191 os.makedirs(run_path)
190 self._chrome_ctl.SetNetworkEmulation( 192 self._chrome_ctl.SetNetworkEmulation(
191 self._GetEmulatorNetworkCondition('browser')) 193 self._GetEmulatorNetworkCondition('browser'))
194 additional_categories = []
195 if self.record_memory_dumps:
196 additional_categories = [MEMORY_DUMP_CATEGORY]
192 # TODO(gabadie): add a way to avoid recording a trace. 197 # TODO(gabadie): add a way to avoid recording a trace.
193 with self._chrome_ctl.Open() as connection: 198 with self._chrome_ctl.Open() as connection:
194 if clear_cache: 199 if clear_cache:
195 connection.ClearCache() 200 connection.ClearCache()
196 if run_path is not None and self.record_video: 201 if run_path is not None and self.record_video:
197 device = self._chrome_ctl.GetDevice() 202 device = self._chrome_ctl.GetDevice()
198 assert device, 'Can only record video on a remote device.' 203 if device is None:
204 raise RuntimeError('Can only record video on a remote device.')
199 video_recording_path = os.path.join(run_path, VIDEO_FILENAME) 205 video_recording_path = os.path.join(run_path, VIDEO_FILENAME)
200 with device_setup.RemoteSpeedIndexRecorder(device, connection, 206 with device_setup.RemoteSpeedIndexRecorder(device, connection,
201 video_recording_path): 207 video_recording_path):
202 trace = loading_trace.LoadingTrace.RecordUrlNavigation( 208 trace = loading_trace.LoadingTrace.RecordUrlNavigation(
203 url=url, 209 url=url,
204 connection=connection, 210 connection=connection,
205 chrome_metadata=self._chrome_ctl.ChromeMetadata(), 211 chrome_metadata=self._chrome_ctl.ChromeMetadata(),
206 additional_categories=ADDITIONAL_CATEGORIES, 212 additional_categories=additional_categories,
207 timeout_seconds=_DEVTOOLS_TIMEOUT) 213 timeout_seconds=_DEVTOOLS_TIMEOUT)
208 else: 214 else:
209 trace = loading_trace.LoadingTrace.RecordUrlNavigation( 215 trace = loading_trace.LoadingTrace.RecordUrlNavigation(
210 url=url, 216 url=url,
211 connection=connection, 217 connection=connection,
212 chrome_metadata=self._chrome_ctl.ChromeMetadata(), 218 chrome_metadata=self._chrome_ctl.ChromeMetadata(),
213 additional_categories=ADDITIONAL_CATEGORIES, 219 additional_categories=additional_categories,
214 timeout_seconds=_DEVTOOLS_TIMEOUT) 220 timeout_seconds=_DEVTOOLS_TIMEOUT)
215 if run_path is not None: 221 if run_path is not None:
216 trace_path = os.path.join(run_path, TRACE_FILENAME) 222 trace_path = os.path.join(run_path, TRACE_FILENAME)
217 trace.ToJsonFile(trace_path) 223 trace.ToJsonFile(trace_path)
218 224
219 def _RunUrl(self, url, run_id): 225 def _RunUrl(self, url, run_id):
220 clear_cache = False 226 clear_cache = False
221 if self.cache_operation == 'clear': 227 if self.cache_operation == 'clear':
222 clear_cache = True 228 clear_cache = True
223 elif self.cache_operation == 'push': 229 elif self.cache_operation == 'push':
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 self._RunUrl(url, run_id=len(ran_urls)) 275 self._RunUrl(url, run_id=len(ran_urls))
270 ran_urls.append(url) 276 ran_urls.append(url)
271 277
272 if self._local_cache_directory_path: 278 if self._local_cache_directory_path:
273 shutil.rmtree(self._local_cache_directory_path) 279 shutil.rmtree(self._local_cache_directory_path)
274 self._local_cache_directory_path = None 280 self._local_cache_directory_path = None
275 if self.cache_operation == 'save': 281 if self.cache_operation == 'save':
276 self._PullCacheFromDevice() 282 self._PullCacheFromDevice()
277 283
278 self._chrome_ctl = None 284 self._chrome_ctl = None
OLDNEW
« no previous file with comments | « tools/android/loading/sandwich_metrics_unittest.py ('k') | tools/android/loading/sandwich_task_builder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698