bensong@google.com | fa1d4ea | 2012-11-27 17:30:26 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be found |
| 4 | # in the LICENSE file. |
| 5 | |
| 6 | """ Analyze recent SkPicture bench data, and output suggested ranges. |
| 7 | |
| 8 | The outputs can be edited and pasted to bench_expectations.txt to trigger |
| 9 | buildbot alerts if the actual benches are out of range. Details are documented |
| 10 | in the .txt file. |
| 11 | |
| 12 | Currently the easiest way to update bench_expectations.txt is to delete all skp |
| 13 | bench lines, run this script, and redirect outputs (">>") to be added to the |
| 14 | .txt file. |
| 15 | TODO(bensong): find a better way for updating the bench lines in place. |
| 16 | |
| 17 | Note: since input data are stored in Google Storage, you will need to set up |
| 18 | the corresponding library. |
| 19 | See http://developers.google.com/storage/docs/gspythonlibrary for details. |
| 20 | """ |
| 21 | |
| 22 | __author__ = 'bensong@google.com (Ben Chen)' |
| 23 | |
| 24 | import bench_util |
| 25 | import boto |
| 26 | import cStringIO |
| 27 | import optparse |
| 28 | import re |
| 29 | import shutil |
| 30 | |
| 31 | from oauth2_plugin import oauth2_plugin |
| 32 | |
| 33 | |
| 34 | # Ratios for calculating suggested picture bench upper and lower bounds. |
bensong@google.com | dc2dd2e | 2012-11-27 21:52:32 +0000 | [diff] [blame] | 35 | BENCH_UB = 1.1 # Allow for 10% room for normal variance on the up side. |
| 36 | BENCH_LB = 0.85 |
bensong@google.com | fa1d4ea | 2012-11-27 17:30:26 +0000 | [diff] [blame] | 37 | |
bensong@google.com | cd63fb5 | 2012-11-30 04:42:59 +0000 | [diff] [blame] | 38 | # Further allow for a fixed amount of noise. This is especially useful for |
| 39 | # benches of smaller absolute value. Keeping this value small will not affect |
| 40 | # performance tunings. |
| 41 | BENCH_ALLOWED_NOISE = 10 |
| 42 | |
bensong@google.com | 92b0f51 | 2013-02-06 20:51:55 +0000 | [diff] [blame] | 43 | # List of platforms to track. Feel free to change it to meet your needs. |
| 44 | PLATFORMS = [#'Mac_Float_Bench_32', |
robertphillips@google.com | f729a71 | 2013-02-08 20:09:56 +0000 | [diff] [blame^] | 45 | #'Nexus10_4-1_Float_Bench_32', |
bensong@google.com | 92b0f51 | 2013-02-06 20:51:55 +0000 | [diff] [blame] | 46 | #'Shuttle_Ubuntu12_ATI5770_Float_Bench_32', |
robertphillips@google.com | f729a71 | 2013-02-08 20:09:56 +0000 | [diff] [blame^] | 47 | 'Shuttle_Win7_Intel_Float_Bench_32', |
bensong@google.com | fa1d4ea | 2012-11-27 17:30:26 +0000 | [diff] [blame] | 48 | ] |
| 49 | |
| 50 | # Filter for configs of no interest. They are old config names replaced by more |
| 51 | # specific ones. |
| 52 | CONFIGS_TO_FILTER = ['gpu', 'raster'] |
| 53 | |
| 54 | # Template for gsutil uri. |
| 55 | GOOGLE_STORAGE_URI_SCHEME = 'gs' |
| 56 | URI_BUCKET = 'chromium-skia-gm' |
| 57 | |
| 58 | # Constants for optparse. |
| 59 | USAGE_STRING = 'USAGE: %s [options]' |
| 60 | HOWTO_STRING = """ |
| 61 | Feel free to revise PLATFORMS for your own needs. The default is the most common |
| 62 | combination that we care most about. Platforms that did not run bench_pictures |
| 63 | in the given revision range will not have corresponding outputs. |
| 64 | Please check http://go/skpbench to choose a range that fits your needs. |
bensong@google.com | cd63fb5 | 2012-11-30 04:42:59 +0000 | [diff] [blame] | 65 | BENCH_UB, BENCH_LB and BENCH_ALLOWED_NOISE can be changed to expand or narrow |
| 66 | the permitted bench ranges without triggering buidbot alerts. |
bensong@google.com | fa1d4ea | 2012-11-27 17:30:26 +0000 | [diff] [blame] | 67 | """ |
| 68 | HELP_STRING = """ |
| 69 | Outputs expectation picture bench ranges for the latest revisions for the given |
| 70 | revision range. For instance, --rev_range=6000:6000 will return only bench |
| 71 | ranges for the bots that ran bench_pictures at rev 6000; --rev-range=6000:7000 |
| 72 | may have multiple bench data points for each bench configuration, and the code |
| 73 | returns bench data for the latest revision of all available (closer to 7000). |
| 74 | """ + HOWTO_STRING |
| 75 | |
| 76 | OPTION_REVISION_RANGE = '--rev-range' |
| 77 | OPTION_REVISION_RANGE_SHORT = '-r' |
| 78 | # Bench bench representation algorithm flag. |
| 79 | OPTION_REPRESENTATION_ALG = '--algorithm' |
| 80 | OPTION_REPRESENTATION_ALG_SHORT = '-a' |
| 81 | |
| 82 | # List of valid representation algorithms. |
| 83 | REPRESENTATION_ALGS = ['avg', 'min', 'med', '25th'] |
| 84 | |
| 85 | def OutputSkpBenchExpectations(rev_min, rev_max, representation_alg): |
| 86 | """Reads skp bench data from google storage, and outputs expectations. |
| 87 | |
| 88 | Ignores data with revisions outside [rev_min, rev_max] integer range. For |
| 89 | bench data with multiple revisions, we use higher revisions to calculate |
| 90 | expected bench values. |
| 91 | Uses the provided representation_alg for calculating bench representations. |
| 92 | """ |
| 93 | expectation_dic = {} |
| 94 | uri = boto.storage_uri(URI_BUCKET, GOOGLE_STORAGE_URI_SCHEME) |
| 95 | for obj in uri.get_bucket(): |
| 96 | # Filters out non-skp-bench files. |
bensong@google.com | 92b0f51 | 2013-02-06 20:51:55 +0000 | [diff] [blame] | 97 | if ((not obj.name.startswith('perfdata/Skia_') and |
| 98 | not obj.name.startswith('playback/perfdata/Skia_')) or |
bensong@google.com | fa1d4ea | 2012-11-27 17:30:26 +0000 | [diff] [blame] | 99 | obj.name.find('_data_skp_') < 0): |
| 100 | continue |
| 101 | # Ignores uninterested platforms. |
bensong@google.com | 6184c97 | 2013-02-08 19:02:21 +0000 | [diff] [blame] | 102 | platform = obj.name.split('/')[1] |
bensong@google.com | 7325818 | 2013-02-08 18:47:02 +0000 | [diff] [blame] | 103 | if not platform.startswith('Skia_'): |
bensong@google.com | 6184c97 | 2013-02-08 19:02:21 +0000 | [diff] [blame] | 104 | platform = obj.name.split('/')[2] |
| 105 | if not platform.startswith('Skia_'): |
| 106 | continue # Ignores non-platform object |
| 107 | platform = platform[5:] # Removes "Skia_" prefix. |
bensong@google.com | fa1d4ea | 2012-11-27 17:30:26 +0000 | [diff] [blame] | 108 | if platform not in PLATFORMS: |
| 109 | continue |
| 110 | # Filters by revision. |
bensong@google.com | 92b0f51 | 2013-02-06 20:51:55 +0000 | [diff] [blame] | 111 | to_filter = True |
bensong@google.com | fa1d4ea | 2012-11-27 17:30:26 +0000 | [diff] [blame] | 112 | for rev in range(rev_min, rev_max + 1): |
bensong@google.com | 92b0f51 | 2013-02-06 20:51:55 +0000 | [diff] [blame] | 113 | if '_r%s_' % rev in obj.name: |
| 114 | to_filter = False |
| 115 | break |
| 116 | if to_filter: |
| 117 | continue |
bensong@google.com | fa1d4ea | 2012-11-27 17:30:26 +0000 | [diff] [blame] | 118 | contents = cStringIO.StringIO() |
| 119 | obj.get_file(contents) |
| 120 | for point in bench_util.parse('', contents.getvalue().split('\n'), |
| 121 | representation_alg): |
| 122 | if point.config in CONFIGS_TO_FILTER: |
| 123 | continue |
bensong@google.com | fa1d4ea | 2012-11-27 17:30:26 +0000 | [diff] [blame] | 124 | |
| 125 | key = '%s_%s_%s,%s-%s' % (point.bench, point.config, point.time_type, |
| 126 | platform, representation_alg) |
| 127 | # It is fine to have later revisions overwrite earlier benches, since we |
| 128 | # only use the latest bench within revision range to set expectations. |
| 129 | expectation_dic[key] = point.time |
| 130 | keys = expectation_dic.keys() |
| 131 | keys.sort() |
| 132 | for key in keys: |
| 133 | bench_val = expectation_dic[key] |
| 134 | # Prints out expectation lines. |
bensong@google.com | cd63fb5 | 2012-11-30 04:42:59 +0000 | [diff] [blame] | 135 | print '%s,%.3f,%.3f,%.3f' % (key, bench_val, |
| 136 | bench_val * BENCH_LB - BENCH_ALLOWED_NOISE, |
| 137 | bench_val * BENCH_UB + BENCH_ALLOWED_NOISE) |
bensong@google.com | fa1d4ea | 2012-11-27 17:30:26 +0000 | [diff] [blame] | 138 | |
| 139 | def main(): |
| 140 | """Parses flags and outputs expected Skia picture bench results.""" |
| 141 | parser = optparse.OptionParser(USAGE_STRING % '%prog' + HELP_STRING) |
| 142 | parser.add_option(OPTION_REVISION_RANGE_SHORT, OPTION_REVISION_RANGE, |
| 143 | dest='rev_range', |
| 144 | help='(Mandatory) revision range separated by ":", e.g., 6000:6005') |
| 145 | parser.add_option(OPTION_REPRESENTATION_ALG_SHORT, OPTION_REPRESENTATION_ALG, |
| 146 | dest='alg', default='25th', |
| 147 | help=('Bench representation algorithm. One of ' |
| 148 | '%s. Default to "25th".' % str(REPRESENTATION_ALGS))) |
| 149 | (options, args) = parser.parse_args() |
| 150 | if options.rev_range: |
| 151 | range_match = re.search('(\d+)\:(\d+)', options.rev_range) |
| 152 | if not range_match: |
| 153 | parser.error('Wrong format for rev-range [%s]' % options.rev_range) |
| 154 | else: |
| 155 | rev_min = int(range_match.group(1)) |
| 156 | rev_max = int(range_match.group(2)) |
| 157 | OutputSkpBenchExpectations(rev_min, rev_max, options.alg) |
| 158 | else: |
| 159 | parser.error('Please provide mandatory flag %s' % OPTION_REVISION_RANGE) |
| 160 | |
| 161 | |
| 162 | if '__main__' == __name__: |
| 163 | main() |