From patchwork Fri Feb 28 17:54:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 869291 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1561:b0:38f:210b:807b with SMTP id 1csp934840wrz; Fri, 28 Feb 2025 09:55:27 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXbHf9Er3RHE/0eH9iy0SHMFEApQ2b/IBxT0uMQjNPWDtGR1UVzCRLykDXyn89UdVR/W0Zl9A==@linaro.org X-Google-Smtp-Source: AGHT+IFU5zlFR3I+mfsEKep+CuvMdmeGYLQfiQ0UWCqN4KWBCva11KpbtC5xgB45Qig4OIzXuHPq X-Received: by 2002:ac8:5a13:0:b0:472:636:f5ff with SMTP id d75a77b69052e-474bc10f3ddmr60038481cf.48.1740765327638; Fri, 28 Feb 2025 09:55:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740765327; cv=none; d=google.com; s=arc-20240605; b=L8SZSSnl1X3jb6VPw/EOwjmZ05IQ6P+2zFO5yirdH5EAgORjgrxPVxsvBZ656dOjbi EMWR26toHg0bK43OTmMlWkkDN/II9IDXfG9kZZQxIgsthYeNW7L0ofAmmniZYDWGekqw J5zlyj094CCTlpI/00CDmFqUPl1HcNL6isAYEXWG284n+QoFlbQs+LxWkfwCDgQrs7+z GUylQmCH45tyl4f5aMLbdfCt8buL/DAlN9SHi4sDh7kLMEUK0p+YOLNvuCa1t3LCLVFh GbJugj5qsS2kUFWGTA2zjxmoVyJxXICjol/x2PsbWvYFo4kBRwk/K5yEUlR2UfDaKdUl VmKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=jtvMelRpMHPT9gIgF1y4kKqGNE8vJVEvR/SuEBPumP4=; fh=Rak4RDPikcnOis4opnKodJtATYDy9C4xWwTq9StZag8=; b=ORGN2FdmKJkWuaOShjKbVON3qTkfTo7XFDdXf3yzWlCmW1dy6GZRwiQKY44nDno8wi StEC+n9LYgIzMIjmZ0JX0/JTfS0dmmZsAxDebwGO4VDpPUJIIBsuTOXmoIsz9Ka1xO82 UlDGK7kyQyVLcJ8u1r98HZmyq97F8ZIMESsY8S+jchMCl6OUhzsfUWBmvmoNxDN0JkNA DnbrRRWCLmpwvOrS+3lslsmOvYj3qLrpF7sqttByWZ9vN33YA/YBwRtbJEbgze9fql9F kckKy8diCQ+rp/DXsMe7cic0j0rjkDdzNUaurOkTYNR/kC3H0c8V1TqGpiSkSRZYFo3j aS7A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zC+UbZvS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4747240e0aasi34624781cf.462.2025.02.28.09.55.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Feb 2025 09:55:27 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zC+UbZvS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1to4Zb-0005SI-9A; Fri, 28 Feb 2025 12:54:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1to4ZZ-0005No-Gt for qemu-devel@nongnu.org; Fri, 28 Feb 2025 12:54:53 -0500 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1to4ZX-0006iM-8M for qemu-devel@nongnu.org; Fri, 28 Feb 2025 12:54:53 -0500 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4397dff185fso21795005e9.2 for ; Fri, 28 Feb 2025 09:54:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740765289; x=1741370089; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=jtvMelRpMHPT9gIgF1y4kKqGNE8vJVEvR/SuEBPumP4=; b=zC+UbZvSxGiLqrwyVReJbbT76AqmTZf+G3YAbpr1Z/7+LeEoYB9gekFAKPBSCKxanU eXyXTa36DOrvki1Prirldp+j+d10zKmMrAVvi9+eJ328ZR228hU4Xa/kK/b/1ukFYbUz aOqERCWVUMHChhGRslZq+nSwcypKnDgrchchgXjB/3+V35fKnGm+WphkBmze7gkBrfEM Yz+jeNqgICbCct0SmX0vQPem+IXuCvhtv3Tcb0smGFZLefg6grFU3HEG1XYt7/X5D+UB K94sf95syhJQcCp7E3xbZ/ouDJ2XhVwyQYsoc3RDLxhIj+ViKWqur8ayi147BD0bmFnK uMrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740765289; x=1741370089; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jtvMelRpMHPT9gIgF1y4kKqGNE8vJVEvR/SuEBPumP4=; b=mHfUxIG//MoQshUXrjF0hplgx1msAFPJv/E79y3viL1pyznmWAoqO9Culvn6svsbhZ S9E8kMYzIQKm8Ogw1jumvIv7mCkTyOjSYyK7lXujKBaulxMhQOdRsjxUefQ6pixppt79 tSfgc2fzDK3kbmiB1A+02xbtsT3mKMq4BRlrl4trs76bOhi0EIsMKiyL+RBU1OsA0wnO FcS3FHTZsglIkdzuro6LocLVQzBbFGy97KXjD9Ua7BtUJPCo95AWgYrVmha5U0TtysdV LJPfD+e4ib/jH4c7xz9bvgkJeEgRvynl1v4Is+BMgqeVMX007CQX9iRTMpBApY5j7AP9 pGoA== X-Gm-Message-State: AOJu0YxT2nkCVCKdYwVUmaO1dJBPip8fjUc06vuR5loeozqBeSyVCuTw URrSfaiyN77orggwPdeHs1L7xbVc3g1Zzaq0sFtYdj3KO9j78XZf2EqtjxkBH2M= X-Gm-Gg: ASbGncvHme0hDYJ/GOfIB4ZkVV1QoDjgz5qiFs6tbwt0fR0kUULhcV+9qGpOLI93tct DXlPvGoHpMhpMYn7fLjRTvMNmcO11/gtghbxhQ1iBCvQTPJnZvUIM6ruorXqlrky7CzgYsPo+ek lJQdG3+jgQnLkq4iAUydpTCznBMphgGrrVzMArsjoHGhmYmXaB9EgbktUreaUOsKNh7iiZDiRES epAOJcfRrqltoXMtMa6RHvJ0CQcS9U+axAQ7AKLehci1SoRRJlFFyvjhQw3PFd4ZGOPesAQ6G0I HV01aHKLQdivsDakjQsrCN8QAD83 X-Received: by 2002:a05:600c:1c8e:b0:43a:b0ac:b10c with SMTP id 5b1f17b1804b1-43ba6744a10mr29506175e9.26.1740765288904; Fri, 28 Feb 2025 09:54:48 -0800 (PST) Received: from draig.lan ([185.126.160.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b73717230sm62409275e9.19.2025.02.28.09.54.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 09:54:48 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 95B615F7DE; Fri, 28 Feb 2025 17:54:47 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Richard Henderson , Thomas Huth Subject: [RFC PATCH] gitlab: add a new build_unit job to track build size Date: Fri, 28 Feb 2025 17:54:41 +0000 Message-Id: <20250228175441.674384-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.google.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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. Signed-off-by: Alex Bennée Cc: Pierrick Bouvier Cc: Philippe Mathieu-Daudé Cc: Richard Henderson Reviewed-by: Pierrick Bouvier --- .gitlab-ci.d/check-units.py | 95 ++++++++++++++++++++++++++++++++++ .gitlab-ci.d/static_checks.yml | 22 ++++++++ 2 files changed, 117 insertions(+) create mode 100755 .gitlab-ci.d/check-units.py diff --git a/.gitlab-ci.d/check-units.py b/.gitlab-ci.d/check-units.py new file mode 100755 index 0000000000..aca63bd481 --- /dev/null +++ b/.gitlab-ci.d/check-units.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +# +# check-units.py: check the number of compilation units and identify +# those that are rebuilt multiple times +# +# Copyright (C) 2025 Linaro Ltd. +# +# SPDX-License-Identifier: GPL-2.0-or-later + +from os import access, R_OK, path +from subprocess import check_output, CalledProcessError +from sys import argv, exit +import re + + +def extract_build_units(cc_path): + """ + Extract the build units and their counds from compile_commands.json file. + + Returns: + Hash table of ["unit"] = count + """ + + # Make jq/shell do the heavy lifting + cmd = f"jq < {cc_path} '.[] | .file' | sort | uniq -c | sort -rn" + + try: + # Execute the shell command and capture the output + result = check_output(cmd, shell=True) + except CalledProcessError as exp: + print(f"Error executing {cmd}: {exp}") + exit(1) + + lines = result.decode().strip().split('\n') + + # Create a dictionary to store the build unit frequencies + build_units = {} + + # extract from string of form: ' 65 "../../fpu/softfloat.c"' + ext_pat = re.compile(r'^\s*(\d+)\s+"([^"]+)"') + + # strip leading ../ + norm_pat = re.compile(r'^((\.\./)+|/+)') + + # Process each line of the output + for line in lines: + match = re.match(ext_pat, line) + if match: + count = int(match.group(1)) + unit_path = re.sub(norm_pat, '', match.group(2)) + + # Store the count in the dictionary + build_units[unit_path] = count + else: + print(f"couldn't process {line}") + + return build_units + + +def analyse_units(build_units): + """ + Analyse the build units and report stats and the top 10 rebuilds + """ + + print(f"Total source files: {len(build_units.keys())}") + print(f"Total build units: {sum(units.values())}") + + # Create a sorted list by number of rebuilds + sorted_build_units = sorted(build_units.items(), + key=lambda item: item[1], + reverse=True) + + print("Most rebuilt units:") + for unit, count in sorted_build_units[:10]: + print(f" {unit} built {count} times") + + print("Least rebuilt units:") + for unit, count in sorted_build_units[-10:]: + print(f" {unit} built {count} times") + + +if __name__ == "__main__": + if len(argv) != 2: + script_name = path.basename(argv[0]) + print(f"Usage: {script_name} ") + exit(1) + + cc_path = argv[1] + if path.isfile(cc_path) and access(cc_path, R_OK): + units = extract_build_units(cc_path) + analyse_units(units) + exit(0) + else: + print(f"{cc_path} doesn't exist or isn't readable") + exit(1) diff --git a/.gitlab-ci.d/static_checks.yml b/.gitlab-ci.d/static_checks.yml index c0ba453382..c3ed6de453 100644 --- a/.gitlab-ci.d/static_checks.yml +++ b/.gitlab-ci.d/static_checks.yml @@ -70,3 +70,25 @@ check-rust-tools-nightly: expire_in: 2 days paths: - rust/target/doc + +check-build-units: + extends: .base_job_template + stage: build + image: $CI_REGISTRY_IMAGE/qemu/debian:$QEMU_CI_CONTAINER_TAG + needs: + job: amd64-debian-container + before_script: + - source scripts/ci/gitlab-ci-section + - section_start setup "Install Tools" + - apt install --assume-yes --no-install-recommends jq + - section_end setup + script: + - mkdir build + - cd build + - section_start configure "Running configure" + - ../configure + - cd .. + - section_end configure + - section_start analyse "Analyse" + - .gitlab-ci.d/check-units.py build/compile_commands.json + - section_end analyse