OLD | NEW |
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 |
11 import logging | 11 import logging |
12 import optparse | 12 import optparse |
13 import os | 13 import os |
14 import random | 14 import random |
15 import re | 15 import re |
16 import subprocess | |
17 import sys | 16 import sys |
18 import time | 17 import time |
19 | 18 |
20 _SRC_PATH = os.path.abspath(os.path.join( | 19 _SRC_PATH = os.path.abspath(os.path.join( |
21 os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir)) | 20 os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir)) |
22 | 21 |
23 sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil')) | 22 sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil')) |
24 from devil.android import device_errors | 23 from devil.android import device_errors |
25 from devil.android import device_utils | 24 from devil.android import device_utils |
26 from devil.android.perf import cache_control | 25 from devil.android.perf import cache_control |
27 from devil.android.sdk import intent | 26 from devil.android.sdk import intent |
28 | 27 |
29 sys.path.append(os.path.join(_SRC_PATH, 'build', 'android')) | 28 sys.path.append(os.path.join(_SRC_PATH, 'build', 'android')) |
30 import devil_chromium | 29 import devil_chromium |
31 | 30 |
32 sys.path.append(os.path.join(_SRC_PATH, 'tools', 'android', 'loading')) | 31 sys.path.append(os.path.join(_SRC_PATH, 'tools', 'android', 'loading')) |
| 32 import chrome_setup |
33 import device_setup | 33 import device_setup |
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. | |
44 CHROME_ARGS = [ | |
45 # Disable backgound network requests that may pollute WPR archive, pollute | |
46 # HTTP cache generation, and introduce noise in loading performance. | |
47 '--disable-background-networking', | |
48 '--disable-default-apps', | |
49 '--no-proxy-server', | |
50 # TODO(droger): Remove once crbug.com/354743 is fixed. | |
51 '--safebrowsing-disable-auto-update', | |
52 | |
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 | |
55 # execution by waiting for user input. | |
56 '--disable-fre', | |
57 '--no-default-browser-check', | |
58 '--no-first-run', | |
59 ] | |
60 | |
61 | |
62 def ResetChromeLocalState(device): | |
63 """Remove the Chrome Profile and the various disk caches.""" | |
64 profile_dirs = ['app_chrome/Default', 'cache', 'app_chrome/ShaderCache', | |
65 'app_tabs'] | |
66 cmd = ['rm', '-rf'] | |
67 cmd.extend( | |
68 '/data/data/{}/{}'.format(_CHROME_PACKAGE, d) for d in profile_dirs) | |
69 device.adb.Shell(subprocess.list2cmdline(cmd)) | |
70 | |
71 | |
72 def RunOnce(device, url, warmup, speculation_mode, delay_to_may_launch_url, | 43 def RunOnce(device, url, warmup, speculation_mode, delay_to_may_launch_url, |
73 delay_to_launch_url, cold, chrome_args, reset_chrome_state): | 44 delay_to_launch_url, cold, chrome_args, reset_chrome_state): |
74 """Runs a test on a device once. | 45 """Runs a test on a device once. |
75 | 46 |
76 Args: | 47 Args: |
77 device: (DeviceUtils) device to run the tests on. | 48 device: (DeviceUtils) device to run the tests on. |
78 url: (str) URL to load. | 49 url: (str) URL to load. |
79 warmup: (bool) Whether to call warmup. | 50 warmup: (bool) Whether to call warmup. |
80 speculation_mode: (str) Speculation Mode. | 51 speculation_mode: (str) Speculation Mode. |
81 delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms. | 52 delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms. |
(...skipping 27 matching lines...) Expand all Loading... |
109 'delay_to_may_launch_url': delay_to_may_launch_url, | 80 'delay_to_may_launch_url': delay_to_may_launch_url, |
110 'delay_to_launch_url': delay_to_launch_url, | 81 'delay_to_launch_url': delay_to_launch_url, |
111 'timeout': timeout_s}) | 82 'timeout': timeout_s}) |
112 result_line_re = re.compile(r'CUSTOMTABSBENCH.*: (.*)') | 83 result_line_re = re.compile(r'CUSTOMTABSBENCH.*: (.*)') |
113 logcat_monitor = device.GetLogcatMonitor(clear=True) | 84 logcat_monitor = device.GetLogcatMonitor(clear=True) |
114 logcat_monitor.Start() | 85 logcat_monitor.Start() |
115 device.ForceStop(_CHROME_PACKAGE) | 86 device.ForceStop(_CHROME_PACKAGE) |
116 device.ForceStop(_TEST_APP_PACKAGE_NAME) | 87 device.ForceStop(_TEST_APP_PACKAGE_NAME) |
117 | 88 |
118 if reset_chrome_state: | 89 if reset_chrome_state: |
119 ResetChromeLocalState(device) | 90 chrome_setup.ResetChromeLocalState(device, _CHROME_PACKAGE) |
120 | 91 |
121 if cold: | 92 if cold: |
122 cache_control.CacheControl(device).DropRamCaches() | 93 cache_control.CacheControl(device).DropRamCaches() |
123 | 94 |
124 device.StartActivity(launch_intent, blocking=True) | 95 device.StartActivity(launch_intent, blocking=True) |
125 | 96 |
126 match = None | 97 match = None |
127 try: | 98 try: |
128 match = logcat_monitor.WaitFor(result_line_re, timeout=logcat_timeout) | 99 match = logcat_monitor.WaitFor(result_line_re, timeout=logcat_timeout) |
129 except device_errors.CommandTimeoutError as _: | 100 except device_errors.CommandTimeoutError as _: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 once: (bool) Run only once. | 144 once: (bool) Run only once. |
174 should_stop: (threading.Event or None) When the event is set, stop looping. | 145 should_stop: (threading.Event or None) When the event is set, stop looping. |
175 """ | 146 """ |
176 with SetupWpr(device, wpr_archive_path, wpr_record, network_condition, | 147 with SetupWpr(device, wpr_archive_path, wpr_record, network_condition, |
177 wpr_log_path) as wpr_attributes: | 148 wpr_log_path) as wpr_attributes: |
178 to_stdout = output_filename == '-' | 149 to_stdout = output_filename == '-' |
179 out = sys.stdout if to_stdout else open(output_filename, 'a') | 150 out = sys.stdout if to_stdout else open(output_filename, 'a') |
180 try: | 151 try: |
181 while should_stop is None or not should_stop.is_set(): | 152 while should_stop is None or not should_stop.is_set(): |
182 config = configs[random.randint(0, len(configs) - 1)] | 153 config = configs[random.randint(0, len(configs) - 1)] |
183 chrome_args = CHROME_ARGS + wpr_attributes.chrome_args | 154 chrome_args = chrome_setup.CHROME_ARGS + wpr_attributes.chrome_args |
184 if config['speculation_mode'] == 'no_state_prefetch': | 155 if config['speculation_mode'] == 'no_state_prefetch': |
185 # NoStatePrefetch is enabled through an experiment. | 156 # NoStatePrefetch is enabled through an experiment. |
186 chrome_args.extend([ | 157 chrome_args.extend([ |
187 '--force-fieldtrials=trial/group', | 158 '--force-fieldtrials=trial/group', |
188 '--force-fieldtrial-params=trial.group:mode/no_state_prefetch', | 159 '--force-fieldtrial-params=trial.group:mode/no_state_prefetch', |
189 '--enable-features="NoStatePrefetch<trial"']) | 160 '--enable-features="NoStatePrefetch<trial"']) |
190 elif config['speculation_mode'] == 'speculative_prefetch': | 161 elif config['speculation_mode'] == 'speculative_prefetch': |
191 # Speculative Prefetch is enabled through an experiment. | 162 # Speculative Prefetch is enabled through an experiment. |
192 chrome_args.extend([ | 163 chrome_args.extend([ |
193 '--force-fieldtrials=trial/group', | 164 '--force-fieldtrials=trial/group', |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 'delay_to_launch_url': options.delay_to_launch_url, | 294 'delay_to_launch_url': options.delay_to_launch_url, |
324 'cold': options.cold, | 295 'cold': options.cold, |
325 } | 296 } |
326 LoopOnDevice(device, [config], options.output_file, options.wpr_archive, | 297 LoopOnDevice(device, [config], options.output_file, options.wpr_archive, |
327 options.record, options.network_condition, options.wpr_log, | 298 options.record, options.network_condition, options.wpr_log, |
328 once=options.once) | 299 once=options.once) |
329 | 300 |
330 | 301 |
331 if __name__ == '__main__': | 302 if __name__ == '__main__': |
332 main() | 303 main() |
OLD | NEW |