|
| 1 | +#!/usr/bin/python3 |
| 2 | +# |
| 3 | +# $ curl -s https://storage.googleapis.com/origin-ci-test/logs/release-openshift-origin-installer-e2e-aws-4.0/6016/artifacts/e2e-aws/pods/openshift-cluster-version_cluster-version-operator-74d8d99566-2bh4q_cluster-version-operator.log.gz | gunzip | cvo-waterfall.py >cvo.svg |
| 4 | + |
| 5 | +import datetime |
| 6 | +import re |
| 7 | +import sys |
| 8 | + |
| 9 | + |
| 10 | +log_regexp = re.compile('^I[0-9]+ ([0-9:.]+) .* (Running sync|Done syncing) for ([^ ]+) "([^"]+)" \(([0-9]+) of ([0-9]+)\)') |
| 11 | + |
| 12 | +resources = {} |
| 13 | +reference_time = None |
| 14 | +for line in sys.stdin.readlines(): |
| 15 | + match = log_regexp.match(line) |
| 16 | + if not match: |
| 17 | + continue |
| 18 | + time, action, objType, name, index, total = match.groups() |
| 19 | + timestamp = datetime.datetime.strptime(time, '%H:%M:%S.%f') |
| 20 | + if reference_time is None: |
| 21 | + reference_time = timestamp |
| 22 | + if objType not in resources: |
| 23 | + resources[objType] = {} |
| 24 | + if name not in resources[objType]: |
| 25 | + resources[objType][name] = { |
| 26 | + 'index': int(index), |
| 27 | + 'total': int(total), |
| 28 | + } |
| 29 | + if action not in resources[objType][name]: |
| 30 | + resources[objType][name][action] = timestamp |
| 31 | + |
| 32 | +time_ranges = [] |
| 33 | +for objType, names in resources.items(): |
| 34 | + for name, data in names.items(): |
| 35 | + if 'Done syncing' not in data: |
| 36 | + continue |
| 37 | + start = (data['Running sync'] - reference_time).total_seconds() |
| 38 | + stop = (data['Done syncing'] - reference_time).total_seconds() |
| 39 | + time_ranges.append((start, stop, objType, name, data)) |
| 40 | + |
| 41 | +rectangles = [] |
| 42 | +y = 0 |
| 43 | +step = 4 |
| 44 | +last_stop = 0 |
| 45 | +for start, stop, objType, name, data in sorted(time_ranges): |
| 46 | + rectangles.append('<rect x="{}" y="{}" width="{}" height="{}" fill="blue"><title>{} {} {}/{} ({})</title></rect>'.format(start, y, stop - start, step, objType, name, data['index'], data['total'], data['Done syncing'] - data['Running sync'])) |
| 47 | + y += step |
| 48 | + if stop > last_stop: |
| 49 | + last_stop = stop |
| 50 | + |
| 51 | +print('<svg viewBox="0 0 {} {}" xmlns="http://www.w3.org/2000/svg">'.format(last_stop, y)) |
| 52 | +for rectangle in rectangles: |
| 53 | + print(' {}'.format(rectangle)) |
| 54 | +print('</svg>') |
0 commit comments