Chromium Code Reviews| Index: tools/resource_prefetch_predictor/common.py |
| diff --git a/tools/resource_prefetch_predictor/common.py b/tools/resource_prefetch_predictor/common.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6b6ec2b88ec4e92a8e840cc3e5ae738b45e19e5f |
| --- /dev/null |
| +++ b/tools/resource_prefetch_predictor/common.py |
| @@ -0,0 +1,60 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Common utils for the speculative resource prefetch evaluation.""" |
| + |
| +import argparse |
| +import logging |
| +import os |
| +import sys |
| + |
| +_SRC_PATH = os.path.abspath(os.path.join( |
| + os.path.dirname(__file__), os.pardir, os.pardir)) |
| + |
| +sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil')) |
| +from devil.android import device_utils |
| + |
| +sys.path.append(os.path.join(_SRC_PATH, 'tools', 'android', 'loading')) |
| +import controller |
| +from options import OPTIONS |
| + |
| + |
| +def CreateBaseArgumentParser(description): |
|
pasko
2016/11/17 15:59:04
inlining this function on every use will increase
Benoit L
2016/11/21 13:40:32
Done.
|
| + """Returns a new ArgumentParser instance with a |description|.""" |
| + return argparse.ArgumentParser(description=description, |
| + parents=[OPTIONS.GetParentParser()]) |
| + |
| + |
| +def ParseAndReturnArgs(parser): |
|
pasko
2016/11/17 15:59:04
as the above, this utility is quite small and does
Benoit L
2016/11/21 13:40:32
Done.
|
| + args = parser.parse_args() |
| + OPTIONS.SetParsedArgs(args) |
| + return args |
| + |
| + |
| +def FindDevice(device_id): |
| + """Returns a device matching |device_id| or the first one if None, or None.""" |
| + devices = device_utils.DeviceUtils.HealthyDevices() |
| + if device_id is None: |
| + return devices[0] |
| + matching_devices = [d for d in devices if str(d) == device_id] |
| + if not matching_devices: |
| + return None |
| + return matching_devices[0] |
| + |
| + |
| +def Setup(device, additional_flags=None): |
| + """Sets up a device and returns an instance of RemoteChromeController.""" |
| + if not device.HasRoot(): |
| + device.EnableRoot() |
| + chrome_controller = controller.RemoteChromeController(device) |
| + device.ForceStop(OPTIONS.ChromePackage().package) |
| + if additional_flags is not None: |
| + chrome_controller.AddChromeArguments(additional_flags) |
| + chrome_controller.ResetBrowserState() |
| + return chrome_controller |
| + |
| + |
| +def DatabaseDevicePath(): |
| + return ('/data/user/0/%s/app_chrome/Default/Network Action Predictor' % |
| + OPTIONS.ChromePackage().package) |