OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """This script runs an automated Cronet performance benchmark. | 6 """This script runs an automated Cronet performance benchmark. |
7 | 7 |
8 This script: | 8 This script: |
9 1. Sets up "USB reverse tethering" which allow network traffic to flow from | 9 1. Sets up "USB reverse tethering" which allow network traffic to flow from |
10 an Android device connected to the host machine via a USB cable. | 10 an Android device connected to the host machine via a USB cable. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 from telemetry import story | 57 from telemetry import story |
58 from telemetry.internal import forwarders | 58 from telemetry.internal import forwarders |
59 from telemetry.internal.forwarders import android_forwarder | 59 from telemetry.internal.forwarders import android_forwarder |
60 from telemetry.value import scalar | 60 from telemetry.value import scalar |
61 from telemetry.web_perf import timeline_based_measurement | 61 from telemetry.web_perf import timeline_based_measurement |
62 | 62 |
63 BUILD_TYPE = 'Release' | 63 BUILD_TYPE = 'Release' |
64 BUILD_DIR = os.path.join(REPOSITORY_ROOT, 'out', BUILD_TYPE) | 64 BUILD_DIR = os.path.join(REPOSITORY_ROOT, 'out', BUILD_TYPE) |
65 QUIC_SERVER = os.path.join(BUILD_DIR, 'quic_server') | 65 QUIC_SERVER = os.path.join(BUILD_DIR, 'quic_server') |
66 QUIC_CLIENT = os.path.join(BUILD_DIR, 'quic_client') | 66 QUIC_CLIENT = os.path.join(BUILD_DIR, 'quic_client') |
| 67 CERT_PATH = os.path.join('net', 'data', 'ssl', 'certificates') |
| 68 QUIC_CERT_DIR = os.path.join(REPOSITORY_ROOT, CERT_PATH) |
| 69 QUIC_CERT_HOST = 'test.example.com' |
| 70 QUIC_CERT_FILENAME = 'quic_%s.crt' % QUIC_CERT_HOST |
| 71 QUIC_CERT = os.path.join(QUIC_CERT_DIR, QUIC_CERT_FILENAME) |
| 72 QUIC_KEY = os.path.join(QUIC_CERT_DIR, 'quic_%s.key.pkcs8' % QUIC_CERT_HOST) |
67 APP_APK = os.path.join(BUILD_DIR, 'apks', 'CronetPerfTest.apk') | 73 APP_APK = os.path.join(BUILD_DIR, 'apks', 'CronetPerfTest.apk') |
68 APP_PACKAGE = 'org.chromium.net' | 74 APP_PACKAGE = 'org.chromium.net' |
69 APP_ACTIVITY = '.CronetPerfTestActivity' | 75 APP_ACTIVITY = '.CronetPerfTestActivity' |
70 APP_ACTION = 'android.intent.action.MAIN' | 76 APP_ACTION = 'android.intent.action.MAIN' |
71 BENCHMARK_CONFIG = { | 77 BENCHMARK_CONFIG = { |
72 # Control various metric recording for further investigation. | 78 # Control various metric recording for further investigation. |
73 'CAPTURE_NETLOG': False, | 79 'CAPTURE_NETLOG': False, |
74 'CAPTURE_TRACE': False, | 80 'CAPTURE_TRACE': False, |
75 'CAPTURE_SAMPLED_TRACE': False, | 81 'CAPTURE_SAMPLED_TRACE': False, |
76 # While running Cronet Async API benchmarks, indicate if callbacks should be | 82 # While running Cronet Async API benchmarks, indicate if callbacks should be |
(...skipping 12 matching lines...) Expand all Loading... |
89 'LARGE_ITERATIONS': 4, | 95 'LARGE_ITERATIONS': 4, |
90 # An on-device file containing benchmark timings. Written by benchmark app. | 96 # An on-device file containing benchmark timings. Written by benchmark app. |
91 'RESULTS_FILE': '/data/data/' + APP_PACKAGE + '/results.txt', | 97 'RESULTS_FILE': '/data/data/' + APP_PACKAGE + '/results.txt', |
92 # An on-device file whose presence indicates benchmark app has terminated. | 98 # An on-device file whose presence indicates benchmark app has terminated. |
93 'DONE_FILE': '/data/data/' + APP_PACKAGE + '/done.txt', | 99 'DONE_FILE': '/data/data/' + APP_PACKAGE + '/done.txt', |
94 # Ports of HTTP and QUIC servers on host. | 100 # Ports of HTTP and QUIC servers on host. |
95 'HTTP_PORT': 9000, | 101 'HTTP_PORT': 9000, |
96 'QUIC_PORT': 9001, | 102 'QUIC_PORT': 9001, |
97 # Maximum read/write buffer size to use. | 103 # Maximum read/write buffer size to use. |
98 'MAX_BUFFER_SIZE': 16384, | 104 'MAX_BUFFER_SIZE': 16384, |
| 105 'HOST': QUIC_CERT_HOST, |
| 106 'QUIC_CERT_FILE': QUIC_CERT_FILENAME, |
99 } | 107 } |
100 # Add benchmark config to global state for easy access. | 108 # Add benchmark config to global state for easy access. |
101 globals().update(BENCHMARK_CONFIG) | 109 globals().update(BENCHMARK_CONFIG) |
102 | 110 |
103 | 111 |
104 def GetDevice(): | 112 def GetDevice(): |
105 devices = device_utils.DeviceUtils.HealthyDevices() | 113 devices = device_utils.DeviceUtils.HealthyDevices() |
106 assert len(devices) == 1 | 114 assert len(devices) == 1 |
107 return devices[0] | 115 return devices[0] |
108 | 116 |
(...skipping 12 matching lines...) Expand all Loading... |
121 | 129 |
122 class CronetPerfTestAndroidStory(android.AndroidStory): | 130 class CronetPerfTestAndroidStory(android.AndroidStory): |
123 # Android AppStory implementation wrapping CronetPerfTest app. | 131 # Android AppStory implementation wrapping CronetPerfTest app. |
124 # Launches Cronet perf test app and waits for execution to complete | 132 # Launches Cronet perf test app and waits for execution to complete |
125 # by waiting for presence of DONE_FILE. | 133 # by waiting for presence of DONE_FILE. |
126 | 134 |
127 def __init__(self, device): | 135 def __init__(self, device): |
128 self._device = device | 136 self._device = device |
129 device.RunShellCommand('rm %s' % DONE_FILE) | 137 device.RunShellCommand('rm %s' % DONE_FILE) |
130 config = BENCHMARK_CONFIG | 138 config = BENCHMARK_CONFIG |
131 config['HOST'] = GetServersHost(device) | 139 config['HOST_IP'] = GetServersHost(device) |
132 start_intent = intent.Intent( | 140 start_intent = intent.Intent( |
133 package=APP_PACKAGE, | 141 package=APP_PACKAGE, |
134 activity=APP_ACTIVITY, | 142 activity=APP_ACTIVITY, |
135 action=APP_ACTION, | 143 action=APP_ACTION, |
136 # |config| maps from configuration value names to the configured values. | 144 # |config| maps from configuration value names to the configured values. |
137 # |config| is encoded as URL parameter names and values and passed to | 145 # |config| is encoded as URL parameter names and values and passed to |
138 # the Cronet perf test app via the Intent data field. | 146 # the Cronet perf test app via the Intent data field. |
139 data='http://dummy/?'+urllib.urlencode(config), | 147 data='http://dummy/?'+urllib.urlencode(config), |
140 extras=None, | 148 extras=None, |
141 category=None) | 149 category=None) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 class QuicServer: | 209 class QuicServer: |
202 | 210 |
203 def __init__(self, quic_server_doc_root): | 211 def __init__(self, quic_server_doc_root): |
204 self._process = None | 212 self._process = None |
205 self._quic_server_doc_root = quic_server_doc_root | 213 self._quic_server_doc_root = quic_server_doc_root |
206 | 214 |
207 def StartupQuicServer(self, device): | 215 def StartupQuicServer(self, device): |
208 self._process = pexpect.spawn(QUIC_SERVER, | 216 self._process = pexpect.spawn(QUIC_SERVER, |
209 ['--quic_in_memory_cache_dir=%s' % | 217 ['--quic_in_memory_cache_dir=%s' % |
210 self._quic_server_doc_root, | 218 self._quic_server_doc_root, |
| 219 '--certificate_file=%s' % QUIC_CERT, |
| 220 '--key_file=%s' % QUIC_KEY, |
211 '--port=%d' % QUIC_PORT]) | 221 '--port=%d' % QUIC_PORT]) |
212 assert self._process != None | 222 assert self._process != None |
213 # Wait for quic_server to start serving. | 223 # Wait for quic_server to start serving. |
214 waited_s = 0 | 224 waited_s = 0 |
215 while subprocess.call([QUIC_CLIENT, | 225 while subprocess.call(['lsof', '-i', 'udp:%d' % QUIC_PORT, '-p', |
216 '--host=%s' % GetServersHost(device), | 226 '%d' % self._process.pid], |
217 '--port=%d' % QUIC_PORT, | |
218 'http://%s:%d/%s' % (GetServersHost(device), | |
219 QUIC_PORT, SMALL_RESOURCE)], | |
220 stdout=open(os.devnull, 'w')) != 0: | 227 stdout=open(os.devnull, 'w')) != 0: |
221 sleep(0.1) | 228 sleep(0.1) |
222 waited_s += 0.1 | 229 waited_s += 0.1 |
223 assert waited_s < 5, "quic_server failed to start after %fs" % waited_s | 230 assert waited_s < 5, "quic_server failed to start after %fs" % waited_s |
| 231 # Push certificate to device. |
| 232 cert = open(QUIC_CERT, 'r').read() |
| 233 device_cert_path = os.path.join(device.GetExternalStoragePath(), CERT_PATH) |
| 234 device.RunShellCommand('mkdir -p %s' % device_cert_path) |
| 235 device.WriteFile(os.path.join(device_cert_path, QUIC_CERT_FILENAME), cert) |
224 | 236 |
225 def ShutdownQuicServer(self): | 237 def ShutdownQuicServer(self): |
226 if self._process: | 238 if self._process: |
227 self._process.terminate() | 239 self._process.terminate() |
228 | 240 |
229 | 241 |
230 def GenerateHttpTestResources(): | 242 def GenerateHttpTestResources(): |
231 http_server_doc_root = tempfile.mkdtemp() | 243 http_server_doc_root = tempfile.mkdtemp() |
232 # Create a small test file to serve. | 244 # Create a small test file to serve. |
233 small_file_name = os.path.join(http_server_doc_root, SMALL_RESOURCE) | 245 small_file_name = os.path.join(http_server_doc_root, SMALL_RESOURCE) |
(...skipping 18 matching lines...) Expand all Loading... |
252 # Use wget to build up fake QUIC in-memory cache dir for serving. | 264 # Use wget to build up fake QUIC in-memory cache dir for serving. |
253 # quic_server expects the dir/file layout that wget produces. | 265 # quic_server expects the dir/file layout that wget produces. |
254 for resource in [SMALL_RESOURCE, LARGE_RESOURCE]: | 266 for resource in [SMALL_RESOURCE, LARGE_RESOURCE]: |
255 assert subprocess.Popen(['wget', '-p', '-q', '--save-headers', | 267 assert subprocess.Popen(['wget', '-p', '-q', '--save-headers', |
256 GetHttpServerURL(device, resource)], | 268 GetHttpServerURL(device, resource)], |
257 cwd=quic_server_doc_root).wait() == 0 | 269 cwd=quic_server_doc_root).wait() == 0 |
258 # wget places results in host:port directory. Adjust for QUIC port. | 270 # wget places results in host:port directory. Adjust for QUIC port. |
259 os.rename(os.path.join(quic_server_doc_root, | 271 os.rename(os.path.join(quic_server_doc_root, |
260 "%s:%d" % (GetServersHost(device), HTTP_PORT)), | 272 "%s:%d" % (GetServersHost(device), HTTP_PORT)), |
261 os.path.join(quic_server_doc_root, | 273 os.path.join(quic_server_doc_root, |
262 "%s:%d" % (GetServersHost(device), QUIC_PORT))) | 274 "%s:%d" % (QUIC_CERT_HOST, QUIC_PORT))) |
263 return quic_server_doc_root | 275 return quic_server_doc_root |
264 | 276 |
265 | 277 |
266 def GenerateLighttpdConfig(config_file, http_server_doc_root, http_server): | 278 def GenerateLighttpdConfig(config_file, http_server_doc_root, http_server): |
267 # Must create customized config file to allow overriding the server.bind | 279 # Must create customized config file to allow overriding the server.bind |
268 # setting. | 280 # setting. |
269 config_file.write('server.document-root = "%s"\n' % http_server_doc_root) | 281 config_file.write('server.document-root = "%s"\n' % http_server_doc_root) |
270 config_file.write('server.port = %d\n' % HTTP_PORT) | 282 config_file.write('server.port = %d\n' % HTTP_PORT) |
271 # These lines are added so lighttpd_server.py's internal test succeeds. | 283 # These lines are added so lighttpd_server.py's internal test succeeds. |
272 config_file.write('server.tag = "%s"\n' % http_server.server_tag) | 284 config_file.write('server.tag = "%s"\n' % http_server.server_tag) |
(...skipping 28 matching lines...) Expand all Loading... |
301 quic_server.StartupQuicServer(device) | 313 quic_server.StartupQuicServer(device) |
302 # Launch Telemetry's benchmark_runner on CronetPerfTestBenchmark. | 314 # Launch Telemetry's benchmark_runner on CronetPerfTestBenchmark. |
303 # By specifying this file's directory as the benchmark directory, it will | 315 # By specifying this file's directory as the benchmark directory, it will |
304 # allow benchmark_runner to in turn open this file up and find the | 316 # allow benchmark_runner to in turn open this file up and find the |
305 # CronetPerfTestBenchmark class to run the benchmark. | 317 # CronetPerfTestBenchmark class to run the benchmark. |
306 top_level_dir = os.path.dirname(os.path.realpath(__file__)) | 318 top_level_dir = os.path.dirname(os.path.realpath(__file__)) |
307 # The perf config file is required to continue using dependencies on the | 319 # The perf config file is required to continue using dependencies on the |
308 # Chromium checkout in Telemetry. | 320 # Chromium checkout in Telemetry. |
309 perf_config_file = os.path.join(REPOSITORY_ROOT, 'tools', 'perf', 'core', | 321 perf_config_file = os.path.join(REPOSITORY_ROOT, 'tools', 'perf', 'core', |
310 'binary_dependencies.json') | 322 'binary_dependencies.json') |
| 323 with open(perf_config_file, "w") as config_file: |
| 324 config_file.write('{"config_type": "BaseConfig"}') |
311 runner_config = benchmark_runner.ProjectConfig( | 325 runner_config = benchmark_runner.ProjectConfig( |
312 top_level_dir=top_level_dir, | 326 top_level_dir=top_level_dir, |
313 benchmark_dirs=[top_level_dir], | 327 benchmark_dirs=[top_level_dir], |
314 client_config=perf_config_file) | 328 client_config=perf_config_file, |
| 329 default_chrome_root=REPOSITORY_ROOT) |
315 sys.argv.insert(1, 'run') | 330 sys.argv.insert(1, 'run') |
316 sys.argv.insert(2, 'run.CronetPerfTestBenchmark') | 331 sys.argv.insert(2, 'run.CronetPerfTestBenchmark') |
317 sys.argv.insert(3, '--android-rndis') | 332 sys.argv.insert(3, '--android-rndis') |
318 benchmark_runner.main(runner_config) | 333 benchmark_runner.main(runner_config) |
319 # Shutdown. | 334 # Shutdown. |
320 quic_server.ShutdownQuicServer() | 335 quic_server.ShutdownQuicServer() |
321 shutil.rmtree(quic_server_doc_root) | 336 shutil.rmtree(quic_server_doc_root) |
322 http_server.ShutdownHttpServer() | 337 http_server.ShutdownHttpServer() |
323 shutil.rmtree(http_server_doc_root) | 338 shutil.rmtree(http_server_doc_root) |
324 | 339 |
325 | 340 |
326 if __name__ == '__main__': | 341 if __name__ == '__main__': |
327 main() | 342 main() |
OLD | NEW |