-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot_cycletimes.py
73 lines (56 loc) · 2.11 KB
/
bot_cycletimes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import base64
import json
import requests
import string
import sys
import urlparse
import datetime
def master_name_from_url(master_url):
return urlparse.urlparse(master_url).path.split('/')[-1]
def stats_url_for_master(master_name):
# FIXME: May need to urlencode master_name.
return ('https://chrome-infra-stats.appspot.com/'
'_ah/api/stats/v1/stats/last/%s/'
'overall__build__result__/2000' % master_name)
def printrow(row, widths, indent=0):
if indent:
print ' ' * indent,
for index, cell in enumerate(row):
print str(cell).rjust(widths[index]),
print
def elapsed(seconds):
return str(datetime.timedelta(seconds=round(seconds)))
def print_tree_stats(tree_name, stats_by_master):
print
print tree_name
master_names = sorted(stats_by_master.keys())
master_width = max(map(len, master_names))
widths = (master_width, 10, 10, 10)
printrow(('master', 'median', '99th', 'maximum'), widths, indent=1)
for master_name in master_names:
stats = stats_by_master[master_name]
printrow((master_name,
elapsed(stats['median']),
elapsed(stats['ninetynine']),
elapsed(stats['maximum'])), widths, indent=1)
def main(args):
trees_url = ('https://chromium.googlesource.com/chromium/'
'tools/build/+/master/scripts/slave/'
'gatekeeper_trees.json?format=TEXT')
trees_encoded = requests.get(trees_url).text
trees = json.loads(base64.b64decode(trees_encoded))
# FIXME: This analysis is wrong for builder/tester pairs
# since it's averaging their cycle time instead of summing.
for tree_name, tree_config in trees.items():
stats_by_master = {}
for master_url in tree_config['masters']:
master_name = master_name_from_url(master_url)
url = stats_url_for_master(master_name)
#print 'requesting %s...' % url
stats_by_master[master_name] = requests.get(url).json()
print_tree_stats(tree_name, stats_by_master)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))