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/customtabs_benchmark/scripts/customtabs_benchmark.py

Issue 2561353002: tools: WPR support for testing speculative_prefetch_predictor. (Closed)
Patch Set: . Created 4 years 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
« no previous file with comments | « no previous file | tools/resource_prefetch_predictor/generate_database.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright 2015 The Chromium Authors. All rights reserved. 3 # Copyright 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Loops Custom Tabs tests and outputs the results into a CSV file.""" 7 """Loops Custom Tabs tests and outputs the results into a CSV file."""
8 8
9 import collections 9 import collections
10 import contextlib 10 import contextlib
(...skipping 23 matching lines...) Expand all
34 34
35 35
36 # Local build of Chrome (not Chromium). 36 # Local build of Chrome (not Chromium).
37 _CHROME_PACKAGE = 'com.google.android.apps.chrome' 37 _CHROME_PACKAGE = 'com.google.android.apps.chrome'
38 _COMMAND_LINE_PATH = '/data/local/tmp/chrome-command-line' 38 _COMMAND_LINE_PATH = '/data/local/tmp/chrome-command-line'
39 _TEST_APP_PACKAGE_NAME = 'org.chromium.customtabsclient.test' 39 _TEST_APP_PACKAGE_NAME = 'org.chromium.customtabsclient.test'
40 _INVALID_VALUE = -1 40 _INVALID_VALUE = -1
41 41
42 42
43 # Command line arguments for Chrome. 43 # Command line arguments for Chrome.
44 _CHROME_ARGS = [ 44 CHROME_ARGS = [
45 # Disable backgound network requests that may pollute WPR archive, pollute 45 # Disable backgound network requests that may pollute WPR archive, pollute
46 # HTTP cache generation, and introduce noise in loading performance. 46 # HTTP cache generation, and introduce noise in loading performance.
47 '--disable-background-networking', 47 '--disable-background-networking',
48 '--disable-default-apps', 48 '--disable-default-apps',
49 '--no-proxy-server', 49 '--no-proxy-server',
50 # TODO(droger): Remove once crbug.com/354743 is fixed. 50 # TODO(droger): Remove once crbug.com/354743 is fixed.
51 '--safebrowsing-disable-auto-update', 51 '--safebrowsing-disable-auto-update',
52 52
53 # Disables actions that chrome performs only on first run or each launches, 53 # Disables actions that chrome performs only on first run or each launches,
54 # which can interfere with page load performance, or even block its 54 # which can interfere with page load performance, or even block its
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 match = None 126 match = None
127 try: 127 try:
128 match = logcat_monitor.WaitFor(result_line_re, timeout=logcat_timeout) 128 match = logcat_monitor.WaitFor(result_line_re, timeout=logcat_timeout)
129 except device_errors.CommandTimeoutError as _: 129 except device_errors.CommandTimeoutError as _:
130 logging.warning('Timeout waiting for the result line') 130 logging.warning('Timeout waiting for the result line')
131 logcat_monitor.Stop() 131 logcat_monitor.Stop()
132 logcat_monitor.Close() 132 logcat_monitor.Close()
133 return match.group(1) if match is not None else None 133 return match.group(1) if match is not None else None
134 134
135 135
136 Result = collections.namedtuple('Result', ['warmup', 'speculation_mode', 136 RESULT_FIELDS = ('warmup', 'speculation_mode', 'delay_to_may_launch_url',
137 'delay_to_may_launch_url', 137 'delay_to_launch_url', 'commit', 'plt',
138 'delay_to_launch_url', 138 'first_contentful_paint')
139 'commit', 'plt', 139 Result = collections.namedtuple('Result', RESULT_FIELDS)
140 'first_contentful_paint'])
141 140
142 141
143 def ParseResult(result_line): 142 def ParseResult(result_line):
144 """Parses a result line, and returns it. 143 """Parses a result line, and returns it.
145 144
146 Args: 145 Args:
147 result_line: (str) A result line, as returned by RunOnce(). 146 result_line: (str) A result line, as returned by RunOnce().
148 147
149 Returns: 148 Returns:
150 An instance of Result. 149 An instance of Result.
(...skipping 23 matching lines...) Expand all
174 once: (bool) Run only once. 173 once: (bool) Run only once.
175 should_stop: (threading.Event or None) When the event is set, stop looping. 174 should_stop: (threading.Event or None) When the event is set, stop looping.
176 """ 175 """
177 with SetupWpr(device, wpr_archive_path, wpr_record, network_condition, 176 with SetupWpr(device, wpr_archive_path, wpr_record, network_condition,
178 wpr_log_path) as wpr_attributes: 177 wpr_log_path) as wpr_attributes:
179 to_stdout = output_filename == '-' 178 to_stdout = output_filename == '-'
180 out = sys.stdout if to_stdout else open(output_filename, 'a') 179 out = sys.stdout if to_stdout else open(output_filename, 'a')
181 try: 180 try:
182 while should_stop is None or not should_stop.is_set(): 181 while should_stop is None or not should_stop.is_set():
183 config = configs[random.randint(0, len(configs) - 1)] 182 config = configs[random.randint(0, len(configs) - 1)]
184 chrome_args = _CHROME_ARGS + wpr_attributes.chrome_args 183 chrome_args = CHROME_ARGS + wpr_attributes.chrome_args
185 if config['speculation_mode'] == 'no_state_prefetch': 184 if config['speculation_mode'] == 'no_state_prefetch':
186 # NoStatePrefetch is enabled through an experiment. 185 # NoStatePrefetch is enabled through an experiment.
187 chrome_args.extend([ 186 chrome_args.extend([
188 '--force-fieldtrials=trial/group', 187 '--force-fieldtrials=trial/group',
189 '--force-fieldtrial-params=trial.group:mode/no_state_prefetch', 188 '--force-fieldtrial-params=trial.group:mode/no_state_prefetch',
190 '--enable-features="NoStatePrefetch<trial"']) 189 '--enable-features="NoStatePrefetch<trial"'])
191 190
192 result = RunOnce(device, config['url'], config['warmup'], 191 result = RunOnce(device, config['url'], config['warmup'],
193 config['speculation_mode'], 192 config['speculation_mode'],
194 config['delay_to_may_launch_url'], 193 config['delay_to_may_launch_url'],
(...skipping 16 matching lines...) Expand all
211 def ProcessOutput(filename): 210 def ProcessOutput(filename):
212 """Reads an output file, and returns a processed numpy array. 211 """Reads an output file, and returns a processed numpy array.
213 212
214 Args: 213 Args:
215 filename: (str) file to process. 214 filename: (str) file to process.
216 215
217 Returns: 216 Returns:
218 A numpy structured array. 217 A numpy structured array.
219 """ 218 """
220 import numpy as np 219 import numpy as np
221 data = np.genfromtxt(filename, delimiter=',') 220 data = np.genfromtxt(filename, delimiter=',', skip_header=1)
222 result = np.array(np.zeros(len(data)), 221 result = np.array(np.zeros(len(data)),
223 dtype=[('warmup', bool), ('speculation_mode', np.int32), 222 dtype=[('warmup', bool), ('speculation_mode', np.int32),
224 ('delay_to_may_launch_url', np.int32), 223 ('delay_to_may_launch_url', np.int32),
225 ('delay_to_launch_url', np.int32), 224 ('delay_to_launch_url', np.int32),
226 ('commit', np.int32), ('plt', np.int32), 225 ('commit', np.int32), ('plt', np.int32),
227 ('first_contentful_paint', np.int32)]) 226 ('first_contentful_paint', np.int32)])
228 result['warmup'] = data[:, 0] 227 result['warmup'] = data[:, 0]
229 result['speculation_mode'] = data[:, 1] 228 result['speculation_mode'] = data[:, 1]
230 result['delay_to_may_launch_url'] = data[:, 2] 229 result['delay_to_may_launch_url'] = data[:, 2]
231 result['delay_to_launch_url'] = data[:, 3] 230 result['delay_to_launch_url'] = data[:, 3]
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 'delay_to_launch_url': options.delay_to_launch_url, 317 'delay_to_launch_url': options.delay_to_launch_url,
319 'cold': options.cold, 318 'cold': options.cold,
320 } 319 }
321 LoopOnDevice(device, [config], options.output_file, options.wpr_archive, 320 LoopOnDevice(device, [config], options.output_file, options.wpr_archive,
322 options.record, options.network_condition, options.wpr_log, 321 options.record, options.network_condition, options.wpr_log,
323 once=options.once) 322 once=options.once)
324 323
325 324
326 if __name__ == '__main__': 325 if __name__ == '__main__':
327 main() 326 main()
OLDNEW
« no previous file with comments | « no previous file | tools/resource_prefetch_predictor/generate_database.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698