| OLD | NEW |
| 1 ''' | 1 ''' |
| 2 Created on May 16, 2011 | 2 Created on May 16, 2011 |
| 3 | 3 |
| 4 @author: bungeman | 4 @author: bungeman |
| 5 ''' | 5 ''' |
| 6 import bench_util | 6 import bench_util |
| 7 import getopt | 7 import getopt |
| 8 import httplib | 8 import httplib |
| 9 import itertools | 9 import itertools |
| 10 import json | 10 import json |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 self.config == other.config and | 73 self.config == other.config and |
| 74 self.time_type == other.time_type and | 74 self.time_type == other.time_type and |
| 75 self.settings == other.settings) | 75 self.settings == other.settings) |
| 76 | 76 |
| 77 def __hash__(self): | 77 def __hash__(self): |
| 78 return (hash(self.bench) ^ | 78 return (hash(self.bench) ^ |
| 79 hash(self.config) ^ | 79 hash(self.config) ^ |
| 80 hash(self.time_type) ^ | 80 hash(self.time_type) ^ |
| 81 hash(frozenset(self.settings.iteritems()))) | 81 hash(frozenset(self.settings.iteritems()))) |
| 82 | 82 |
| 83 def parse_dir(directory, default_settings, revision, rep): | |
| 84 """Parses bench data from bench logs files. | |
| 85 revision can be either svn revision or git commit hash. | |
| 86 """ | |
| 87 revision_data_points = [] # list of BenchDataPoint | |
| 88 file_list = os.listdir(directory) | |
| 89 file_list.sort() | |
| 90 for bench_file in file_list: | |
| 91 scalar_type = None | |
| 92 # Scalar type, if any, is in the bench filename after revision | |
| 93 if (len(revision) > MAX_SVN_REV_LENGTH and | |
| 94 bench_file.startswith('bench_' + revision + '_')): | |
| 95 # The revision is GIT commit hash. | |
| 96 scalar_type = bench_file[len(revision) + len('bench_') + 1:] | |
| 97 elif (bench_file.startswith('bench_r' + revision + '_') and | |
| 98 revision.isdigit()): | |
| 99 # The revision is SVN number | |
| 100 scalar_type = bench_file[len(revision) + len('bench_r') + 1:] | |
| 101 else: | |
| 102 continue | |
| 103 | |
| 104 file_handle = open(directory + '/' + bench_file, 'r') | |
| 105 | |
| 106 default_settings['scalar'] = scalar_type | |
| 107 revision_data_points.extend( | |
| 108 bench_util.parse(default_settings, file_handle, rep)) | |
| 109 file_handle.close() | |
| 110 return revision_data_points | |
| 111 | |
| 112 def create_bench_dict(revision_data_points): | 83 def create_bench_dict(revision_data_points): |
| 113 """Convert current revision data into a dictionary of line data. | 84 """Convert current revision data into a dictionary of line data. |
| 114 | 85 |
| 115 Args: | 86 Args: |
| 116 revision_data_points: a list of bench data points | 87 revision_data_points: a list of bench data points |
| 117 | 88 |
| 118 Returns: | 89 Returns: |
| 119 a dictionary of this form: | 90 a dictionary of this form: |
| 120 keys = Label objects | 91 keys = Label objects |
| 121 values = the corresponding bench value | 92 values = the corresponding bench value |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 for ratio in ratios: | 170 for ratio in ratios: |
| 200 li.extend(exceptions[i][ratio]) | 171 li.extend(exceptions[i][ratio]) |
| 201 header = '%s benches got slower (sorted by %% difference):' % len(li) | 172 header = '%s benches got slower (sorted by %% difference):' % len(li) |
| 202 if i == FASTER: | 173 if i == FASTER: |
| 203 header = header.replace('slower', 'faster') | 174 header = header.replace('slower', 'faster') |
| 204 outputs.extend(['', header] + li) | 175 outputs.extend(['', header] + li) |
| 205 | 176 |
| 206 if outputs: | 177 if outputs: |
| 207 raise Exception('\n'.join(outputs)) | 178 raise Exception('\n'.join(outputs)) |
| 208 | 179 |
| 180 |
| 209 def main(): | 181 def main(): |
| 210 """Parses command line and checks bench expectations.""" | 182 """Parses command line and checks bench expectations.""" |
| 211 try: | 183 try: |
| 212 opts, _ = getopt.getopt(sys.argv[1:], | 184 opts, _ = getopt.getopt(sys.argv[1:], |
| 213 "a:b:d:e:r:", | 185 "a:b:d:e:r:", |
| 214 "default-setting=") | 186 "default-setting=") |
| 215 except getopt.GetoptError, err: | 187 except getopt.GetoptError, err: |
| 216 print str(err) | 188 print str(err) |
| 217 usage() | 189 usage() |
| 218 sys.exit(2) | 190 sys.exit(2) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 241 except ValueError: | 213 except ValueError: |
| 242 usage() | 214 usage() |
| 243 sys.exit(2) | 215 sys.exit(2) |
| 244 | 216 |
| 245 if directory is None or bot is None or rev is None: | 217 if directory is None or bot is None or rev is None: |
| 246 usage() | 218 usage() |
| 247 sys.exit(2) | 219 sys.exit(2) |
| 248 | 220 |
| 249 platform_and_alg = bot + '-' + rep | 221 platform_and_alg = bot + '-' + rep |
| 250 | 222 |
| 251 data_points = parse_dir(directory, | 223 data_points = bench_util.parse_skp_bench_data(directory, rev, rep) |
| 252 {}, # Sets default settings to empty. | |
| 253 rev, | |
| 254 rep) | |
| 255 | 224 |
| 256 bench_dict = create_bench_dict(data_points) | 225 bench_dict = create_bench_dict(data_points) |
| 257 | 226 |
| 258 if bench_expectations: | 227 if bench_expectations: |
| 259 check_expectations(bench_dict, bench_expectations, platform_and_alg) | 228 check_expectations(bench_dict, bench_expectations, platform_and_alg) |
| 260 | 229 |
| 261 | 230 |
| 262 if __name__ == "__main__": | 231 if __name__ == "__main__": |
| 263 main() | 232 main() |
| OLD | NEW |