File: pipeline-stats.py

package info (click to toggle)
coq 8.20.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 44,116 kB
  • sloc: ml: 234,160; sh: 4,301; python: 3,270; ansic: 2,644; makefile: 882; lisp: 172; javascript: 63; xml: 24; sed: 2
file content (62 lines) | stat: -rwxr-xr-x 1,790 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3

import os
import gitlab
from tabulate import tabulate

gt = gitlab.Gitlab(url="https://gitlab.inria.fr", private_token=os.getenv("PIPELINE_STATS_TOKEN"), api_version="4")

prj = gt.projects.get("coq/coq")

pipeline_id=os.getenv("CI_PIPELINE_ID")
pipeline = prj.pipelines.get(pipeline_id)

def pptime(seconds):
    if seconds >= 60 * 60:
        hours = seconds / (60 * 60)
        minutes = (seconds % (60 * 60)) / 60
        return f"{hours:.0f}h {minutes:.0f}min"
    elif seconds >= 60:
        minutes = seconds / 60
        rest = seconds % 60
        return f"{minutes:.0f}min {rest:.0f}s"
    else:
        return f"{seconds:.0f}s"

def ppsize(size, decimal_places=2):
    for unit in ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']:
        if size < 1024.0 or unit == 'PiB':
            break
        size /= 1024.0
    return f"{size:.{decimal_places}f} {unit}"

res=[]
total_time=0.0
total_size=0
total_log_size=0

for j in pipeline.jobs.list(iterator=True):
    if j.duration is None:
        continue # non-finished job, eg bench or pipeline stats
    size=0
    log_size=0
    if 'artifacts' in j.attributes:
        for art in j.attributes['artifacts']:
            if art['file_type'] == 'trace':
                log_size += art['size']
            else:
                size += art['size']
    res += [[j.name, j.duration, size, log_size, j.id]]
    total_time += j.duration
    total_size += size
    total_log_size += log_size

res += [['total', total_time, total_size, total_log_size, pipeline_id]]

def sortkey(v):
    return v[1]

ppres = [ [v[0], pptime(v[1]), ppsize(v[2]), ppsize(v[3]), v[4]]
          for v in sorted(res, key=sortkey) ]

print(tabulate(ppres, headers=['name', 'duration', 'artifacts size', 'log size', 'id'], tablefmt='orgtbl'))