From 3bea8970730b4d4746d67081257befbb905308d1 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 16 Oct 2025 10:02:42 -0500 Subject: [PATCH] tools/metrics.py: Tersely show the commits in the size report. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will show a line for both the reference and comparison, e.g., Reference: zephyr/boards: Add PocketBeagle 2 rev A1… [00a926e99e] Comparison: metrics: Tersely show the commi… [merge of c7ac411e22] When the comparison is a merge commit (as it is during CI) the second parent of that commit is shown instead. This will be helpful when checking which revision of the code size report comment on a PR corresponds to which revision of the code. Signed-off-by: Jeff Epler --- tools/ci.sh | 13 +++++++++++-- tools/metrics.py | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/ci.sh b/tools/ci.sh index 0fb9263591..fdaf8b7eed 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -80,6 +80,10 @@ function ci_code_size_setup { ci_picotool_setup } +function _ci_is_git_merge { + [[ $(git log -1 --format=%P "$1" | wc -w) > 1 ]] +} + function ci_code_size_build { # check the following ports for the change in their code size # Override the list by setting PORTS_TO_CHECK in the environment before invoking ci. @@ -112,21 +116,26 @@ function ci_code_size_build { OUTFILE=$2 IGNORE_ERRORS=$3 - echo "Building ${COMMIT}..." git checkout --detach $COMMIT git submodule update --init $SUBMODULES git show -s tools/metrics.py clean "$PORTS_TO_CHECK" # Allow errors from tools/metrics.py to propagate out of the pipe below. set -o pipefail - tools/metrics.py build "$PORTS_TO_CHECK" | tee $OUTFILE || $IGNORE_ERRORS + tools/metrics.py build "$PORTS_TO_CHECK" | tee -a $OUTFILE || $IGNORE_ERRORS return $? } # build reference, save to size0 # ignore any errors with this build, in case master is failing + echo "BUILDING $(git log --format='%s [%h]' -1 ${REFERENCE})" > ~/size0 code_size_build_step $REFERENCE ~/size0 true # build PR/branch, save to size1 + if _ci_is_git_merge "$COMPARISON"; then + echo "BUILDING $(git log --oneline -1 --format='%s [merge of %h]' ${COMPARISON}^2)" + else + echo "BUILDING $(git log --oneline -1 --formta='%s [%h]' ${COMPARISON})" + fi > ~/size1 code_size_build_step $COMPARISON ~/size1 false ) } diff --git a/tools/metrics.py b/tools/metrics.py index d552857c4b..8bb96ba119 100755 --- a/tools/metrics.py +++ b/tools/metrics.py @@ -127,6 +127,8 @@ def read_build_log(filename): with open(filename) as f: for line in f: line = line.strip() + if line.startswith("BUILDING ") and "_ref" not in data: + data["_ref"] = line.removeprefix("BUILDING ") if line.strip() == "COMPUTING SIZES": found_sizes = True elif found_sizes: @@ -158,6 +160,10 @@ def do_diff(args): data1 = read_build_log(args[0]) data2 = read_build_log(args[1]) + ref1 = data1.pop("_ref", "(unknown ref)") + ref2 = data2.pop("_ref", "(unknown ref)") + print(f"Reference: {ref1}") + print(f"Comparison: {ref2}") max_delta = None for key, value1 in data1.items(): value2 = data2[key]