| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2013 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 | |
| 7 """ Verify that the most recent compile builds are under an appropriate | |
| 8 threshold. """ | |
| 9 | |
| 10 | |
| 11 from build_step import BuildStep, BuildStepFailure | |
| 12 from builder_name_schema import BUILDER_ROLE_BUILD | |
| 13 import config_private | |
| 14 import json | |
| 15 import sys | |
| 16 import urllib2 | |
| 17 | |
| 18 | |
| 19 BUILD_MASTER_URL = 'http://%s:%s' % ( | |
| 20 config_private.Master.Skia.master_host, | |
| 21 config_private.Master.Skia.master_port_alt) | |
| 22 COMPILE_TIME_LIMIT = 10000 # TODO(borenet): Make this something reasonable! | |
| 23 | |
| 24 | |
| 25 def IsBuildFinished(build_info): | |
| 26 """ Determine whether the given build is finished, based on its start and end | |
| 27 times. Returns True iff the start and end times are not None and are not zero. | |
| 28 """ | |
| 29 return build_info['times'][0] and build_info['times'][1] | |
| 30 | |
| 31 | |
| 32 def GetBuildInfo(builder_name, build_num): | |
| 33 """ Returns a dictionary containing information about a given build. | |
| 34 | |
| 35 builder_name: string; the name of the desired builder. | |
| 36 build_num: string; the number of the desired build. | |
| 37 """ | |
| 38 url = '%s/json/builders/%s/builds/%s' % (BUILD_MASTER_URL, | |
| 39 builder_name, | |
| 40 build_num) | |
| 41 return json.load(urllib2.urlopen(url)) | |
| 42 | |
| 43 | |
| 44 def GetLastFinishedBuildInfo(builder_name, cached_builds): | |
| 45 """ Returns a dictionary containing information about the last finished build | |
| 46 for the given builder. | |
| 47 | |
| 48 builder_name: string; the name of the desired builder. | |
| 49 cached_builds: list of strings; candidate build numbers. | |
| 50 """ | |
| 51 cached_builds.sort(reverse=True) | |
| 52 for build_num in cached_builds: | |
| 53 build_info = GetBuildInfo(builder_name, build_num) | |
| 54 if IsBuildFinished(build_info): | |
| 55 return build_info | |
| 56 return None | |
| 57 | |
| 58 | |
| 59 class CheckCompileTimes(BuildStep): | |
| 60 def _Run(self): | |
| 61 # Obtain the list of Compile builders from the master. | |
| 62 builders = json.load(urllib2.urlopen(BUILD_MASTER_URL + '/json/builders')) | |
| 63 | |
| 64 # Figure out which ones are too slow. | |
| 65 too_slow = [] | |
| 66 no_builds = [] | |
| 67 longest_build = None | |
| 68 for builder_name in builders.keys(): | |
| 69 if builder_name.startswith(BUILDER_ROLE_BUILD): | |
| 70 cached_builds = sorted(builders[builder_name]['cachedBuilds']) | |
| 71 if cached_builds: | |
| 72 build_info = GetLastFinishedBuildInfo(builder_name, cached_builds) | |
| 73 if build_info: | |
| 74 duration = build_info['times'][1] - build_info['times'][0] | |
| 75 summarized_build_info = {'builder': builder_name, | |
| 76 'number': build_info['number'], | |
| 77 'duration': duration} | |
| 78 if duration > COMPILE_TIME_LIMIT: | |
| 79 too_slow.append(summarized_build_info) | |
| 80 if not longest_build or duration > longest_build['duration']: | |
| 81 longest_build = summarized_build_info | |
| 82 else: | |
| 83 no_builds.append(builder_name) | |
| 84 if longest_build: | |
| 85 print 'Longest build: %(builder)s #%(number)s: %(duration)ds' % \ | |
| 86 longest_build | |
| 87 print '%s/builders/%s/builds/%s' % (BUILD_MASTER_URL, | |
| 88 longest_build['builder'], | |
| 89 longest_build['number']) | |
| 90 print | |
| 91 if no_builds: | |
| 92 print 'Warning: No builds found for the following builders:' | |
| 93 for builder in no_builds: | |
| 94 print ' %s' % builder | |
| 95 print | |
| 96 if too_slow: | |
| 97 print 'The following builds exceeded the time limit of %ds:' % \ | |
| 98 COMPILE_TIME_LIMIT | |
| 99 for summarized_build_info in too_slow: | |
| 100 print ' %(builder)s #%(number)s: %(duration)ds' % summarized_build_info | |
| 101 raise BuildStepFailure('Builds exceeded time limit.') | |
| 102 | |
| 103 | |
| 104 | |
| 105 if '__main__' == __name__: | |
| 106 sys.exit(BuildStep.RunBuildStep(CheckCompileTimes)) | |
| OLD | NEW |