Debian Codegraph @

dev/tools/pipeline-stats.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 #!/usr/bin/python3
2
3 import os
4 import gitlab
5 from tabulate import tabulate
6
7 gt = gitlab.Gitlab(url="https://gitlab.inria.fr", private_token=os.getenv("PIPELINE_STATS_TOKEN"), api_version="4")
8
9 prj = gt.projects.get("coq/coq")
10
11 pipeline_id=os.getenv("CI_PIPELINE_ID")
12 pipeline = prj.pipelines.get(pipeline_id)
13
14 def pptime(seconds):
15 if seconds >= 60 * 60:
16 hours = seconds / (60 * 60)
17 minutes = (seconds % (60 * 60)) / 60
18 return f"{hours:.0f}h {minutes:.0f}min"
19 elif seconds >= 60:
20 minutes = seconds / 60
21 rest = seconds % 60
22 return f"{minutes:.0f}min {rest:.0f}s"
23 else:
24 return f"{seconds:.0f}s"
25
26 def ppsize(size, decimal_places=2):
27 for unit in ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']:
28 if size < 1024.0 or unit == 'PiB':
29 break
30 size /= 1024.0
31 return f"{size:.{decimal_places}f} {unit}"
32
33 res=[]
34 total_time=0.0
35 total_size=0
36 total_log_size=0
37
38 for j in pipeline.jobs.list(iterator=True):
39 if j.duration is None:
40 continue # non-finished job, eg bench or pipeline stats
41 size=0
42 log_size=0
43 if 'artifacts' in j.attributes:
44 for art in j.attributes['artifacts']:
45 if art['file_type'] == 'trace':
46 log_size += art['size']
47 else:
48 size += art['size']
49 res += [[j.name, j.duration, size, log_size, j.id]]
50 total_time += j.duration
51 total_size += size
52 total_log_size += log_size
53
54 res += [['total', total_time, total_size, total_log_size, pipeline_id]]
55
56 def sortkey(v):
57 return v[1]
58
59 ppres = [ [v[0], pptime(v[1]), ppsize(v[2]), ppsize(v[3]), v[4]]
60 for v in sorted(res, key=sortkey) ]
61
62 print(tabulate(ppres, headers=['name', 'duration', 'artifacts size', 'log size', 'id'], tablefmt='orgtbl'))