bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 1 | ''' |
| 2 | Created on May 16, 2011 |
| 3 | |
| 4 | @author: bungeman |
| 5 | ''' |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 6 | import bench_util |
bensong@google.com | 848fa2b | 2013-03-07 17:12:43 +0000 | [diff] [blame] | 7 | import getopt |
| 8 | import httplib |
| 9 | import itertools |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 10 | import json |
bensong@google.com | 848fa2b | 2013-03-07 17:12:43 +0000 | [diff] [blame] | 11 | import os |
| 12 | import re |
| 13 | import sys |
| 14 | import urllib |
| 15 | import urllib2 |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 16 | import xml.sax.saxutils |
| 17 | |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 18 | # We throw out any measurement outside this range, and log a warning. |
| 19 | MIN_REASONABLE_TIME = 0 |
| 20 | MAX_REASONABLE_TIME = 99999 |
| 21 | |
bensong@google.com | ad0c5d2 | 2012-09-13 21:08:52 +0000 | [diff] [blame] | 22 | # Constants for prefixes in output title used in buildbot. |
| 23 | TITLE_PREAMBLE = 'Bench_Performance_for_Skia_' |
| 24 | TITLE_PREAMBLE_LENGTH = len(TITLE_PREAMBLE) |
| 25 | |
bensong@google.com | 848fa2b | 2013-03-07 17:12:43 +0000 | [diff] [blame] | 26 | # Number of data points to send to appengine at once. |
bensong@google.com | eb6a41d | 2013-04-02 16:41:55 +0000 | [diff] [blame] | 27 | DATA_POINT_BATCHSIZE = 66 |
bensong@google.com | 848fa2b | 2013-03-07 17:12:43 +0000 | [diff] [blame] | 28 | |
| 29 | def grouper(n, iterable): |
| 30 | """Groups list into list of lists for a given size. See itertools doc: |
| 31 | http://docs.python.org/2/library/itertools.html#module-itertools |
| 32 | """ |
| 33 | args = [iter(iterable)] * n |
| 34 | return [[n for n in t if n] for t in itertools.izip_longest(*args)] |
| 35 | |
| 36 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 37 | def usage(): |
| 38 | """Prints simple usage information.""" |
bensong@google.com | 848fa2b | 2013-03-07 17:12:43 +0000 | [diff] [blame] | 39 | |
| 40 | print '-a <url> the url to use for adding bench values to app engine app.' |
| 41 | print ' Example: "https://skiadash.appspot.com/add_point".' |
| 42 | print ' If not set, will skip this step.' |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 43 | print '-b <bench> the bench to show.' |
| 44 | print '-c <config> the config to show (GPU, 8888, 565, etc).' |
epoger@google.com | 5b2e01c | 2012-06-25 20:29:04 +0000 | [diff] [blame] | 45 | print '-d <dir> a directory containing bench_r<revision>_<scalar> files.' |
bensong@google.com | ad0c5d2 | 2012-09-13 21:08:52 +0000 | [diff] [blame] | 46 | print '-e <file> file containing expected bench values/ranges.' |
| 47 | print ' Will raise exception if actual bench values are out of range.' |
| 48 | print ' See bench_expectations.txt for data format and examples.' |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 49 | print '-f <revision>[:<revision>] the revisions to use for fitting.' |
epoger@google.com | 3726000 | 2011-08-08 20:27:04 +0000 | [diff] [blame] | 50 | print ' Negative <revision> is taken as offset from most recent revision.' |
bensong@google.com | 8ccfa55 | 2012-08-17 21:42:14 +0000 | [diff] [blame] | 51 | print '-i <time> the time to ignore (w, c, g, etc).' |
| 52 | print ' The flag is ignored when -t is set; otherwise we plot all the' |
| 53 | print ' times except the one specified here.' |
epoger@google.com | 5b2e01c | 2012-06-25 20:29:04 +0000 | [diff] [blame] | 54 | print '-l <title> title to use for the output graph' |
bensong@google.com | 8ccfa55 | 2012-08-17 21:42:14 +0000 | [diff] [blame] | 55 | print '-m <representation> representation of bench value.' |
| 56 | print ' See _ListAlgorithm class in bench_util.py.' |
borenet@google.com | 5dc0678 | 2013-03-12 17:16:07 +0000 | [diff] [blame] | 57 | print '-o <path> path to which to write output.' |
epoger@google.com | 5b2e01c | 2012-06-25 20:29:04 +0000 | [diff] [blame] | 58 | print '-r <revision>[:<revision>] the revisions to show.' |
| 59 | print ' Negative <revision> is taken as offset from most recent revision.' |
| 60 | print '-s <setting>[=<value>] a setting to show (alpha, scalar, etc).' |
| 61 | print '-t <time> the time to show (w, c, g, etc).' |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 62 | print '-x <int> the desired width of the svg.' |
| 63 | print '-y <int> the desired height of the svg.' |
| 64 | print '--default-setting <setting>[=<value>] setting for those without.' |
| 65 | |
| 66 | |
| 67 | class Label: |
| 68 | """The information in a label. |
| 69 | |
| 70 | (str, str, str, str, {str:str})""" |
| 71 | def __init__(self, bench, config, time_type, settings): |
| 72 | self.bench = bench |
| 73 | self.config = config |
| 74 | self.time_type = time_type |
| 75 | self.settings = settings |
| 76 | |
| 77 | def __repr__(self): |
| 78 | return "Label(%s, %s, %s, %s)" % ( |
| 79 | str(self.bench), |
| 80 | str(self.config), |
| 81 | str(self.time_type), |
| 82 | str(self.settings), |
| 83 | ) |
| 84 | |
| 85 | def __str__(self): |
| 86 | return "%s_%s_%s_%s" % ( |
| 87 | str(self.bench), |
| 88 | str(self.config), |
| 89 | str(self.time_type), |
| 90 | str(self.settings), |
| 91 | ) |
| 92 | |
| 93 | def __eq__(self, other): |
| 94 | return (self.bench == other.bench and |
| 95 | self.config == other.config and |
| 96 | self.time_type == other.time_type and |
| 97 | self.settings == other.settings) |
| 98 | |
| 99 | def __hash__(self): |
| 100 | return (hash(self.bench) ^ |
| 101 | hash(self.config) ^ |
| 102 | hash(self.time_type) ^ |
| 103 | hash(frozenset(self.settings.iteritems()))) |
| 104 | |
epoger@google.com | 3726000 | 2011-08-08 20:27:04 +0000 | [diff] [blame] | 105 | def get_latest_revision(directory): |
| 106 | """Returns the latest revision number found within this directory. |
| 107 | """ |
| 108 | latest_revision_found = -1 |
| 109 | for bench_file in os.listdir(directory): |
| 110 | file_name_match = re.match('bench_r(\d+)_(\S+)', bench_file) |
| 111 | if (file_name_match is None): |
| 112 | continue |
| 113 | revision = int(file_name_match.group(1)) |
| 114 | if revision > latest_revision_found: |
| 115 | latest_revision_found = revision |
| 116 | if latest_revision_found < 0: |
| 117 | return None |
| 118 | else: |
| 119 | return latest_revision_found |
| 120 | |
bensong@google.com | 8734816 | 2012-08-15 17:31:46 +0000 | [diff] [blame] | 121 | def parse_dir(directory, default_settings, oldest_revision, newest_revision, |
| 122 | rep): |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 123 | """Parses bench data from files like bench_r<revision>_<scalar>. |
| 124 | |
| 125 | (str, {str, str}, Number, Number) -> {int:[BenchDataPoints]}""" |
| 126 | revision_data_points = {} # {revision : [BenchDataPoints]} |
epoger@google.com | e9b31fa | 2013-02-14 20:13:32 +0000 | [diff] [blame] | 127 | file_list = os.listdir(directory) |
| 128 | file_list.sort() |
| 129 | for bench_file in file_list: |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 130 | file_name_match = re.match('bench_r(\d+)_(\S+)', bench_file) |
| 131 | if (file_name_match is None): |
| 132 | continue |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 133 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 134 | revision = int(file_name_match.group(1)) |
| 135 | scalar_type = file_name_match.group(2) |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 136 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 137 | if (revision < oldest_revision or revision > newest_revision): |
| 138 | continue |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 139 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 140 | file_handle = open(directory + '/' + bench_file, 'r') |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 141 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 142 | if (revision not in revision_data_points): |
| 143 | revision_data_points[revision] = [] |
| 144 | default_settings['scalar'] = scalar_type |
| 145 | revision_data_points[revision].extend( |
bensong@google.com | 8734816 | 2012-08-15 17:31:46 +0000 | [diff] [blame] | 146 | bench_util.parse(default_settings, file_handle, rep)) |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 147 | file_handle.close() |
| 148 | return revision_data_points |
| 149 | |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 150 | def add_to_revision_data_points(new_point, revision, revision_data_points): |
| 151 | """Add new_point to set of revision_data_points we are building up. |
| 152 | """ |
| 153 | if (revision not in revision_data_points): |
| 154 | revision_data_points[revision] = [] |
| 155 | revision_data_points[revision].append(new_point) |
| 156 | |
| 157 | def filter_data_points(unfiltered_revision_data_points): |
| 158 | """Filter out any data points that are utterly bogus. |
| 159 | |
| 160 | Returns (allowed_revision_data_points, ignored_revision_data_points): |
| 161 | allowed_revision_data_points: points that survived the filter |
| 162 | ignored_revision_data_points: points that did NOT survive the filter |
| 163 | """ |
| 164 | allowed_revision_data_points = {} # {revision : [BenchDataPoints]} |
| 165 | ignored_revision_data_points = {} # {revision : [BenchDataPoints]} |
| 166 | revisions = unfiltered_revision_data_points.keys() |
| 167 | revisions.sort() |
| 168 | for revision in revisions: |
| 169 | for point in unfiltered_revision_data_points[revision]: |
| 170 | if point.time < MIN_REASONABLE_TIME or point.time > MAX_REASONABLE_TIME: |
| 171 | add_to_revision_data_points(point, revision, ignored_revision_data_points) |
| 172 | else: |
| 173 | add_to_revision_data_points(point, revision, allowed_revision_data_points) |
| 174 | return (allowed_revision_data_points, ignored_revision_data_points) |
| 175 | |
epoger@google.com | 1513f6e | 2012-06-27 13:38:37 +0000 | [diff] [blame] | 176 | def get_abs_path(relative_path): |
| 177 | """My own implementation of os.path.abspath() that better handles paths |
| 178 | which approach Window's 260-character limit. |
| 179 | See https://code.google.com/p/skia/issues/detail?id=674 |
| 180 | |
| 181 | This implementation adds path components one at a time, resolving the |
| 182 | absolute path each time, to take advantage of any chdirs into outer |
| 183 | directories that will shorten the total path length. |
| 184 | |
| 185 | TODO: share a single implementation with upload_to_bucket.py, instead |
| 186 | of pasting this same code into both files.""" |
| 187 | if os.path.isabs(relative_path): |
| 188 | return relative_path |
| 189 | path_parts = relative_path.split(os.sep) |
| 190 | abs_path = os.path.abspath('.') |
| 191 | for path_part in path_parts: |
| 192 | abs_path = os.path.abspath(os.path.join(abs_path, path_part)) |
| 193 | return abs_path |
| 194 | |
epoger@google.com | 5b2e01c | 2012-06-25 20:29:04 +0000 | [diff] [blame] | 195 | def redirect_stdout(output_path): |
| 196 | """Redirect all following stdout to a file. |
| 197 | |
| 198 | You may be asking yourself, why redirect stdout within Python rather than |
| 199 | redirecting the script's output in the calling shell? |
| 200 | The answer lies in https://code.google.com/p/skia/issues/detail?id=674 |
| 201 | ('buildbot: windows GenerateBenchGraphs step fails due to filename length'): |
| 202 | On Windows, we need to generate the absolute path within Python to avoid |
| 203 | the operating system's 260-character pathname limit, including chdirs.""" |
epoger@google.com | 1513f6e | 2012-06-27 13:38:37 +0000 | [diff] [blame] | 204 | abs_path = get_abs_path(output_path) |
epoger@google.com | 5b2e01c | 2012-06-25 20:29:04 +0000 | [diff] [blame] | 205 | sys.stdout = open(abs_path, 'w') |
| 206 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 207 | def create_lines(revision_data_points, settings |
bensong@google.com | 8ccfa55 | 2012-08-17 21:42:14 +0000 | [diff] [blame] | 208 | , bench_of_interest, config_of_interest, time_of_interest |
| 209 | , time_to_ignore): |
epoger@google.com | 2459a39 | 2013-02-14 18:58:05 +0000 | [diff] [blame] | 210 | """Convert revision data into a dictionary of line data. |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 211 | |
bensong@google.com | 848fa2b | 2013-03-07 17:12:43 +0000 | [diff] [blame] | 212 | Args: |
| 213 | revision_data_points: a dictionary with integer keys (revision #) and a |
| 214 | list of bench data points as values |
| 215 | settings: a dictionary of setting names to value |
| 216 | bench_of_interest: optional filter parameters: which bench type is of |
| 217 | interest. If None, process them all. |
| 218 | config_of_interest: optional filter parameters: which config type is of |
| 219 | interest. If None, process them all. |
| 220 | time_of_interest: optional filter parameters: which timer type is of |
| 221 | interest. If None, process them all. |
| 222 | time_to_ignore: optional timer type to ignore |
| 223 | |
| 224 | Returns: |
| 225 | a dictionary of this form: |
| 226 | keys = Label objects |
| 227 | values = a list of (x, y) tuples sorted such that x values increase |
| 228 | monotonically |
| 229 | """ |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 230 | revisions = revision_data_points.keys() |
| 231 | revisions.sort() |
| 232 | lines = {} # {Label:[(x,y)] | x[n] <= x[n+1]} |
| 233 | for revision in revisions: |
| 234 | for point in revision_data_points[revision]: |
| 235 | if (bench_of_interest is not None and |
| 236 | not bench_of_interest == point.bench): |
| 237 | continue |
| 238 | |
| 239 | if (config_of_interest is not None and |
| 240 | not config_of_interest == point.config): |
| 241 | continue |
| 242 | |
| 243 | if (time_of_interest is not None and |
| 244 | not time_of_interest == point.time_type): |
| 245 | continue |
bensong@google.com | 8ccfa55 | 2012-08-17 21:42:14 +0000 | [diff] [blame] | 246 | elif (time_to_ignore is not None and |
| 247 | time_to_ignore == point.time_type): |
| 248 | continue |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 249 | |
| 250 | skip = False |
| 251 | for key, value in settings.items(): |
| 252 | if key in point.settings and point.settings[key] != value: |
| 253 | skip = True |
| 254 | break |
| 255 | if skip: |
| 256 | continue |
| 257 | |
| 258 | line_name = Label(point.bench |
| 259 | , point.config |
| 260 | , point.time_type |
| 261 | , point.settings) |
| 262 | |
| 263 | if line_name not in lines: |
| 264 | lines[line_name] = [] |
| 265 | |
| 266 | lines[line_name].append((revision, point.time)) |
| 267 | |
| 268 | return lines |
| 269 | |
| 270 | def bounds(lines): |
| 271 | """Finds the bounding rectangle for the lines. |
| 272 | |
| 273 | {Label:[(x,y)]} -> ((min_x, min_y),(max_x,max_y))""" |
| 274 | min_x = bench_util.Max |
| 275 | min_y = bench_util.Max |
| 276 | max_x = bench_util.Min |
| 277 | max_y = bench_util.Min |
| 278 | |
| 279 | for line in lines.itervalues(): |
| 280 | for x, y in line: |
| 281 | min_x = min(min_x, x) |
| 282 | min_y = min(min_y, y) |
| 283 | max_x = max(max_x, x) |
| 284 | max_y = max(max_y, y) |
| 285 | |
| 286 | return ((min_x, min_y), (max_x, max_y)) |
| 287 | |
| 288 | def create_regressions(lines, start_x, end_x): |
| 289 | """Creates regression data from line segments. |
| 290 | |
| 291 | ({Label:[(x,y)] | [n].x <= [n+1].x}, Number, Number) |
| 292 | -> {Label:LinearRegression}""" |
| 293 | regressions = {} # {Label : LinearRegression} |
| 294 | |
| 295 | for label, line in lines.iteritems(): |
| 296 | regression_line = [p for p in line if start_x <= p[0] <= end_x] |
| 297 | |
| 298 | if (len(regression_line) < 2): |
| 299 | continue |
| 300 | regression = bench_util.LinearRegression(regression_line) |
| 301 | regressions[label] = regression |
| 302 | |
| 303 | return regressions |
| 304 | |
| 305 | def bounds_slope(regressions): |
| 306 | """Finds the extreme up and down slopes of a set of linear regressions. |
| 307 | |
| 308 | ({Label:LinearRegression}) -> (max_up_slope, min_down_slope)""" |
| 309 | max_up_slope = 0 |
| 310 | min_down_slope = 0 |
| 311 | for regression in regressions.itervalues(): |
| 312 | min_slope = regression.find_min_slope() |
| 313 | max_up_slope = max(max_up_slope, min_slope) |
| 314 | min_down_slope = min(min_down_slope, min_slope) |
| 315 | |
| 316 | return (max_up_slope, min_down_slope) |
| 317 | |
| 318 | def main(): |
| 319 | """Parses command line and writes output.""" |
| 320 | |
| 321 | try: |
| 322 | opts, _ = getopt.getopt(sys.argv[1:] |
bensong@google.com | 848fa2b | 2013-03-07 17:12:43 +0000 | [diff] [blame] | 323 | , "a:b:c:d:e:f:i:l:m:o:r:s:t:x:y:" |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 324 | , "default-setting=") |
| 325 | except getopt.GetoptError, err: |
| 326 | print str(err) |
| 327 | usage() |
| 328 | sys.exit(2) |
| 329 | |
| 330 | directory = None |
| 331 | config_of_interest = None |
| 332 | bench_of_interest = None |
| 333 | time_of_interest = None |
bensong@google.com | 8ccfa55 | 2012-08-17 21:42:14 +0000 | [diff] [blame] | 334 | time_to_ignore = None |
borenet@google.com | 5dc0678 | 2013-03-12 17:16:07 +0000 | [diff] [blame] | 335 | output_path = None |
bensong@google.com | ad0c5d2 | 2012-09-13 21:08:52 +0000 | [diff] [blame] | 336 | bench_expectations = {} |
bensong@google.com | 848fa2b | 2013-03-07 17:12:43 +0000 | [diff] [blame] | 337 | appengine_url = None # used for adding data to appengine datastore |
bensong@google.com | b6204b1 | 2012-08-16 20:49:28 +0000 | [diff] [blame] | 338 | rep = None # bench representation algorithm |
epoger@google.com | 3726000 | 2011-08-08 20:27:04 +0000 | [diff] [blame] | 339 | revision_range = '0:' |
| 340 | regression_range = '0:' |
| 341 | latest_revision = None |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 342 | requested_height = None |
| 343 | requested_width = None |
epoger@google.com | 3726000 | 2011-08-08 20:27:04 +0000 | [diff] [blame] | 344 | title = 'Bench graph' |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 345 | settings = {} |
| 346 | default_settings = {} |
epoger@google.com | 3726000 | 2011-08-08 20:27:04 +0000 | [diff] [blame] | 347 | |
| 348 | def parse_range(range): |
| 349 | """Takes '<old>[:<new>]' as a string and returns (old, new). |
| 350 | Any revision numbers that are dependent on the latest revision number |
| 351 | will be filled in based on latest_revision. |
| 352 | """ |
| 353 | old, _, new = range.partition(":") |
| 354 | old = int(old) |
| 355 | if old < 0: |
| 356 | old += latest_revision; |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 357 | if not new: |
epoger@google.com | 3726000 | 2011-08-08 20:27:04 +0000 | [diff] [blame] | 358 | new = latest_revision; |
| 359 | new = int(new) |
| 360 | if new < 0: |
| 361 | new += latest_revision; |
| 362 | return (old, new) |
| 363 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 364 | def add_setting(settings, setting): |
| 365 | """Takes <key>[=<value>] adds {key:value} or {key:True} to settings.""" |
| 366 | name, _, value = setting.partition('=') |
| 367 | if not value: |
| 368 | settings[name] = True |
| 369 | else: |
| 370 | settings[name] = value |
bensong@google.com | ad0c5d2 | 2012-09-13 21:08:52 +0000 | [diff] [blame] | 371 | |
| 372 | def read_expectations(expectations, filename): |
| 373 | """Reads expectations data from file and put in expectations dict.""" |
| 374 | for expectation in open(filename).readlines(): |
| 375 | elements = expectation.strip().split(',') |
| 376 | if not elements[0] or elements[0].startswith('#'): |
| 377 | continue |
| 378 | if len(elements) != 5: |
| 379 | raise Exception("Invalid expectation line format: %s" % |
| 380 | expectation) |
| 381 | bench_entry = elements[0] + ',' + elements[1] |
| 382 | if bench_entry in expectations: |
| 383 | raise Exception("Dup entries for bench expectation %s" % |
| 384 | bench_entry) |
| 385 | # [<Bench_BmpConfig_TimeType>,<Platform-Alg>] -> (LB, UB) |
| 386 | expectations[bench_entry] = (float(elements[-2]), |
| 387 | float(elements[-1])) |
| 388 | |
| 389 | def check_expectations(lines, expectations, newest_revision, key_suffix): |
| 390 | """Check if there are benches in latest rev outside expected range.""" |
| 391 | exceptions = [] |
| 392 | for line in lines: |
| 393 | line_str = str(line) |
| 394 | bench_platform_key = (line_str[ : line_str.find('_{')] + ',' + |
| 395 | key_suffix) |
| 396 | this_revision, this_bench_value = lines[line][-1] |
| 397 | if (this_revision != newest_revision or |
| 398 | bench_platform_key not in expectations): |
| 399 | # Skip benches without value for latest revision. |
| 400 | continue |
| 401 | this_min, this_max = expectations[bench_platform_key] |
| 402 | if this_bench_value < this_min or this_bench_value > this_max: |
| 403 | exceptions.append('Bench %s value %s out of range [%s, %s].' % |
| 404 | (bench_platform_key, this_bench_value, this_min, this_max)) |
| 405 | if exceptions: |
| 406 | raise Exception('Bench values out of range:\n' + |
| 407 | '\n'.join(exceptions)) |
| 408 | |
bensong@google.com | 848fa2b | 2013-03-07 17:12:43 +0000 | [diff] [blame] | 409 | def write_to_appengine(line_data_dict, url, newest_revision, bot): |
| 410 | """Writes latest bench values to appengine datastore. |
| 411 | line_data_dict: dictionary from create_lines. |
| 412 | url: the appengine url used to send bench values to write |
| 413 | newest_revision: the latest revision that this script reads |
| 414 | bot: the bot platform the bench is run on |
| 415 | """ |
| 416 | data = [] |
| 417 | for label in line_data_dict.iterkeys(): |
| 418 | if not label.bench.endswith('.skp') or label.time_type: |
| 419 | # filter out non-picture and non-walltime benches |
| 420 | continue |
| 421 | config = label.config |
| 422 | rev, val = line_data_dict[label][-1] |
| 423 | # This assumes that newest_revision is >= the revision of the last |
| 424 | # data point we have for each line. |
| 425 | if rev != newest_revision: |
| 426 | continue |
| 427 | data.append({'master': 'Skia', 'bot': bot, |
| 428 | 'test': config + '/' + label.bench.replace('.skp', ''), |
| 429 | 'revision': rev, 'value': val, 'error': 0}) |
| 430 | for curr_data in grouper(DATA_POINT_BATCHSIZE, data): |
| 431 | req = urllib2.Request(appengine_url, |
| 432 | urllib.urlencode({'data': json.dumps(curr_data)})) |
| 433 | try: |
| 434 | urllib2.urlopen(req) |
| 435 | except urllib2.HTTPError, e: |
| 436 | sys.stderr.write("HTTPError for JSON data %s: %s\n" % ( |
| 437 | data, e)) |
| 438 | except urllib2.URLError, e: |
| 439 | sys.stderr.write("URLError for JSON data %s: %s\n" % ( |
| 440 | data, e)) |
| 441 | except httplib.HTTPException, e: |
| 442 | sys.stderr.write("HTTPException for JSON data %s: %s\n" % ( |
| 443 | data, e)) |
| 444 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 445 | try: |
| 446 | for option, value in opts: |
bensong@google.com | 848fa2b | 2013-03-07 17:12:43 +0000 | [diff] [blame] | 447 | if option == "-a": |
| 448 | appengine_url = value |
| 449 | elif option == "-b": |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 450 | bench_of_interest = value |
| 451 | elif option == "-c": |
| 452 | config_of_interest = value |
epoger@google.com | 5b2e01c | 2012-06-25 20:29:04 +0000 | [diff] [blame] | 453 | elif option == "-d": |
| 454 | directory = value |
bensong@google.com | ad0c5d2 | 2012-09-13 21:08:52 +0000 | [diff] [blame] | 455 | elif option == "-e": |
| 456 | read_expectations(bench_expectations, value) |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 457 | elif option == "-f": |
epoger@google.com | 3726000 | 2011-08-08 20:27:04 +0000 | [diff] [blame] | 458 | regression_range = value |
bensong@google.com | 8ccfa55 | 2012-08-17 21:42:14 +0000 | [diff] [blame] | 459 | elif option == "-i": |
| 460 | time_to_ignore = value |
epoger@google.com | 5b2e01c | 2012-06-25 20:29:04 +0000 | [diff] [blame] | 461 | elif option == "-l": |
| 462 | title = value |
bensong@google.com | 8734816 | 2012-08-15 17:31:46 +0000 | [diff] [blame] | 463 | elif option == "-m": |
| 464 | rep = value |
epoger@google.com | 5b2e01c | 2012-06-25 20:29:04 +0000 | [diff] [blame] | 465 | elif option == "-o": |
borenet@google.com | 5dc0678 | 2013-03-12 17:16:07 +0000 | [diff] [blame] | 466 | output_path = value |
| 467 | redirect_stdout(output_path) |
epoger@google.com | 5b2e01c | 2012-06-25 20:29:04 +0000 | [diff] [blame] | 468 | elif option == "-r": |
| 469 | revision_range = value |
| 470 | elif option == "-s": |
| 471 | add_setting(settings, value) |
| 472 | elif option == "-t": |
| 473 | time_of_interest = value |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 474 | elif option == "-x": |
| 475 | requested_width = int(value) |
| 476 | elif option == "-y": |
| 477 | requested_height = int(value) |
| 478 | elif option == "--default-setting": |
| 479 | add_setting(default_settings, value) |
| 480 | else: |
| 481 | usage() |
| 482 | assert False, "unhandled option" |
| 483 | except ValueError: |
| 484 | usage() |
| 485 | sys.exit(2) |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 486 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 487 | if directory is None: |
| 488 | usage() |
| 489 | sys.exit(2) |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 490 | |
borenet@google.com | 5dc0678 | 2013-03-12 17:16:07 +0000 | [diff] [blame] | 491 | if not output_path: |
| 492 | print 'Warning: No output path provided. No graphs will be written.' |
| 493 | |
bensong@google.com | 8ccfa55 | 2012-08-17 21:42:14 +0000 | [diff] [blame] | 494 | if time_of_interest: |
| 495 | time_to_ignore = None |
| 496 | |
bensong@google.com | ad0c5d2 | 2012-09-13 21:08:52 +0000 | [diff] [blame] | 497 | # The title flag (-l) provided in buildbot slave is in the format |
| 498 | # Bench_Performance_for_Skia_<platform>, and we want to extract <platform> |
| 499 | # for use in platform_and_alg to track matching benches later. If title flag |
| 500 | # is not in this format, there may be no matching benches in the file |
| 501 | # provided by the expectation_file flag (-e). |
bensong@google.com | 848fa2b | 2013-03-07 17:12:43 +0000 | [diff] [blame] | 502 | bot = title # To store the platform as bot name |
bensong@google.com | ad0c5d2 | 2012-09-13 21:08:52 +0000 | [diff] [blame] | 503 | platform_and_alg = title |
| 504 | if platform_and_alg.startswith(TITLE_PREAMBLE): |
bensong@google.com | 848fa2b | 2013-03-07 17:12:43 +0000 | [diff] [blame] | 505 | bot = platform_and_alg[TITLE_PREAMBLE_LENGTH:] |
| 506 | platform_and_alg = bot + '-' + rep |
bensong@google.com | 8c1de76 | 2012-08-15 18:27:38 +0000 | [diff] [blame] | 507 | title += ' [representation: %s]' % rep |
| 508 | |
epoger@google.com | 3726000 | 2011-08-08 20:27:04 +0000 | [diff] [blame] | 509 | latest_revision = get_latest_revision(directory) |
| 510 | oldest_revision, newest_revision = parse_range(revision_range) |
| 511 | oldest_regression, newest_regression = parse_range(regression_range) |
| 512 | |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 513 | unfiltered_revision_data_points = parse_dir(directory |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 514 | , default_settings |
| 515 | , oldest_revision |
bensong@google.com | 8734816 | 2012-08-15 17:31:46 +0000 | [diff] [blame] | 516 | , newest_revision |
| 517 | , rep) |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 518 | |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 519 | # Filter out any data points that are utterly bogus... make sure to report |
| 520 | # that we did so later! |
| 521 | (allowed_revision_data_points, ignored_revision_data_points) = filter_data_points( |
| 522 | unfiltered_revision_data_points) |
| 523 | |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 524 | # Update oldest_revision and newest_revision based on the data we could find |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 525 | all_revision_numbers = allowed_revision_data_points.keys() |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 526 | oldest_revision = min(all_revision_numbers) |
| 527 | newest_revision = max(all_revision_numbers) |
| 528 | |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 529 | lines = create_lines(allowed_revision_data_points |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 530 | , settings |
| 531 | , bench_of_interest |
| 532 | , config_of_interest |
bensong@google.com | 8ccfa55 | 2012-08-17 21:42:14 +0000 | [diff] [blame] | 533 | , time_of_interest |
| 534 | , time_to_ignore) |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 535 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 536 | regressions = create_regressions(lines |
| 537 | , oldest_regression |
| 538 | , newest_regression) |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 539 | |
borenet@google.com | 5dc0678 | 2013-03-12 17:16:07 +0000 | [diff] [blame] | 540 | if output_path: |
| 541 | output_xhtml(lines, oldest_revision, newest_revision, |
| 542 | ignored_revision_data_points, regressions, requested_width, |
| 543 | requested_height, title) |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 544 | |
bensong@google.com | 848fa2b | 2013-03-07 17:12:43 +0000 | [diff] [blame] | 545 | if appengine_url: |
| 546 | write_to_appengine(lines, appengine_url, newest_revision, bot) |
| 547 | |
borenet@google.com | 5dc0678 | 2013-03-12 17:16:07 +0000 | [diff] [blame] | 548 | if bench_expectations: |
| 549 | check_expectations(lines, bench_expectations, newest_revision, |
| 550 | platform_and_alg) |
bensong@google.com | ad0c5d2 | 2012-09-13 21:08:52 +0000 | [diff] [blame] | 551 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 552 | def qa(out): |
| 553 | """Stringify input and quote as an xml attribute.""" |
| 554 | return xml.sax.saxutils.quoteattr(str(out)) |
| 555 | def qe(out): |
| 556 | """Stringify input and escape as xml data.""" |
| 557 | return xml.sax.saxutils.escape(str(out)) |
| 558 | |
| 559 | def create_select(qualifier, lines, select_id=None): |
| 560 | """Output select with options showing lines which qualifier maps to it. |
| 561 | |
| 562 | ((Label) -> str, {Label:_}, str?) -> _""" |
| 563 | options = {} #{ option : [Label]} |
| 564 | for label in lines.keys(): |
| 565 | option = qualifier(label) |
| 566 | if (option not in options): |
| 567 | options[option] = [] |
| 568 | options[option].append(label) |
| 569 | option_list = list(options.keys()) |
| 570 | option_list.sort() |
| 571 | print '<select class="lines"', |
| 572 | if select_id is not None: |
| 573 | print 'id=%s' % qa(select_id) |
| 574 | print 'multiple="true" size="10" onchange="updateSvg();">' |
| 575 | for option in option_list: |
| 576 | print '<option value=' + qa('[' + |
| 577 | reduce(lambda x,y:x+json.dumps(str(y))+',',options[option],"")[0:-1] |
| 578 | + ']') + '>'+qe(option)+'</option>' |
| 579 | print '</select>' |
| 580 | |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 581 | def output_ignored_data_points_warning(ignored_revision_data_points): |
| 582 | """Write description of ignored_revision_data_points to stdout as xhtml. |
| 583 | """ |
| 584 | num_ignored_points = 0 |
| 585 | description = '' |
| 586 | revisions = ignored_revision_data_points.keys() |
| 587 | if revisions: |
| 588 | revisions.sort() |
| 589 | revisions.reverse() |
| 590 | for revision in revisions: |
| 591 | num_ignored_points += len(ignored_revision_data_points[revision]) |
| 592 | points_at_this_revision = [] |
| 593 | for point in ignored_revision_data_points[revision]: |
| 594 | points_at_this_revision.append(point.bench) |
| 595 | points_at_this_revision.sort() |
| 596 | description += 'r%d: %s\n' % (revision, points_at_this_revision) |
| 597 | if num_ignored_points == 0: |
| 598 | print 'Did not discard any data points; all were within the range [%d-%d]' % ( |
| 599 | MIN_REASONABLE_TIME, MAX_REASONABLE_TIME) |
| 600 | else: |
| 601 | print '<table width="100%" bgcolor="ff0000"><tr><td align="center">' |
| 602 | print 'Discarded %d data points outside of range [%d-%d]' % ( |
| 603 | num_ignored_points, MIN_REASONABLE_TIME, MAX_REASONABLE_TIME) |
| 604 | print '</td></tr><tr><td width="100%" align="center">' |
| 605 | print ('<textarea rows="4" style="width:97%" readonly="true" wrap="off">' |
| 606 | + qe(description) + '</textarea>') |
| 607 | print '</td></tr></table>' |
| 608 | |
| 609 | def output_xhtml(lines, oldest_revision, newest_revision, ignored_revision_data_points, |
epoger@google.com | 3726000 | 2011-08-08 20:27:04 +0000 | [diff] [blame] | 610 | regressions, requested_width, requested_height, title): |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 611 | """Outputs an svg/xhtml view of the data.""" |
| 612 | print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"', |
| 613 | print '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' |
| 614 | print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' |
| 615 | print '<head>' |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 616 | print '<title>%s</title>' % qe(title) |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 617 | print '</head>' |
| 618 | print '<body>' |
| 619 | |
| 620 | output_svg(lines, regressions, requested_width, requested_height) |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 621 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 622 | #output the manipulation controls |
| 623 | print """ |
| 624 | <script type="text/javascript">//<![CDATA[ |
| 625 | function getElementsByClass(node, searchClass, tag) { |
| 626 | var classElements = new Array(); |
| 627 | var elements = node.getElementsByTagName(tag); |
| 628 | var pattern = new RegExp("^|\\s"+searchClass+"\\s|$"); |
| 629 | for (var i = 0, elementsFound = 0; i < elements.length; ++i) { |
| 630 | if (pattern.test(elements[i].className)) { |
| 631 | classElements[elementsFound] = elements[i]; |
| 632 | ++elementsFound; |
| 633 | } |
| 634 | } |
| 635 | return classElements; |
| 636 | } |
| 637 | function getAllLines() { |
| 638 | var selectElem = document.getElementById('benchSelect'); |
| 639 | var linesObj = {}; |
| 640 | for (var i = 0; i < selectElem.options.length; ++i) { |
| 641 | var lines = JSON.parse(selectElem.options[i].value); |
| 642 | for (var j = 0; j < lines.length; ++j) { |
| 643 | linesObj[lines[j]] = true; |
| 644 | } |
| 645 | } |
| 646 | return linesObj; |
| 647 | } |
| 648 | function getOptions(selectElem) { |
| 649 | var linesSelectedObj = {}; |
| 650 | for (var i = 0; i < selectElem.options.length; ++i) { |
| 651 | if (!selectElem.options[i].selected) continue; |
| 652 | |
| 653 | var linesSelected = JSON.parse(selectElem.options[i].value); |
| 654 | for (var j = 0; j < linesSelected.length; ++j) { |
| 655 | linesSelectedObj[linesSelected[j]] = true; |
| 656 | } |
| 657 | } |
| 658 | return linesSelectedObj; |
| 659 | } |
| 660 | function objectEmpty(obj) { |
| 661 | for (var p in obj) { |
| 662 | return false; |
| 663 | } |
| 664 | return true; |
| 665 | } |
| 666 | function markSelectedLines(selectElem, allLines) { |
| 667 | var linesSelected = getOptions(selectElem); |
| 668 | if (!objectEmpty(linesSelected)) { |
| 669 | for (var line in allLines) { |
| 670 | allLines[line] &= (linesSelected[line] == true); |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | function updateSvg() { |
| 675 | var allLines = getAllLines(); |
| 676 | |
| 677 | var selects = getElementsByClass(document, 'lines', 'select'); |
| 678 | for (var i = 0; i < selects.length; ++i) { |
| 679 | markSelectedLines(selects[i], allLines); |
| 680 | } |
| 681 | |
| 682 | for (var line in allLines) { |
| 683 | var svgLine = document.getElementById(line); |
| 684 | var display = (allLines[line] ? 'inline' : 'none'); |
| 685 | svgLine.setAttributeNS(null,'display', display); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | function mark(markerId) { |
| 690 | for (var line in getAllLines()) { |
| 691 | var svgLineGroup = document.getElementById(line); |
| 692 | var display = svgLineGroup.getAttributeNS(null,'display'); |
| 693 | if (display == null || display == "" || display != "none") { |
| 694 | var svgLine = document.getElementById(line+'_line'); |
| 695 | if (markerId == null) { |
| 696 | svgLine.removeAttributeNS(null,'marker-mid'); |
| 697 | } else { |
| 698 | svgLine.setAttributeNS(null,'marker-mid', markerId); |
| 699 | } |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | //]]></script>""" |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 704 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 705 | all_settings = {} |
| 706 | variant_settings = set() |
| 707 | for label in lines.keys(): |
| 708 | for key, value in label.settings.items(): |
| 709 | if key not in all_settings: |
| 710 | all_settings[key] = value |
| 711 | elif all_settings[key] != value: |
| 712 | variant_settings.add(key) |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 713 | |
bungeman@google.com | 752acc7 | 2012-09-12 19:34:17 +0000 | [diff] [blame] | 714 | print '<table border="0" width="%s">' % requested_width |
| 715 | #output column headers |
| 716 | print """ |
| 717 | <tr valign="top"><td width="50%"> |
| 718 | <table border="0" width="100%"> |
| 719 | <tr><td align="center"><table border="0"> |
| 720 | <form> |
| 721 | <tr valign="bottom" align="center"> |
| 722 | <td width="1">Bench Type</td> |
| 723 | <td width="1">Bitmap Config</td> |
| 724 | <td width="1">Timer Type (Cpu/Gpu/wall)</td> |
| 725 | """ |
| 726 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 727 | for k in variant_settings: |
bungeman@google.com | 752acc7 | 2012-09-12 19:34:17 +0000 | [diff] [blame] | 728 | print '<td width="1">%s</td>' % qe(k) |
| 729 | |
| 730 | print '<td width="1"><!--buttons--></td></tr>' |
| 731 | |
| 732 | #output column contents |
| 733 | print '<tr valign="top" align="center">' |
| 734 | print '<td width="1">' |
| 735 | create_select(lambda l: l.bench, lines, 'benchSelect') |
| 736 | print '</td><td width="1">' |
| 737 | create_select(lambda l: l.config, lines) |
| 738 | print '</td><td width="1">' |
| 739 | create_select(lambda l: l.time_type, lines) |
| 740 | |
| 741 | for k in variant_settings: |
| 742 | print '</td><td width="1">' |
| 743 | create_select(lambda l: l.settings.get(k, " "), lines) |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 744 | |
| 745 | print '</td><td width="1"><button type="button"', |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 746 | print 'onclick=%s' % qa("mark('url(#circleMark)'); return false;"), |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 747 | print '>Mark Points</button>' |
| 748 | print '<button type="button" onclick="mark(null);">Clear Points</button>' |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 749 | print '</td>' |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 750 | print """ |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 751 | </tr> |
| 752 | </form> |
| 753 | </table></td></tr> |
| 754 | <tr><td align="center"> |
| 755 | <hr /> |
| 756 | """ |
| 757 | |
| 758 | output_ignored_data_points_warning(ignored_revision_data_points) |
| 759 | print '</td></tr></table>' |
| 760 | print '</td><td width="2%"><!--gutter--></td>' |
| 761 | |
| 762 | print '<td><table border="0">' |
| 763 | print '<tr><td align="center">%s<br></br>revisions r%s - r%s</td></tr>' % ( |
| 764 | qe(title), |
| 765 | bench_util.CreateRevisionLink(oldest_revision), |
| 766 | bench_util.CreateRevisionLink(newest_revision)) |
| 767 | print """ |
| 768 | <tr><td align="left"> |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 769 | <p>Brighter red indicates tests that have gotten worse; brighter green |
| 770 | indicates tests that have gotten better.</p> |
| 771 | <p>To highlight individual tests, hold down CONTROL and mouse over |
| 772 | graph lines.</p> |
| 773 | <p>To highlight revision numbers, hold down SHIFT and mouse over |
| 774 | the graph area.</p> |
| 775 | <p>To only show certain tests on the graph, select any combination of |
| 776 | tests in the selectors at left. (To show all, select all.)</p> |
| 777 | <p>Use buttons at left to mark/clear points on the lines for selected |
| 778 | benchmarks.</p> |
epoger@google.com | 3d8cd17 | 2012-05-11 18:26:16 +0000 | [diff] [blame] | 779 | </td></tr> |
| 780 | </table> |
| 781 | |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 782 | </td> |
| 783 | </tr> |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 784 | </table> |
| 785 | </body> |
| 786 | </html>""" |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 787 | |
| 788 | def compute_size(requested_width, requested_height, rev_width, time_height): |
| 789 | """Converts potentially empty requested size into a concrete size. |
| 790 | |
| 791 | (Number?, Number?) -> (Number, Number)""" |
| 792 | pic_width = 0 |
| 793 | pic_height = 0 |
| 794 | if (requested_width is not None and requested_height is not None): |
| 795 | pic_height = requested_height |
| 796 | pic_width = requested_width |
| 797 | |
| 798 | elif (requested_width is not None): |
| 799 | pic_width = requested_width |
| 800 | pic_height = pic_width * (float(time_height) / rev_width) |
| 801 | |
| 802 | elif (requested_height is not None): |
| 803 | pic_height = requested_height |
| 804 | pic_width = pic_height * (float(rev_width) / time_height) |
| 805 | |
| 806 | else: |
| 807 | pic_height = 800 |
| 808 | pic_width = max(rev_width*3 |
| 809 | , pic_height * (float(rev_width) / time_height)) |
| 810 | |
| 811 | return (pic_width, pic_height) |
| 812 | |
| 813 | def output_svg(lines, regressions, requested_width, requested_height): |
| 814 | """Outputs an svg view of the data.""" |
| 815 | |
| 816 | (global_min_x, _), (global_max_x, global_max_y) = bounds(lines) |
| 817 | max_up_slope, min_down_slope = bounds_slope(regressions) |
| 818 | |
| 819 | #output |
| 820 | global_min_y = 0 |
| 821 | x = global_min_x |
| 822 | y = global_min_y |
| 823 | w = global_max_x - global_min_x |
| 824 | h = global_max_y - global_min_y |
| 825 | font_size = 16 |
| 826 | line_width = 2 |
| 827 | |
| 828 | pic_width, pic_height = compute_size(requested_width, requested_height |
| 829 | , w, h) |
| 830 | |
| 831 | def cw(w1): |
| 832 | """Converts a revision difference to display width.""" |
| 833 | return (pic_width / float(w)) * w1 |
| 834 | def cx(x): |
| 835 | """Converts a revision to a horizontal display position.""" |
| 836 | return cw(x - global_min_x) |
| 837 | |
| 838 | def ch(h1): |
| 839 | """Converts a time difference to a display height.""" |
| 840 | return -(pic_height / float(h)) * h1 |
| 841 | def cy(y): |
| 842 | """Converts a time to a vertical display position.""" |
| 843 | return pic_height + ch(y - global_min_y) |
| 844 | |
bensong@google.com | 7426743 | 2012-08-30 18:19:02 +0000 | [diff] [blame] | 845 | print '<!--Picture height %.2f corresponds to bench value %.2f.-->' % ( |
| 846 | pic_height, h) |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 847 | print '<svg', |
| 848 | print 'width=%s' % qa(str(pic_width)+'px') |
| 849 | print 'height=%s' % qa(str(pic_height)+'px') |
| 850 | print 'viewBox="0 0 %s %s"' % (str(pic_width), str(pic_height)) |
| 851 | print 'onclick=%s' % qa( |
| 852 | "var event = arguments[0] || window.event;" |
| 853 | " if (event.shiftKey) { highlightRevision(null); }" |
| 854 | " if (event.ctrlKey) { highlight(null); }" |
| 855 | " return false;") |
| 856 | print 'xmlns="http://www.w3.org/2000/svg"' |
| 857 | print 'xmlns:xlink="http://www.w3.org/1999/xlink">' |
| 858 | |
| 859 | print """ |
| 860 | <defs> |
| 861 | <marker id="circleMark" |
| 862 | viewBox="0 0 2 2" refX="1" refY="1" |
| 863 | markerUnits="strokeWidth" |
| 864 | markerWidth="2" markerHeight="2" |
| 865 | orient="0"> |
| 866 | <circle cx="1" cy="1" r="1"/> |
| 867 | </marker> |
| 868 | </defs>""" |
| 869 | |
| 870 | #output the revisions |
| 871 | print """ |
| 872 | <script type="text/javascript">//<![CDATA[ |
| 873 | var previousRevision; |
| 874 | var previousRevisionFill; |
| 875 | var previousRevisionStroke |
| 876 | function highlightRevision(id) { |
| 877 | if (previousRevision == id) return; |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 878 | |
| 879 | document.getElementById('revision').firstChild.nodeValue = 'r' + id; |
| 880 | document.getElementById('rev_link').setAttribute('xlink:href', |
| 881 | 'http://code.google.com/p/skia/source/detail?r=' + id); |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 882 | |
| 883 | var preRevision = document.getElementById(previousRevision); |
| 884 | if (preRevision) { |
| 885 | preRevision.setAttributeNS(null,'fill', previousRevisionFill); |
| 886 | preRevision.setAttributeNS(null,'stroke', previousRevisionStroke); |
| 887 | } |
| 888 | |
| 889 | var revision = document.getElementById(id); |
| 890 | previousRevision = id; |
| 891 | if (revision) { |
| 892 | previousRevisionFill = revision.getAttributeNS(null,'fill'); |
| 893 | revision.setAttributeNS(null,'fill','rgb(100%, 95%, 95%)'); |
| 894 | |
| 895 | previousRevisionStroke = revision.getAttributeNS(null,'stroke'); |
| 896 | revision.setAttributeNS(null,'stroke','rgb(100%, 90%, 90%)'); |
| 897 | } |
| 898 | } |
| 899 | //]]></script>""" |
| 900 | |
| 901 | def print_rect(x, y, w, h, revision): |
| 902 | """Outputs a revision rectangle in display space, |
| 903 | taking arguments in revision space.""" |
| 904 | disp_y = cy(y) |
| 905 | disp_h = ch(h) |
| 906 | if disp_h < 0: |
| 907 | disp_y += disp_h |
| 908 | disp_h = -disp_h |
| 909 | |
| 910 | print '<rect id=%s x=%s y=%s' % (qa(revision), qa(cx(x)), qa(disp_y),), |
| 911 | print 'width=%s height=%s' % (qa(cw(w)), qa(disp_h),), |
| 912 | print 'fill="white"', |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 913 | print 'stroke="rgb(98%%,98%%,88%%)" stroke-width=%s' % qa(line_width), |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 914 | print 'onmouseover=%s' % qa( |
| 915 | "var event = arguments[0] || window.event;" |
| 916 | " if (event.shiftKey) {" |
| 917 | " highlightRevision('"+str(revision)+"');" |
| 918 | " return false;" |
| 919 | " }"), |
| 920 | print ' />' |
| 921 | |
| 922 | xes = set() |
| 923 | for line in lines.itervalues(): |
| 924 | for point in line: |
| 925 | xes.add(point[0]) |
| 926 | revisions = list(xes) |
| 927 | revisions.sort() |
| 928 | |
| 929 | left = x |
| 930 | current_revision = revisions[0] |
| 931 | for next_revision in revisions[1:]: |
| 932 | width = (((next_revision - current_revision) / 2.0) |
| 933 | + (current_revision - left)) |
| 934 | print_rect(left, y, width, h, current_revision) |
| 935 | left += width |
| 936 | current_revision = next_revision |
| 937 | print_rect(left, y, x+w - left, h, current_revision) |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 938 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 939 | #output the lines |
| 940 | print """ |
| 941 | <script type="text/javascript">//<![CDATA[ |
| 942 | var previous; |
| 943 | var previousColor; |
| 944 | var previousOpacity; |
| 945 | function highlight(id) { |
| 946 | if (previous == id) return; |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 947 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 948 | document.getElementById('label').firstChild.nodeValue = id; |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 949 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 950 | var preGroup = document.getElementById(previous); |
| 951 | if (preGroup) { |
| 952 | var preLine = document.getElementById(previous+'_line'); |
| 953 | preLine.setAttributeNS(null,'stroke', previousColor); |
| 954 | preLine.setAttributeNS(null,'opacity', previousOpacity); |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 955 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 956 | var preSlope = document.getElementById(previous+'_linear'); |
| 957 | if (preSlope) { |
| 958 | preSlope.setAttributeNS(null,'visibility', 'hidden'); |
| 959 | } |
| 960 | } |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 961 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 962 | var group = document.getElementById(id); |
| 963 | previous = id; |
| 964 | if (group) { |
| 965 | group.parentNode.appendChild(group); |
| 966 | |
| 967 | var line = document.getElementById(id+'_line'); |
| 968 | previousColor = line.getAttributeNS(null,'stroke'); |
| 969 | previousOpacity = line.getAttributeNS(null,'opacity'); |
| 970 | line.setAttributeNS(null,'stroke', 'blue'); |
| 971 | line.setAttributeNS(null,'opacity', '1'); |
| 972 | |
| 973 | var slope = document.getElementById(id+'_linear'); |
| 974 | if (slope) { |
| 975 | slope.setAttributeNS(null,'visibility', 'visible'); |
| 976 | } |
| 977 | } |
| 978 | } |
| 979 | //]]></script>""" |
epoger@google.com | 2459a39 | 2013-02-14 18:58:05 +0000 | [diff] [blame] | 980 | |
| 981 | # Add a new element to each item in the 'lines' list: the label in string |
| 982 | # form. Then use that element to sort the list. |
| 983 | sorted_lines = [] |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 984 | for label, line in lines.items(): |
epoger@google.com | 2459a39 | 2013-02-14 18:58:05 +0000 | [diff] [blame] | 985 | sorted_lines.append([str(label), label, line]) |
| 986 | sorted_lines.sort() |
| 987 | |
| 988 | for label_as_string, label, line in sorted_lines: |
| 989 | print '<g id=%s>' % qa(label_as_string) |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 990 | r = 128 |
| 991 | g = 128 |
| 992 | b = 128 |
| 993 | a = .10 |
| 994 | if label in regressions: |
| 995 | regression = regressions[label] |
| 996 | min_slope = regression.find_min_slope() |
| 997 | if min_slope < 0: |
| 998 | d = max(0, (min_slope / min_down_slope)) |
| 999 | g += int(d*128) |
| 1000 | a += d*0.9 |
| 1001 | elif min_slope > 0: |
| 1002 | d = max(0, (min_slope / max_up_slope)) |
| 1003 | r += int(d*128) |
| 1004 | a += d*0.9 |
| 1005 | |
| 1006 | slope = regression.slope |
| 1007 | intercept = regression.intercept |
| 1008 | min_x = regression.min_x |
| 1009 | max_x = regression.max_x |
| 1010 | print '<polyline id=%s' % qa(str(label)+'_linear'), |
| 1011 | print 'fill="none" stroke="yellow"', |
| 1012 | print 'stroke-width=%s' % qa(abs(ch(regression.serror*2))), |
| 1013 | print 'opacity="0.5" pointer-events="none" visibility="hidden"', |
| 1014 | print 'points="', |
| 1015 | print '%s,%s' % (str(cx(min_x)), str(cy(slope*min_x + intercept))), |
| 1016 | print '%s,%s' % (str(cx(max_x)), str(cy(slope*max_x + intercept))), |
| 1017 | print '"/>' |
| 1018 | |
| 1019 | print '<polyline id=%s' % qa(str(label)+'_line'), |
| 1020 | print 'onmouseover=%s' % qa( |
| 1021 | "var event = arguments[0] || window.event;" |
| 1022 | " if (event.ctrlKey) {" |
| 1023 | " highlight('"+str(label).replace("'", "\\'")+"');" |
| 1024 | " return false;" |
| 1025 | " }"), |
| 1026 | print 'fill="none" stroke="rgb(%s,%s,%s)"' % (str(r), str(g), str(b)), |
| 1027 | print 'stroke-width=%s' % qa(line_width), |
| 1028 | print 'opacity=%s' % qa(a), |
| 1029 | print 'points="', |
| 1030 | for point in line: |
| 1031 | print '%s,%s' % (str(cx(point[0])), str(cy(point[1]))), |
| 1032 | print '"/>' |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 1033 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 1034 | print '</g>' |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 1035 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 1036 | #output the labels |
| 1037 | print '<text id="label" x="0" y=%s' % qa(font_size), |
| 1038 | print 'font-size=%s> </text>' % qa(font_size) |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 1039 | |
| 1040 | print '<a id="rev_link" xlink:href="" target="_top">' |
| 1041 | print '<text id="revision" x="0" y=%s style="' % qa(font_size*2) |
| 1042 | print 'font-size: %s; ' % qe(font_size) |
| 1043 | print 'stroke: #0000dd; text-decoration: underline; ' |
| 1044 | print '"> </text></a>' |
| 1045 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 1046 | print '</svg>' |
epoger@google.com | c71174d | 2011-08-08 17:19:23 +0000 | [diff] [blame] | 1047 | |
bungeman@google.com | 85669f9 | 2011-06-17 13:58:14 +0000 | [diff] [blame] | 1048 | if __name__ == "__main__": |
| 1049 | main() |