Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
| 2 | # Copyright 2016, Google Inc. |
| 3 | # All rights reserved. |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are |
| 7 | # met: |
| 8 | # |
| 9 | # * Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # * Redistributions in binary form must reproduce the above |
| 12 | # copyright notice, this list of conditions and the following disclaimer |
| 13 | # in the documentation and/or other materials provided with the |
| 14 | # distribution. |
| 15 | # * Neither the name of Google Inc. nor the names of its |
| 16 | # contributors may be used to endorse or promote products derived from |
| 17 | # this software without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | """Run performance tests locally or remotely.""" |
| 32 | |
siddharthshukla | 0589e53 | 2016-07-07 16:08:01 +0200 | [diff] [blame] | 33 | from __future__ import print_function |
| 34 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 35 | import argparse |
Craig Tiller | accf16b | 2016-09-15 09:08:32 -0700 | [diff] [blame] | 36 | import collections |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 37 | import itertools |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 38 | import json |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 39 | import multiprocessing |
| 40 | import os |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 41 | import pipes |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 42 | import re |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 43 | import subprocess |
| 44 | import sys |
| 45 | import tempfile |
| 46 | import time |
Jan Tattermusch | ee9032c | 2016-04-14 08:35:51 -0700 | [diff] [blame] | 47 | import traceback |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 48 | import uuid |
Jan Tattermusch | 5c79a31 | 2016-12-20 11:02:50 +0100 | [diff] [blame] | 49 | |
| 50 | import performance.scenario_config as scenario_config |
| 51 | import python_utils.jobset as jobset |
| 52 | import python_utils.report_utils as report_utils |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 53 | |
| 54 | |
| 55 | _ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..')) |
| 56 | os.chdir(_ROOT) |
| 57 | |
| 58 | |
| 59 | _REMOTE_HOST_USERNAME = 'jenkins' |
| 60 | |
| 61 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 62 | class QpsWorkerJob: |
| 63 | """Encapsulates a qps worker server job.""" |
| 64 | |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 65 | def __init__(self, spec, language, host_and_port, perf_file_base_name=None): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 66 | self._spec = spec |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 67 | self.language = language |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 68 | self.host_and_port = host_and_port |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 69 | self._job = None |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 70 | self.perf_file_base_name = perf_file_base_name |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 71 | |
| 72 | def start(self): |
Craig Tiller | c197ec1 | 2016-09-15 09:19:33 -0700 | [diff] [blame] | 73 | self._job = jobset.Job(self._spec, newline_on_success=True, travis=True, add_env={}) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 74 | |
| 75 | def is_running(self): |
| 76 | """Polls a job and returns True if given job is still running.""" |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 77 | return self._job and self._job.state() == jobset._RUNNING |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 78 | |
| 79 | def kill(self): |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 80 | if self._job: |
| 81 | self._job.kill() |
| 82 | self._job = None |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 83 | |
| 84 | |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 85 | def create_qpsworker_job(language, shortname=None, port=10000, remote_host=None, perf_cmd=None): |
| 86 | cmdline = (language.worker_cmdline() + ['--driver_port=%s' % port]) |
| 87 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 88 | if remote_host: |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 89 | host_and_port='%s:%s' % (remote_host, port) |
| 90 | else: |
| 91 | host_and_port='localhost:%s' % port |
| 92 | |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 93 | perf_file_base_name = None |
| 94 | if perf_cmd: |
| 95 | perf_file_base_name = '%s-%s' % (host_and_port, shortname) |
| 96 | # specify -o output file so perf.data gets collected when worker stopped |
| 97 | cmdline = perf_cmd + ['-o', '%s-perf.data' % perf_file_base_name] + cmdline |
| 98 | |
Alexander Polcyn | 76be306 | 2017-02-01 12:06:23 -0800 | [diff] [blame] | 99 | worker_timeout = 3 * 60 |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 100 | if remote_host: |
| 101 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host) |
| 102 | ssh_cmd = ['ssh'] |
Alexander Polcyn | 76be306 | 2017-02-01 12:06:23 -0800 | [diff] [blame] | 103 | cmdline = ['timeout', '%s' % (worker_timeout + 30)] + cmdline |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 104 | ssh_cmd.extend([str(user_at_host), 'cd ~/performance_workspace/grpc/ && %s' % ' '.join(cmdline)]) |
| 105 | cmdline = ssh_cmd |
| 106 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 107 | jobspec = jobset.JobSpec( |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 108 | cmdline=cmdline, |
| 109 | shortname=shortname, |
Alexander Polcyn | 76be306 | 2017-02-01 12:06:23 -0800 | [diff] [blame] | 110 | timeout_seconds=worker_timeout, # workers get restarted after each scenario |
Jan Tattermusch | 447548b | 2016-10-17 12:04:56 +0200 | [diff] [blame] | 111 | verbose_success=True) |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 112 | return QpsWorkerJob(jobspec, language, host_and_port, perf_file_base_name) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 113 | |
| 114 | |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 115 | def create_scenario_jobspec(scenario_json, workers, remote_host=None, |
Yuxuan Li | ac87a46 | 2016-11-11 12:05:11 -0800 | [diff] [blame] | 116 | bq_result_table=None, server_cpu_load=0): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 117 | """Runs one scenario using QPS driver.""" |
| 118 | # setting QPS_WORKERS env variable here makes sure it works with SSH too. |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 119 | cmd = 'QPS_WORKERS="%s" ' % ','.join(workers) |
| 120 | if bq_result_table: |
| 121 | cmd += 'BQ_RESULT_TABLE="%s" ' % bq_result_table |
| 122 | cmd += 'tools/run_tests/performance/run_qps_driver.sh ' |
| 123 | cmd += '--scenarios_json=%s ' % pipes.quote(json.dumps({'scenarios': [scenario_json]})) |
Yuxuan Li | ac87a46 | 2016-11-11 12:05:11 -0800 | [diff] [blame] | 124 | cmd += '--scenario_result_file=scenario_result.json ' |
| 125 | if server_cpu_load != 0: |
| 126 | cmd += '--search_param=offered_load --initial_search_value=1000 --targeted_cpu_load=%d --stride=500 --error_tolerance=0.01' % server_cpu_load |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 127 | if remote_host: |
| 128 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host) |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 129 | cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % (user_at_host, pipes.quote(cmd)) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 130 | |
| 131 | return jobset.JobSpec( |
| 132 | cmdline=[cmd], |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 133 | shortname='qps_json_driver.%s' % scenario_json['name'], |
Yuxuan Li | ac87a46 | 2016-11-11 12:05:11 -0800 | [diff] [blame] | 134 | timeout_seconds=12*60, |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 135 | shell=True, |
| 136 | verbose_success=True) |
| 137 | |
| 138 | |
| 139 | def create_quit_jobspec(workers, remote_host=None): |
| 140 | """Runs quit using QPS driver.""" |
| 141 | # setting QPS_WORKERS env variable here makes sure it works with SSH too. |
Craig Tiller | 025972d | 2016-09-15 09:26:50 -0700 | [diff] [blame] | 142 | cmd = 'QPS_WORKERS="%s" bins/opt/qps_json_driver --quit' % ','.join(w.host_and_port for w in workers) |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 143 | if remote_host: |
| 144 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, remote_host) |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 145 | cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % (user_at_host, pipes.quote(cmd)) |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 146 | |
| 147 | return jobset.JobSpec( |
| 148 | cmdline=[cmd], |
vjpai | 29089c7 | 2016-04-20 12:38:16 -0700 | [diff] [blame] | 149 | shortname='qps_json_driver.quit', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 150 | timeout_seconds=3*60, |
| 151 | shell=True, |
| 152 | verbose_success=True) |
| 153 | |
| 154 | |
Jan Tattermusch | 4de2c32 | 2016-05-10 14:33:07 -0700 | [diff] [blame] | 155 | def create_netperf_jobspec(server_host='localhost', client_host=None, |
| 156 | bq_result_table=None): |
| 157 | """Runs netperf benchmark.""" |
| 158 | cmd = 'NETPERF_SERVER_HOST="%s" ' % server_host |
| 159 | if bq_result_table: |
| 160 | cmd += 'BQ_RESULT_TABLE="%s" ' % bq_result_table |
Jan Tattermusch | ad17bf7 | 2016-05-11 12:41:37 -0700 | [diff] [blame] | 161 | if client_host: |
| 162 | # If netperf is running remotely, the env variables populated by Jenkins |
| 163 | # won't be available on the client, but we need them for uploading results |
| 164 | # to BigQuery. |
| 165 | jenkins_job_name = os.getenv('JOB_NAME') |
| 166 | if jenkins_job_name: |
| 167 | cmd += 'JOB_NAME="%s" ' % jenkins_job_name |
| 168 | jenkins_build_number = os.getenv('BUILD_NUMBER') |
| 169 | if jenkins_build_number: |
| 170 | cmd += 'BUILD_NUMBER="%s" ' % jenkins_build_number |
| 171 | |
Jan Tattermusch | 4de2c32 | 2016-05-10 14:33:07 -0700 | [diff] [blame] | 172 | cmd += 'tools/run_tests/performance/run_netperf.sh' |
| 173 | if client_host: |
| 174 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, client_host) |
| 175 | cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % (user_at_host, pipes.quote(cmd)) |
| 176 | |
| 177 | return jobset.JobSpec( |
| 178 | cmdline=[cmd], |
| 179 | shortname='netperf', |
| 180 | timeout_seconds=60, |
| 181 | shell=True, |
| 182 | verbose_success=True) |
| 183 | |
| 184 | |
Jan Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 185 | def archive_repo(languages): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 186 | """Archives local version of repo including submodules.""" |
Jan Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 187 | cmdline=['tar', '-cf', '../grpc.tar', '../grpc/'] |
| 188 | if 'java' in languages: |
| 189 | cmdline.append('../grpc-java') |
| 190 | if 'go' in languages: |
| 191 | cmdline.append('../grpc-go') |
| 192 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 193 | archive_job = jobset.JobSpec( |
Jan Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 194 | cmdline=cmdline, |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 195 | shortname='archive_repo', |
| 196 | timeout_seconds=3*60) |
| 197 | |
| 198 | jobset.message('START', 'Archiving local repository.', do_newline=True) |
| 199 | num_failures, _ = jobset.run( |
| 200 | [archive_job], newline_on_success=True, maxjobs=1) |
| 201 | if num_failures == 0: |
| 202 | jobset.message('SUCCESS', |
Jan Tattermusch | de874a1 | 2016-04-18 09:21:37 -0700 | [diff] [blame] | 203 | 'Archive with local repository created successfully.', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 204 | do_newline=True) |
| 205 | else: |
| 206 | jobset.message('FAILED', 'Failed to archive local repository.', |
| 207 | do_newline=True) |
| 208 | sys.exit(1) |
| 209 | |
| 210 | |
Jan Tattermusch | 1408920 | 2016-04-27 17:55:27 -0700 | [diff] [blame] | 211 | def prepare_remote_hosts(hosts, prepare_local=False): |
| 212 | """Prepares remote hosts (and maybe prepare localhost as well).""" |
| 213 | prepare_timeout = 5*60 |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 214 | prepare_jobs = [] |
| 215 | for host in hosts: |
| 216 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, host) |
| 217 | prepare_jobs.append( |
| 218 | jobset.JobSpec( |
| 219 | cmdline=['tools/run_tests/performance/remote_host_prepare.sh'], |
| 220 | shortname='remote_host_prepare.%s' % host, |
| 221 | environ = {'USER_AT_HOST': user_at_host}, |
Jan Tattermusch | 1408920 | 2016-04-27 17:55:27 -0700 | [diff] [blame] | 222 | timeout_seconds=prepare_timeout)) |
| 223 | if prepare_local: |
| 224 | # Prepare localhost as well |
| 225 | prepare_jobs.append( |
| 226 | jobset.JobSpec( |
| 227 | cmdline=['tools/run_tests/performance/kill_workers.sh'], |
| 228 | shortname='local_prepare', |
| 229 | timeout_seconds=prepare_timeout)) |
| 230 | jobset.message('START', 'Preparing hosts.', do_newline=True) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 231 | num_failures, _ = jobset.run( |
| 232 | prepare_jobs, newline_on_success=True, maxjobs=10) |
| 233 | if num_failures == 0: |
| 234 | jobset.message('SUCCESS', |
Jan Tattermusch | 1408920 | 2016-04-27 17:55:27 -0700 | [diff] [blame] | 235 | 'Prepare step completed successfully.', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 236 | do_newline=True) |
| 237 | else: |
| 238 | jobset.message('FAILED', 'Failed to prepare remote hosts.', |
| 239 | do_newline=True) |
| 240 | sys.exit(1) |
| 241 | |
| 242 | |
Craig Tiller | d92d5c5 | 2016-04-04 13:49:29 -0700 | [diff] [blame] | 243 | def build_on_remote_hosts(hosts, languages=scenario_config.LANGUAGES.keys(), build_local=False): |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 244 | """Builds performance worker on remote hosts (and maybe also locally).""" |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 245 | build_timeout = 15*60 |
| 246 | build_jobs = [] |
| 247 | for host in hosts: |
| 248 | user_at_host = '%s@%s' % (_REMOTE_HOST_USERNAME, host) |
| 249 | build_jobs.append( |
| 250 | jobset.JobSpec( |
Craig Tiller | 7797e3f | 2016-04-01 07:41:05 -0700 | [diff] [blame] | 251 | cmdline=['tools/run_tests/performance/remote_host_build.sh'] + languages, |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 252 | shortname='remote_host_build.%s' % host, |
| 253 | environ = {'USER_AT_HOST': user_at_host, 'CONFIG': 'opt'}, |
| 254 | timeout_seconds=build_timeout)) |
| 255 | if build_local: |
| 256 | # Build locally as well |
| 257 | build_jobs.append( |
| 258 | jobset.JobSpec( |
Craig Tiller | 7797e3f | 2016-04-01 07:41:05 -0700 | [diff] [blame] | 259 | cmdline=['tools/run_tests/performance/build_performance.sh'] + languages, |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 260 | shortname='local_build', |
| 261 | environ = {'CONFIG': 'opt'}, |
| 262 | timeout_seconds=build_timeout)) |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 263 | jobset.message('START', 'Building.', do_newline=True) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 264 | num_failures, _ = jobset.run( |
| 265 | build_jobs, newline_on_success=True, maxjobs=10) |
| 266 | if num_failures == 0: |
| 267 | jobset.message('SUCCESS', |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 268 | 'Built successfully.', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 269 | do_newline=True) |
| 270 | else: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 271 | jobset.message('FAILED', 'Build failed.', |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 272 | do_newline=True) |
| 273 | sys.exit(1) |
| 274 | |
| 275 | |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 276 | def create_qpsworkers(languages, worker_hosts, perf_cmd=None): |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 277 | """Creates QPS workers (but does not start them).""" |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 278 | if not worker_hosts: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 279 | # run two workers locally (for each language) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 280 | workers=[(None, 10000), (None, 10010)] |
| 281 | elif len(worker_hosts) == 1: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 282 | # run two workers on the remote host (for each language) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 283 | workers=[(worker_hosts[0], 10000), (worker_hosts[0], 10010)] |
| 284 | else: |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 285 | # run one worker per each remote host (for each language) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 286 | workers=[(worker_host, 10000) for worker_host in worker_hosts] |
| 287 | |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 288 | return [create_qpsworker_job(language, |
| 289 | shortname= 'qps_worker_%s_%s' % (language, |
| 290 | worker_idx), |
| 291 | port=worker[1] + language.worker_port_offset(), |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 292 | remote_host=worker[0], |
| 293 | perf_cmd=perf_cmd) |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 294 | for language in languages |
| 295 | for worker_idx, worker in enumerate(workers)] |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 296 | |
| 297 | |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 298 | def perf_report_processor_job(worker_host, perf_base_name, output_filename): |
| 299 | print('Creating perf report collection job for %s' % worker_host) |
| 300 | cmd = '' |
| 301 | if worker_host != 'localhost': |
| 302 | user_at_host = "%s@%s" % (_REMOTE_HOST_USERNAME, worker_host) |
| 303 | cmd = "USER_AT_HOST=%s OUTPUT_FILENAME=%s OUTPUT_DIR=%s PERF_BASE_NAME=%s\ |
| 304 | tools/run_tests/performance/process_remote_perf_flamegraphs.sh" \ |
Alexander Polcyn | 66c6782 | 2016-12-09 10:22:50 -0800 | [diff] [blame] | 305 | % (user_at_host, output_filename, args.flame_graph_reports, perf_base_name) |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 306 | else: |
| 307 | cmd = "OUTPUT_FILENAME=%s OUTPUT_DIR=%s PERF_BASE_NAME=%s\ |
| 308 | tools/run_tests/performance/process_local_perf_flamegraphs.sh" \ |
Alexander Polcyn | 66c6782 | 2016-12-09 10:22:50 -0800 | [diff] [blame] | 309 | % (output_filename, args.flame_graph_reports, perf_base_name) |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 310 | |
| 311 | return jobset.JobSpec(cmdline=cmd, |
| 312 | timeout_seconds=3*60, |
| 313 | shell=True, |
| 314 | verbose_success=True, |
| 315 | shortname='process perf report') |
| 316 | |
| 317 | |
Craig Tiller | 677966a | 2016-09-26 07:37:28 -0700 | [diff] [blame] | 318 | Scenario = collections.namedtuple('Scenario', 'jobspec workers name') |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 319 | |
| 320 | |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 321 | def create_scenarios(languages, workers_by_lang, remote_host=None, regex='.*', |
Jan Tattermusch | 4de2c32 | 2016-05-10 14:33:07 -0700 | [diff] [blame] | 322 | category='all', bq_result_table=None, |
Yuxuan Li | ac87a46 | 2016-11-11 12:05:11 -0800 | [diff] [blame] | 323 | netperf=False, netperf_hosts=[], server_cpu_load=0): |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 324 | """Create jobspecs for scenarios to run.""" |
Ken Payson | 0482c10 | 2016-04-19 12:08:34 -0700 | [diff] [blame] | 325 | all_workers = [worker |
| 326 | for workers in workers_by_lang.values() |
| 327 | for worker in workers] |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 328 | scenarios = [] |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 329 | _NO_WORKERS = [] |
Jan Tattermusch | 4de2c32 | 2016-05-10 14:33:07 -0700 | [diff] [blame] | 330 | |
| 331 | if netperf: |
| 332 | if not netperf_hosts: |
| 333 | netperf_server='localhost' |
| 334 | netperf_client=None |
| 335 | elif len(netperf_hosts) == 1: |
| 336 | netperf_server=netperf_hosts[0] |
| 337 | netperf_client=netperf_hosts[0] |
| 338 | else: |
| 339 | netperf_server=netperf_hosts[0] |
| 340 | netperf_client=netperf_hosts[1] |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 341 | scenarios.append(Scenario( |
| 342 | create_netperf_jobspec(server_host=netperf_server, |
| 343 | client_host=netperf_client, |
| 344 | bq_result_table=bq_result_table), |
Craig Tiller | 677966a | 2016-09-26 07:37:28 -0700 | [diff] [blame] | 345 | _NO_WORKERS, 'netperf')) |
Jan Tattermusch | 4de2c32 | 2016-05-10 14:33:07 -0700 | [diff] [blame] | 346 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 347 | for language in languages: |
Craig Tiller | 0bda0b3 | 2016-03-03 12:51:53 -0800 | [diff] [blame] | 348 | for scenario_json in language.scenarios(): |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 349 | if re.search(args.regex, scenario_json['name']): |
Craig Tiller | b6df247 | 2016-09-13 09:41:26 -0700 | [diff] [blame] | 350 | categories = scenario_json.get('CATEGORIES', ['scalable', 'smoketest']) |
| 351 | if category in categories or category == 'all': |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 352 | workers = workers_by_lang[str(language)][:] |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 353 | # 'SERVER_LANGUAGE' is an indicator for this script to pick |
| 354 | # a server in different language. |
| 355 | custom_server_lang = scenario_json.get('SERVER_LANGUAGE', None) |
Jan Tattermusch | 37a907e | 2016-05-13 13:49:43 -0700 | [diff] [blame] | 356 | custom_client_lang = scenario_json.get('CLIENT_LANGUAGE', None) |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 357 | scenario_json = scenario_config.remove_nonproto_fields(scenario_json) |
Jan Tattermusch | 37a907e | 2016-05-13 13:49:43 -0700 | [diff] [blame] | 358 | if custom_server_lang and custom_client_lang: |
| 359 | raise Exception('Cannot set both custom CLIENT_LANGUAGE and SERVER_LANGUAGE' |
| 360 | 'in the same scenario') |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 361 | if custom_server_lang: |
| 362 | if not workers_by_lang.get(custom_server_lang, []): |
siddharthshukla | 0589e53 | 2016-07-07 16:08:01 +0200 | [diff] [blame] | 363 | print('Warning: Skipping scenario %s as' % scenario_json['name']) |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 364 | print('SERVER_LANGUAGE is set to %s yet the language has ' |
| 365 | 'not been selected with -l' % custom_server_lang) |
| 366 | continue |
| 367 | for idx in range(0, scenario_json['num_servers']): |
| 368 | # replace first X workers by workers of a different language |
| 369 | workers[idx] = workers_by_lang[custom_server_lang][idx] |
Jan Tattermusch | 37a907e | 2016-05-13 13:49:43 -0700 | [diff] [blame] | 370 | if custom_client_lang: |
| 371 | if not workers_by_lang.get(custom_client_lang, []): |
siddharthshukla | 0589e53 | 2016-07-07 16:08:01 +0200 | [diff] [blame] | 372 | print('Warning: Skipping scenario %s as' % scenario_json['name']) |
Jan Tattermusch | 37a907e | 2016-05-13 13:49:43 -0700 | [diff] [blame] | 373 | print('CLIENT_LANGUAGE is set to %s yet the language has ' |
| 374 | 'not been selected with -l' % custom_client_lang) |
| 375 | continue |
| 376 | for idx in range(scenario_json['num_servers'], len(workers)): |
| 377 | # replace all client workers by workers of a different language, |
| 378 | # leave num_server workers as they are server workers. |
| 379 | workers[idx] = workers_by_lang[custom_client_lang][idx] |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 380 | scenario = Scenario( |
| 381 | create_scenario_jobspec(scenario_json, |
| 382 | [w.host_and_port for w in workers], |
| 383 | remote_host=remote_host, |
Yuxuan Li | ac87a46 | 2016-11-11 12:05:11 -0800 | [diff] [blame] | 384 | bq_result_table=bq_result_table, |
| 385 | server_cpu_load=server_cpu_load), |
Craig Tiller | 677966a | 2016-09-26 07:37:28 -0700 | [diff] [blame] | 386 | workers, |
| 387 | scenario_json['name']) |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 388 | scenarios.append(scenario) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 389 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 390 | return scenarios |
| 391 | |
| 392 | |
| 393 | def finish_qps_workers(jobs): |
| 394 | """Waits for given jobs to finish and eventually kills them.""" |
| 395 | retries = 0 |
Alexander Polcyn | 4979667 | 2016-10-17 10:01:37 -0700 | [diff] [blame] | 396 | num_killed = 0 |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 397 | while any(job.is_running() for job in jobs): |
| 398 | for job in qpsworker_jobs: |
| 399 | if job.is_running(): |
siddharthshukla | 0589e53 | 2016-07-07 16:08:01 +0200 | [diff] [blame] | 400 | print('QPS worker "%s" is still running.' % job.host_and_port) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 401 | if retries > 10: |
siddharthshukla | 0589e53 | 2016-07-07 16:08:01 +0200 | [diff] [blame] | 402 | print('Killing all QPS workers.') |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 403 | for job in jobs: |
| 404 | job.kill() |
Alexander Polcyn | 4979667 | 2016-10-17 10:01:37 -0700 | [diff] [blame] | 405 | num_killed += 1 |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 406 | retries += 1 |
| 407 | time.sleep(3) |
siddharthshukla | 0589e53 | 2016-07-07 16:08:01 +0200 | [diff] [blame] | 408 | print('All QPS workers finished.') |
Alexander Polcyn | 4979667 | 2016-10-17 10:01:37 -0700 | [diff] [blame] | 409 | return num_killed |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 410 | |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 411 | profile_output_files = [] |
| 412 | |
| 413 | # Collect perf text reports and flamegraphs if perf_cmd was used |
| 414 | # Note the base names of perf text reports are used when creating and processing |
| 415 | # perf data. The scenario name uniqifies the output name in the final |
| 416 | # perf reports directory. |
| 417 | # Alos, the perf profiles need to be fetched and processed after each scenario |
| 418 | # in order to avoid clobbering the output files. |
| 419 | def run_collect_perf_profile_jobs(hosts_and_base_names, scenario_name): |
| 420 | perf_report_jobs = [] |
| 421 | global profile_output_files |
| 422 | for host_and_port in hosts_and_base_names: |
| 423 | perf_base_name = hosts_and_base_names[host_and_port] |
| 424 | output_filename = '%s-%s' % (scenario_name, perf_base_name) |
| 425 | # from the base filename, create .svg output filename |
| 426 | host = host_and_port.split(':')[0] |
| 427 | profile_output_files.append('%s.svg' % output_filename) |
| 428 | perf_report_jobs.append(perf_report_processor_job(host, perf_base_name, output_filename)) |
| 429 | |
| 430 | jobset.message('START', 'Collecting perf reports from qps workers', do_newline=True) |
| 431 | failures, _ = jobset.run(perf_report_jobs, newline_on_success=True, maxjobs=1) |
| 432 | jobset.message('END', 'Collecting perf reports from qps workers', do_newline=True) |
| 433 | return failures |
| 434 | |
| 435 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 436 | argp = argparse.ArgumentParser(description='Run performance tests.') |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 437 | argp.add_argument('-l', '--language', |
Craig Tiller | d92d5c5 | 2016-04-04 13:49:29 -0700 | [diff] [blame] | 438 | choices=['all'] + sorted(scenario_config.LANGUAGES.keys()), |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 439 | nargs='+', |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 440 | required=True, |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 441 | help='Languages to benchmark.') |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 442 | argp.add_argument('--remote_driver_host', |
| 443 | default=None, |
| 444 | help='Run QPS driver on given host. By default, QPS driver is run locally.') |
| 445 | argp.add_argument('--remote_worker_host', |
| 446 | nargs='+', |
| 447 | default=[], |
| 448 | help='Worker hosts where to start QPS workers.') |
Craig Tiller | 677966a | 2016-09-26 07:37:28 -0700 | [diff] [blame] | 449 | argp.add_argument('--dry_run', |
| 450 | default=False, |
| 451 | action='store_const', |
| 452 | const=True, |
| 453 | help='Just list scenarios to be run, but don\'t run them.') |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 454 | argp.add_argument('-r', '--regex', default='.*', type=str, |
| 455 | help='Regex to select scenarios to run.') |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 456 | argp.add_argument('--bq_result_table', default=None, type=str, |
| 457 | help='Bigquery "dataset.table" to upload results to.') |
Jan Tattermusch | 427699b | 2016-05-05 18:10:14 -0700 | [diff] [blame] | 458 | argp.add_argument('--category', |
Craig Tiller | 6388da5 | 2016-09-07 17:06:29 -0700 | [diff] [blame] | 459 | choices=['smoketest','all','scalable','sweep'], |
Jan Tattermusch | 37a907e | 2016-05-13 13:49:43 -0700 | [diff] [blame] | 460 | default='all', |
| 461 | help='Select a category of tests to run.') |
Jan Tattermusch | 4de2c32 | 2016-05-10 14:33:07 -0700 | [diff] [blame] | 462 | argp.add_argument('--netperf', |
| 463 | default=False, |
| 464 | action='store_const', |
| 465 | const=True, |
| 466 | help='Run netperf benchmark as one of the scenarios.') |
Yuxuan Li | ac87a46 | 2016-11-11 12:05:11 -0800 | [diff] [blame] | 467 | argp.add_argument('--server_cpu_load', |
| 468 | default=0, type=int, |
| 469 | help='Select a targeted server cpu load to run. 0 means ignore this flag') |
Jan Tattermusch | 88818ae | 2016-11-18 14:21:33 +0100 | [diff] [blame] | 470 | argp.add_argument('-x', '--xml_report', default='report.xml', type=str, |
| 471 | help='Name of XML report file to generate.') |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 472 | argp.add_argument('--perf_args', |
| 473 | help=('Example usage: "--perf_args=record -F 99 -g". ' |
| 474 | 'Wrap QPS workers in a perf command ' |
| 475 | 'with the arguments to perf specified here. ' |
| 476 | '".svg" flame graph profiles will be ' |
| 477 | 'created for each Qps Worker on each scenario. ' |
Alexander Polcyn | 66c6782 | 2016-12-09 10:22:50 -0800 | [diff] [blame] | 478 | 'Files will output to "<repo_root>/<args.flame_graph_reports>" ' |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 479 | 'directory. Output files from running the worker ' |
| 480 | 'under perf are saved in the repo root where its ran. ' |
| 481 | 'Note that the perf "-g" flag is necessary for ' |
| 482 | 'flame graphs generation to work (assuming the binary ' |
| 483 | 'being profiled uses frame pointers, check out ' |
| 484 | '"--call-graph dwarf" option using libunwind otherwise.) ' |
| 485 | 'Also note that the entire "--perf_args=<arg(s)>" must ' |
| 486 | 'be wrapped in quotes as in the example usage. ' |
| 487 | 'If the "--perg_args" is unspecified, "perf" will ' |
| 488 | 'not be used at all. ' |
| 489 | 'See http://www.brendangregg.com/perf.html ' |
| 490 | 'for more general perf examples.')) |
| 491 | argp.add_argument('--skip_generate_flamegraphs', |
| 492 | default=False, |
| 493 | action='store_const', |
| 494 | const=True, |
| 495 | help=('Turn flame graph generation off. ' |
| 496 | 'May be useful if "perf_args" arguments do not make sense for ' |
| 497 | 'generating flamegraphs (e.g., "--perf_args=stat ...")')) |
Alexander Polcyn | 66c6782 | 2016-12-09 10:22:50 -0800 | [diff] [blame] | 498 | argp.add_argument('-f', '--flame_graph_reports', default='perf_reports', type=str, |
| 499 | help='Name of directory to output flame graph profiles to, if any are created.') |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 500 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 501 | args = argp.parse_args() |
| 502 | |
Craig Tiller | d92d5c5 | 2016-04-04 13:49:29 -0700 | [diff] [blame] | 503 | languages = set(scenario_config.LANGUAGES[l] |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 504 | for l in itertools.chain.from_iterable( |
Craig Tiller | d92d5c5 | 2016-04-04 13:49:29 -0700 | [diff] [blame] | 505 | scenario_config.LANGUAGES.iterkeys() if x == 'all' else [x] |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 506 | for x in args.language)) |
| 507 | |
Jan Tattermusch | 6d7fa55 | 2016-04-14 17:42:54 -0700 | [diff] [blame] | 508 | |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 509 | # Put together set of remote hosts where to run and build |
| 510 | remote_hosts = set() |
| 511 | if args.remote_worker_host: |
| 512 | for host in args.remote_worker_host: |
| 513 | remote_hosts.add(host) |
| 514 | if args.remote_driver_host: |
| 515 | remote_hosts.add(args.remote_driver_host) |
| 516 | |
Craig Tiller | 677966a | 2016-09-26 07:37:28 -0700 | [diff] [blame] | 517 | if not args.dry_run: |
| 518 | if remote_hosts: |
| 519 | archive_repo(languages=[str(l) for l in languages]) |
| 520 | prepare_remote_hosts(remote_hosts, prepare_local=True) |
| 521 | else: |
| 522 | prepare_remote_hosts([], prepare_local=True) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 523 | |
| 524 | build_local = False |
| 525 | if not args.remote_driver_host: |
| 526 | build_local = True |
Craig Tiller | 677966a | 2016-09-26 07:37:28 -0700 | [diff] [blame] | 527 | if not args.dry_run: |
| 528 | build_on_remote_hosts(remote_hosts, languages=[str(l) for l in languages], build_local=build_local) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 529 | |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 530 | perf_cmd = None |
| 531 | if args.perf_args: |
Alexander Polcyn | 66c6782 | 2016-12-09 10:22:50 -0800 | [diff] [blame] | 532 | print('Running workers under perf profiler') |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 533 | # Expect /usr/bin/perf to be installed here, as is usual |
Alexander Polcyn | 66c6782 | 2016-12-09 10:22:50 -0800 | [diff] [blame] | 534 | perf_cmd = ['/usr/bin/perf'] |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 535 | perf_cmd.extend(re.split('\s+', args.perf_args)) |
| 536 | |
| 537 | qpsworker_jobs = create_qpsworkers(languages, args.remote_worker_host, perf_cmd=perf_cmd) |
Jan Tattermusch | 38becc2 | 2016-04-14 08:00:35 -0700 | [diff] [blame] | 538 | |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 539 | # get list of worker addresses for each language. |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 540 | workers_by_lang = dict([(str(language), []) for language in languages]) |
Jan Tattermusch | bb1a453 | 2016-03-30 18:04:01 -0700 | [diff] [blame] | 541 | for job in qpsworker_jobs: |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 542 | workers_by_lang[str(job.language)].append(job) |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 543 | |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 544 | scenarios = create_scenarios(languages, |
Craig Tiller | d82fccc | 2016-09-15 09:15:23 -0700 | [diff] [blame] | 545 | workers_by_lang=workers_by_lang, |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 546 | remote_host=args.remote_driver_host, |
| 547 | regex=args.regex, |
| 548 | category=args.category, |
| 549 | bq_result_table=args.bq_result_table, |
| 550 | netperf=args.netperf, |
Yuxuan Li | ac87a46 | 2016-11-11 12:05:11 -0800 | [diff] [blame] | 551 | netperf_hosts=args.remote_worker_host, |
| 552 | server_cpu_load=args.server_cpu_load) |
Jan Tattermusch | 4de2c32 | 2016-05-10 14:33:07 -0700 | [diff] [blame] | 553 | |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 554 | if not scenarios: |
| 555 | raise Exception('No scenarios to run') |
Jan Tattermusch | b275844 | 2016-03-28 09:32:20 -0700 | [diff] [blame] | 556 | |
Alex Polcyn | cac93f6 | 2016-10-19 09:27:57 -0700 | [diff] [blame] | 557 | total_scenario_failures = 0 |
Alexander Polcyn | 898a2e9 | 2016-10-22 17:41:23 -0700 | [diff] [blame] | 558 | qps_workers_killed = 0 |
Jan Tattermusch | 94d40cb | 2016-10-24 21:06:40 +0200 | [diff] [blame] | 559 | merged_resultset = {} |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 560 | perf_report_failures = 0 |
| 561 | |
Craig Tiller | c1b54f2 | 2016-09-15 08:57:14 -0700 | [diff] [blame] | 562 | for scenario in scenarios: |
Craig Tiller | 677966a | 2016-09-26 07:37:28 -0700 | [diff] [blame] | 563 | if args.dry_run: |
| 564 | print(scenario.name) |
| 565 | else: |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 566 | scenario_failures = 0 |
Craig Tiller | 677966a | 2016-09-26 07:37:28 -0700 | [diff] [blame] | 567 | try: |
| 568 | for worker in scenario.workers: |
| 569 | worker.start() |
Alex Polcyn | fcf09ea | 2016-12-06 04:00:05 +0000 | [diff] [blame] | 570 | jobs = [scenario.jobspec] |
Alex Polcyn | ca5e924 | 2016-12-06 04:21:37 +0000 | [diff] [blame] | 571 | if scenario.workers: |
Alex Polcyn | fcf09ea | 2016-12-06 04:00:05 +0000 | [diff] [blame] | 572 | jobs.append(create_quit_jobspec(scenario.workers, remote_host=args.remote_driver_host)) |
| 573 | scenario_failures, resultset = jobset.run(jobs, newline_on_success=True, maxjobs=1) |
Alex Polcyn | cac93f6 | 2016-10-19 09:27:57 -0700 | [diff] [blame] | 574 | total_scenario_failures += scenario_failures |
Jan Tattermusch | 94d40cb | 2016-10-24 21:06:40 +0200 | [diff] [blame] | 575 | merged_resultset = dict(itertools.chain(merged_resultset.iteritems(), |
| 576 | resultset.iteritems())) |
Craig Tiller | 677966a | 2016-09-26 07:37:28 -0700 | [diff] [blame] | 577 | finally: |
Alexander Polcyn | 898a2e9 | 2016-10-22 17:41:23 -0700 | [diff] [blame] | 578 | # Consider qps workers that need to be killed as failures |
| 579 | qps_workers_killed += finish_qps_workers(scenario.workers) |
Alexander Polcyn | 4979667 | 2016-10-17 10:01:37 -0700 | [diff] [blame] | 580 | |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 581 | if perf_cmd and scenario_failures == 0 and not args.skip_generate_flamegraphs: |
| 582 | workers_and_base_names = {} |
| 583 | for worker in scenario.workers: |
| 584 | if not worker.perf_file_base_name: |
| 585 | raise Exception('using perf buf perf report filename is unspecified') |
| 586 | workers_and_base_names[worker.host_and_port] = worker.perf_file_base_name |
| 587 | perf_report_failures += run_collect_perf_profile_jobs(workers_and_base_names, scenario.name) |
| 588 | |
| 589 | |
| 590 | # Still write the index.html even if some scenarios failed. |
| 591 | # 'profile_output_files' will only have names for scenarios that passed |
| 592 | if perf_cmd and not args.skip_generate_flamegraphs: |
| 593 | # write the index fil to the output dir, with all profiles from all scenarios/workers |
Alexander Polcyn | 66c6782 | 2016-12-09 10:22:50 -0800 | [diff] [blame] | 594 | report_utils.render_perf_profiling_results('%s/index.html' % args.flame_graph_reports, profile_output_files) |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 595 | |
Alexander Polcyn | 41fe579 | 2017-02-02 10:46:51 -0800 | [diff] [blame] | 596 | report_utils.render_junit_xml_report(merged_resultset, args.xml_report, |
| 597 | suite_name='benchmarks') |
| 598 | |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 599 | if total_scenario_failures > 0 or qps_workers_killed > 0: |
| 600 | print('%s scenarios failed and %s qps worker jobs killed' % (total_scenario_failures, qps_workers_killed)) |
| 601 | sys.exit(1) |
Jan Tattermusch | 94d40cb | 2016-10-24 21:06:40 +0200 | [diff] [blame] | 602 | |
Alexander Polcyn | 9f08d11 | 2016-10-24 12:25:02 -0700 | [diff] [blame] | 603 | if perf_report_failures > 0: |
| 604 | print('%s perf profile collection jobs failed' % perf_report_failures) |
Alex Polcyn | cac93f6 | 2016-10-19 09:27:57 -0700 | [diff] [blame] | 605 | sys.exit(1) |