Skip to content

Commit

Permalink
CI: add job printing stats about the current pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
SkySkimmer committed Dec 13, 2024
1 parent e2dc7ac commit 4f65f0a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
13 changes: 12 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ stages:
- build-2
- build-3+
- deploy
- stats

# We set "needs" to contain all transitive dependencies. We include the
# transitive dependencies as otherwise we don't get their artifacts
Expand All @@ -40,7 +41,7 @@ variables:
# echo $(md5sum dev/ci/docker/old_ubuntu_lts/Dockerfile | head -c 10)
# echo $(md5sum dev/ci/docker/edge_ubuntu/Dockerfile | head -c 10)
BASE_CACHEKEY: "old_ubuntu_lts-V2024-10-11-f72b1aa7c6"
EDGE_CACHEKEY: "edge_ubuntu-V2024-12-02-8a4b2ae476"
EDGE_CACHEKEY: "edge_ubuntu-V2024-12-13-5c140221f4"
BASE_IMAGE: "$CI_REGISTRY_IMAGE:$BASE_CACHEKEY"
EDGE_IMAGE: "$CI_REGISTRY_IMAGE:$EDGE_CACHEKEY"

Expand Down Expand Up @@ -1271,3 +1272,13 @@ doc:ci-refman:
- _build/log
- _build/default/doc/refman-html
- _build/default/doc/refman-pdf

pipeline-stats:
image: $EDGE_IMAGE
extends: .auto-use-tags
stage: stats
dependencies: []
before_script: []
script:
- dev/tools/pipeline-stats.py
when: always
2 changes: 2 additions & 0 deletions dev/ci/docker/edge_ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ RUN apt-get update -qq && apt-get install --no-install-recommends -y -qq \
# Dependencies of stdlib and sphinx doc
texlive-latex-extra texlive-fonts-recommended texlive-xetex latexmk \
python3-pip python3-setuptools python3-pexpect python3-bs4 fonts-freefont-otf \
# pipeline-stats
python3-gitlab python3-tabulate \
# Dependencies of source-doc and coq-makefile
texlive-latex-extra texlive-science tipa \
# Dependencies of HB (test suite)
Expand Down
62 changes: 62 additions & 0 deletions dev/tools/pipeline-stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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'))

0 comments on commit 4f65f0a

Please sign in to comment.