Guest User

Untitled

a guest
Aug 18th, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.75 KB | None | 0 0
  1. # Copyright 2014 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4.  
  5. import datetime
  6. import functools
  7. import math
  8. import requests
  9. import sys
  10.  
  11. # inspired by https://github.com/eseidel/cycletimes/blob/master/bot_cycletimes.py
  12.  
  13. # from http://code.activestate.com/recipes/511478-finding-the-percentile-of-the-values
  14. def percentile(data, percent):
  15.   if not data:
  16.     return None
  17.   k = (len(data) - 1) * percent
  18.   f = math.floor(k)
  19.   c = math.ceil(k)
  20.   if f == c:
  21.     return data[int(k)]
  22.   d0 = data[int(f)] * (c - k)
  23.   d1 = data[int(c)] * (k - f)
  24.   return d0 + d1
  25.    
  26. median = functools.partial(percentile, percent=0.5)
  27.  
  28. def printrow(row, widths, indent=0):
  29.   if indent:
  30.     print ' ' * indent,
  31.   for index, cell in enumerate(row):
  32.     print str(cell).rjust(widths[index]),
  33.   print
  34.  
  35. def elapsed(seconds):
  36.   return str(datetime.timedelta(seconds=round(seconds)))
  37.  
  38. def stats_url_for_master(master_name, trybot_name):
  39.   return ('https://chrome-infra-stats.appspot.com/_ah/api/stats/v1/steps/last/%s/%s/overall__build__result__/2000' % (master_name, trybot_name))
  40.  
  41. def print_bot_stats(master, builder, stats, widths):
  42.   times = []
  43.   for i in stats['step_records']:
  44.     if i['result'] == '0':
  45.       times.append(i['step_time'])
  46.   times = sorted(times)
  47.   printrow((builder, elapsed(median(times)), elapsed(percentile(times, 0.9)), len(times)), widths, indent=1)
  48.  
  49. def main(args):
  50.   # data from https://chrome-internal.googlesource.com/infra/infra_internal/+/master/commit_queue/queue_config/chromium.json
  51.   bots = [
  52.   ['tryserver.chromium.linux', ['linux_chromium_rel_swarming', 'linux_chromium_chromeos_rel_swarming', 'linux_chromium_gn_rel', 'chromium_presubmit', 'android_dbg', 'android_dbg_triggered_tests', 'android_dbg_tests_recipe', 'android_clang_dbg', 'android_aosp', 'android_chromium_gn_compile_rel']],
  53.   ['tryserver.chromium.mac', ['mac_chromium_rel_swarming', 'mac_chromium_compile_dbg', 'ios_dbg_simulator', 'ios_rel_device', 'ios_rel_device_ninja']],
  54.   ['tryserver.chromium.win', ['win_chromium_rel_swarming', 'win_chromium_x64_rel_swarming', 'win8_chromium_rel', 'win_chromium_compile_dbg']],
  55.   ['tryserver.chromium.gpu', ['linux_gpu', 'linux_gpu_triggered_tests', 'mac_gpu', 'mac_gpu_retina_triggered_tests', 'mac_gpu_triggered_tests', 'win_gpu', 'win_gpu_triggered_tests']]
  56.   ]
  57.  
  58.   widths = (40, 10, 10, 15)
  59.   printrow(('master', 'median', '90th', 'success_count'), widths, indent=1)
  60.   for master, builders in bots:
  61.     for builder in builders:
  62.       url = stats_url_for_master(master, builder)
  63.       stats = requests.get(url).json()
  64.       print_bot_stats(master, builder, stats, widths)
  65.  
  66. if __name__ == '__main__':
  67.   sys.exit(main(sys.argv[1:]))
Advertisement
Add Comment
Please, Sign In to add comment