-
Notifications
You must be signed in to change notification settings - Fork 3
/
duration_summary.py
executable file
·38 lines (33 loc) · 1.08 KB
/
duration_summary.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
#!/usr/bin/env python3
# Pass the large_image_wheels build log.txt to stdin:
# docker run --rm girder/large_image_wheels:latest cat log.txt | ./build_duration.py
import subprocess
import sys
import dateutil.parser
if len(sys.argv) == 1:
record = sys.stdin.readlines()
else:
id = sys.argv[1]
if id == 'recent':
id = subprocess.check_output(
['docker', 'images', '-q'], encoding='utf8').split('\n')[0].strip()
record = subprocess.check_output(
['docker', 'run', '--rm', id, 'cat', 'log.txt'], encoding='utf8').split('\n')
starts = {}
totals = {}
for line in record:
key = line[28:].strip()
if not len(key):
continue
date = dateutil.parser.parse(line[:28])
if key not in starts:
starts[key] = date
else:
totals[key] = totals.get(key, 0) + (date - starts[key]).total_seconds()
del starts[key]
durations = [(val, key) for key, val in totals.items()]
if len(sys.argv) <= 2:
durations.sort()
for _, key in durations:
print('%4.0f %s' % (totals[key], key))
print('%4.0f %s' % (sum(totals.values()), 'total'))