| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 | 7 |
| 8 """Generate new bench expectations from results of trybots on a code review.""" | 8 """Generate new bench expectations from results of trybots on a code review.""" |
| 9 | 9 |
| 10 | 10 |
| 11 import collections | 11 import collections |
| 12 import compare_codereview | 12 import compare_codereview |
| 13 import json | 13 import json |
| 14 import os | 14 import os |
| 15 import re | 15 import re |
| 16 import shutil | 16 import shutil |
| 17 import subprocess |
| 17 import sys | 18 import sys |
| 18 import urllib2 | 19 import urllib2 |
| 19 | 20 |
| 20 import fix_pythonpath # pylint: disable=W0611 | |
| 21 from common.py.utils import shell_utils | |
| 22 | |
| 23 | 21 |
| 24 BENCH_DATA_URL = 'gs://chromium-skia-gm/perfdata/%s/%s/bench_*_data_*' | 22 BENCH_DATA_URL = 'gs://chromium-skia-gm/perfdata/%s/%s/bench_*_data_*' |
| 25 BUILD_STATUS_SUCCESS = 0 | 23 BUILD_STATUS_SUCCESS = 0 |
| 26 BUILD_STATUS_WARNINGS = 1 | 24 BUILD_STATUS_WARNINGS = 1 |
| 27 CHECKOUT_PATH = os.path.realpath(os.path.join( | 25 CHECKOUT_PATH = os.path.realpath(os.path.join( |
| 28 os.path.dirname(os.path.abspath(__file__)), os.pardir)) | 26 os.path.dirname(os.path.abspath(__file__)), os.pardir)) |
| 29 TMP_BENCH_DATA_DIR = os.path.join(CHECKOUT_PATH, '.bench_data') | 27 TMP_BENCH_DATA_DIR = os.path.join(CHECKOUT_PATH, '.bench_data') |
| 30 | 28 |
| 31 | 29 |
| 32 TryBuild = collections.namedtuple( | 30 TryBuild = collections.namedtuple( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 89 |
| 92 def get_bench_data(builder, build_num, dest_dir): | 90 def get_bench_data(builder, build_num, dest_dir): |
| 93 """Download the bench data for the given builder at the given build_num. | 91 """Download the bench data for the given builder at the given build_num. |
| 94 | 92 |
| 95 Args: | 93 Args: |
| 96 builder: string; name of the builder. | 94 builder: string; name of the builder. |
| 97 build_num: string; build number. | 95 build_num: string; build number. |
| 98 dest_dir: string; destination directory for the bench data. | 96 dest_dir: string; destination directory for the bench data. |
| 99 """ | 97 """ |
| 100 url = BENCH_DATA_URL % (builder, build_num) | 98 url = BENCH_DATA_URL % (builder, build_num) |
| 101 shell_utils.run(['gsutil', 'cp', '-R', url, dest_dir]) | 99 subprocess.check_call(['gsutil', 'cp', '-R', url, dest_dir]) |
| 102 | 100 |
| 103 | 101 |
| 104 def find_revision_from_downloaded_data(dest_dir): | 102 def find_revision_from_downloaded_data(dest_dir): |
| 105 """Finds the revision at which the downloaded data was generated. | 103 """Finds the revision at which the downloaded data was generated. |
| 106 | 104 |
| 107 Args: | 105 Args: |
| 108 dest_dir: string; directory holding the downloaded data. | 106 dest_dir: string; directory holding the downloaded data. |
| 109 | 107 |
| 110 Returns: | 108 Returns: |
| 111 The revision (git commit hash) at which the downloaded data was | 109 The revision (git commit hash) at which the downloaded data was |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 if try_builder in failed_run: | 190 if try_builder in failed_run: |
| 193 continue | 191 continue |
| 194 | 192 |
| 195 builder = try_builder.replace('-Trybot', '') | 193 builder = try_builder.replace('-Trybot', '') |
| 196 | 194 |
| 197 # Download the data. | 195 # Download the data. |
| 198 dest_dir = os.path.join(TMP_BENCH_DATA_DIR, builder) | 196 dest_dir = os.path.join(TMP_BENCH_DATA_DIR, builder) |
| 199 os.makedirs(dest_dir) | 197 os.makedirs(dest_dir) |
| 200 try: | 198 try: |
| 201 get_bench_data(try_builder, try_build.build_number, dest_dir) | 199 get_bench_data(try_builder, try_build.build_number, dest_dir) |
| 202 except shell_utils.CommandFailedException: | 200 except subprocess.CalledProcessError: |
| 203 failed_data_pull.append(try_builder) | 201 failed_data_pull.append(try_builder) |
| 204 continue | 202 continue |
| 205 | 203 |
| 206 # Find the revision at which the data was generated. | 204 # Find the revision at which the data was generated. |
| 207 revision = find_revision_from_downloaded_data(dest_dir) | 205 revision = find_revision_from_downloaded_data(dest_dir) |
| 208 if not revision: | 206 if not revision: |
| 209 # If we can't find a revision, then something is wrong with the data we | 207 # If we can't find a revision, then something is wrong with the data we |
| 210 # downloaded. Skip this builder. | 208 # downloaded. Skip this builder. |
| 211 failed_data_pull.append(try_builder) | 209 failed_data_pull.append(try_builder) |
| 212 continue | 210 continue |
| 213 | 211 |
| 214 # Generate new expectations. | 212 # Generate new expectations. |
| 215 output_file = os.path.join(CHECKOUT_PATH, 'expectations', 'bench', | 213 output_file = os.path.join(CHECKOUT_PATH, 'expectations', 'bench', |
| 216 'bench_expectations_%s.txt' % builder) | 214 'bench_expectations_%s.txt' % builder) |
| 217 try: | 215 try: |
| 218 shell_utils.run(['python', | 216 subprocess.check_call(['python', |
| 219 os.path.join(CHECKOUT_PATH, 'bench', | 217 os.path.join(CHECKOUT_PATH, 'bench', |
| 220 'gen_bench_expectations.py'), | 218 'gen_bench_expectations.py'), |
| 221 '-b', builder, '-o', output_file, | 219 '-b', builder, '-o', output_file, |
| 222 '-d', dest_dir, '-r', revision]) | 220 '-d', dest_dir, '-r', revision]) |
| 223 except shell_utils.CommandFailedException: | 221 except subprocess.CalledProcessError: |
| 224 failed_gen_expectations.append(builder) | 222 failed_gen_expectations.append(builder) |
| 225 | 223 |
| 226 failure = '' | 224 failure = '' |
| 227 if failed_data_pull: | 225 if failed_data_pull: |
| 228 failure += 'Failed to load data for: %s\n\n' % ','.join(failed_data_pull) | 226 failure += 'Failed to load data for: %s\n\n' % ','.join(failed_data_pull) |
| 229 if failed_gen_expectations: | 227 if failed_gen_expectations: |
| 230 failure += 'Failed to generate expectations for: %s\n\n' % ','.join( | 228 failure += 'Failed to generate expectations for: %s\n\n' % ','.join( |
| 231 failed_gen_expectations) | 229 failed_gen_expectations) |
| 232 if failure: | 230 if failure: |
| 233 raise Exception(failure) | 231 raise Exception(failure) |
| 234 | 232 |
| 235 | 233 |
| 236 if __name__ == '__main__': | 234 if __name__ == '__main__': |
| 237 gen_bench_expectations_from_codereview(sys.argv[1]) | 235 gen_bench_expectations_from_codereview(sys.argv[1]) |
| 238 | 236 |
| OLD | NEW |