OLD | NEW |
---|---|
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import contextlib | 5 import contextlib |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import shutil | 8 import shutil |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
11 import tempfile | 11 import tempfile |
12 import time | 12 import time |
13 | 13 |
14 _SRC_DIR = os.path.abspath(os.path.join( | 14 _SRC_DIR = os.path.abspath(os.path.join( |
15 os.path.dirname(__file__), '..', '..', '..')) | 15 os.path.dirname(__file__), '..', '..', '..')) |
16 | 16 |
17 sys.path.append(os.path.join(_SRC_DIR, 'third_party', 'catapult', 'devil')) | 17 sys.path.append(os.path.join(_SRC_DIR, 'third_party', 'catapult', 'devil')) |
18 from devil.android import device_utils | 18 from devil.android import device_utils |
19 from devil.android.sdk import intent | 19 from devil.android.sdk import intent |
20 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.
| |
20 | 21 |
21 sys.path.append(os.path.join(_SRC_DIR, 'build', 'android')) | 22 sys.path.append(os.path.join(_SRC_DIR, 'build', 'android')) |
22 from pylib import constants | 23 from pylib import constants |
23 from pylib import flag_changer | 24 from pylib import flag_changer |
24 | 25 |
26 sys.path.append(os.path.join(_SRC_DIR, 'tools', 'perf')) | |
27 from chrome_telemetry_build import chromium_config | |
28 | |
29 sys.path.append(chromium_config.GetTelemetryDir()) | |
30 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
| |
31 | |
25 import devtools_monitor | 32 import devtools_monitor |
26 | 33 |
27 DEVTOOLS_PORT = 9222 | 34 DEVTOOLS_PORT = 9222 |
28 DEVTOOLS_HOSTNAME = 'localhost' | 35 DEVTOOLS_HOSTNAME = 'localhost' |
29 DEFAULT_CHROME_PACKAGE = 'chrome' | 36 DEFAULT_CHROME_PACKAGE = 'chrome' |
30 | 37 |
31 | 38 |
32 @contextlib.contextmanager | 39 @contextlib.contextmanager |
33 def TemporaryDirectory(): | 40 def TemporaryDirectory(): |
34 """Returns a freshly-created directory that gets automatically deleted after | 41 """Returns a freshly-created directory that gets automatically deleted after |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 device.adb.ForwardRemove(local) | 104 device.adb.ForwardRemove(local) |
98 | 105 |
99 | 106 |
100 def _SetUpDevice(device, package_info): | 107 def _SetUpDevice(device, package_info): |
101 """Enables root and closes Chrome on a device.""" | 108 """Enables root and closes Chrome on a device.""" |
102 device.EnableRoot() | 109 device.EnableRoot() |
103 device.KillAll(package_info.package, quiet=True) | 110 device.KillAll(package_info.package, quiet=True) |
104 | 111 |
105 | 112 |
106 @contextlib.contextmanager | 113 @contextlib.contextmanager |
114 def WprHost(device, wpr_archive_path, record=False): | |
115 """Launch web page replay host. | |
Benoit L
2016/02/10 13:58:27
nit: Launches the
gabadie
2016/02/10 14:19:50
Done.
| |
116 | |
117 Args: | |
118 device: Android device. | |
119 wpr_archive_path: host sided WPR archive's path. | |
120 record: Enables or disables WPR archive recording. | |
121 | |
122 Returns: | |
123 Additional flags list that may be used for chromium to load web page through | |
124 the running web page replay host. | |
125 """ | |
126 assert device | |
127 if wpr_archive_path == None: | |
128 yield [] | |
129 return | |
130 | |
131 wpr_server_args = ['--use_closest_match'] | |
132 if record: | |
133 wpr_server_args.append('--record') | |
134 if os.path.exists(wpr_archive_path): | |
135 os.remove(wpr_archive_path) | |
136 else: | |
137 assert os.path.exists(wpr_archive_path) | |
138 wpr_server = webpagereplay.ReplayServer(wpr_archive_path, | |
139 '127.0.0.1', 0, 0, None, wpr_server_args) | |
140 ports = wpr_server.StartServer()[:-1] | |
141 host_http_port = ports[0] | |
142 host_https_port = ports[1] | |
143 | |
144 forwarder.Forwarder.Map([(0, host_http_port), (0, host_https_port)], device) | |
145 device_http_port = forwarder.Forwarder.DevicePortForHostPort(host_http_port) | |
146 device_https_port = forwarder.Forwarder.DevicePortForHostPort(host_https_port) | |
147 | |
148 try: | |
149 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.
| |
150 '--host-resolver-rules="MAP * 127.0.0.1,EXCLUDE localhost"', | |
151 '--testing-fixed-http-port={}'.format(device_http_port), | |
152 '--testing-fixed-https-port={}'.format(device_https_port)] | |
153 finally: | |
154 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
| |
155 wpr_server.StopServer() | |
156 | |
157 @contextlib.contextmanager | |
107 def DeviceConnection(device, | 158 def DeviceConnection(device, |
108 package=DEFAULT_CHROME_PACKAGE, | 159 package=DEFAULT_CHROME_PACKAGE, |
109 hostname=DEVTOOLS_HOSTNAME, | 160 hostname=DEVTOOLS_HOSTNAME, |
110 port=DEVTOOLS_PORT, | 161 port=DEVTOOLS_PORT, |
111 host_exe='out/Release/chrome', | 162 host_exe='out/Release/chrome', |
112 host_profile_dir=None): | 163 host_profile_dir=None, |
164 additional_flags=[]): | |
113 """Context for starting recording on a device. | 165 """Context for starting recording on a device. |
114 | 166 |
115 Sets up and restores any device and tracing appropriately | 167 Sets up and restores any device and tracing appropriately |
116 | 168 |
117 Args: | 169 Args: |
118 device: Android device, or None for a local run (in which case chrome needs | 170 device: Android device, or None for a local run (in which case chrome needs |
119 to have been started with --remote-debugging-port=XXX). | 171 to have been started with --remote-debugging-port=XXX). |
120 package: The key for chrome package info. | 172 package: The key for chrome package info. |
121 port: The port on which to enable remote debugging. | 173 port: The port on which to enable remote debugging. |
122 host_exe: The binary to execute when running on the host. | 174 host_exe: The binary to execute when running on the host. |
123 host_profile_dir: The profile dir to use when running on the host (if None, | 175 host_profile_dir: The profile dir to use when running on the host (if None, |
124 a fresh profile dir will be used). | 176 a fresh profile dir will be used). |
177 additional_flags: Additional chromium arguments. | |
125 | 178 |
126 Returns: | 179 Returns: |
127 A context manager type which evaluates to a DevToolsConnection. | 180 A context manager type which evaluates to a DevToolsConnection. |
128 """ | 181 """ |
129 package_info = constants.PACKAGE_INFO[package] | 182 package_info = constants.PACKAGE_INFO[package] |
130 command_line_path = '/data/local/chrome-command-line' | 183 command_line_path = '/data/local/chrome-command-line' |
131 new_flags = ['--disable-fre', | 184 new_flags = ['--disable-fre', |
132 '--enable-test-events', | 185 '--enable-test-events', |
133 '--remote-debugging-port=%d' % port] | 186 '--remote-debugging-port=%d' % port] + additional_flags |
134 if device: | 187 if device: |
135 _SetUpDevice(device, package_info) | 188 _SetUpDevice(device, package_info) |
136 with FlagReplacer(device, command_line_path, new_flags): | 189 with FlagReplacer(device, command_line_path, new_flags): |
137 host_process = None | 190 host_process = None |
138 if device: | 191 if device: |
139 start_intent = intent.Intent( | 192 start_intent = intent.Intent( |
140 package=package_info.package, activity=package_info.activity, | 193 package=package_info.package, activity=package_info.activity, |
141 data='about:blank') | 194 data='about:blank') |
142 device.StartActivity(start_intent, blocking=True) | 195 device.StartActivity(start_intent, blocking=True) |
143 else: | 196 else: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 package: the key for chrome package info. | 228 package: the key for chrome package info. |
176 fn: the function to execute that launches chrome and performs the | 229 fn: the function to execute that launches chrome and performs the |
177 appropriate instrumentation. The function will receive a | 230 appropriate instrumentation. The function will receive a |
178 DevToolsConnection as its sole parameter. | 231 DevToolsConnection as its sole parameter. |
179 | 232 |
180 Returns: | 233 Returns: |
181 As fn() returns. | 234 As fn() returns. |
182 """ | 235 """ |
183 with DeviceConnection(device, package) as connection: | 236 with DeviceConnection(device, package) as connection: |
184 return fn(connection) | 237 return fn(connection) |
OLD | NEW |