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