blob: 8165c9810169afcb59d9ed488a1f45d81099c5a0 [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.'
epoger@google.com5b2e01c2012-06-25 20:29:04 +000026 print '-l <title> title to use for the output graph'
27 print '-o <path> path to which to write output; writes to stdout if not specified'
28 print '-r <revision>[:<revision>] the revisions to show.'
29 print ' Negative <revision> is taken as offset from most recent revision.'
30 print '-s <setting>[=<value>] a setting to show (alpha, scalar, etc).'
31 print '-t <time> the time to show (w, c, g, etc).'
bungeman@google.com85669f92011-06-17 13:58:14 +000032 print '-x <int> the desired width of the svg.'
33 print '-y <int> the desired height of the svg.'
34 print '--default-setting <setting>[=<value>] setting for those without.'
35
36
37class Label:
38 """The information in a label.
39
40 (str, str, str, str, {str:str})"""
41 def __init__(self, bench, config, time_type, settings):
42 self.bench = bench
43 self.config = config
44 self.time_type = time_type
45 self.settings = settings
46
47 def __repr__(self):
48 return "Label(%s, %s, %s, %s)" % (
49 str(self.bench),
50 str(self.config),
51 str(self.time_type),
52 str(self.settings),
53 )
54
55 def __str__(self):
56 return "%s_%s_%s_%s" % (
57 str(self.bench),
58 str(self.config),
59 str(self.time_type),
60 str(self.settings),
61 )
62
63 def __eq__(self, other):
64 return (self.bench == other.bench and
65 self.config == other.config and
66 self.time_type == other.time_type and
67 self.settings == other.settings)
68
69 def __hash__(self):
70 return (hash(self.bench) ^
71 hash(self.config) ^
72 hash(self.time_type) ^
73 hash(frozenset(self.settings.iteritems())))
74
epoger@google.com37260002011-08-08 20:27:04 +000075def get_latest_revision(directory):
76 """Returns the latest revision number found within this directory.
77 """
78 latest_revision_found = -1
79 for bench_file in os.listdir(directory):
80 file_name_match = re.match('bench_r(\d+)_(\S+)', bench_file)
81 if (file_name_match is None):
82 continue
83 revision = int(file_name_match.group(1))
84 if revision > latest_revision_found:
85 latest_revision_found = revision
86 if latest_revision_found < 0:
87 return None
88 else:
89 return latest_revision_found
90
bungeman@google.com85669f92011-06-17 13:58:14 +000091def parse_dir(directory, default_settings, oldest_revision, newest_revision):
92 """Parses bench data from files like bench_r<revision>_<scalar>.
93
94 (str, {str, str}, Number, Number) -> {int:[BenchDataPoints]}"""
95 revision_data_points = {} # {revision : [BenchDataPoints]}
96 for bench_file in os.listdir(directory):
97 file_name_match = re.match('bench_r(\d+)_(\S+)', bench_file)
98 if (file_name_match is None):
99 continue
epoger@google.com3d8cd172012-05-11 18:26:16 +0000100
bungeman@google.com85669f92011-06-17 13:58:14 +0000101 revision = int(file_name_match.group(1))
102 scalar_type = file_name_match.group(2)
epoger@google.com3d8cd172012-05-11 18:26:16 +0000103
bungeman@google.com85669f92011-06-17 13:58:14 +0000104 if (revision < oldest_revision or revision > newest_revision):
105 continue
epoger@google.com3d8cd172012-05-11 18:26:16 +0000106
bungeman@google.com85669f92011-06-17 13:58:14 +0000107 file_handle = open(directory + '/' + bench_file, 'r')
epoger@google.com3d8cd172012-05-11 18:26:16 +0000108
bungeman@google.com85669f92011-06-17 13:58:14 +0000109 if (revision not in revision_data_points):
110 revision_data_points[revision] = []
111 default_settings['scalar'] = scalar_type
112 revision_data_points[revision].extend(
113 bench_util.parse(default_settings, file_handle))
114 file_handle.close()
115 return revision_data_points
116
epoger@google.com3d8cd172012-05-11 18:26:16 +0000117def add_to_revision_data_points(new_point, revision, revision_data_points):
118 """Add new_point to set of revision_data_points we are building up.
119 """
120 if (revision not in revision_data_points):
121 revision_data_points[revision] = []
122 revision_data_points[revision].append(new_point)
123
124def filter_data_points(unfiltered_revision_data_points):
125 """Filter out any data points that are utterly bogus.
126
127 Returns (allowed_revision_data_points, ignored_revision_data_points):
128 allowed_revision_data_points: points that survived the filter
129 ignored_revision_data_points: points that did NOT survive the filter
130 """
131 allowed_revision_data_points = {} # {revision : [BenchDataPoints]}
132 ignored_revision_data_points = {} # {revision : [BenchDataPoints]}
133 revisions = unfiltered_revision_data_points.keys()
134 revisions.sort()
135 for revision in revisions:
136 for point in unfiltered_revision_data_points[revision]:
137 if point.time < MIN_REASONABLE_TIME or point.time > MAX_REASONABLE_TIME:
138 add_to_revision_data_points(point, revision, ignored_revision_data_points)
139 else:
140 add_to_revision_data_points(point, revision, allowed_revision_data_points)
141 return (allowed_revision_data_points, ignored_revision_data_points)
142
epoger@google.com1513f6e2012-06-27 13:38:37 +0000143def get_abs_path(relative_path):
144 """My own implementation of os.path.abspath() that better handles paths
145 which approach Window's 260-character limit.
146 See https://code.google.com/p/skia/issues/detail?id=674
147
148 This implementation adds path components one at a time, resolving the
149 absolute path each time, to take advantage of any chdirs into outer
150 directories that will shorten the total path length.
151
152 TODO: share a single implementation with upload_to_bucket.py, instead
153 of pasting this same code into both files."""
154 if os.path.isabs(relative_path):
155 return relative_path
156 path_parts = relative_path.split(os.sep)
157 abs_path = os.path.abspath('.')
158 for path_part in path_parts:
159 abs_path = os.path.abspath(os.path.join(abs_path, path_part))
160 return abs_path
161
epoger@google.com5b2e01c2012-06-25 20:29:04 +0000162def redirect_stdout(output_path):
163 """Redirect all following stdout to a file.
164
165 You may be asking yourself, why redirect stdout within Python rather than
166 redirecting the script's output in the calling shell?
167 The answer lies in https://code.google.com/p/skia/issues/detail?id=674
168 ('buildbot: windows GenerateBenchGraphs step fails due to filename length'):
169 On Windows, we need to generate the absolute path within Python to avoid
170 the operating system's 260-character pathname limit, including chdirs."""
epoger@google.com1513f6e2012-06-27 13:38:37 +0000171 abs_path = get_abs_path(output_path)
epoger@google.com5b2e01c2012-06-25 20:29:04 +0000172 sys.stdout = open(abs_path, 'w')
173
bungeman@google.com85669f92011-06-17 13:58:14 +0000174def create_lines(revision_data_points, settings
175 , bench_of_interest, config_of_interest, time_of_interest):
176 """Convert revision data into sorted line data.
177
178 ({int:[BenchDataPoints]}, {str:str}, str?, str?, str?)
179 -> {Label:[(x,y)] | [n].x <= [n+1].x}"""
180 revisions = revision_data_points.keys()
181 revisions.sort()
182 lines = {} # {Label:[(x,y)] | x[n] <= x[n+1]}
183 for revision in revisions:
184 for point in revision_data_points[revision]:
185 if (bench_of_interest is not None and
186 not bench_of_interest == point.bench):
187 continue
188
189 if (config_of_interest is not None and
190 not config_of_interest == point.config):
191 continue
192
193 if (time_of_interest is not None and
194 not time_of_interest == point.time_type):
195 continue
196
197 skip = False
198 for key, value in settings.items():
199 if key in point.settings and point.settings[key] != value:
200 skip = True
201 break
202 if skip:
203 continue
204
205 line_name = Label(point.bench
206 , point.config
207 , point.time_type
208 , point.settings)
209
210 if line_name not in lines:
211 lines[line_name] = []
212
213 lines[line_name].append((revision, point.time))
214
215 return lines
216
217def bounds(lines):
218 """Finds the bounding rectangle for the lines.
219
220 {Label:[(x,y)]} -> ((min_x, min_y),(max_x,max_y))"""
221 min_x = bench_util.Max
222 min_y = bench_util.Max
223 max_x = bench_util.Min
224 max_y = bench_util.Min
225
226 for line in lines.itervalues():
227 for x, y in line:
228 min_x = min(min_x, x)
229 min_y = min(min_y, y)
230 max_x = max(max_x, x)
231 max_y = max(max_y, y)
232
233 return ((min_x, min_y), (max_x, max_y))
234
235def create_regressions(lines, start_x, end_x):
236 """Creates regression data from line segments.
237
238 ({Label:[(x,y)] | [n].x <= [n+1].x}, Number, Number)
239 -> {Label:LinearRegression}"""
240 regressions = {} # {Label : LinearRegression}
241
242 for label, line in lines.iteritems():
243 regression_line = [p for p in line if start_x <= p[0] <= end_x]
244
245 if (len(regression_line) < 2):
246 continue
247 regression = bench_util.LinearRegression(regression_line)
248 regressions[label] = regression
249
250 return regressions
251
252def bounds_slope(regressions):
253 """Finds the extreme up and down slopes of a set of linear regressions.
254
255 ({Label:LinearRegression}) -> (max_up_slope, min_down_slope)"""
256 max_up_slope = 0
257 min_down_slope = 0
258 for regression in regressions.itervalues():
259 min_slope = regression.find_min_slope()
260 max_up_slope = max(max_up_slope, min_slope)
261 min_down_slope = min(min_down_slope, min_slope)
262
263 return (max_up_slope, min_down_slope)
264
265def main():
266 """Parses command line and writes output."""
267
268 try:
269 opts, _ = getopt.getopt(sys.argv[1:]
epoger@google.com5b2e01c2012-06-25 20:29:04 +0000270 , "b:c:d:f:l:o:r:s:t:x:y:"
bungeman@google.com85669f92011-06-17 13:58:14 +0000271 , "default-setting=")
272 except getopt.GetoptError, err:
273 print str(err)
274 usage()
275 sys.exit(2)
276
277 directory = None
278 config_of_interest = None
279 bench_of_interest = None
280 time_of_interest = None
epoger@google.com37260002011-08-08 20:27:04 +0000281 revision_range = '0:'
282 regression_range = '0:'
283 latest_revision = None
bungeman@google.com85669f92011-06-17 13:58:14 +0000284 requested_height = None
285 requested_width = None
epoger@google.com37260002011-08-08 20:27:04 +0000286 title = 'Bench graph'
bungeman@google.com85669f92011-06-17 13:58:14 +0000287 settings = {}
288 default_settings = {}
epoger@google.com37260002011-08-08 20:27:04 +0000289
290 def parse_range(range):
291 """Takes '<old>[:<new>]' as a string and returns (old, new).
292 Any revision numbers that are dependent on the latest revision number
293 will be filled in based on latest_revision.
294 """
295 old, _, new = range.partition(":")
296 old = int(old)
297 if old < 0:
298 old += latest_revision;
bungeman@google.com85669f92011-06-17 13:58:14 +0000299 if not new:
epoger@google.com37260002011-08-08 20:27:04 +0000300 new = latest_revision;
301 new = int(new)
302 if new < 0:
303 new += latest_revision;
304 return (old, new)
305
bungeman@google.com85669f92011-06-17 13:58:14 +0000306 def add_setting(settings, setting):
307 """Takes <key>[=<value>] adds {key:value} or {key:True} to settings."""
308 name, _, value = setting.partition('=')
309 if not value:
310 settings[name] = True
311 else:
312 settings[name] = value
313
314 try:
315 for option, value in opts:
epoger@google.com5b2e01c2012-06-25 20:29:04 +0000316 if option == "-b":
bungeman@google.com85669f92011-06-17 13:58:14 +0000317 bench_of_interest = value
318 elif option == "-c":
319 config_of_interest = value
epoger@google.com5b2e01c2012-06-25 20:29:04 +0000320 elif option == "-d":
321 directory = value
bungeman@google.com85669f92011-06-17 13:58:14 +0000322 elif option == "-f":
epoger@google.com37260002011-08-08 20:27:04 +0000323 regression_range = value
epoger@google.com5b2e01c2012-06-25 20:29:04 +0000324 elif option == "-l":
325 title = value
326 elif option == "-o":
327 redirect_stdout(value)
328 elif option == "-r":
329 revision_range = value
330 elif option == "-s":
331 add_setting(settings, value)
332 elif option == "-t":
333 time_of_interest = value
bungeman@google.com85669f92011-06-17 13:58:14 +0000334 elif option == "-x":
335 requested_width = int(value)
336 elif option == "-y":
337 requested_height = int(value)
338 elif option == "--default-setting":
339 add_setting(default_settings, value)
340 else:
341 usage()
342 assert False, "unhandled option"
343 except ValueError:
344 usage()
345 sys.exit(2)
epoger@google.comc71174d2011-08-08 17:19:23 +0000346
bungeman@google.com85669f92011-06-17 13:58:14 +0000347 if directory is None:
348 usage()
349 sys.exit(2)
epoger@google.comc71174d2011-08-08 17:19:23 +0000350
epoger@google.com37260002011-08-08 20:27:04 +0000351 latest_revision = get_latest_revision(directory)
352 oldest_revision, newest_revision = parse_range(revision_range)
353 oldest_regression, newest_regression = parse_range(regression_range)
354
epoger@google.com3d8cd172012-05-11 18:26:16 +0000355 unfiltered_revision_data_points = parse_dir(directory
bungeman@google.com85669f92011-06-17 13:58:14 +0000356 , default_settings
357 , oldest_revision
358 , newest_revision)
epoger@google.comc71174d2011-08-08 17:19:23 +0000359
epoger@google.com3d8cd172012-05-11 18:26:16 +0000360 # Filter out any data points that are utterly bogus... make sure to report
361 # that we did so later!
362 (allowed_revision_data_points, ignored_revision_data_points) = filter_data_points(
363 unfiltered_revision_data_points)
364
epoger@google.comc71174d2011-08-08 17:19:23 +0000365 # Update oldest_revision and newest_revision based on the data we could find
epoger@google.com3d8cd172012-05-11 18:26:16 +0000366 all_revision_numbers = allowed_revision_data_points.keys()
epoger@google.comc71174d2011-08-08 17:19:23 +0000367 oldest_revision = min(all_revision_numbers)
368 newest_revision = max(all_revision_numbers)
369
epoger@google.com3d8cd172012-05-11 18:26:16 +0000370 lines = create_lines(allowed_revision_data_points
bungeman@google.com85669f92011-06-17 13:58:14 +0000371 , settings
372 , bench_of_interest
373 , config_of_interest
374 , time_of_interest)
epoger@google.comc71174d2011-08-08 17:19:23 +0000375
bungeman@google.com85669f92011-06-17 13:58:14 +0000376 regressions = create_regressions(lines
377 , oldest_regression
378 , newest_regression)
epoger@google.comc71174d2011-08-08 17:19:23 +0000379
epoger@google.com3d8cd172012-05-11 18:26:16 +0000380 output_xhtml(lines, oldest_revision, newest_revision, ignored_revision_data_points,
epoger@google.com37260002011-08-08 20:27:04 +0000381 regressions, requested_width, requested_height, title)
bungeman@google.com85669f92011-06-17 13:58:14 +0000382
383def qa(out):
384 """Stringify input and quote as an xml attribute."""
385 return xml.sax.saxutils.quoteattr(str(out))
386def qe(out):
387 """Stringify input and escape as xml data."""
388 return xml.sax.saxutils.escape(str(out))
389
390def create_select(qualifier, lines, select_id=None):
391 """Output select with options showing lines which qualifier maps to it.
392
393 ((Label) -> str, {Label:_}, str?) -> _"""
394 options = {} #{ option : [Label]}
395 for label in lines.keys():
396 option = qualifier(label)
397 if (option not in options):
398 options[option] = []
399 options[option].append(label)
400 option_list = list(options.keys())
401 option_list.sort()
402 print '<select class="lines"',
403 if select_id is not None:
404 print 'id=%s' % qa(select_id)
405 print 'multiple="true" size="10" onchange="updateSvg();">'
406 for option in option_list:
407 print '<option value=' + qa('[' +
408 reduce(lambda x,y:x+json.dumps(str(y))+',',options[option],"")[0:-1]
409 + ']') + '>'+qe(option)+'</option>'
410 print '</select>'
411
epoger@google.com3d8cd172012-05-11 18:26:16 +0000412def output_ignored_data_points_warning(ignored_revision_data_points):
413 """Write description of ignored_revision_data_points to stdout as xhtml.
414 """
415 num_ignored_points = 0
416 description = ''
417 revisions = ignored_revision_data_points.keys()
418 if revisions:
419 revisions.sort()
420 revisions.reverse()
421 for revision in revisions:
422 num_ignored_points += len(ignored_revision_data_points[revision])
423 points_at_this_revision = []
424 for point in ignored_revision_data_points[revision]:
425 points_at_this_revision.append(point.bench)
426 points_at_this_revision.sort()
427 description += 'r%d: %s\n' % (revision, points_at_this_revision)
428 if num_ignored_points == 0:
429 print 'Did not discard any data points; all were within the range [%d-%d]' % (
430 MIN_REASONABLE_TIME, MAX_REASONABLE_TIME)
431 else:
432 print '<table width="100%" bgcolor="ff0000"><tr><td align="center">'
433 print 'Discarded %d data points outside of range [%d-%d]' % (
434 num_ignored_points, MIN_REASONABLE_TIME, MAX_REASONABLE_TIME)
435 print '</td></tr><tr><td width="100%" align="center">'
436 print ('<textarea rows="4" style="width:97%" readonly="true" wrap="off">'
437 + qe(description) + '</textarea>')
438 print '</td></tr></table>'
439
440def output_xhtml(lines, oldest_revision, newest_revision, ignored_revision_data_points,
epoger@google.com37260002011-08-08 20:27:04 +0000441 regressions, requested_width, requested_height, title):
bungeman@google.com85669f92011-06-17 13:58:14 +0000442 """Outputs an svg/xhtml view of the data."""
443 print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"',
444 print '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
445 print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'
446 print '<head>'
epoger@google.com3d8cd172012-05-11 18:26:16 +0000447 print '<title>%s</title>' % qe(title)
bungeman@google.com85669f92011-06-17 13:58:14 +0000448 print '</head>'
449 print '<body>'
450
451 output_svg(lines, regressions, requested_width, requested_height)
epoger@google.com3d8cd172012-05-11 18:26:16 +0000452
bungeman@google.com85669f92011-06-17 13:58:14 +0000453 #output the manipulation controls
454 print """
455<script type="text/javascript">//<![CDATA[
456 function getElementsByClass(node, searchClass, tag) {
457 var classElements = new Array();
458 var elements = node.getElementsByTagName(tag);
459 var pattern = new RegExp("^|\\s"+searchClass+"\\s|$");
460 for (var i = 0, elementsFound = 0; i < elements.length; ++i) {
461 if (pattern.test(elements[i].className)) {
462 classElements[elementsFound] = elements[i];
463 ++elementsFound;
464 }
465 }
466 return classElements;
467 }
468 function getAllLines() {
469 var selectElem = document.getElementById('benchSelect');
470 var linesObj = {};
471 for (var i = 0; i < selectElem.options.length; ++i) {
472 var lines = JSON.parse(selectElem.options[i].value);
473 for (var j = 0; j < lines.length; ++j) {
474 linesObj[lines[j]] = true;
475 }
476 }
477 return linesObj;
478 }
479 function getOptions(selectElem) {
480 var linesSelectedObj = {};
481 for (var i = 0; i < selectElem.options.length; ++i) {
482 if (!selectElem.options[i].selected) continue;
483
484 var linesSelected = JSON.parse(selectElem.options[i].value);
485 for (var j = 0; j < linesSelected.length; ++j) {
486 linesSelectedObj[linesSelected[j]] = true;
487 }
488 }
489 return linesSelectedObj;
490 }
491 function objectEmpty(obj) {
492 for (var p in obj) {
493 return false;
494 }
495 return true;
496 }
497 function markSelectedLines(selectElem, allLines) {
498 var linesSelected = getOptions(selectElem);
499 if (!objectEmpty(linesSelected)) {
500 for (var line in allLines) {
501 allLines[line] &= (linesSelected[line] == true);
502 }
503 }
504 }
505 function updateSvg() {
506 var allLines = getAllLines();
507
508 var selects = getElementsByClass(document, 'lines', 'select');
509 for (var i = 0; i < selects.length; ++i) {
510 markSelectedLines(selects[i], allLines);
511 }
512
513 for (var line in allLines) {
514 var svgLine = document.getElementById(line);
515 var display = (allLines[line] ? 'inline' : 'none');
516 svgLine.setAttributeNS(null,'display', display);
517 }
518 }
519
520 function mark(markerId) {
521 for (var line in getAllLines()) {
522 var svgLineGroup = document.getElementById(line);
523 var display = svgLineGroup.getAttributeNS(null,'display');
524 if (display == null || display == "" || display != "none") {
525 var svgLine = document.getElementById(line+'_line');
526 if (markerId == null) {
527 svgLine.removeAttributeNS(null,'marker-mid');
528 } else {
529 svgLine.setAttributeNS(null,'marker-mid', markerId);
530 }
531 }
532 }
533 }
534//]]></script>"""
epoger@google.comc71174d2011-08-08 17:19:23 +0000535
536 print '<table border="0" width="%s">' % requested_width
537 print """
epoger@google.com3d8cd172012-05-11 18:26:16 +0000538<tr valign="top"><td width="50%">
539<table border="0" width="100%">
540<tr><td align="center"><table border="0">
epoger@google.comc71174d2011-08-08 17:19:23 +0000541<form>
542<tr valign="bottom" align="center">
543<td width="1">Bench&nbsp;Type</td>
544<td width="1">Bitmap Config</td>
545<td width="1">Timer&nbsp;Type (Cpu/Gpu/wall)</td>
546<td width="1"><!--buttons--></td>
epoger@google.com3d8cd172012-05-11 18:26:16 +0000547</tr><tr valign="top" align="center">
548"""
epoger@google.comc71174d2011-08-08 17:19:23 +0000549 print '<td width="1">'
bungeman@google.com85669f92011-06-17 13:58:14 +0000550 create_select(lambda l: l.bench, lines, 'benchSelect')
epoger@google.comc71174d2011-08-08 17:19:23 +0000551 print '</td><td width="1">'
bungeman@google.com85669f92011-06-17 13:58:14 +0000552 create_select(lambda l: l.config, lines)
epoger@google.comc71174d2011-08-08 17:19:23 +0000553 print '</td><td width="1">'
bungeman@google.com85669f92011-06-17 13:58:14 +0000554 create_select(lambda l: l.time_type, lines)
epoger@google.comc71174d2011-08-08 17:19:23 +0000555
bungeman@google.com85669f92011-06-17 13:58:14 +0000556 all_settings = {}
557 variant_settings = set()
558 for label in lines.keys():
559 for key, value in label.settings.items():
560 if key not in all_settings:
561 all_settings[key] = value
562 elif all_settings[key] != value:
563 variant_settings.add(key)
epoger@google.comc71174d2011-08-08 17:19:23 +0000564
bungeman@google.com85669f92011-06-17 13:58:14 +0000565 for k in variant_settings:
bungeman@google.comb6981552012-07-10 15:31:52 +0000566 create_select(lambda l: l.settings.get(k, "<missing>"), lines)
epoger@google.comc71174d2011-08-08 17:19:23 +0000567
568 print '</td><td width="1"><button type="button"',
bungeman@google.com85669f92011-06-17 13:58:14 +0000569 print 'onclick=%s' % qa("mark('url(#circleMark)'); return false;"),
epoger@google.comc71174d2011-08-08 17:19:23 +0000570 print '>Mark Points</button>'
571 print '<button type="button" onclick="mark(null);">Clear Points</button>'
epoger@google.com3d8cd172012-05-11 18:26:16 +0000572 print '</td>'
epoger@google.comc71174d2011-08-08 17:19:23 +0000573 print """
epoger@google.com3d8cd172012-05-11 18:26:16 +0000574</tr>
575</form>
576</table></td></tr>
577<tr><td align="center">
578<hr />
579"""
580
581 output_ignored_data_points_warning(ignored_revision_data_points)
582 print '</td></tr></table>'
583 print '</td><td width="2%"><!--gutter--></td>'
584
585 print '<td><table border="0">'
586 print '<tr><td align="center">%s<br></br>revisions r%s - r%s</td></tr>' % (
587 qe(title),
588 bench_util.CreateRevisionLink(oldest_revision),
589 bench_util.CreateRevisionLink(newest_revision))
590 print """
591<tr><td align="left">
epoger@google.comc71174d2011-08-08 17:19:23 +0000592<p>Brighter red indicates tests that have gotten worse; brighter green
593indicates tests that have gotten better.</p>
594<p>To highlight individual tests, hold down CONTROL and mouse over
595graph lines.</p>
596<p>To highlight revision numbers, hold down SHIFT and mouse over
597the graph area.</p>
598<p>To only show certain tests on the graph, select any combination of
599tests in the selectors at left. (To show all, select all.)</p>
600<p>Use buttons at left to mark/clear points on the lines for selected
601benchmarks.</p>
epoger@google.com3d8cd172012-05-11 18:26:16 +0000602</td></tr>
603</table>
604
epoger@google.comc71174d2011-08-08 17:19:23 +0000605</td>
606</tr>
epoger@google.comc71174d2011-08-08 17:19:23 +0000607</table>
608</body>
609</html>"""
bungeman@google.com85669f92011-06-17 13:58:14 +0000610
611def compute_size(requested_width, requested_height, rev_width, time_height):
612 """Converts potentially empty requested size into a concrete size.
613
614 (Number?, Number?) -> (Number, Number)"""
615 pic_width = 0
616 pic_height = 0
617 if (requested_width is not None and requested_height is not None):
618 pic_height = requested_height
619 pic_width = requested_width
620
621 elif (requested_width is not None):
622 pic_width = requested_width
623 pic_height = pic_width * (float(time_height) / rev_width)
624
625 elif (requested_height is not None):
626 pic_height = requested_height
627 pic_width = pic_height * (float(rev_width) / time_height)
628
629 else:
630 pic_height = 800
631 pic_width = max(rev_width*3
632 , pic_height * (float(rev_width) / time_height))
633
634 return (pic_width, pic_height)
635
636def output_svg(lines, regressions, requested_width, requested_height):
637 """Outputs an svg view of the data."""
638
639 (global_min_x, _), (global_max_x, global_max_y) = bounds(lines)
640 max_up_slope, min_down_slope = bounds_slope(regressions)
641
642 #output
643 global_min_y = 0
644 x = global_min_x
645 y = global_min_y
646 w = global_max_x - global_min_x
647 h = global_max_y - global_min_y
648 font_size = 16
649 line_width = 2
650
651 pic_width, pic_height = compute_size(requested_width, requested_height
652 , w, h)
653
654 def cw(w1):
655 """Converts a revision difference to display width."""
656 return (pic_width / float(w)) * w1
657 def cx(x):
658 """Converts a revision to a horizontal display position."""
659 return cw(x - global_min_x)
660
661 def ch(h1):
662 """Converts a time difference to a display height."""
663 return -(pic_height / float(h)) * h1
664 def cy(y):
665 """Converts a time to a vertical display position."""
666 return pic_height + ch(y - global_min_y)
667
668 print '<svg',
669 print 'width=%s' % qa(str(pic_width)+'px')
670 print 'height=%s' % qa(str(pic_height)+'px')
671 print 'viewBox="0 0 %s %s"' % (str(pic_width), str(pic_height))
672 print 'onclick=%s' % qa(
673 "var event = arguments[0] || window.event;"
674 " if (event.shiftKey) { highlightRevision(null); }"
675 " if (event.ctrlKey) { highlight(null); }"
676 " return false;")
677 print 'xmlns="http://www.w3.org/2000/svg"'
678 print 'xmlns:xlink="http://www.w3.org/1999/xlink">'
679
680 print """
681<defs>
682 <marker id="circleMark"
683 viewBox="0 0 2 2" refX="1" refY="1"
684 markerUnits="strokeWidth"
685 markerWidth="2" markerHeight="2"
686 orient="0">
687 <circle cx="1" cy="1" r="1"/>
688 </marker>
689</defs>"""
690
691 #output the revisions
692 print """
693<script type="text/javascript">//<![CDATA[
694 var previousRevision;
695 var previousRevisionFill;
696 var previousRevisionStroke
697 function highlightRevision(id) {
698 if (previousRevision == id) return;
epoger@google.comc71174d2011-08-08 17:19:23 +0000699
700 document.getElementById('revision').firstChild.nodeValue = 'r' + id;
701 document.getElementById('rev_link').setAttribute('xlink:href',
702 'http://code.google.com/p/skia/source/detail?r=' + id);
bungeman@google.com85669f92011-06-17 13:58:14 +0000703
704 var preRevision = document.getElementById(previousRevision);
705 if (preRevision) {
706 preRevision.setAttributeNS(null,'fill', previousRevisionFill);
707 preRevision.setAttributeNS(null,'stroke', previousRevisionStroke);
708 }
709
710 var revision = document.getElementById(id);
711 previousRevision = id;
712 if (revision) {
713 previousRevisionFill = revision.getAttributeNS(null,'fill');
714 revision.setAttributeNS(null,'fill','rgb(100%, 95%, 95%)');
715
716 previousRevisionStroke = revision.getAttributeNS(null,'stroke');
717 revision.setAttributeNS(null,'stroke','rgb(100%, 90%, 90%)');
718 }
719 }
720//]]></script>"""
721
722 def print_rect(x, y, w, h, revision):
723 """Outputs a revision rectangle in display space,
724 taking arguments in revision space."""
725 disp_y = cy(y)
726 disp_h = ch(h)
727 if disp_h < 0:
728 disp_y += disp_h
729 disp_h = -disp_h
730
731 print '<rect id=%s x=%s y=%s' % (qa(revision), qa(cx(x)), qa(disp_y),),
732 print 'width=%s height=%s' % (qa(cw(w)), qa(disp_h),),
733 print 'fill="white"',
epoger@google.comc71174d2011-08-08 17:19:23 +0000734 print 'stroke="rgb(98%%,98%%,88%%)" stroke-width=%s' % qa(line_width),
bungeman@google.com85669f92011-06-17 13:58:14 +0000735 print 'onmouseover=%s' % qa(
736 "var event = arguments[0] || window.event;"
737 " if (event.shiftKey) {"
738 " highlightRevision('"+str(revision)+"');"
739 " return false;"
740 " }"),
741 print ' />'
742
743 xes = set()
744 for line in lines.itervalues():
745 for point in line:
746 xes.add(point[0])
747 revisions = list(xes)
748 revisions.sort()
749
750 left = x
751 current_revision = revisions[0]
752 for next_revision in revisions[1:]:
753 width = (((next_revision - current_revision) / 2.0)
754 + (current_revision - left))
755 print_rect(left, y, width, h, current_revision)
756 left += width
757 current_revision = next_revision
758 print_rect(left, y, x+w - left, h, current_revision)
epoger@google.comc71174d2011-08-08 17:19:23 +0000759
bungeman@google.com85669f92011-06-17 13:58:14 +0000760 #output the lines
761 print """
762<script type="text/javascript">//<![CDATA[
763 var previous;
764 var previousColor;
765 var previousOpacity;
766 function highlight(id) {
767 if (previous == id) return;
epoger@google.comc71174d2011-08-08 17:19:23 +0000768
bungeman@google.com85669f92011-06-17 13:58:14 +0000769 document.getElementById('label').firstChild.nodeValue = id;
epoger@google.comc71174d2011-08-08 17:19:23 +0000770
bungeman@google.com85669f92011-06-17 13:58:14 +0000771 var preGroup = document.getElementById(previous);
772 if (preGroup) {
773 var preLine = document.getElementById(previous+'_line');
774 preLine.setAttributeNS(null,'stroke', previousColor);
775 preLine.setAttributeNS(null,'opacity', previousOpacity);
epoger@google.comc71174d2011-08-08 17:19:23 +0000776
bungeman@google.com85669f92011-06-17 13:58:14 +0000777 var preSlope = document.getElementById(previous+'_linear');
778 if (preSlope) {
779 preSlope.setAttributeNS(null,'visibility', 'hidden');
780 }
781 }
epoger@google.comc71174d2011-08-08 17:19:23 +0000782
bungeman@google.com85669f92011-06-17 13:58:14 +0000783 var group = document.getElementById(id);
784 previous = id;
785 if (group) {
786 group.parentNode.appendChild(group);
787
788 var line = document.getElementById(id+'_line');
789 previousColor = line.getAttributeNS(null,'stroke');
790 previousOpacity = line.getAttributeNS(null,'opacity');
791 line.setAttributeNS(null,'stroke', 'blue');
792 line.setAttributeNS(null,'opacity', '1');
793
794 var slope = document.getElementById(id+'_linear');
795 if (slope) {
796 slope.setAttributeNS(null,'visibility', 'visible');
797 }
798 }
799 }
800//]]></script>"""
801 for label, line in lines.items():
802 print '<g id=%s>' % qa(label)
803 r = 128
804 g = 128
805 b = 128
806 a = .10
807 if label in regressions:
808 regression = regressions[label]
809 min_slope = regression.find_min_slope()
810 if min_slope < 0:
811 d = max(0, (min_slope / min_down_slope))
812 g += int(d*128)
813 a += d*0.9
814 elif min_slope > 0:
815 d = max(0, (min_slope / max_up_slope))
816 r += int(d*128)
817 a += d*0.9
818
819 slope = regression.slope
820 intercept = regression.intercept
821 min_x = regression.min_x
822 max_x = regression.max_x
823 print '<polyline id=%s' % qa(str(label)+'_linear'),
824 print 'fill="none" stroke="yellow"',
825 print 'stroke-width=%s' % qa(abs(ch(regression.serror*2))),
826 print 'opacity="0.5" pointer-events="none" visibility="hidden"',
827 print 'points="',
828 print '%s,%s' % (str(cx(min_x)), str(cy(slope*min_x + intercept))),
829 print '%s,%s' % (str(cx(max_x)), str(cy(slope*max_x + intercept))),
830 print '"/>'
831
832 print '<polyline id=%s' % qa(str(label)+'_line'),
833 print 'onmouseover=%s' % qa(
834 "var event = arguments[0] || window.event;"
835 " if (event.ctrlKey) {"
836 " highlight('"+str(label).replace("'", "\\'")+"');"
837 " return false;"
838 " }"),
839 print 'fill="none" stroke="rgb(%s,%s,%s)"' % (str(r), str(g), str(b)),
840 print 'stroke-width=%s' % qa(line_width),
841 print 'opacity=%s' % qa(a),
842 print 'points="',
843 for point in line:
844 print '%s,%s' % (str(cx(point[0])), str(cy(point[1]))),
845 print '"/>'
epoger@google.comc71174d2011-08-08 17:19:23 +0000846
bungeman@google.com85669f92011-06-17 13:58:14 +0000847 print '</g>'
epoger@google.comc71174d2011-08-08 17:19:23 +0000848
bungeman@google.com85669f92011-06-17 13:58:14 +0000849 #output the labels
850 print '<text id="label" x="0" y=%s' % qa(font_size),
851 print 'font-size=%s> </text>' % qa(font_size)
epoger@google.comc71174d2011-08-08 17:19:23 +0000852
853 print '<a id="rev_link" xlink:href="" target="_top">'
854 print '<text id="revision" x="0" y=%s style="' % qa(font_size*2)
855 print 'font-size: %s; ' % qe(font_size)
856 print 'stroke: #0000dd; text-decoration: underline; '
857 print '"> </text></a>'
858
bungeman@google.com85669f92011-06-17 13:58:14 +0000859 print '</svg>'
epoger@google.comc71174d2011-08-08 17:19:23 +0000860
bungeman@google.com85669f92011-06-17 13:58:14 +0000861if __name__ == "__main__":
862 main()