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 os | 13 import os |
14 import re | 14 import re |
15 import shutil | 15 import shutil |
16 import subprocess | 16 import subprocess |
17 import sys | 17 import sys |
18 | 18 |
19 | 19 |
20 BENCH_DATA_URL = 'gs://chromium-skia-gm/perfdata/%s/%s/*' | 20 BENCH_DATA_URL = 'gs://chromium-skia-gm/perfdata/%s/%s/*' |
21 CHECKOUT_PATH = os.path.realpath(os.path.join( | 21 CHECKOUT_PATH = os.path.realpath(os.path.join( |
22 os.path.dirname(os.path.abspath(__file__)), os.pardir)) | 22 os.path.dirname(os.path.abspath(__file__)), os.pardir)) |
23 TMP_BENCH_DATA_DIR = os.path.join(CHECKOUT_PATH, '.bench_data') | 23 TMP_BENCH_DATA_DIR = os.path.join(CHECKOUT_PATH, '.bench_data') |
24 | 24 |
25 | 25 |
26 TryBuild = collections.namedtuple( | |
27 'TryBuild', ['builder_name', 'build_number', 'is_finished']) | |
28 | |
29 | |
26 def find_all_builds(codereview_url): | 30 def find_all_builds(codereview_url): |
27 """Finds and returns information about trybot runs for a code review. | 31 """Finds and returns information about trybot runs for a code review. |
28 | 32 |
29 Args: | 33 Args: |
30 codereview_url: URL of the codereview in question. | 34 codereview_url: URL of the codereview in question. |
31 | 35 |
32 Returns: | 36 Returns: |
33 List of NamedTuples: (builder_name, build_number, is_finished) | 37 List of NamedTuples: (builder_name, build_number, is_finished) |
34 """ | 38 """ |
35 results = compare_codereview.CodeReviewHTMLParser().parse(codereview_url) | 39 results = compare_codereview.CodeReviewHTMLParser().parse(codereview_url) |
36 TryBuild = collections.namedtuple( | |
37 'TryBuild', ['builder_name', 'build_number', 'is_finished']) | |
38 try_builds = [] | 40 try_builds = [] |
39 | |
40 for builder, data in results.iteritems(): | 41 for builder, data in results.iteritems(): |
41 if builder.startswith('Perf'): | 42 if builder.startswith('Perf'): |
42 try_builds.append(TryBuild(builder, data.url.split('/')[-1], | 43 try_builds.append(TryBuild(builder, data.url.split('/')[-1], |
43 data.status != 'pending')) | 44 data.status != 'pending')) |
44 return try_builds | 45 return try_builds |
45 | 46 |
46 | 47 |
48 def _all_trybots_finished(try_builds): | |
49 """Return True iff all of the given try jobs have finished. | |
50 | |
51 Args: | |
52 try_builds: list of TryBuild instances. | |
53 | |
54 Returns: | |
55 True if all of the given try jobs have finished, otherwise False. | |
56 """ | |
57 for try_build in try_builds: | |
58 if not try_build.is_finished: | |
59 return False | |
60 return True | |
61 | |
62 | |
63 def all_trybots_finished(codereview_url): | |
64 """Return True iff all of the try jobs on the given codereview have finished. | |
65 | |
66 Args: | |
67 codereview_url: string; URL of the codereview. | |
68 | |
69 Returns: | |
70 True if all of the try jobs have finished, otherwise False. | |
71 """ | |
72 return _all_trybots_finished(find_all_builds(codereview_url)) | |
73 | |
74 | |
47 def get_bench_data(builder, build_num, dest_dir): | 75 def get_bench_data(builder, build_num, dest_dir): |
48 """Download the bench data for the given builder at the given build_num. | 76 """Download the bench data for the given builder at the given build_num. |
49 | 77 |
50 Args: | 78 Args: |
51 builder: string; name of the builder. | 79 builder: string; name of the builder. |
52 build_num: string; build number. | 80 build_num: string; build number. |
53 dest_dir: string; destination directory for the bench data. | 81 dest_dir: string; destination directory for the bench data. |
54 """ | 82 """ |
55 url = BENCH_DATA_URL % (builder, build_num) | 83 url = BENCH_DATA_URL % (builder, build_num) |
56 subprocess.check_call(['gsutil', 'cp', '-R', url, dest_dir], | 84 subprocess.check_call(['gsutil', 'cp', '-R', url, dest_dir], |
(...skipping 30 matching lines...) Expand all Loading... | |
87 finished trybots and uses them to generate new expectations for their | 115 finished trybots and uses them to generate new expectations for their |
88 waterfall counterparts. | 116 waterfall counterparts. |
89 | 117 |
90 Args: | 118 Args: |
91 url: string; URL of the code review. | 119 url: string; URL of the code review. |
92 error_on_unfinished: bool; throw an error if any trybot has not finished. | 120 error_on_unfinished: bool; throw an error if any trybot has not finished. |
93 """ | 121 """ |
94 try_builds = find_all_builds(codereview_url) | 122 try_builds = find_all_builds(codereview_url) |
95 | 123 |
96 # Verify that all trybots have finished running. | 124 # Verify that all trybots have finished running. |
97 if error_on_unfinished: | 125 if error_on_unfinished and not _all_trybots_finished(try_builds): |
benchen
2014/05/29 13:20:26
all_trybots_finished(codereview_url) defined above
borenet
2014/05/29 13:21:59
It's going to be used by the RecreateSKPs bot.
| |
98 for try_build in try_builds: | 126 raise TrybotNotFinishedError('Not all trybots have finished.') |
99 if not try_build.is_finished: | 127 |
100 raise TrybotNotFinishedError('%s: #%s is not finished.' % ( | |
101 try_build.builder_name, | |
102 try_build.build_number)) | |
103 failed_data_pull = [] | 128 failed_data_pull = [] |
104 failed_gen_expectations = [] | 129 failed_gen_expectations = [] |
105 | 130 |
106 if os.path.isdir(TMP_BENCH_DATA_DIR): | 131 if os.path.isdir(TMP_BENCH_DATA_DIR): |
107 shutil.rmtree(TMP_BENCH_DATA_DIR) | 132 shutil.rmtree(TMP_BENCH_DATA_DIR) |
108 | 133 |
109 for try_build in try_builds: | 134 for try_build in try_builds: |
110 try_builder = try_build.builder_name | 135 try_builder = try_build.builder_name |
111 builder = try_builder.replace('-Trybot', '') | 136 builder = try_builder.replace('-Trybot', '') |
112 | 137 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 if failed_gen_expectations: | 170 if failed_gen_expectations: |
146 failure += 'Failed to generate expectations for: %s\n\n' % ','.join( | 171 failure += 'Failed to generate expectations for: %s\n\n' % ','.join( |
147 failed_gen_expectations) | 172 failed_gen_expectations) |
148 if failure: | 173 if failure: |
149 raise Exception(failure) | 174 raise Exception(failure) |
150 | 175 |
151 | 176 |
152 if __name__ == '__main__': | 177 if __name__ == '__main__': |
153 gen_bench_expectations_from_codereview(sys.argv[1]) | 178 gen_bench_expectations_from_codereview(sys.argv[1]) |
154 | 179 |
OLD | NEW |