| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright 2016 The Chromium Authors. All rights reserved. | 3 # Copyright 2016 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 """Loads a web page with speculative prefetch, and collects loading metrics.""" | 7 """Loads a web page with speculative prefetch, and collects loading metrics.""" |
| 8 | 8 |
| 9 import argparse | 9 import argparse |
| 10 import logging | 10 import logging |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 import device_setup | 22 import device_setup |
| 23 | 23 |
| 24 sys.path.append(os.path.join(_SRC_PATH, 'tools', 'android', 'loading')) | 24 sys.path.append(os.path.join(_SRC_PATH, 'tools', 'android', 'loading')) |
| 25 import controller | 25 import controller |
| 26 from options import OPTIONS | 26 from options import OPTIONS |
| 27 | 27 |
| 28 sys.path.append(os.path.join(_SRC_PATH, 'build', 'android')) | 28 sys.path.append(os.path.join(_SRC_PATH, 'build', 'android')) |
| 29 import devil_chromium | 29 import devil_chromium |
| 30 | 30 |
| 31 sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil')) | 31 sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil')) |
| 32 from devil.android import flag_changer |
| 32 from devil.android.sdk import intent | 33 from devil.android.sdk import intent |
| 33 | 34 |
| 34 import prefetch_predictor_common | 35 import prefetch_predictor_common |
| 35 | 36 |
| 36 | 37 |
| 37 def _CreateArgumentParser(): | 38 def _CreateArgumentParser(): |
| 38 """Creates and returns the argument parser.""" | 39 """Creates and returns the argument parser.""" |
| 39 parser = argparse.ArgumentParser( | 40 parser = argparse.ArgumentParser( |
| 40 ('Loads a URL with the resource_prefetch_predictor and prints loading ' | 41 ('Loads a URL with the resource_prefetch_predictor and prints loading ' |
| 41 'metrics.'), parents=[OPTIONS.GetParentParser()]) | 42 'metrics.'), parents=[OPTIONS.GetParentParser()]) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 61 """Sets up a device and returns an instance of RemoteChromeController.""" | 62 """Sets up a device and returns an instance of RemoteChromeController.""" |
| 62 chrome_controller = prefetch_predictor_common.Setup(device) | 63 chrome_controller = prefetch_predictor_common.Setup(device) |
| 63 chrome_package = OPTIONS.ChromePackage() | 64 chrome_package = OPTIONS.ChromePackage() |
| 64 device.ForceStop(chrome_package.package) | 65 device.ForceStop(chrome_package.package) |
| 65 chrome_controller.ResetBrowserState() | 66 chrome_controller.ResetBrowserState() |
| 66 device_database_filename = prefetch_predictor_common.DatabaseDevicePath() | 67 device_database_filename = prefetch_predictor_common.DatabaseDevicePath() |
| 67 owner = group = None | 68 owner = group = None |
| 68 | 69 |
| 69 # Make sure that the speculative prefetch predictor is enabled to ensure | 70 # Make sure that the speculative prefetch predictor is enabled to ensure |
| 70 # that the disk database is re-created. | 71 # that the disk database is re-created. |
| 71 with device_setup.FlagReplacer( | 72 with flag_changer.CustomCommandLineFlags( |
| 72 device, chrome_package.cmdline_file, ['--disable-fre']): | 73 device, chrome_package.cmdline_file, ['--disable-fre']): |
| 73 # Launch Chrome for the first time to recreate the local state. | 74 # Launch Chrome for the first time to recreate the local state. |
| 74 launch_intent = intent.Intent( | 75 launch_intent = intent.Intent( |
| 75 action='android.intent.action.MAIN', | 76 action='android.intent.action.MAIN', |
| 76 package=chrome_package.package, | 77 package=chrome_package.package, |
| 77 activity=chrome_package.activity) | 78 activity=chrome_package.activity) |
| 78 device.StartActivity(launch_intent, blocking=True) | 79 device.StartActivity(launch_intent, blocking=True) |
| 79 time.sleep(5) | 80 time.sleep(5) |
| 80 device.ForceStop(chrome_package.package) | 81 device.ForceStop(chrome_package.package) |
| 81 assert device.FileExists(device_database_filename) | 82 assert device.FileExists(device_database_filename) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 while True: | 152 while True: |
| 152 delay = delays[random.randint(0, len(delays) - 1)] | 153 delay = delays[random.randint(0, len(delays) - 1)] |
| 153 _RunOnce(device, args.database, args.url, delay, args.output_filename, | 154 _RunOnce(device, args.database, args.url, delay, args.output_filename, |
| 154 args.wpr_archive, args.network_condition) | 155 args.wpr_archive, args.network_condition) |
| 155 if args.once: | 156 if args.once: |
| 156 return | 157 return |
| 157 | 158 |
| 158 | 159 |
| 159 if __name__ == '__main__': | 160 if __name__ == '__main__': |
| 160 main() | 161 main() |
| OLD | NEW |