Index: tools/android/customtabs_benchmark/scripts/customtabs_benchmark.py |
diff --git a/tools/android/customtabs_benchmark/scripts/customtabs_benchmark.py b/tools/android/customtabs_benchmark/scripts/customtabs_benchmark.py |
index 4dff7d3c0dec81b1c793c01200f305f56f5a74af..e8974eafcb98ecda2a4d1018be0dbd2f38ad44a8 100755 |
--- a/tools/android/customtabs_benchmark/scripts/customtabs_benchmark.py |
+++ b/tools/android/customtabs_benchmark/scripts/customtabs_benchmark.py |
@@ -26,11 +26,33 @@ from devil.android.sdk import intent |
sys.path.append(os.path.join(_SRC_PATH, 'build', 'android')) |
import devil_chromium |
+sys.path.append(os.path.join(_SRC_PATH, 'tools', 'android', 'loading')) |
+import device_setup |
+ |
# Local build of Chrome (not Chromium). |
_CHROME_PACKAGE = 'com.google.android.apps.chrome' |
+# Command line arguments for Chrome. |
+_CHROME_ARGS = [ |
+ # Disable backgound network requests that may pollute WPR archive, pollute |
+ # HTTP cache generation, and introduce noise in loading performance. |
+ '--disable-background-networking', |
+ '--disable-default-apps', |
+ '--no-proxy-server', |
+ # TODO(droger): Remove once crbug.com/354743 is fixed. |
+ '--safebrowsing-disable-auto-update', |
+ |
+ # Disables actions that chrome performs only on first run or each launches, |
+ # which can interfere with page load performance, or even block its |
+ # execution by waiting for user input. |
+ '--disable-fre', |
+ '--no-default-browser-check', |
+ '--no-first-run', |
+] |
+ |
+ |
def ResetChromeLocalState(device): |
"""Remove the Chrome Profile and the various disk caches.""" |
profile_dirs = ['app_chrome/Default', 'cache', 'app_chrome/ShaderCache', |
@@ -41,21 +63,21 @@ def ResetChromeLocalState(device): |
device.adb.Shell(subprocess.list2cmdline(cmd)) |
-def RunOnce(device, url, warmup, no_prerendering, delay_to_may_launch_url, |
+def RunOnce(device, url, warmup, prerender_mode, delay_to_may_launch_url, |
delay_to_launch_url, cold): |
"""Runs a test on a device once. |
Args: |
device: (DeviceUtils) device to run the tests on. |
warmup: (bool) Whether to call warmup. |
- no_prerendering: (bool) Whether to disable prerendering. |
+ prerender_mode: (str) Prerender mode (disabled, enabled or prefetch). |
delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms. |
delay_to_launch_url: (int) Delay to launchUrl() in ms. |
cold: (bool) Whether the page cache should be dropped. |
Returns: |
The output line (str), like this (one line only): |
- <warmup>,<no_prerendering>,<delay_to_may_launch_url>,<delay_to_launch>, |
+ <warmup>,<prerender_mode>,<delay_to_may_launch_url>,<delay_to_launch>, |
<intent_sent_ms>,<page_load_started_ms>,<page_load_finished_ms> |
or None on error. |
""" |
@@ -63,7 +85,7 @@ def RunOnce(device, url, warmup, no_prerendering, delay_to_may_launch_url, |
action='android.intent.action.MAIN', |
package='org.chromium.customtabsclient.test', |
activity='org.chromium.customtabs.test.MainActivity', |
- extras={'url': url, 'warmup': warmup, 'no_prerendering': no_prerendering, |
+ extras={'url': url, 'warmup': warmup, 'prerender_mode': prerender_mode, |
'delay_to_may_launch_url': delay_to_may_launch_url, |
'delay_to_launch_url': delay_to_launch_url}) |
result_line_re = re.compile(r'CUSTOMTABSBENCH.*: (.*)') |
@@ -86,7 +108,7 @@ def RunOnce(device, url, warmup, no_prerendering, delay_to_may_launch_url, |
return match.group(1) if match is not None else None |
-def LoopOnDevice(device, url, warmup, no_prerendering, delay_to_may_launch_url, |
+def LoopOnDevice(device, url, warmup, prerender_mode, delay_to_may_launch_url, |
delay_to_launch_url, cold, output_filename, once=False): |
"""Loops the tests on a device. |
@@ -94,7 +116,7 @@ def LoopOnDevice(device, url, warmup, no_prerendering, delay_to_may_launch_url, |
device: (DeviceUtils) device to run the tests on. |
url: (str) URL to navigate to. |
warmup: (bool) Whether to call warmup. |
- no_prerendering: (bool) Whether to disable prerendering. |
+ prerender_mode: (str) Prerender mode (disabled, enabled or prefetch). |
delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms. |
delay_to_launch_url: (int) Delay to launchUrl() in ms. |
cold: (bool) Whether the page cache should be dropped. |
@@ -104,7 +126,7 @@ def LoopOnDevice(device, url, warmup, no_prerendering, delay_to_may_launch_url, |
while True: |
out = sys.stdout if output_filename == '-' else open(output_filename, 'a') |
try: |
- result = RunOnce(device, url, warmup, no_prerendering, |
+ result = RunOnce(device, url, warmup, prerender_mode, |
delay_to_may_launch_url, delay_to_launch_url, cold) |
if result is not None: |
out.write(result + '\n') |
@@ -129,12 +151,12 @@ def ProcessOutput(filename): |
import numpy as np |
data = np.genfromtxt(filename, delimiter=',') |
result = np.array(np.zeros(len(data)), |
- dtype=[('warmup', bool), ('no_prerendering', bool), |
+ dtype=[('warmup', bool), ('prerender_mode', np.int32), |
('delay_to_may_launch_url', np.int32), |
('delay_to_launch_url', np.int32), |
('commit', np.int32), ('plt', np.int32)]) |
result['warmup'] = data[:, 0] |
- result['no_prerendering'] = data[:, 1] |
+ result['prerender_mode'] = data[:, 1] |
result['delay_to_may_launch_url'] = data[:, 2] |
result['delay_to_launch_url'] = data[:, 3] |
result['commit'] = data[:, 5] - data[:, 4] |
@@ -151,8 +173,9 @@ def _CreateOptionParser(): |
default='https://www.android.com') |
parser.add_option('--warmup', help='Call warmup.', default=False, |
action='store_true') |
- parser.add_option('--no_prerendering', help='Disable prerendering.', |
- default=False, action='store_true') |
+ parser.add_option('--prerender_mode', default='enabled', |
+ help='The prerender mode (disabled, enabled or prefetch).', |
+ choices=['disabled', 'enabled', 'prefetch']) |
parser.add_option('--delay_to_may_launch_url', |
help='Delay before calling mayLaunchUrl() in ms.', |
type='int') |
@@ -183,9 +206,14 @@ def main(): |
logging.error('Device not found.') |
sys.exit(0) |
device = matching_devices[0] |
- LoopOnDevice(device, options.url, options.warmup, options.no_prerendering, |
- options.delay_to_may_launch_url, options.delay_to_launch_url, |
- options.cold, options.output_file, options.once) |
+ |
+ with device_setup.FlagReplacer( |
+ device, '/data/local/tmp/chrome-command-line', |
+ _CHROME_ARGS + ['--prerender=' + options.prerender_mode]): |
+ LoopOnDevice(device, options.url, options.warmup, |
+ options.prerender_mode, |
+ options.delay_to_may_launch_url, options.delay_to_launch_url, |
+ options.cold, options.output_file, options.once) |
if __name__ == '__main__': |