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