Skip to content

Commit 3df360c

Browse files
committed
gitlab: add a new build_unit job to track build size
We want to reduce the total number of build units in the system to get on our way to a single binary. It will help to have some numbers so lets add a job to gitlab to track our progress. Cc: Pierrick Bouvier <[email protected]> Cc: Philippe Mathieu-Daudé <[email protected]> Cc: Richard Henderson <[email protected]> Signed-off-by: Alex Bennée <[email protected]> Message-Id: <[email protected]>
1 parent c05aec9 commit 3df360c

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

.gitlab-ci.d/check-units.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python3
2+
#
3+
# check-units.py: check the number of compilation units and identify
4+
# those that are rebuilt multiple times
5+
#
6+
# Copyright (C) 2025 Linaro Ltd.
7+
#
8+
# SPDX-License-Identifier: GPL-2.0-or-later
9+
10+
from os import access, R_OK, path
11+
from sys import argv, exit
12+
import json
13+
from collections import Counter
14+
15+
16+
def extract_build_units(cc_path):
17+
"""
18+
Extract the build units and their counds from compile_commands.json file.
19+
20+
Returns:
21+
Hash table of ["unit"] = count
22+
"""
23+
24+
j = json.load(open(cc_path, 'r'))
25+
files = [f['file'] for f in j]
26+
build_units = Counter(files)
27+
28+
return build_units
29+
30+
31+
def analyse_units(build_units):
32+
"""
33+
Analyse the build units and report stats and the top 10 rebuilds
34+
"""
35+
36+
print(f"Total source files: {len(build_units.keys())}")
37+
print(f"Total build units: {sum(units.values())}")
38+
39+
# Create a sorted list by number of rebuilds
40+
sorted_build_units = sorted(build_units.items(),
41+
key=lambda item: item[1],
42+
reverse=True)
43+
44+
print("Most rebuilt units:")
45+
for unit, count in sorted_build_units[:20]:
46+
print(f" {unit} built {count} times")
47+
48+
print("Least rebuilt units:")
49+
for unit, count in sorted_build_units[-10:]:
50+
print(f" {unit} built {count} times")
51+
52+
53+
if __name__ == "__main__":
54+
if len(argv) != 2:
55+
script_name = path.basename(argv[0])
56+
print(f"Usage: {script_name} <path_to_compile_commands.json>")
57+
exit(1)
58+
59+
cc_path = argv[1]
60+
if path.isfile(cc_path) and access(cc_path, R_OK):
61+
units = extract_build_units(cc_path)
62+
analyse_units(units)
63+
exit(0)
64+
else:
65+
print(f"{cc_path} doesn't exist or isn't readable")
66+
exit(1)

.gitlab-ci.d/static_checks.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,25 @@ check-rust-tools-nightly:
7070
expire_in: 2 days
7171
paths:
7272
- rust/target/doc
73+
74+
check-build-units:
75+
extends: .base_job_template
76+
stage: build
77+
image: $CI_REGISTRY_IMAGE/qemu/debian:$QEMU_CI_CONTAINER_TAG
78+
needs:
79+
job: amd64-debian-container
80+
before_script:
81+
- source scripts/ci/gitlab-ci-section
82+
- section_start setup "Install Tools"
83+
- apt install --assume-yes --no-install-recommends jq
84+
- section_end setup
85+
script:
86+
- mkdir build
87+
- cd build
88+
- section_start configure "Running configure"
89+
- ../configure
90+
- cd ..
91+
- section_end configure
92+
- section_start analyse "Analyse"
93+
- .gitlab-ci.d/check-units.py build/compile_commands.json
94+
- section_end analyse

0 commit comments

Comments
 (0)