blob: 50cba552659ca8d83180436e3ec41b72fbbcfd7f [file] [log] [blame]
bungeman@google.com85669f92011-06-17 13:58:14 +00001'''
2Created on May 16, 2011
3
4@author: bungeman
5'''
6import sys
7import getopt
8import re
9import os
10import bench_util
11import json
12import xml.sax.saxutils
13
epoger@google.com3d8cd172012-05-11 18:26:16 +000014# We throw out any measurement outside this range, and log a warning.
15MIN_REASONABLE_TIME = 0
16MAX_REASONABLE_TIME = 99999
17
bungeman@google.com85669f92011-06-17 13:58:14 +000018def usage():
19 """Prints simple usage information."""
20
bungeman@google.com85669f92011-06-17 13:58:14 +000021 print '-b <bench> the bench to show.'
22 print '-c <config> the config to show (GPU, 8888, 565, etc).'
epoger@google.com5b2e01c2012-06-25 20:29:04 +000023 print '-d <dir> a directory containing bench_r<revision>_<scalar> files.'
bungeman@google.com85669f92011-06-17 13:58:14 +000024 print '-f <revision>[:<revision>] the revisions to use for fitting.'
epoger@google.com37260002011-08-08 20:27:04 +000025 print ' Negative <revision> is taken as offset from most recent revision.'
bensong@google.com8ccfa552012-08-17 21:42:14 +000026 print '-i <time> the time to ignore (w, c, g, etc).'
27 print ' The flag is ignored when -t is set; otherwise we plot all the'
28 print ' times except the one specified here.'
epoger@google.com5b2e01c2012-06-25 20:29:04 +000029 print '-l <title> title to use for the output graph'
bensong@google.com8ccfa552012-08-17 21:42:14 +000030 print '-m <representation> representation of bench value.'
31 print ' See _ListAlgorithm class in bench_util.py.'
epoger@google.com5b2e01c2012-06-25 20:29:04 +000032 print '-o <path> path to which to write output; writes to stdout if not specified'
33 print '-r <revision>[:<revision>] the revisions to show.'
34 print ' Negative <revision> is taken as offset from most recent revision.'
35 print '-s <setting>[=<value>] a setting to show (alpha, scalar, etc).'
36 print '-t <time> the time to show (w, c, g, etc).'
bungeman@google.com85669f92011-06-17 13:58:14 +000037 print '-x <int> the desired width of the svg.'
38 print '-y <int> the desired height of the svg.'
39 print '--default-setting <setting>[=<value>] setting for those without.'
40
41
42class Label:
43 """The information in a label.
44
45 (str, str, str, str, {str:str})"""
46 def __init__(self, bench, config, time_type, settings):
47 self.bench = bench
48 self.config = config
49 self.time_type = time_type
50 self.settings = settings
51
52 def __repr__(self):
53 return "Label(%s, %s, %s, %s)" % (
54 str(self.bench),
55 str(self.config),
56 str(self.time_type),
57 str(self.settings),
58 )
59
60 def __str__(self):
61 return "%s_%s_%s_%s" % (
62 str(self.bench),
63 str(self.config),
64 str(self.time_type),
65 str(self.settings),
66 )
67
68 def __eq__(self, other):
69 return (self.bench == other.bench and
70 self.config == other.config and
71 self.time_type == other.time_type and
72 self.settings == other.settings)
73
74 def __hash__(self):
75 return (hash(self.bench) ^
76 hash(self.config) ^
77 hash(self.time_type) ^
78 hash(frozenset(self.settings.iteritems())))
79
epoger@google.com37260002011-08-08 20:27:04 +000080def get_latest_revision(directory):
81 """Returns the latest revision number found within this directory.
82 """
83 latest_revision_found = -1
84 for bench_file in os.listdir(directory):
85 file_name_match = re.match('bench_r(\d+)_(\S+)', bench_file)
86 if (file_name_match is None):
87 continue
88 revision = int(file_name_match.group(1))
89 if revision > latest_revision_found:
90 latest_revision_found = revision
91 if latest_revision_found < 0:
92 return None
93 else:
94 return latest_revision_found
95
bensong@google.com87348162012-08-15 17:31:46 +000096def parse_dir(directory, default_settings, oldest_revision, newest_revision,
97 rep):
bungeman@google.com85669f92011-06-17 13:58:14 +000098 """Parses bench data from files like bench_r<revision>_<scalar>.
99
100 (str, {str, str}, Number, Number) -> {int:[BenchDataPoints]}"""
101 revision_data_points = {} # {revision : [BenchDataPoints]}
102 for bench_file in os.listdir(directory):
103 file_name_match = re.match('bench_r(\d+)_(\S+)', bench_file)
104 if (file_name_match is None):
105 continue
epoger@google.com3d8cd172012-05-11 18:26:16 +0000106
bungeman@google.com85669f92011-06-17 13:58:14 +0000107 revision = int(file_name_match.group(1))
108 scalar_type = file_name_match.group(2)
epoger@google.com3d8cd172012-05-11 18:26:16 +0000109
bungeman@google.com85669f92011-06-17 13:58:14 +0000110 if (revision < oldest_revision or revision > newest_revision):
111 continue
epoger@google.com3d8cd172012-05-11 18:26:16 +0000112
bungeman@google.com85669f92011-06-17 13:58:14 +0000113 file_handle = open(directory + '/' + bench_file, 'r')
epoger@google.com3d8cd172012-05-11 18:26:16 +0000114
bungeman@google.com85669f92011-06-17 13:58:14 +0000115 if (revision not in revision_data_points):
116 revision_data_points[revision] = []
117 default_settings['scalar'] = scalar_type
118 revision_data_points[revision].extend(
bensong@google.com87348162012-08-15 17:31:46 +0000119 bench_util.parse(default_settings, file_handle, rep))
bungeman@google.com85669f92011-06-17 13:58:14 +0000120 file_handle.close()
121 return revision_data_points
122
epoger@google.com3d8cd172012-05-11 18:26:16 +0000123def add_to_revision_data_points(new_point, revision, revision_data_points):
124 """Add new_point to set of revision_data_points we are building up.
125 """
126 if (revision not in revision_data_points):
127 revision_data_points[revision] = []
128 revision_data_points[revision].append(new_point)
129
130def filter_data_points(unfiltered_revision_data_points):
131 """Filter out any data points that are utterly bogus.
132
133 Returns (allowed_revision_data_points, ignored_revision_data_points):
134 allowed_revision_data_points: points that survived the filter
135 ignored_revision_data_points: points that did NOT survive the filter
136 """
137 allowed_revision_data_points = {} # {revision : [BenchDataPoints]}
138 ignored_revision_data_points = {} # {revision : [BenchDataPoints]}
139 revisions = unfiltered_revision_data_points.keys()
140 revisions.sort()
141 for revision in revisions:
142 for point in unfiltered_revision_data_points[revision]:
143 if point.time < MIN_REASONABLE_TIME or point.time > MAX_REASONABLE_TIME:
144 add_to_revision_data_points(point, revision, ignored_revision_data_points)
145 else:
146 add_to_revision_data_points(point, revision, allowed_revision_data_points)
147 return (allowed_revision_data_points, ignored_revision_data_points)
148
epoger@google.com1513f6e2012-06-27 13:38:37 +0000149def get_abs_path(relative_path):
150 """My own implementation of os.path.abspath() that better handles paths
151 which approach Window's 260-character limit.
152 See https://code.google.com/p/skia/issues/detail?id=674
153
154 This implementation adds path components one at a time, resolving the
155 absolute path each time, to take advantage of any chdirs into outer
156 directories that will shorten the total path length.
157
158 TODO: share a single implementation with upload_to_bucket.py, instead
159 of pasting this same code into both files."""
160 if os.path.isabs(relative_path):
161 return relative_path
162 path_parts = relative_path.split(os.sep)
163 abs_path = os.path.abspath('.')
164 for path_part in path_parts:
165 abs_path = os.path.abspath(os.path.join(abs_path, path_part))
166 return abs_path
167
epoger@google.com5b2e01c2012-06-25 20:29:04 +0000168def redirect_stdout(output_path):
169 """Redirect all following stdout to a file.
170
171 You may be asking yourself, why redirect stdout within Python rather than
172 redirecting the script's output in the calling shell?
173 The answer lies in https://code.google.com/p/skia/issues/detail?id=674
174 ('buildbot: windows GenerateBenchGraphs step fails due to filename length'):
175 On Windows, we need to generate the absolute path within Python to avoid
176 the operating system's 260-character pathname limit, including chdirs."""
epoger@google.com1513f6e2012-06-27 13:38:37 +0000177 abs_path = get_abs_path(output_path)
epoger@google.com5b2e01c2012-06-25 20:29:04 +0000178 sys.stdout = open(abs_path, 'w')
179
bungeman@google.com85669f92011-06-17 13:58:14 +0000180def create_lines(revision_data_points, settings
bensong@google.com8ccfa552012-08-17 21:42:14 +0000181 , bench_of_interest, config_of_interest, time_of_interest
182 , time_to_ignore):
bungeman@google.com85669f92011-06-17 13:58:14 +0000183 """Convert revision data into sorted line data.
184
185 ({int:[BenchDataPoints]}, {str:str}, str?, str?, str?)
186 -> {Label:[(x,y)] | [n].x <= [n+1].x}"""
187 revisions = revision_data_points.keys()
188 revisions.sort()
189 lines = {} # {Label:[(x,y)] | x[n] <= x[n+1]}
190 for revision in revisions:
191 for point in revision_data_points[revision]:
192 if (bench_of_interest is not None and
193 not bench_of_interest == point.bench):
194 continue
195
196 if (config_of_interest is not None and
197 not config_of_interest == point.config):
198 continue
199
200 if (time_of_interest is not None and
201 not time_of_interest == point.time_type):
202 continue
bensong@google.com8ccfa552012-08-17 21:42:14 +0000203 elif (time_to_ignore is not None and
204 time_to_ignore == point.time_type):
205 continue
bungeman@google.com85669f92011-06-17 13:58:14 +0000206
207 skip = False
208 for key, value in settings.items():
209 if key in point.settings and point.settings[key] != value:
210 skip = True
211 break
212 if skip:
213 continue
214
215 line_name = Label(point.bench
216 , point.config
217 , point.time_type
218 , point.settings)
219
220 if line_name not in lines:
221 lines[line_name] = []
222
223 lines[line_name].append((revision, point.time))
224
225 return lines
226
227def bounds(lines):
228 """Finds the bounding rectangle for the lines.
229
230 {Label:[(x,y)]} -> ((min_x, min_y),(max_x,max_y))"""
231 min_x = bench_util.Max
232 min_y = bench_util.Max
233 max_x = bench_util.Min
234 max_y = bench_util.Min
235
236 for line in lines.itervalues():
237 for x, y in line:
238 min_x = min(min_x, x)
239 min_y = min(min_y, y)
240 max_x = max(max_x, x)
241 max_y = max(max_y, y)
242
243 return ((min_x, min_y), (max_x, max_y))
244
245def create_regressions(lines, start_x, end_x):
246 """Creates regression data from line segments.
247
248 ({Label:[(x,y)] | [n].x <= [n+1].x}, Number, Number)
249 -> {Label:LinearRegression}"""
250 regressions = {} # {Label : LinearRegression}
251
252 for label, line in lines.iteritems():
253 regression_line = [p for p in line if start_x <= p[0] <= end_x]
254
255 if (len(regression_line) < 2):
256 continue
257 regression = bench_util.LinearRegression(regression_line)
258 regressions[label] = regression
259
260 return regressions
261
262def bounds_slope(regressions):
263 """Finds the extreme up and down slopes of a set of linear regressions.
264
265 ({Label:LinearRegression}) -> (max_up_slope, min_down_slope)"""
266 max_up_slope = 0
267 min_down_slope = 0
268 for regression in regressions.itervalues():
269 min_slope = regression.find_min_slope()
270 max_up_slope = max(max_up_slope, min_slope)
271 min_down_slope = min(min_down_slope, min_slope)
272
273 return (max_up_slope, min_down_slope)
274
275def main():
276 """Parses command line and writes output."""
277
278 try:
279 opts, _ = getopt.getopt(sys.argv[1:]
bensong@google.com8ccfa552012-08-17 21:42:14 +0000280 , "b:c:d:f:i:l:m:o:r:s:t:x:y:"
bungeman@google.com85669f92011-06-17 13:58:14 +0000281 , "default-setting=")
282 except getopt.GetoptError, err:
283 print str(err)
284 usage()
285 sys.exit(2)
286
287 directory = None
288 config_of_interest = None
289 bench_of_interest = None
290 time_of_interest = None
bensong@google.com8ccfa552012-08-17 21:42:14 +0000291 time_to_ignore = None
bensong@google.comb6204b12012-08-16 20:49:28 +0000292 rep = None # bench representation algorithm
epoger@google.com37260002011-08-08 20:27:04 +0000293 revision_range = '0:'
294 regression_range = '0:'
295 latest_revision = None
bungeman@google.com85669f92011-06-17 13:58:14 +0000296 requested_height = None
297 requested_width = None
epoger@google.com37260002011-08-08 20:27:04 +0000298 title = 'Bench graph'
bungeman@google.com85669f92011-06-17 13:58:14 +0000299 settings = {}
300 default_settings = {}
epoger@google.com37260002011-08-08 20:27:04 +0000301
302 def parse_range(range):
303 """Takes '<old>[:<new>]' as a string and returns (old, new).
304 Any revision numbers that are dependent on the latest revision number
305 will be filled in based on latest_revision.
306 """
307 old, _, new = range.partition(":")
308 old = int(old)
309 if old < 0:
310 old += latest_revision;
bungeman@google.com85669f92011-06-17 13:58:14 +0000311 if not new:
epoger@google.com37260002011-08-08 20:27:04 +0000312 new = latest_revision;
313 new = int(new)
314 if new < 0:
315 new += latest_revision;
316 return (old, new)
317
bungeman@google.com85669f92011-06-17 13:58:14 +0000318 def add_setting(settings, setting):
319 """Takes <key>[=<value>] adds {key:value} or {key:True} to settings."""
320 name, _, value = setting.partition('=')
321 if not value:
322 settings[name] = True
323 else:
324 settings[name] = value
325
326 try:
327 for option, value in opts:
epoger@google.com5b2e01c2012-06-25 20:29:04 +0000328 if option == "-b":
bungeman@google.com85669f92011-06-17 13:58:14 +0000329 bench_of_interest = value
330 elif option == "-c":
331 config_of_interest = value
epoger@google.com5b2e01c2012-06-25 20:29:04 +0000332 elif option == "-d":
333 directory = value
bungeman@google.com85669f92011-06-17 13:58:14 +0000334 elif option == "-f":
epoger@google.com37260002011-08-08 20:27:04 +0000335 regression_range = value
bensong@google.com8ccfa552012-08-17 21:42:14 +0000336 elif option == "-i":
337 time_to_ignore = value
epoger@google.com5b2e01c2012-06-25 20:29:04 +0000338 elif option == "-l":
339 title = value
bensong@google.com87348162012-08-15 17:31:46 +0000340 elif option == "-m":
341 rep = value
epoger@google.com5b2e01c2012-06-25 20:29:04 +0000342 elif option == "-o":
343 redirect_stdout(value)
344 elif option == "-r":
345 revision_range = value
346 elif option == "-s":
347 add_setting(settings, value)
348 elif option == "-t":
349 time_of_interest = value
bungeman@google.com85669f92011-06-17 13:58:14 +0000350 elif option == "-x":
351 requested_width = int(value)
352 elif option == "-y":
353 requested_height = int(value)
354 elif option == "--default-setting":
355 add_setting(default_settings, value)
356 else:
357 usage()
358 assert False, "unhandled option"
359 except ValueError:
360 usage()
361 sys.exit(2)
epoger@google.comc71174d2011-08-08 17:19:23 +0000362
bungeman@google.com85669f92011-06-17 13:58:14 +0000363 if directory is None:
364 usage()
365 sys.exit(2)
epoger@google.comc71174d2011-08-08 17:19:23 +0000366
bensong@google.com8ccfa552012-08-17 21:42:14 +0000367 if time_of_interest:
368 time_to_ignore = None
369
bensong@google.com8c1de762012-08-15 18:27:38 +0000370 title += ' [representation: %s]' % rep
371
epoger@google.com37260002011-08-08 20:27:04 +0000372 latest_revision = get_latest_revision(directory)
373 oldest_revision, newest_revision = parse_range(revision_range)
374 oldest_regression, newest_regression = parse_range(regression_range)
375
epoger@google.com3d8cd172012-05-11 18:26:16 +0000376 unfiltered_revision_data_points = parse_dir(directory
bungeman@google.com85669f92011-06-17 13:58:14 +0000377 , default_settings
378 , oldest_revision
bensong@google.com87348162012-08-15 17:31:46 +0000379 , newest_revision
380 , rep)
epoger@google.comc71174d2011-08-08 17:19:23 +0000381
epoger@google.com3d8cd172012-05-11 18:26:16 +0000382 # Filter out any data points that are utterly bogus... make sure to report
383 # that we did so later!
384 (allowed_revision_data_points, ignored_revision_data_points) = filter_data_points(
385 unfiltered_revision_data_points)
386
epoger@google.comc71174d2011-08-08 17:19:23 +0000387 # Update oldest_revision and newest_revision based on the data we could find
epoger@google.com3d8cd172012-05-11 18:26:16 +0000388 all_revision_numbers = allowed_revision_data_points.keys()
epoger@google.comc71174d2011-08-08 17:19:23 +0000389 oldest_revision = min(all_revision_numbers)
390 newest_revision = max(all_revision_numbers)
391
epoger@google.com3d8cd172012-05-11 18:26:16 +0000392 lines = create_lines(allowed_revision_data_points
bungeman@google.com85669f92011-06-17 13:58:14 +0000393 , settings
394 , bench_of_interest
395 , config_of_interest
bensong@google.com8ccfa552012-08-17 21:42:14 +0000396 , time_of_interest
397 , time_to_ignore)
epoger@google.comc71174d2011-08-08 17:19:23 +0000398
bungeman@google.com85669f92011-06-17 13:58:14 +0000399 regressions = create_regressions(lines
400 , oldest_regression
401 , newest_regression)
epoger@google.comc71174d2011-08-08 17:19:23 +0000402
epoger@google.com3d8cd172012-05-11 18:26:16 +0000403 output_xhtml(lines, oldest_revision, newest_revision, ignored_revision_data_points,
epoger@google.com37260002011-08-08 20:27:04 +0000404 regressions, requested_width, requested_height, title)
bungeman@google.com85669f92011-06-17 13:58:14 +0000405
406def qa(out):
407 """Stringify input and quote as an xml attribute."""
408 return xml.sax.saxutils.quoteattr(str(out))
409def qe(out):
410 """Stringify input and escape as xml data."""
411 return xml.sax.saxutils.escape(str(out))
412
413def create_select(qualifier, lines, select_id=None):
414 """Output select with options showing lines which qualifier maps to it.
415
416 ((Label) -> str, {Label:_}, str?) -> _"""
417 options = {} #{ option : [Label]}
418 for label in lines.keys():
419 option = qualifier(label)
420 if (option not in options):
421 options[option] = []
422 options[option].append(label)
423 option_list = list(options.keys())
424 option_list.sort()
425 print '<select class="lines"',
426 if select_id is not None:
427 print 'id=%s' % qa(select_id)
428 print 'multiple="true" size="10" onchange="updateSvg();">'
429 for option in option_list:
430 print '<option value=' + qa('[' +
431 reduce(lambda x,y:x+json.dumps(str(y))+',',options[option],"")[0:-1]
432 + ']') + '>'+qe(option)+'</option>'
433 print '</select>'
434
epoger@google.com3d8cd172012-05-11 18:26:16 +0000435def output_ignored_data_points_warning(ignored_revision_data_points):
436 """Write description of ignored_revision_data_points to stdout as xhtml.
437 """
438 num_ignored_points = 0
439 description = ''
440 revisions = ignored_revision_data_points.keys()
441 if revisions:
442 revisions.sort()
443 revisions.reverse()
444 for revision in revisions:
445 num_ignored_points += len(ignored_revision_data_points[revision])
446 points_at_this_revision = []
447 for point in ignored_revision_data_points[revision]:
448 points_at_this_revision.append(point.bench)
449 points_at_this_revision.sort()
450 description += 'r%d: %s\n' % (revision, points_at_this_revision)
451 if num_ignored_points == 0:
452 print 'Did not discard any data points; all were within the range [%d-%d]' % (
453 MIN_REASONABLE_TIME, MAX_REASONABLE_TIME)
454 else:
455 print '<table width="100%" bgcolor="ff0000"><tr><td align="center">'
456 print 'Discarded %d data points outside of range [%d-%d]' % (
457 num_ignored_points, MIN_REASONABLE_TIME, MAX_REASONABLE_TIME)
458 print '</td></tr><tr><td width="100%" align="center">'
459 print ('<textarea rows="4" style="width:97%" readonly="true" wrap="off">'
460 + qe(description) + '</textarea>')
461 print '</td></tr></table>'
462
463def output_xhtml(lines, oldest_revision, newest_revision, ignored_revision_data_points,
epoger@google.com37260002011-08-08 20:27:04 +0000464 regressions, requested_width, requested_height, title):
bungeman@google.com85669f92011-06-17 13:58:14 +0000465 """Outputs an svg/xhtml view of the data."""
466 print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"',
467 print '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
468 print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'
469 print '<head>'
epoger@google.com3d8cd172012-05-11 18:26:16 +0000470 print '<title>%s</title>' % qe(title)
bungeman@google.com85669f92011-06-17 13:58:14 +0000471 print '</head>'
472 print '<body>'
473
474 output_svg(lines, regressions, requested_width, requested_height)
epoger@google.com3d8cd172012-05-11 18:26:16 +0000475
bungeman@google.com85669f92011-06-17 13:58:14 +0000476 #output the manipulation controls
477 print """
478<script type="text/javascript">//<![CDATA[
479 function getElementsByClass(node, searchClass, tag) {
480 var classElements = new Array();
481 var elements = node.getElementsByTagName(tag);
482 var pattern = new RegExp("^|\\s"+searchClass+"\\s|$");
483 for (var i = 0, elementsFound = 0; i < elements.length; ++i) {
484 if (pattern.test(elements[i].className)) {
485 classElements[elementsFound] = elements[i];
486 ++elementsFound;
487 }
488 }
489 return classElements;
490 }
491 function getAllLines() {
492 var selectElem = document.getElementById('benchSelect');
493 var linesObj = {};
494 for (var i = 0; i < selectElem.options.length; ++i) {
495 var lines = JSON.parse(selectElem.options[i].value);
496 for (var j = 0; j < lines.length; ++j) {
497 linesObj[lines[j]] = true;
498 }
499 }
500 return linesObj;
501 }
502 function getOptions(selectElem) {
503 var linesSelectedObj = {};
504 for (var i = 0; i < selectElem.options.length; ++i) {
505 if (!selectElem.options[i].selected) continue;
506
507 var linesSelected = JSON.parse(selectElem.options[i].value);
508 for (var j = 0; j < linesSelected.length; ++j) {
509 linesSelectedObj[linesSelected[j]] = true;
510 }
511 }
512 return linesSelectedObj;
513 }
514 function objectEmpty(obj) {
515 for (var p in obj) {
516 return false;
517 }
518 return true;
519 }
520 function markSelectedLines(selectElem, allLines) {
521 var linesSelected = getOptions(selectElem);
522 if (!objectEmpty(linesSelected)) {
523 for (var line in allLines) {
524 allLines[line] &= (linesSelected[line] == true);
525 }
526 }
527 }
528 function updateSvg() {
529 var allLines = getAllLines();
530
531 var selects = getElementsByClass(document, 'lines', 'select');
532 for (var i = 0; i < selects.length; ++i) {
533 markSelectedLines(selects[i], allLines);
534 }
535
536 for (var line in allLines) {
537 var svgLine = document.getElementById(line);
538 var display = (allLines[line] ? 'inline' : 'none');
539 svgLine.setAttributeNS(null,'display', display);
540 }
541 }
542
543 function mark(markerId) {
544 for (var line in getAllLines()) {
545 var svgLineGroup = document.getElementById(line);
546 var display = svgLineGroup.getAttributeNS(null,'display');
547 if (display == null || display == "" || display != "none") {
548 var svgLine = document.getElementById(line+'_line');
549 if (markerId == null) {
550 svgLine.removeAttributeNS(null,'marker-mid');
551 } else {
552 svgLine.setAttributeNS(null,'marker-mid', markerId);
553 }
554 }
555 }
556 }
557//]]></script>"""
epoger@google.comc71174d2011-08-08 17:19:23 +0000558
559 print '<table border="0" width="%s">' % requested_width
560 print """
epoger@google.com3d8cd172012-05-11 18:26:16 +0000561<tr valign="top"><td width="50%">
562<table border="0" width="100%">
563<tr><td align="center"><table border="0">
epoger@google.comc71174d2011-08-08 17:19:23 +0000564<form>
565<tr valign="bottom" align="center">
566<td width="1">Bench&nbsp;Type</td>
567<td width="1">Bitmap Config</td>
568<td width="1">Timer&nbsp;Type (Cpu/Gpu/wall)</td>
569<td width="1"><!--buttons--></td>
epoger@google.com3d8cd172012-05-11 18:26:16 +0000570</tr><tr valign="top" align="center">
571"""
epoger@google.comc71174d2011-08-08 17:19:23 +0000572 print '<td width="1">'
bungeman@google.com85669f92011-06-17 13:58:14 +0000573 create_select(lambda l: l.bench, lines, 'benchSelect')
epoger@google.comc71174d2011-08-08 17:19:23 +0000574 print '</td><td width="1">'
bungeman@google.com85669f92011-06-17 13:58:14 +0000575 create_select(lambda l: l.config, lines)
epoger@google.comc71174d2011-08-08 17:19:23 +0000576 print '</td><td width="1">'
bungeman@google.com85669f92011-06-17 13:58:14 +0000577 create_select(lambda l: l.time_type, lines)
epoger@google.comc71174d2011-08-08 17:19:23 +0000578
bungeman@google.com85669f92011-06-17 13:58:14 +0000579 all_settings = {}
580 variant_settings = set()
581 for label in lines.keys():
582 for key, value in label.settings.items():
583 if key not in all_settings:
584 all_settings[key] = value
585 elif all_settings[key] != value:
586 variant_settings.add(key)
epoger@google.comc71174d2011-08-08 17:19:23 +0000587
bungeman@google.com85669f92011-06-17 13:58:14 +0000588 for k in variant_settings:
bungeman@google.comb6981552012-07-10 15:31:52 +0000589 create_select(lambda l: l.settings.get(k, "<missing>"), lines)
epoger@google.comc71174d2011-08-08 17:19:23 +0000590
591 print '</td><td width="1"><button type="button"',
bungeman@google.com85669f92011-06-17 13:58:14 +0000592 print 'onclick=%s' % qa("mark('url(#circleMark)'); return false;"),
epoger@google.comc71174d2011-08-08 17:19:23 +0000593 print '>Mark Points</button>'
594 print '<button type="button" onclick="mark(null);">Clear Points</button>'
epoger@google.com3d8cd172012-05-11 18:26:16 +0000595 print '</td>'
epoger@google.comc71174d2011-08-08 17:19:23 +0000596 print """
epoger@google.com3d8cd172012-05-11 18:26:16 +0000597</tr>
598</form>
599</table></td></tr>
600<tr><td align="center">
601<hr />
602"""
603
604 output_ignored_data_points_warning(ignored_revision_data_points)
605 print '</td></tr></table>'
606 print '</td><td width="2%"><!--gutter--></td>'
607
608 print '<td><table border="0">'
609 print '<tr><td align="center">%s<br></br>revisions r%s - r%s</td></tr>' % (
610 qe(title),
611 bench_util.CreateRevisionLink(oldest_revision),
612 bench_util.CreateRevisionLink(newest_revision))
613 print """
614<tr><td align="left">
epoger@google.comc71174d2011-08-08 17:19:23 +0000615<p>Brighter red indicates tests that have gotten worse; brighter green
616indicates tests that have gotten better.</p>
617<p>To highlight individual tests, hold down CONTROL and mouse over
618graph lines.</p>
619<p>To highlight revision numbers, hold down SHIFT and mouse over
620the graph area.</p>
621<p>To only show certain tests on the graph, select any combination of
622tests in the selectors at left. (To show all, select all.)</p>
623<p>Use buttons at left to mark/clear points on the lines for selected
624benchmarks.</p>
epoger@google.com3d8cd172012-05-11 18:26:16 +0000625</td></tr>
626</table>
627
epoger@google.comc71174d2011-08-08 17:19:23 +0000628</td>
629</tr>
epoger@google.comc71174d2011-08-08 17:19:23 +0000630</table>
631</body>
632</html>"""
bungeman@google.com85669f92011-06-17 13:58:14 +0000633
634def compute_size(requested_width, requested_height, rev_width, time_height):
635 """Converts potentially empty requested size into a concrete size.
636
637 (Number?, Number?) -> (Number, Number)"""
638 pic_width = 0
639 pic_height = 0
640 if (requested_width is not None and requested_height is not None):
641 pic_height = requested_height
642 pic_width = requested_width
643
644 elif (requested_width is not None):
645 pic_width = requested_width
646 pic_height = pic_width * (float(time_height) / rev_width)
647
648 elif (requested_height is not None):
649 pic_height = requested_height
650 pic_width = pic_height * (float(rev_width) / time_height)
651
652 else:
653 pic_height = 800
654 pic_width = max(rev_width*3
655 , pic_height * (float(rev_width) / time_height))
656
657 return (pic_width, pic_height)
658
659def output_svg(lines, regressions, requested_width, requested_height):
660 """Outputs an svg view of the data."""
661
662 (global_min_x, _), (global_max_x, global_max_y) = bounds(lines)
663 max_up_slope, min_down_slope = bounds_slope(regressions)
664
665 #output
666 global_min_y = 0
667 x = global_min_x
668 y = global_min_y
669 w = global_max_x - global_min_x
670 h = global_max_y - global_min_y
671 font_size = 16
672 line_width = 2
673
674 pic_width, pic_height = compute_size(requested_width, requested_height
675 , w, h)
676
677 def cw(w1):
678 """Converts a revision difference to display width."""
679 return (pic_width / float(w)) * w1
680 def cx(x):
681 """Converts a revision to a horizontal display position."""
682 return cw(x - global_min_x)
683
684 def ch(h1):
685 """Converts a time difference to a display height."""
686 return -(pic_height / float(h)) * h1
687 def cy(y):
688 """Converts a time to a vertical display position."""
689 return pic_height + ch(y - global_min_y)
690
bensong@google.com74267432012-08-30 18:19:02 +0000691 print '<!--Picture height %.2f corresponds to bench value %.2f.-->' % (
692 pic_height, h)
bungeman@google.com85669f92011-06-17 13:58:14 +0000693 print '<svg',
694 print 'width=%s' % qa(str(pic_width)+'px')
695 print 'height=%s' % qa(str(pic_height)+'px')
696 print 'viewBox="0 0 %s %s"' % (str(pic_width), str(pic_height))
697 print 'onclick=%s' % qa(
698 "var event = arguments[0] || window.event;"
699 " if (event.shiftKey) { highlightRevision(null); }"
700 " if (event.ctrlKey) { highlight(null); }"
701 " return false;")
702 print 'xmlns="http://www.w3.org/2000/svg"'
703 print 'xmlns:xlink="http://www.w3.org/1999/xlink">'
704
705 print """
706<defs>
707 <marker id="circleMark"
708 viewBox="0 0 2 2" refX="1" refY="1"
709 markerUnits="strokeWidth"
710 markerWidth="2" markerHeight="2"
711 orient="0">
712 <circle cx="1" cy="1" r="1"/>
713 </marker>
714</defs>"""
715
716 #output the revisions
717 print """
718<script type="text/javascript">//<![CDATA[
719 var previousRevision;
720 var previousRevisionFill;
721 var previousRevisionStroke
722 function highlightRevision(id) {
723 if (previousRevision == id) return;
epoger@google.comc71174d2011-08-08 17:19:23 +0000724
725 document.getElementById('revision').firstChild.nodeValue = 'r' + id;
726 document.getElementById('rev_link').setAttribute('xlink:href',
727 'http://code.google.com/p/skia/source/detail?r=' + id);
bungeman@google.com85669f92011-06-17 13:58:14 +0000728
729 var preRevision = document.getElementById(previousRevision);
730 if (preRevision) {
731 preRevision.setAttributeNS(null,'fill', previousRevisionFill);
732 preRevision.setAttributeNS(null,'stroke', previousRevisionStroke);
733 }
734
735 var revision = document.getElementById(id);
736 previousRevision = id;
737 if (revision) {
738 previousRevisionFill = revision.getAttributeNS(null,'fill');
739 revision.setAttributeNS(null,'fill','rgb(100%, 95%, 95%)');
740
741 previousRevisionStroke = revision.getAttributeNS(null,'stroke');
742 revision.setAttributeNS(null,'stroke','rgb(100%, 90%, 90%)');
743 }
744 }
745//]]></script>"""
746
747 def print_rect(x, y, w, h, revision):
748 """Outputs a revision rectangle in display space,
749 taking arguments in revision space."""
750 disp_y = cy(y)
751 disp_h = ch(h)
752 if disp_h < 0:
753 disp_y += disp_h
754 disp_h = -disp_h
755
756 print '<rect id=%s x=%s y=%s' % (qa(revision), qa(cx(x)), qa(disp_y),),
757 print 'width=%s height=%s' % (qa(cw(w)), qa(disp_h),),
758 print 'fill="white"',
epoger@google.comc71174d2011-08-08 17:19:23 +0000759 print 'stroke="rgb(98%%,98%%,88%%)" stroke-width=%s' % qa(line_width),
bungeman@google.com85669f92011-06-17 13:58:14 +0000760 print 'onmouseover=%s' % qa(
761 "var event = arguments[0] || window.event;"
762 " if (event.shiftKey) {"
763 " highlightRevision('"+str(revision)+"');"
764 " return false;"
765 " }"),
766 print ' />'
767
768 xes = set()
769 for line in lines.itervalues():
770 for point in line:
771 xes.add(point[0])
772 revisions = list(xes)
773 revisions.sort()
774
775 left = x
776 current_revision = revisions[0]
777 for next_revision in revisions[1:]:
778 width = (((next_revision - current_revision) / 2.0)
779 + (current_revision - left))
780 print_rect(left, y, width, h, current_revision)
781 left += width
782 current_revision = next_revision
783 print_rect(left, y, x+w - left, h, current_revision)
epoger@google.comc71174d2011-08-08 17:19:23 +0000784
bungeman@google.com85669f92011-06-17 13:58:14 +0000785 #output the lines
786 print """
787<script type="text/javascript">//<![CDATA[
788 var previous;
789 var previousColor;
790 var previousOpacity;
791 function highlight(id) {
792 if (previous == id) return;
epoger@google.comc71174d2011-08-08 17:19:23 +0000793
bungeman@google.com85669f92011-06-17 13:58:14 +0000794 document.getElementById('label').firstChild.nodeValue = id;
epoger@google.comc71174d2011-08-08 17:19:23 +0000795
bungeman@google.com85669f92011-06-17 13:58:14 +0000796 var preGroup = document.getElementById(previous);
797 if (preGroup) {
798 var preLine = document.getElementById(previous+'_line');
799 preLine.setAttributeNS(null,'stroke', previousColor);
800 preLine.setAttributeNS(null,'opacity', previousOpacity);
epoger@google.comc71174d2011-08-08 17:19:23 +0000801
bungeman@google.com85669f92011-06-17 13:58:14 +0000802 var preSlope = document.getElementById(previous+'_linear');
803 if (preSlope) {
804 preSlope.setAttributeNS(null,'visibility', 'hidden');
805 }
806 }
epoger@google.comc71174d2011-08-08 17:19:23 +0000807
bungeman@google.com85669f92011-06-17 13:58:14 +0000808 var group = document.getElementById(id);
809 previous = id;
810 if (group) {
811 group.parentNode.appendChild(group);
812
813 var line = document.getElementById(id+'_line');
814 previousColor = line.getAttributeNS(null,'stroke');
815 previousOpacity = line.getAttributeNS(null,'opacity');
816 line.setAttributeNS(null,'stroke', 'blue');
817 line.setAttributeNS(null,'opacity', '1');
818
819 var slope = document.getElementById(id+'_linear');
820 if (slope) {
821 slope.setAttributeNS(null,'visibility', 'visible');
822 }
823 }
824 }
825//]]></script>"""
826 for label, line in lines.items():
827 print '<g id=%s>' % qa(label)
828 r = 128
829 g = 128
830 b = 128
831 a = .10
832 if label in regressions:
833 regression = regressions[label]
834 min_slope = regression.find_min_slope()
835 if min_slope < 0:
836 d = max(0, (min_slope / min_down_slope))
837 g += int(d*128)
838 a += d*0.9
839 elif min_slope > 0:
840 d = max(0, (min_slope / max_up_slope))
841 r += int(d*128)
842 a += d*0.9
843
844 slope = regression.slope
845 intercept = regression.intercept
846 min_x = regression.min_x
847 max_x = regression.max_x
848 print '<polyline id=%s' % qa(str(label)+'_linear'),
849 print 'fill="none" stroke="yellow"',
850 print 'stroke-width=%s' % qa(abs(ch(regression.serror*2))),
851 print 'opacity="0.5" pointer-events="none" visibility="hidden"',
852 print 'points="',
853 print '%s,%s' % (str(cx(min_x)), str(cy(slope*min_x + intercept))),
854 print '%s,%s' % (str(cx(max_x)), str(cy(slope*max_x + intercept))),
855 print '"/>'
856
857 print '<polyline id=%s' % qa(str(label)+'_line'),
858 print 'onmouseover=%s' % qa(
859 "var event = arguments[0] || window.event;"
860 " if (event.ctrlKey) {"
861 " highlight('"+str(label).replace("'", "\\'")+"');"
862 " return false;"
863 " }"),
864 print 'fill="none" stroke="rgb(%s,%s,%s)"' % (str(r), str(g), str(b)),
865 print 'stroke-width=%s' % qa(line_width),
866 print 'opacity=%s' % qa(a),
867 print 'points="',
868 for point in line:
869 print '%s,%s' % (str(cx(point[0])), str(cy(point[1]))),
870 print '"/>'
epoger@google.comc71174d2011-08-08 17:19:23 +0000871
bungeman@google.com85669f92011-06-17 13:58:14 +0000872 print '</g>'
epoger@google.comc71174d2011-08-08 17:19:23 +0000873
bungeman@google.com85669f92011-06-17 13:58:14 +0000874 #output the labels
875 print '<text id="label" x="0" y=%s' % qa(font_size),
876 print 'font-size=%s> </text>' % qa(font_size)
epoger@google.comc71174d2011-08-08 17:19:23 +0000877
878 print '<a id="rev_link" xlink:href="" target="_top">'
879 print '<text id="revision" x="0" y=%s style="' % qa(font_size*2)
880 print 'font-size: %s; ' % qe(font_size)
881 print 'stroke: #0000dd; text-decoration: underline; '
882 print '"> </text></a>'
883
bungeman@google.com85669f92011-06-17 13:58:14 +0000884 print '</svg>'
epoger@google.comc71174d2011-08-08 17:19:23 +0000885
bungeman@google.com85669f92011-06-17 13:58:14 +0000886if __name__ == "__main__":
887 main()