| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python2.7 | |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Script to pull chromium.perf stats from chrome-infra-stats API. | |
| 7 | |
| 8 Currently this just pulls success rates from the API, averages daily per | |
| 9 builder, and outputs a CSV. It could be improved to provide more detailed | |
| 10 success rates or build times. | |
| 11 | |
| 12 The API documentation for chrome-infra-stats is at: | |
| 13 https://apis-explorer.appspot.com/apis-explorer/? | |
| 14 base=https://chrome-infra-stats.appspot.com/_ah/api#p/ | |
| 15 """ | |
| 16 import calendar | |
| 17 import csv | |
| 18 import json | |
| 19 import sys | |
| 20 import urllib | |
| 21 import urllib2 | |
| 22 | |
| 23 BUILDER_LIST_URL = ('https://chrome-infra-stats.appspot.com/' | |
| 24 '_ah/api/stats/v1/masters/chromium.perf') | |
| 25 | |
| 26 BUILDER_STATS_URL = ('https://chrome-infra-stats.appspot.com/_ah/api/stats/v1/' | |
| 27 'stats/chromium.perf/%s/overall__build__result__/%s') | |
| 28 | |
| 29 USAGE = 'Usage: chrome-perf-stats.py <outfilename> <year> <month> [<day>]' | |
| 30 | |
| 31 if len(sys.argv) != 4 and len(sys.argv) != 5: | |
| 32 print USAGE | |
| 33 sys.exit(0) | |
| 34 outfilename = sys.argv[1] | |
| 35 year = int(sys.argv[2]) | |
| 36 if year > 2016 or year < 2014: | |
| 37 print USAGE | |
| 38 sys.exit(0) | |
| 39 month = int(sys.argv[3]) | |
| 40 if month > 12 or month <= 0: | |
| 41 print USAGE | |
| 42 sys.exit(0) | |
| 43 days = range(1, calendar.monthrange(year, month)[1] + 1) | |
| 44 if len(sys.argv) == 5: | |
| 45 day = int(sys.argv[4]) | |
| 46 if day > 31 or day <=0: | |
| 47 print USAGE | |
| 48 sys.exit(0) | |
| 49 days = [day] | |
| 50 | |
| 51 response = urllib2.urlopen(BUILDER_LIST_URL) | |
| 52 builders = [builder['name'] for builder in json.load(response)['builders']] | |
| 53 | |
| 54 success_rates = {} | |
| 55 | |
| 56 for day in days: | |
| 57 for hour in range(24): | |
| 58 date_str = '%d-%02d-%02dT%02d:00Z' % (year, month, day, hour) | |
| 59 date_dict_str = '%d-%02d-%02d' % (year, month, day) | |
| 60 for builder in builders: | |
| 61 url = BUILDER_STATS_URL % (urllib.quote(builder), urllib.quote(date_str)) | |
| 62 print url | |
| 63 response = urllib2.urlopen(url) | |
| 64 results = json.load(response) | |
| 65 count = int(results['count']) | |
| 66 if count == 0: | |
| 67 continue | |
| 68 success_count = count - int(results['failure_count']) | |
| 69 success_rates.setdefault(date_dict_str, {}) | |
| 70 success_rates[date_dict_str].setdefault(builder, { | |
| 71 'count': 0, | |
| 72 'success_count': 0 | |
| 73 }) | |
| 74 success_rates[date_dict_str][builder]['count'] += count | |
| 75 success_rates[date_dict_str][builder]['success_count'] += success_count | |
| 76 | |
| 77 overall_success_rates = [] | |
| 78 for day, results in success_rates.iteritems(): | |
| 79 success_rate_sum = 0 | |
| 80 success_rate_count = 0 | |
| 81 for builder, rates in results.iteritems(): | |
| 82 if rates['count'] == 0: | |
| 83 continue | |
| 84 success_rate_sum += (float(rates['success_count']) / float(rates['count'])) | |
| 85 success_rate_count += 1 | |
| 86 overall_success_rates.append( | |
| 87 [day, float(success_rate_sum) / float(success_rate_count)]) | |
| 88 | |
| 89 with open(outfilename, 'wb') as f: | |
| 90 writer = csv.writer(f) | |
| 91 writer.writerows(overall_success_rates) | |
| OLD | NEW |