Index: tools/android/loading/device_setup.py |
diff --git a/tools/android/loading/device_setup.py b/tools/android/loading/device_setup.py |
index c3847078948cdbb809cdf6d66f99c9fa2993653a..8625d10430be70f0ed1a41102acf3ece36d7a53e 100644 |
--- a/tools/android/loading/device_setup.py |
+++ b/tools/android/loading/device_setup.py |
@@ -17,11 +17,18 @@ _SRC_DIR = os.path.abspath(os.path.join( |
sys.path.append(os.path.join(_SRC_DIR, 'third_party', 'catapult', 'devil')) |
from devil.android import device_utils |
from devil.android.sdk import intent |
+from devil.android import forwarder |
Benoit L
2016/02/10 13:58:27
Wrong import ordering (move to line 19).
gabadie
2016/02/10 14:19:50
Done.
|
sys.path.append(os.path.join(_SRC_DIR, 'build', 'android')) |
from pylib import constants |
from pylib import flag_changer |
+sys.path.append(os.path.join(_SRC_DIR, 'tools', 'perf')) |
+from chrome_telemetry_build import chromium_config |
+ |
+sys.path.append(chromium_config.GetTelemetryDir()) |
+from telemetry.internal.util import webpagereplay |
Benoit L
2016/02/10 13:58:27
Is webpagereplay in catapult now?
gabadie
2016/02/10 14:19:50
Webpage replay it self is in its own third_party t
|
+ |
import devtools_monitor |
DEVTOOLS_PORT = 9222 |
@@ -104,12 +111,57 @@ def _SetUpDevice(device, package_info): |
@contextlib.contextmanager |
+def WprHost(device, wpr_archive_path, record=False): |
+ """Launch web page replay host. |
Benoit L
2016/02/10 13:58:27
nit: Launches the
gabadie
2016/02/10 14:19:50
Done.
|
+ |
+ Args: |
+ device: Android device. |
+ wpr_archive_path: host sided WPR archive's path. |
+ record: Enables or disables WPR archive recording. |
+ |
+ Returns: |
+ Additional flags list that may be used for chromium to load web page through |
+ the running web page replay host. |
+ """ |
+ assert device |
+ if wpr_archive_path == None: |
+ yield [] |
+ return |
+ |
+ wpr_server_args = ['--use_closest_match'] |
+ if record: |
+ wpr_server_args.append('--record') |
+ if os.path.exists(wpr_archive_path): |
+ os.remove(wpr_archive_path) |
+ else: |
+ assert os.path.exists(wpr_archive_path) |
+ wpr_server = webpagereplay.ReplayServer(wpr_archive_path, |
+ '127.0.0.1', 0, 0, None, wpr_server_args) |
+ ports = wpr_server.StartServer()[:-1] |
+ host_http_port = ports[0] |
+ host_https_port = ports[1] |
+ |
+ forwarder.Forwarder.Map([(0, host_http_port), (0, host_https_port)], device) |
+ device_http_port = forwarder.Forwarder.DevicePortForHostPort(host_http_port) |
+ device_https_port = forwarder.Forwarder.DevicePortForHostPort(host_https_port) |
+ |
+ try: |
+ yield [ |
mattcary
2016/02/10 14:01:01
This is fine for now. Note that if the WPR interfa
gabadie
2016/02/10 14:19:50
Acknowledged.
|
+ '--host-resolver-rules="MAP * 127.0.0.1,EXCLUDE localhost"', |
+ '--testing-fixed-http-port={}'.format(device_http_port), |
+ '--testing-fixed-https-port={}'.format(device_https_port)] |
+ finally: |
+ forwarder.Forwarder.UnmapAllDevicePorts(device) |
Benoit L
2016/02/10 13:58:27
I don't know whether that's relevant here, but thi
gabadie
2016/02/10 14:19:50
Indeed but since there is a dependency, that is ru
|
+ wpr_server.StopServer() |
+ |
+@contextlib.contextmanager |
def DeviceConnection(device, |
package=DEFAULT_CHROME_PACKAGE, |
hostname=DEVTOOLS_HOSTNAME, |
port=DEVTOOLS_PORT, |
host_exe='out/Release/chrome', |
- host_profile_dir=None): |
+ host_profile_dir=None, |
+ additional_flags=[]): |
"""Context for starting recording on a device. |
Sets up and restores any device and tracing appropriately |
@@ -122,6 +174,7 @@ def DeviceConnection(device, |
host_exe: The binary to execute when running on the host. |
host_profile_dir: The profile dir to use when running on the host (if None, |
a fresh profile dir will be used). |
+ additional_flags: Additional chromium arguments. |
Returns: |
A context manager type which evaluates to a DevToolsConnection. |
@@ -130,7 +183,7 @@ def DeviceConnection(device, |
command_line_path = '/data/local/chrome-command-line' |
new_flags = ['--disable-fre', |
'--enable-test-events', |
- '--remote-debugging-port=%d' % port] |
+ '--remote-debugging-port=%d' % port] + additional_flags |
if device: |
_SetUpDevice(device, package_info) |
with FlagReplacer(device, command_line_path, new_flags): |