| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ | 6 """ |
| 7 Estimates capacity needs for all builders of a given master. | 7 Estimates capacity needs for all builders of a given master. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import argparse | 10 import argparse |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 return { | 75 return { |
| 76 'hourly_bots': min_bots(hourly_buckets, 3600), | 76 'hourly_bots': min_bots(hourly_buckets, 3600), |
| 77 'daily_bots': min_bots(daily_buckets, 3600 * 24), | 77 'daily_bots': min_bots(daily_buckets, 3600 * 24), |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 def main(argv): | 81 def main(argv): |
| 82 parser = argparse.ArgumentParser() | 82 parser = argparse.ArgumentParser() |
| 83 parser.add_argument('master') | 83 parser.add_argument('master') |
| 84 parser.add_argument('--days', type=int, default=14) | 84 parser.add_argument('--days', type=int, default=14) |
| 85 parser.add_argument('--ignore-cls-by', action='append') | 85 parser.add_argument('--filter-by-blamelist') |
| 86 parser.add_argument('--filter-by-patch-project') |
| 86 | 87 |
| 87 args = parser.parse_args(argv) | 88 args = parser.parse_args(argv) |
| 88 | 89 |
| 89 with tempfile.NamedTemporaryFile() as f: | 90 with tempfile.NamedTemporaryFile() as f: |
| 90 subprocess.check_call([ | 91 subprocess.check_call([ |
| 91 os.path.join(BASE_DIR, 'scripts', 'tools', 'runit.py'), | 92 os.path.join(BASE_DIR, 'scripts', 'tools', 'runit.py'), |
| 92 os.path.join(BASE_DIR, 'scripts', 'tools', 'dump_master_cfg.py'), | 93 os.path.join(BASE_DIR, 'scripts', 'tools', 'dump_master_cfg.py'), |
| 93 'masters/%s' % args.master, | 94 'masters/%s' % args.master, |
| 94 f.name]) | 95 f.name]) |
| 95 master_config = json.load(f) | 96 master_config = json.load(f) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 119 } | 120 } |
| 120 # TODO(phajdan.jr): use multiprocessing pool to speed this up. | 121 # TODO(phajdan.jr): use multiprocessing pool to speed this up. |
| 121 for builddir, builders in pool['builders'].iteritems(): | 122 for builddir, builders in pool['builders'].iteritems(): |
| 122 print ' builddir "%s":' % builddir | 123 print ' builddir "%s":' % builddir |
| 123 for builder in builders: | 124 for builder in builders: |
| 124 raw_builds = get_builds( | 125 raw_builds = get_builds( |
| 125 args.master.replace('master.', ''), builder, days) | 126 args.master.replace('master.', ''), builder, days) |
| 126 | 127 |
| 127 builds = [] | 128 builds = [] |
| 128 for build in raw_builds: | 129 for build in raw_builds: |
| 130 properties = {p[0]: p[1] for p in build.get('properties', [])} |
| 131 if (args.filter_by_patch_project and |
| 132 properties.get('patch_project') != args.filter_by_patch_project): |
| 133 continue |
| 134 |
| 129 blamelist = build.get('blame', []) | 135 blamelist = build.get('blame', []) |
| 130 ignore_cl = False | 136 if (args.filter_by_blamelist and |
| 131 for entry in blamelist: | 137 args.filter_by_blamelist not in blamelist): |
| 132 if entry in args.ignore_cls_by: | 138 continue |
| 133 ignore_cl = True | |
| 134 break | |
| 135 if not ignore_cl: | |
| 136 builds.append(build) | |
| 137 | 139 |
| 138 capacity = estimate_capacity(builds) | 140 capacity = estimate_capacity(builds) |
| 139 for key in ('hourly_bots', 'daily_bots'): | 141 for key in ('hourly_bots', 'daily_bots'): |
| 140 pool_capacity[key] += capacity[key] | 142 pool_capacity[key] += capacity[key] |
| 141 print ' %-45s %5.1f %5.1f' % ( | 143 print ' %-45s %5.1f %5.1f' % ( |
| 142 builder, | 144 builder, |
| 143 capacity['daily_bots'], | 145 capacity['daily_bots'], |
| 144 capacity['hourly_bots']) | 146 capacity['hourly_bots']) |
| 145 print ' %-45s %5.1f %5.1f %5.1f' % ( | 147 print ' %-45s %5.1f %5.1f %5.1f' % ( |
| 146 'total', | 148 'total', |
| 147 pool_capacity['daily_bots'], | 149 pool_capacity['daily_bots'], |
| 148 pool_capacity['hourly_bots'], | 150 pool_capacity['hourly_bots'], |
| 149 len(pool['slave_set'])) | 151 len(pool['slave_set'])) |
| 150 | 152 |
| 151 return 0 | 153 return 0 |
| 152 | 154 |
| 153 | 155 |
| 154 if __name__ == '__main__': | 156 if __name__ == '__main__': |
| 155 sys.exit(main(sys.argv[1:])) | 157 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |