Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 2 | |
| 3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 4 # for details. All rights reserved. Use of this source code is governed by a | |
| 5 # BSD-style license that can be found in the LICENSE file. | |
| 6 | |
| 7 import datetime | |
| 8 import math | |
| 9 from matplotlib.font_manager import FontProperties | |
| 10 import matplotlib.pyplot as plt | |
| 11 import os | |
| 12 import platform | |
| 13 import shutil | |
| 14 import subprocess | |
| 15 import time | |
| 16 import traceback | |
| 17 | |
| 18 """This script runs to track performance and correctness progress of | |
| 19 different svn revisions. It tests to see if there a newer version of the code on | |
| 20 the server, and will sync and run the performance tests if so.""" | |
| 21 | |
| 22 DART_INSTALL_LOCATION = os.path.join(os.path.dirname(os.path.abspath(__file__)), | |
| 23 '..', '..', '..') | |
| 24 V8_MEAN = 'V8 Mean' | |
| 25 FROG_MEAN = 'frog Mean' | |
| 26 COMMAND_LINE = 'commandline' | |
| 27 V8 = 'v8' | |
| 28 FROG = 'frog' | |
| 29 V8_AND_FROG = [V8, FROG] | |
| 30 CORRECTNESS = 'Percent passing' | |
| 31 BENCHMARKS = ['Mandelbrot', 'DeltaBlue', 'Richards', 'NBody', | |
| 32 'BinaryTrees', 'Fannkuch', 'Meteor', 'BubbleSort', 'Fibonacci', | |
| 33 'Loop', 'Permute', 'Queens', 'QuickSort', 'Recurse', 'Sieve', 'Sum', | |
| 34 'Tak', 'Takl', 'Towers', 'TreeSort'] | |
| 35 COLORS = ['blue', 'green', 'red', 'cyan', 'magenta', 'black'] | |
| 36 GRAPH_OUT_DIR = 'graphs' | |
| 37 | |
| 38 """First, some utility methods.""" | |
| 39 | |
| 40 def RunCmd(string): | |
| 41 """Run the specified command and print out any output to stdout. | |
| 42 Args: | |
| 43 string the command to run""" | |
| 44 p = subprocess.Popen(string, shell = True, stdout = subprocess.PIPE, | |
| 45 stderr = subprocess.STDOUT, close_fds=True) | |
| 46 lines = p.stdout.readlines() | |
| 47 for line in lines: | |
| 48 print line, | |
|
Siggi Cherem (dart-lang)
2011/11/30 01:40:21
you probably want the runcmd to wait until the com
Emily Fortuna
2011/11/30 01:57:46
Done.
| |
| 49 return lines | |
| 50 | |
| 51 def SyncAndBuild(failed_once=False): | |
| 52 """Make sure we have the latest version of of the repo, and build it. We | |
| 53 begin and end standing in DART_INSTALL_LOCATION. | |
| 54 Args: | |
| 55 failed_once True if we have attempted to build this once before, and we've | |
| 56 failed, indicating .""" | |
| 57 os.chdir(DART_INSTALL_LOCATION) | |
| 58 #Revert our newly built frogsh to prevent conflicts when we update | |
| 59 RunCmd('svn revert ' + os.path.join(os.getcwd(), 'frog', 'frogsh')) | |
| 60 | |
| 61 RunCmd('gclient sync') | |
| 62 lines = RunCmd('%s -m release' % os.path.join('.', 'tools', 'build.py')) | |
| 63 os.chdir('frog') | |
| 64 lines += RunCmd('%s -m debug,release' % os.path.join('..', 'tools', | |
| 65 'build.py')) | |
| 66 os.chdir('..') | |
| 67 | |
| 68 for line in lines: | |
| 69 if '** BUILD FAILED **' in lines: | |
| 70 if TestRunner.failed_once: | |
| 71 # Someone checked in a broken build! Just stop trying to make it work | |
| 72 # and wait for the next hour to try again. | |
| 73 print 'Broken Build' | |
| 74 sys.exit(0) | |
| 75 #Remove the xcode directory and attempt to build again. If it still | |
| 76 #fails, abort, and try again next hour. | |
| 77 out_dir = 'out' | |
| 78 if platform.system() == 'Darwin': | |
| 79 out_dir = 'xcodebuild' | |
| 80 os.removedirs(os.getcwd() + os.path.join('dart', out_dir, 'Release_ia32')) | |
| 81 os.removedirs(os.getcwd() + os.path.join('dart', 'frog', out_dir, | |
| 82 'Release_ia32')) | |
| 83 os.removedirs(os.getcwd() + os.path.join('dart', 'frog', out_dir, | |
| 84 'Debug_ia32')) | |
| 85 TestRunner.failed_once = True | |
| 86 SyncAndBuild() | |
| 87 | |
| 88 def EnsureOutputDirectory(dir_name): | |
| 89 """Test that the listed directory name exists, and if not, create one for | |
| 90 our output to be placed.""" | |
| 91 dir_path = os.path.join(DART_INSTALL_LOCATION, 'tools', 'testing', | |
| 92 'perf_testing', dir_name) | |
| 93 if not os.path.exists(dir_path): | |
| 94 os.mkdir(dir_path) | |
| 95 print 'Creating output directory ', dir_path | |
| 96 | |
| 97 def HasNewCode(): | |
| 98 """Tests if there are any newer versions of files on the server.""" | |
| 99 os.chdir(DART_INSTALL_LOCATION) | |
| 100 results = RunCmd('svn st -u') | |
| 101 for line in results: | |
| 102 if '*' in line: | |
| 103 return True | |
| 104 return False | |
| 105 | |
| 106 def GetBrowsers(): | |
| 107 browsers = ['ff', 'chrome'] | |
| 108 if platform.system() == 'Windows': | |
| 109 browsers += ['ie'] | |
| 110 return browsers | |
| 111 | |
| 112 class TestRunner(object): | |
| 113 """The base clas to provide shared code for different tests we will run and | |
| 114 graph.""" | |
| 115 | |
| 116 def __init__(self, result_folder_name, platform_list, v8_and_or_frog_list, | |
| 117 values_list): | |
| 118 """Args: | |
| 119 result_folder_name the name of the folder where a tracefile of | |
| 120 performance results will be stored. | |
| 121 platform_list a list containing the platform(s) that our data has been | |
| 122 run on. (command line, firefox, chrome, etc) | |
| 123 v8_and_or_frog_list a list specifying whether we hold data about Frog | |
| 124 generated code, plain JS code (v8), or a combination of both. | |
| 125 values_list a list containing the type of data we will be graphing | |
| 126 (benchmarks, percentage passing, etc)""" | |
| 127 self.result_folder_name = result_folder_name | |
| 128 # cur_time is used as a timestamp of when this performance test was run. | |
| 129 self.cur_time = str(time.mktime(datetime.datetime.now().timetuple())) | |
| 130 self.browser_color = {'chrome': 'green', 'ie': 'blue', 'ff': 'red'} | |
| 131 self.values_list = values_list | |
| 132 self.platform_list = platform_list | |
| 133 self.revision_dict = dict() | |
| 134 self.values_dict = dict() | |
| 135 self.color_index = 0 | |
| 136 for platform in platform_list: | |
| 137 self.revision_dict[platform] = dict() | |
| 138 self.values_dict[platform] = dict() | |
| 139 for f in v8_and_or_frog_list: | |
| 140 self.revision_dict[platform][f] = dict() | |
| 141 self.values_dict[platform][f] = dict() | |
| 142 for val in values_list: | |
| 143 self.revision_dict[platform][f][val] = [] | |
| 144 self.values_dict[platform][f][val] = [] | |
| 145 if V8 in v8_and_or_frog_list: | |
| 146 self.revision_dict[platform][V8][V8_MEAN] = [] | |
| 147 self.values_dict[platform][V8][V8_MEAN] = [] | |
| 148 if FROG in v8_and_or_frog_list: | |
| 149 self.revision_dict[platform][FROG][FROG_MEAN] = [] | |
| 150 self.values_dict[platform][FROG][FROG_MEAN] = [] | |
| 151 | |
| 152 def getColor(self): | |
|
Siggi Cherem (dart-lang)
2011/11/30 01:40:21
getColor => GetColor
Emily Fortuna
2011/11/30 01:57:46
Done.
| |
| 153 color = COLORS[self.color_index] | |
| 154 self.color_index += 1 | |
| 155 if self.color_index >= len(COLORS): | |
| 156 self.color_index = 0 | |
|
Siggi Cherem (dart-lang)
2011/11/30 01:40:21
how about:
self.color_index = (self.color_index +
Emily Fortuna
2011/11/30 01:57:46
Done.
| |
| 157 return color | |
| 158 | |
| 159 def getMarker(self): | |
| 160 #TODO(efortuna) | |
|
Siggi Cherem (dart-lang)
2011/11/30 01:40:21
include explanation?
Emily Fortuna
2011/11/30 01:57:46
Done.
| |
| 161 return '.' | |
| 162 | |
| 163 def StyleAndSavePerfPlot(self, chart_title, y_axis_label, size_x, size_y, | |
| 164 legend_loc, filename, platform_list, v8_and_or_frog_list, values_list, | |
| 165 should_clear_axes=True): | |
| 166 """Sets style preferences for chart boilerplate that is consistent across | |
| 167 all charts, and saves the chart as a png. | |
| 168 Args: | |
| 169 size_x the size of the printed chart, in inches, in the horizontal | |
| 170 direction | |
| 171 size_y the size of the printed chart, in inches in the vertical direction | |
| 172 legend_loc the location of the legend in on the chart. See suitable | |
| 173 arguments for the loc argument in matplotlib | |
| 174 filename the filename that we want to save the resulting chart as | |
| 175 platform_list a list containing the platform(s) that our data has been run | |
| 176 on. (command line, firefox, chrome, etc) | |
| 177 values_list a list containing the type of data we will be graphing | |
| 178 (performance, percentage passing, etc) | |
| 179 should_clear_axes True if we want to create a fresh graph, instead of | |
| 180 plotting additional lines on the current graph.""" | |
| 181 if should_clear_axes: | |
| 182 plt.cla() # cla = clear current axes | |
| 183 for platform in platform_list: | |
| 184 for f in v8_and_or_frog_list: | |
| 185 for val in values_list: | |
| 186 plt.plot(self.revision_dict[platform][f][val], | |
| 187 self.values_dict[platform][f][val], | |
| 188 color=self.getColor(), marker=self.getMarker(), | |
| 189 label='%s-%s-%s' % (platform, f, val)) | |
| 190 | |
| 191 plt.xlabel('Revision Number') | |
| 192 plt.ylabel(y_axis_label) | |
| 193 plt.title(chart_title) | |
| 194 fontP = FontProperties() | |
| 195 fontP.set_size('small') | |
| 196 plt.legend(loc=legend_loc, prop = fontP) | |
| 197 | |
| 198 fig = plt.gcf() | |
| 199 fig.set_size_inches(size_x, size_y) | |
| 200 fig.savefig(os.path.join(GRAPH_OUT_DIR, filename)) | |
| 201 | |
| 202 def AddSvnRevisionToTrace(self, outfile): | |
| 203 """Add the svn version number to the provided tracefile.""" | |
| 204 p = subprocess.Popen('svn info ', shell = True, | |
| 205 stdout = subprocess.PIPE, stderr = subprocess.STDOUT, close_fds=True) | |
| 206 lines = p.stdout.readlines() | |
| 207 for line in lines: | |
| 208 if 'Revision' in line: | |
| 209 RunCmd('echo "%s" > %s' % (line.strip(), outfile)) | |
| 210 | |
| 211 def WriteHtml(self, delimiter, rev_nums, label_1, dict_1, label_2, dict_2, | |
| 212 cleanFile=False): | |
| 213 """Adds an html table to the webpage to display the data values. This method | |
| 214 will be removed when we have a nicer way to display data values.""" | |
| 215 #TODO(efortuna): fix this. | |
| 216 return | |
| 217 #TODO(efortuna): Take this method out when have finalized where the data is | |
| 218 # going to be displayed. | |
| 219 f = '' | |
| 220 out = '' | |
| 221 if cleanFile: | |
| 222 f = open('template.html') | |
| 223 else: | |
| 224 shutil.copy('index.html', 'temp.html') | |
| 225 f = open('temp.html') | |
| 226 out = open('index.html', 'w') | |
| 227 inTable = False | |
| 228 for line in f.readlines(): | |
| 229 if not inTable: | |
| 230 out.write(line) | |
| 231 if delimiter in line: | |
| 232 inTable = not inTable | |
| 233 if inTable: | |
| 234 out.write('<table border="1"> <tr> <td> svn revision </td>') | |
| 235 for revision in rev_nums: | |
| 236 out.write('<td>%d</td>' % revision) | |
| 237 out.write('</tr>\n<tr><td> %s</td>' % label_1) | |
| 238 for perf in dict_1: | |
| 239 out.write('<td>%f</td>' % perf) | |
| 240 out.write('</tr>\n<tr><td> %s</td>' % label_2) | |
| 241 for perf in dict_2: | |
| 242 out.write('<td>%f</td>' % perf) | |
| 243 out.write('</tr> </table>') | |
| 244 | |
| 245 def CalculateGeometricMean(self, platform, frog_or_v8, svn_revision): | |
| 246 """Calculate the aggregate geometric mean for V8 and frog benchmark sets, | |
| 247 given two benchmark dictionaries.""" | |
| 248 geo_mean = 0 | |
| 249 for benchmark in BENCHMARKS: | |
| 250 geo_mean += math.log(self.values_dict[platform][frog_or_v8][benchmark][ | |
| 251 len(self.values_dict[platform][frog_or_v8][benchmark]) - 1]) | |
| 252 | |
| 253 mean = V8_MEAN | |
| 254 if frog_or_v8 == FROG: | |
| 255 mean = FROG_MEAN | |
| 256 self.values_dict[platform][frog_or_v8][mean] += \ | |
| 257 [math.pow(math.e, geo_mean / len(BENCHMARKS))] | |
| 258 self.revision_dict[platform][frog_or_v8][mean] += [svn_revision] | |
| 259 | |
| 260 def Run(self): | |
| 261 """Run the benchmarks/tests from the command line and plot the | |
| 262 results.""" | |
| 263 plt.cla() # cla = clear current axes | |
| 264 os.chdir(DART_INSTALL_LOCATION) | |
| 265 EnsureOutputDirectory(self.result_folder_name) | |
| 266 EnsureOutputDirectory(GRAPH_OUT_DIR) | |
| 267 self.RunTests() | |
| 268 os.chdir(os.path.join('tools', 'testing', 'perf_testing')) | |
| 269 | |
| 270 # TODO(efortuna): You will want to make this only use a subset of the files | |
| 271 # eventually. | |
| 272 files = os.listdir(self.result_folder_name) | |
| 273 | |
| 274 for afile in files: | |
| 275 if not afile.startswith('.'): | |
| 276 self.ProcessFile(afile) | |
| 277 self.PlotResults('%s.png' % self.result_folder_name) | |
| 278 | |
| 279 class PerformanceTestRunner(TestRunner): | |
| 280 """Super class for all performance testing.""" | |
| 281 def __init__(self, result_folder_name, platform_list, platform_type): | |
| 282 super(PerformanceTestRunner, self).__init__(result_folder_name, | |
| 283 platform_list, V8_AND_FROG, BENCHMARKS) | |
| 284 self.platform_list = platform_list | |
| 285 self.platform_type = platform_type | |
| 286 | |
| 287 def PlotAllPerf(self, png_filename): | |
| 288 """Create a plot that shows the performance changes of individual benchmarks | |
| 289 run by V8 and generated by frog, over svn history.""" | |
| 290 for benchmark in BENCHMARKS: | |
| 291 self.StyleAndSavePerfPlot( | |
| 292 'Performance of %s over time on the %s' % (benchmark, | |
| 293 self.platform_type), 'Speed (bigger = better)', 16, 14, 'lower left', | |
| 294 benchmark + png_filename, self.platform_list, V8_AND_FROG, | |
| 295 [benchmark]) | |
| 296 | |
| 297 def PlotAvgPerf(self, png_filename): | |
| 298 """Generate a plot that shows the performance changes of the geomentric mean | |
| 299 of V8 and frog benchmark performance over svn history.""" | |
| 300 (title, y_axis, size_x, size_y, loc, filename) = \ | |
| 301 ('Geometric Mean of benchmark %s performance' % self.platform_type, | |
| 302 'Speed (bigger = better)', 16, 5, 'center', 'avg'+png_filename) | |
| 303 for platform in self.platform_list: | |
| 304 self.StyleAndSavePerfPlot(title, y_axis, size_x, size_y, loc, filename, | |
| 305 [platform], [V8], [V8_MEAN], True) | |
| 306 self.StyleAndSavePerfPlot(title, y_axis, size_x, size_y, loc, filename, | |
| 307 [platform], [FROG], [FROG_MEAN], False) | |
| 308 self.WriteHtml('table', | |
| 309 self.revision_dict[platform][V8], | |
| 310 'V8 mean', self.values_dict[platform][V8][V8_MEAN], | |
| 311 'Frog mean', self.values_dict[platform][FROG][FROG_MEAN], | |
| 312 True) | |
| 313 | |
| 314 def PlotResults(self, png_filename): | |
| 315 self.PlotAllPerf(png_filename) | |
| 316 self.PlotAvgPerf('2' + png_filename) | |
| 317 | |
| 318 class CommandLinePerformanceTestRunner(PerformanceTestRunner): | |
| 319 """Run performance tests from the command line.""" | |
| 320 | |
| 321 def __init__(self, result_folder_name): | |
| 322 super(CommandLinePerformanceTestRunner, self).__init__(result_folder_name, | |
| 323 [COMMAND_LINE], 'command line') | |
| 324 | |
| 325 def ProcessFile(self, afile): | |
| 326 """Pull all the relevant information out of a given tracefile. | |
| 327 | |
| 328 Args: | |
| 329 afile is the filename string we will be processing.""" | |
| 330 f = open(os.path.join(self.result_folder_name, afile)) | |
| 331 tabulate_data = False | |
| 332 revision_num = 0 | |
| 333 for line in f.readlines(): | |
| 334 if 'Revision' in line: | |
| 335 revision_num = int(line.split()[1]) | |
| 336 elif 'Benchmark' in line: | |
| 337 tabulate_data = True | |
| 338 elif tabulate_data: | |
| 339 tokens = line.split() | |
| 340 if len(tokens) < 4 or tokens[0] not in BENCHMARKS: | |
| 341 #Done tabulating data. | |
| 342 break | |
| 343 v8_value = float(tokens[1]) | |
| 344 frog_value = float(tokens[3]) | |
| 345 if v8_value == 0 or frog_value == 0: | |
| 346 #Then there was an error when this performance test was run. Do not | |
| 347 #count it in our numbers. | |
| 348 return | |
| 349 benchmark = tokens[0] | |
| 350 self.revision_dict[COMMAND_LINE][V8][benchmark] += [revision_num] | |
| 351 self.values_dict[COMMAND_LINE][V8][benchmark] += [v8_value] | |
| 352 self.revision_dict[COMMAND_LINE][FROG][benchmark] += [revision_num] | |
| 353 self.values_dict[COMMAND_LINE][FROG][benchmark] += [frog_value] | |
| 354 f.close() | |
| 355 | |
| 356 self.CalculateGeometricMean(COMMAND_LINE, FROG, revision_num) | |
| 357 self.CalculateGeometricMean(COMMAND_LINE, V8, revision_num) | |
| 358 | |
| 359 def RunTests(self): | |
| 360 """Run a performance test on our updated system.""" | |
| 361 os.chdir('frog') | |
| 362 file_path = os.path.join('..', 'tools', 'testing', 'perf_testing', | |
| 363 self.result_folder_name, 'result') | |
| 364 RunCmd('python %s > %s%s' % (os.path.join('benchmarks', | |
| 365 'perf_tests.py'), file_path, self.cur_time)) | |
| 366 os.chdir('..') | |
| 367 | |
| 368 | |
| 369 class BrowserPerformanceTestRunner(PerformanceTestRunner): | |
| 370 """Runs performance tests, in the browser.""" | |
| 371 | |
| 372 def __init__(self, result_folder_name): | |
| 373 super(BrowserPerformanceTestRunner, self).__init__( | |
| 374 result_folder_name, GetBrowsers(), 'browser') | |
| 375 | |
| 376 def RunTests(self): | |
| 377 """Run a performance test in the browser.""" | |
| 378 os.chdir('frog') | |
| 379 RunCmd('python benchmarks/make_web_benchmarks.py') | |
| 380 os.chdir('..') | |
| 381 | |
| 382 for browser in GetBrowsers(): | |
| 383 for version in V8_AND_FROG: | |
| 384 self.AddSvnRevisionToTrace(os.path.join('tools', 'testing', | |
| 385 'perf_testing', self.result_folder_name, | |
| 386 'perf-%s-%s-%s' % (self.cur_time, browser, version))) | |
| 387 RunCmd('python %s -out %s -browser %s -timeout 1000 -perf >> %s' % | |
| 388 (os.path.join('tools', 'testing', 'run_selenium.py'), | |
| 389 os.path.join(os.getcwd(), 'internal', 'browserBenchmarks', | |
| 390 'benchmark_page_%s.html' % version), | |
| 391 browser, | |
| 392 os.path.join('tools', 'testing', 'perf_testing', | |
| 393 self.result_folder_name, 'perf-%s-%s-%s' % (self.cur_time, browser, | |
| 394 version)))) | |
| 395 | |
| 396 def ProcessFile(self, afile): | |
| 397 """Comb through the html to find the performance results.""" | |
| 398 parts = afile.split('-') | |
| 399 browser = parts[2] | |
| 400 version = parts[3] | |
| 401 f = open(os.path.join(self.result_folder_name, afile)) | |
| 402 lines = f.readlines() | |
| 403 line = '' | |
| 404 i = 0 | |
| 405 revision_num = 0 | |
| 406 while '<div id="results">' not in line and i < len(lines): | |
| 407 if 'Revision' in line: | |
| 408 revision_num = int(line.split()[1]) | |
| 409 line = lines[i] | |
| 410 i += 1 | |
| 411 | |
| 412 if i >= len(lines) or revision_num == 0: | |
| 413 # Then this run did not complete. Ignore this tracefile. | |
| 414 return | |
| 415 | |
| 416 line = lines[i] | |
| 417 i += 1 | |
| 418 results = [] | |
| 419 if line.find('<br>') > -1: | |
| 420 results = line.split('<br>') | |
| 421 else: | |
| 422 results = line.split('<br />') | |
| 423 for result in results: | |
| 424 name_and_score = result.split(':') | |
| 425 if len(name_and_score) < 2: | |
| 426 break | |
| 427 name = name_and_score[0].strip() | |
| 428 score = name_and_score[1].strip() | |
| 429 if version == V8: | |
| 430 bench_dict = self.values_dict[browser][V8] | |
| 431 else: | |
| 432 bench_dict = self.values_dict[browser][FROG] | |
| 433 bench_dict[name] += [float(score)] | |
| 434 self.revision_dict[browser][version][name] += [revision_num] | |
| 435 | |
| 436 f.close() | |
| 437 self.CalculateGeometricMean(browser, version, revision_num) | |
| 438 | |
| 439 def WriteHtml(self, delimiter, rev_nums, label_1, dict_1, label_2, dict_2, | |
| 440 cleanFile=False): | |
| 441 #TODO(efortuna) | |
| 442 pass | |
| 443 | |
| 444 class BrowserCorrectnessTestRunner(TestRunner): | |
| 445 def __init__(self, test_type, result_folder_name): | |
| 446 super(BrowserCorrectnessTestRunner, self).__init__(result_folder_name, | |
| 447 GetBrowsers(), [FROG], [CORRECTNESS]) | |
| 448 self.test_type = test_type | |
| 449 | |
| 450 def RunTests(self): | |
| 451 """Run a test of the latest svn revision.""" | |
| 452 for browser in GetBrowsers(): | |
| 453 current_file = 'correctness%s-%s' % (self.cur_time, browser) | |
| 454 current_file_path = os.path.join('tools', 'testing', | |
| 455 'perf_testing', self.result_folder_name, current_file) | |
| 456 self.AddSvnRevisionToTrace(current_file_path) | |
| 457 RunCmd(os.path.join('.', 'tools', 'test.py') + | |
| 458 ' --component=webdriver --flag=%s --report --timeout=20 ' % browser + | |
| 459 '--progress=color --mode=release -j1 %s >>' % self.test_type + | |
| 460 current_file_path) | |
| 461 | |
| 462 def ProcessFile(self, afile): | |
| 463 """Given a trace file, extract all the relevant information out of it to | |
| 464 determine the number of correctly passing tests. | |
| 465 | |
| 466 Arguments: | |
| 467 afile the filename string""" | |
| 468 browser = afile.rpartition('-')[2] | |
| 469 f = open(os.path.join(self.result_folder_name, afile)) | |
| 470 revision_num = 0 | |
| 471 lines = f.readlines() | |
| 472 total_tests = 0 | |
| 473 num_failed = 0 | |
| 474 expect_fail = 0 | |
| 475 for line in lines: | |
| 476 if 'Total:' in line: | |
| 477 total_tests = int(line.split()[1]) | |
| 478 if 'will be skipped' in line: | |
| 479 total_tests -= int(line.split()[1]) | |
| 480 if 'we should fix' in line: | |
| 481 expect_fail += int(line.split()[1]) | |
| 482 if 'Revision' in line: | |
| 483 revision_num = int(line.split()[1]) | |
| 484 if '--- TIMEOUT ---' in line or 'FAIL:' in line or 'PASS' in line: | |
| 485 # (A printed out 'PASS' indicates we incorrectly passed a negative | |
| 486 # test.) | |
| 487 num_failed += 1 | |
| 488 | |
| 489 self.revision_dict[browser][FROG][CORRECTNESS] += [revision_num] | |
| 490 self.values_dict[browser][FROG][CORRECTNESS] += [100.0 * | |
| 491 (((float)(total_tests - (expect_fail + num_failed))) /total_tests)] | |
| 492 f.close() | |
| 493 | |
| 494 def PlotResults(self, png_filename): | |
| 495 first_time = True | |
| 496 for browser in GetBrowsers(): | |
| 497 self.StyleAndSavePerfPlot('Percentage of language tests passing in ' | |
| 498 'different browsers', '% of tests passed', 8, 8, 'lower left', | |
| 499 png_filename, [browser], [FROG], [CORRECTNESS], first_time) | |
| 500 first_time = False | |
| 501 | |
| 502 | |
| 503 class CompileTimeAndSizeTestRunner(TestRunner): | |
| 504 """Run tests to determine how long frogsh takes to compile, and the compiled | |
| 505 file output size of some benchmarking files.""" | |
| 506 def __init__(self, result_folder_name): | |
| 507 super(CompileTimeAndSizeTestRunner, self).__init__(result_folder_name, | |
| 508 [COMMAND_LINE], [FROG], ['Compiling on Dart VM', 'Bootstrapping', | |
| 509 'frogsh', 'swarm', 'total']) | |
| 510 self.failure_threshold = {'Compiling on Dart VM' : 1, 'Bootstrapping' : .5, | |
| 511 'frogsh' : 100, 'swarm' : 100, 'total' : 100} | |
| 512 | |
| 513 def TimeCmd(self, cmd): | |
|
Siggi Cherem (dart-lang)
2011/11/30 01:40:21
this can also be at the top-level
Emily Fortuna
2011/11/30 01:57:46
Done.
| |
| 514 start = time.time() | |
| 515 RunCmd(cmd) | |
| 516 return time.time() - start | |
| 517 | |
| 518 def RunTests(self): | |
| 519 os.chdir('frog') | |
| 520 current_file_path = os.path.join('..', 'tools', 'testing', 'perf_testing', | |
| 521 self.result_folder_name, self.result_folder_name + self.cur_time) | |
| 522 | |
| 523 self.AddSvnRevisionToTrace(current_file_path) | |
| 524 | |
| 525 elapsed = self.TimeCmd(os.path.join('.', 'frog.py') + | |
| 526 ' --vm_flags="--compile_all --enable_type_checks --enable_asserts" --' | |
| 527 ' --compile_all --enable_type_checks --out=frogsh frog.dart') | |
| 528 RunCmd('echo "%f Compiling on Dart VM in checked mode in' % elapsed + | |
| 529 ' seconds" >> %s' % current_file_path) | |
| 530 RunCmd('chmod +x frogsh') | |
| 531 elapsed = self.TimeCmd(os.path.join('.', 'frogsh') + ' --out=frogsh ' | |
| 532 '--enable_type_checks frog.dart --enable_type_checks ' + | |
| 533 os.path.join('tests', 'hello.dart')) | |
| 534 if elapsed < self.failure_threshold['Bootstrapping']: | |
| 535 #frogsh didn't compile correctly. Stop testing now, because subsequent | |
| 536 #numbers will be meaningless. | |
| 537 return | |
| 538 size = os.path.getsize('frogsh') | |
| 539 RunCmd('echo "%f Bootstrapping time in seconds in checked mode"' % | |
| 540 elapsed + ' >> %s' % current_file_path) | |
| 541 RunCmd('echo "%d Generated checked frogsh size "' % size + | |
| 542 ' >> %s' % current_file_path) | |
| 543 | |
| 544 RunCmd(os.path.join('.', 'frogsh') + ' --out=swarm-result ' | |
| 545 '--compile-only ' + os.path.join('..', 'client', 'samples', 'swarm', | |
| 546 'swarm.dart')) | |
| 547 swarm_size = 0 | |
| 548 try: | |
| 549 swarm_size = os.path.getsize('swarm-result') | |
| 550 except OSError: | |
| 551 pass #If compilation failed, continue on running other tests. | |
| 552 | |
| 553 RunCmd(os.path.join('.', 'frogsh') + ' --out=total-result ' | |
| 554 '--compile-only ' + os.path.join('..', 'client', 'samples', 'total', | |
| 555 'src', 'Total.dart')) | |
| 556 total_size = 0 | |
| 557 try: | |
| 558 total_size = os.path.getsize('total-result') | |
| 559 except OSError: | |
| 560 pass #If compilation failed, continue on running other tests. | |
| 561 | |
| 562 RunCmd('echo "%d Generated checked swarm size "' % swarm_size + | |
| 563 ' >> %s' % current_file_path) | |
| 564 | |
| 565 RunCmd('echo "%d Generated checked total size "' % total_size + | |
| 566 ' >> %s' % current_file_path) | |
| 567 os.chdir('..') | |
| 568 | |
| 569 def ProcessFile(self, afile): | |
| 570 """Pull all the relevant information out of a given tracefile. | |
| 571 Args: | |
| 572 afile is the filename string we will be processing.""" | |
| 573 f = open(os.path.join(self.result_folder_name, afile)) | |
| 574 tabulate_data = False | |
| 575 revision_num = 0 | |
| 576 for line in f.readlines(): | |
| 577 tokens = line.split() | |
| 578 if 'Revision' in line: | |
| 579 revision_num = int(line.split()[1]) | |
| 580 else: | |
| 581 for metric in self.values_list: | |
| 582 if metric in line: | |
| 583 num = tokens[0] | |
| 584 if num.find('.') == -1: | |
| 585 num = int(num) | |
| 586 else: | |
| 587 num = float(num) | |
| 588 self.values_dict[COMMAND_LINE][FROG][metric] += [num] | |
| 589 self.revision_dict[COMMAND_LINE][FROG][metric] += [revision_num] | |
| 590 | |
| 591 if revision_num != 0: | |
| 592 for metric in self.values_list: | |
| 593 self.revision_dict[COMMAND_LINE][FROG][metric].pop() | |
| 594 self.revision_dict[COMMAND_LINE][FROG][metric] += [revision_num] | |
| 595 # Fill 0 if compilation failed. | |
| 596 if self.values_dict[COMMAND_LINE][FROG][metric][-1] < \ | |
| 597 self.failure_threshold[metric]: | |
| 598 self.values_dict[COMMAND_LINE][FROG][metric] += [0] | |
| 599 self.revision_dict[COMMAND_LINE][FROG][metric] += [revision_num] | |
| 600 | |
| 601 f.close() | |
| 602 | |
| 603 def PlotResults(self, png_filename): | |
| 604 self.StyleAndSavePerfPlot('Compiled frogsh Sizes', | |
| 605 'Size (in bytes)', 10, 10, 'center', png_filename, [COMMAND_LINE], | |
| 606 [FROG], ['swarm', 'total', 'frogsh']) | |
| 607 self.WriteHtml('bar', self.revision_dict[COMMAND_LINE][FROG]['frogsh'], | |
| 608 'frogsh size', self.values_dict[COMMAND_LINE][FROG]['frogsh'], '', []) | |
| 609 | |
| 610 self.StyleAndSavePerfPlot('Time to compile and bootstrap', | |
| 611 'Seconds', 10, 10, 'center', '2' + png_filename, [COMMAND_LINE], [FROG], | |
| 612 ['Bootstrapping', 'Compiling on Dart VM']) | |
| 613 self.WriteHtml('baz', | |
| 614 self.revision_dict[COMMAND_LINE][FROG]['Bootstrapping'], | |
| 615 'Bootstrapping', self.values_dict[COMMAND_LINE][FROG]['Bootstrapping'], | |
| 616 'Compiling on Dart VM', | |
| 617 self.values_dict[COMMAND_LINE][FROG]['Compiling on Dart VM']) | |
| 618 | |
| 619 | |
| 620 def main(): | |
| 621 if HasNewCode(): | |
| 622 SyncAndBuild() | |
| 623 CommandLinePerformanceTestRunner('cl-results').Run() | |
| 624 CompileTimeAndSizeTestRunner('code-time-size').Run() | |
| 625 BrowserCorrectnessTestRunner('language', 'browser-correctness').Run() | |
| 626 BrowserPerformanceTestRunner('browser-perf').Run() | |
| 627 | |
| 628 if __name__ == '__main__': | |
| 629 main() | |
| 630 | |
| OLD | NEW |