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

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: 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 [MEMORY_DUMP_CATEGORY] if self.record_memory_dumps else []
pasko 2016/04/28 15:04:59 More straightforward and does not require awkward
gabadie 2016/04/28 15:56:22 Done.
192 # TODO(gabadie): add a way to avoid recording a trace. 196 # TODO(gabadie): add a way to avoid recording a trace.
193 with self._chrome_ctl.Open() as connection: 197 with self._chrome_ctl.Open() as connection:
194 if clear_cache: 198 if clear_cache:
195 connection.ClearCache() 199 connection.ClearCache()
196 if run_path is not None and self.record_video: 200 if run_path is not None and self.record_video:
197 device = self._chrome_ctl.GetDevice() 201 device = self._chrome_ctl.GetDevice()
198 assert device, 'Can only record video on a remote device.' 202 if device is None:
203 raise RuntimeError('Can only record video on a remote device.')
199 video_recording_path = os.path.join(run_path, VIDEO_FILENAME) 204 video_recording_path = os.path.join(run_path, VIDEO_FILENAME)
200 with device_setup.RemoteSpeedIndexRecorder(device, connection, 205 with device_setup.RemoteSpeedIndexRecorder(device, connection,
201 video_recording_path): 206 video_recording_path):
202 trace = loading_trace.LoadingTrace.RecordUrlNavigation( 207 trace = loading_trace.LoadingTrace.RecordUrlNavigation(
203 url=url, 208 url=url,
204 connection=connection, 209 connection=connection,
205 chrome_metadata=self._chrome_ctl.ChromeMetadata(), 210 chrome_metadata=self._chrome_ctl.ChromeMetadata(),
206 additional_categories=ADDITIONAL_CATEGORIES, 211 additional_categories=additional_categories,
207 timeout_seconds=_DEVTOOLS_TIMEOUT) 212 timeout_seconds=_DEVTOOLS_TIMEOUT)
208 else: 213 else:
209 trace = loading_trace.LoadingTrace.RecordUrlNavigation( 214 trace = loading_trace.LoadingTrace.RecordUrlNavigation(
210 url=url, 215 url=url,
211 connection=connection, 216 connection=connection,
212 chrome_metadata=self._chrome_ctl.ChromeMetadata(), 217 chrome_metadata=self._chrome_ctl.ChromeMetadata(),
213 additional_categories=ADDITIONAL_CATEGORIES, 218 additional_categories=additional_categories,
214 timeout_seconds=_DEVTOOLS_TIMEOUT) 219 timeout_seconds=_DEVTOOLS_TIMEOUT)
215 if run_path is not None: 220 if run_path is not None:
216 trace_path = os.path.join(run_path, TRACE_FILENAME) 221 trace_path = os.path.join(run_path, TRACE_FILENAME)
217 trace.ToJsonFile(trace_path) 222 trace.ToJsonFile(trace_path)
218 223
219 def _RunUrl(self, url, run_id): 224 def _RunUrl(self, url, run_id):
220 clear_cache = False 225 clear_cache = False
221 if self.cache_operation == 'clear': 226 if self.cache_operation == 'clear':
222 clear_cache = True 227 clear_cache = True
223 elif self.cache_operation == 'push': 228 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)) 274 self._RunUrl(url, run_id=len(ran_urls))
270 ran_urls.append(url) 275 ran_urls.append(url)
271 276
272 if self._local_cache_directory_path: 277 if self._local_cache_directory_path:
273 shutil.rmtree(self._local_cache_directory_path) 278 shutil.rmtree(self._local_cache_directory_path)
274 self._local_cache_directory_path = None 279 self._local_cache_directory_path = None
275 if self.cache_operation == 'save': 280 if self.cache_operation == 'save':
276 self._PullCacheFromDevice() 281 self._PullCacheFromDevice()
277 282
278 self._chrome_ctl = None 283 self._chrome_ctl = None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698