From 4316d043f52ccead1da5c85fad01cec11ad86551 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Fri, 26 Nov 2021 08:34:27 +1100 Subject: [PATCH 1/8] Add script for performing compilation size regression investigations. --- util/size_regression.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 util/size_regression.sh diff --git a/util/size_regression.sh b/util/size_regression.sh new file mode 100755 index 000000000000..dd9bc1c52aae --- /dev/null +++ b/util/size_regression.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +if [[ -z $1 ]] ; then + echo "Usage: $0 planck/rev6:default" + exit 1 +fi + +keyboard_target=$1 + +function build_executor() { + git rev-list --oneline --no-merges 0.11.0...upstream/develop ^upstream/master | while IFS= read -r line ; do + revision=$(echo $line | cut -d' ' -f1) + + make distclean >/dev/null 2>&1 + git checkout $revision >/dev/null 2>&1 + make -j $keyboard_target >/dev/null 2>&1 + file_size=$(arm-none-eabi-size .build/*.elf | awk '/elf/ {print $1}') + + printf "%8d -- %s\n" "$file_size" "$line" + done +} + +# The actual execution of all the builds needs to be the last command in the entire script +# - During builds, this script file will disappear, so we need the entire script to be +# loaded into the script interpreter at the time of execution. Do not refactor. +build_executor \ No newline at end of file From e6e0b2d4953b0d8cfdc13fb9f2558202404ad51c Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Fri, 26 Nov 2021 11:05:20 +1100 Subject: [PATCH 2/8] Print deltas --- util/size_regression.sh | 59 +++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/util/size_regression.sh b/util/size_regression.sh index dd9bc1c52aae..4e3bf192d89c 100755 --- a/util/size_regression.sh +++ b/util/size_regression.sh @@ -1,26 +1,69 @@ #!/bin/bash -if [[ -z $1 ]] ; then - echo "Usage: $0 planck/rev6:default" +set -eEuo pipefail + +source_ref="0.11.0" +dest_ref="develop" +ignore_ref="master" + +function usage() { + echo "Usage: $(basename "$0") [-s ] [-d ] [-u] planck/rev6:default" + echo " -s : use source commit, branch, tag, or sha1 to start the search" + echo " defaults to \`$source_ref\`." + echo " -d : use destination commit, branch, tag, or sha1 to end the search" + echo " defaults to \`$dest_ref\`." + echo " -i : the branch to ignore refs from" + echo " defaults to \`$ignore_ref\`." exit 1 +} + +if [[ ${#} -eq 0 ]]; then + usage fi +while getopts "s:d:i:" opt "$@" ; do + case "$opt" in + s) source_ref="${OPTARG:-}";; + d) dest_ref="${OPTARG:-}";; + i) ignore_ref="${OPTARG:-}";; + \?) usage >&2; exit 1;; + esac +done + +# Work out the target board +shift $((OPTIND-1)) keyboard_target=$1 +last_size=0 +last_line="" function build_executor() { - git rev-list --oneline --no-merges 0.11.0...upstream/develop ^upstream/master | while IFS= read -r line ; do + git rev-list --oneline --no-merges ${source_ref}...${dest_ref} ^${ignore_ref} | while IFS= read -r line ; do revision=$(echo $line | cut -d' ' -f1) make distclean >/dev/null 2>&1 - git checkout $revision >/dev/null 2>&1 - make -j $keyboard_target >/dev/null 2>&1 - file_size=$(arm-none-eabi-size .build/*.elf | awk '/elf/ {print $1}') + git checkout $revision >/dev/null 2>&1 || { echo "Failed to check out revision ${revision}" >&2 ; exit 1 ; } + make -j $keyboard_target >/dev/null 2>&1 || true + file_size=$(arm-none-eabi-size .build/*.elf 2>&1 | awk '/elf/ {print $1}' 2>&1 || true) - printf "%8d -- %s\n" "$file_size" "$line" + if [[ "$last_size" == 0 ]] ; then last_size=$file_size ; fi + if [[ -z "$file_size" ]] ; then file_size=0 ; fi + + if [[ -n "$last_line" ]] ; then + size_delta=$(( $last_size - $file_size )) + printf "Size: %8d, delta: %+6d -- %s\n" "$last_size" "$size_delta" "$last_line" + fi + + last_size=$file_size + last_line=$line done } +if [ -n "$last_line" ] ; then + size_delta=0 + printf "Size: %8d, delta: %+6d -- %s\n" "$last_size" "$size_delta" "$last_line" +fi + # The actual execution of all the builds needs to be the last command in the entire script # - During builds, this script file will disappear, so we need the entire script to be # loaded into the script interpreter at the time of execution. Do not refactor. -build_executor \ No newline at end of file +build_executor From f74fa46d4dbbf95cc06fedc3eb4f71066a60fcf8 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Fri, 26 Nov 2021 16:48:23 +1100 Subject: [PATCH 3/8] Correct scoping. --- util/size_regression.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/size_regression.sh b/util/size_regression.sh index 4e3bf192d89c..88a99e455266 100755 --- a/util/size_regression.sh +++ b/util/size_regression.sh @@ -56,12 +56,12 @@ function build_executor() { last_size=$file_size last_line=$line done -} -if [ -n "$last_line" ] ; then - size_delta=0 - printf "Size: %8d, delta: %+6d -- %s\n" "$last_size" "$size_delta" "$last_line" -fi + if [ -n "$last_line" ] ; then + size_delta=0 + printf "Size: %8d, delta: %+6d -- %s\n" "$last_size" "$size_delta" "$last_line" + fi +} # The actual execution of all the builds needs to be the last command in the entire script # - During builds, this script file will disappear, so we need the entire script to be From e85f665163ba650144a42c9336b17587ef23d3b5 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Fri, 26 Nov 2021 16:58:05 +1100 Subject: [PATCH 4/8] Concurrency control --- util/size_regression.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/util/size_regression.sh b/util/size_regression.sh index 88a99e455266..19a40a59d150 100755 --- a/util/size_regression.sh +++ b/util/size_regression.sh @@ -2,18 +2,21 @@ set -eEuo pipefail +job_count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2) source_ref="0.11.0" dest_ref="develop" ignore_ref="master" function usage() { echo "Usage: $(basename "$0") [-s ] [-d ] [-u] planck/rev6:default" - echo " -s : use source commit, branch, tag, or sha1 to start the search" - echo " defaults to \`$source_ref\`." - echo " -d : use destination commit, branch, tag, or sha1 to end the search" - echo " defaults to \`$dest_ref\`." - echo " -i : the branch to ignore refs from" - echo " defaults to \`$ignore_ref\`." + echo " -j : change the number of threads to execute with" + echo " defaults to \`$job_count\`." + echo " -s : use source commit, branch, tag, or sha1 to start the search" + echo " defaults to \`$source_ref\`." + echo " -d : use destination commit, branch, tag, or sha1 to end the search" + echo " defaults to \`$dest_ref\`." + echo " -i : the branch to ignore refs from" + echo " defaults to \`$ignore_ref\`." exit 1 } @@ -21,8 +24,9 @@ if [[ ${#} -eq 0 ]]; then usage fi -while getopts "s:d:i:" opt "$@" ; do +while getopts "j:s:d:i:" opt "$@" ; do case "$opt" in + j) job_count="${OPTARG:-}";; s) source_ref="${OPTARG:-}";; d) dest_ref="${OPTARG:-}";; i) ignore_ref="${OPTARG:-}";; @@ -42,7 +46,7 @@ function build_executor() { make distclean >/dev/null 2>&1 git checkout $revision >/dev/null 2>&1 || { echo "Failed to check out revision ${revision}" >&2 ; exit 1 ; } - make -j $keyboard_target >/dev/null 2>&1 || true + make -j${job_count} $keyboard_target >/dev/null 2>&1 || true file_size=$(arm-none-eabi-size .build/*.elf 2>&1 | awk '/elf/ {print $1}' 2>&1 || true) if [[ "$last_size" == 0 ]] ; then last_size=$file_size ; fi From 74431238419d9520dc12037bd04cf76f9fcf4bc5 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Sat, 27 Nov 2021 08:42:16 +1100 Subject: [PATCH 5/8] Job count control, skip zeros (unless no build output), fix usage. --- util/size_regression.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/util/size_regression.sh b/util/size_regression.sh index 19a40a59d150..6bc0cac44ef6 100755 --- a/util/size_regression.sh +++ b/util/size_regression.sh @@ -6,17 +6,19 @@ job_count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu 2>/dev/nu source_ref="0.11.0" dest_ref="develop" ignore_ref="master" +unset skip_zero function usage() { - echo "Usage: $(basename "$0") [-s ] [-d ] [-u] planck/rev6:default" + echo "Usage: $(basename "$0") [-j ] [-s ] [-d ] [-n] planck/rev6:default" echo " -j : change the number of threads to execute with" - echo " defaults to \`$job_count\`." + echo " defaults to \`$job_count\`" echo " -s : use source commit, branch, tag, or sha1 to start the search" - echo " defaults to \`$source_ref\`." + echo " defaults to \`$source_ref\`" echo " -d : use destination commit, branch, tag, or sha1 to end the search" - echo " defaults to \`$dest_ref\`." + echo " defaults to \`$dest_ref\`" echo " -i : the branch to ignore refs from" - echo " defaults to \`$ignore_ref\`." + echo " defaults to \`$ignore_ref\`" + echo " -n : skips printing changes if the delta is zero" exit 1 } @@ -24,12 +26,13 @@ if [[ ${#} -eq 0 ]]; then usage fi -while getopts "j:s:d:i:" opt "$@" ; do +while getopts "j:s:d:i:n" opt "$@" ; do case "$opt" in j) job_count="${OPTARG:-}";; s) source_ref="${OPTARG:-}";; d) dest_ref="${OPTARG:-}";; i) ignore_ref="${OPTARG:-}";; + n) skip_zero=1;; \?) usage >&2; exit 1;; esac done @@ -47,14 +50,16 @@ function build_executor() { make distclean >/dev/null 2>&1 git checkout $revision >/dev/null 2>&1 || { echo "Failed to check out revision ${revision}" >&2 ; exit 1 ; } make -j${job_count} $keyboard_target >/dev/null 2>&1 || true - file_size=$(arm-none-eabi-size .build/*.elf 2>&1 | awk '/elf/ {print $1}' 2>&1 || true) + file_size=$(arm-none-eabi-size .build/*.elf 2>/dev/null | awk '/elf/ {print $1}' 2>/dev/null || true) if [[ "$last_size" == 0 ]] ; then last_size=$file_size ; fi if [[ -z "$file_size" ]] ; then file_size=0 ; fi if [[ -n "$last_line" ]] ; then size_delta=$(( $last_size - $file_size )) - printf "Size: %8d, delta: %+6d -- %s\n" "$last_size" "$size_delta" "$last_line" + if { [[ -n "${skip_zero:-}" ]] && [[ $size_delta -ne 0 ]] ; } || [[ $file_size -eq 0 ]] ; then + printf "Size: %8d, delta: %+6d -- %s\n" "$last_size" "$size_delta" "$last_line" + fi fi last_size=$file_size From 17ab14a514eba947b6f7f7ac48c38cff13863bfa Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Sat, 27 Nov 2021 08:47:03 +1100 Subject: [PATCH 6/8] Add usage under -h arg. --- util/size_regression.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/size_regression.sh b/util/size_regression.sh index 6bc0cac44ef6..4c999542009c 100755 --- a/util/size_regression.sh +++ b/util/size_regression.sh @@ -26,8 +26,9 @@ if [[ ${#} -eq 0 ]]; then usage fi -while getopts "j:s:d:i:n" opt "$@" ; do +while getopts "hj:s:d:i:n" opt "$@" ; do case "$opt" in + h) usage; exit 0;; j) job_count="${OPTARG:-}";; s) source_ref="${OPTARG:-}";; d) dest_ref="${OPTARG:-}";; From 472a32ddec22b079c5fdebd6505728c120a8290f Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Sat, 27 Nov 2021 08:48:50 +1100 Subject: [PATCH 7/8] Updated usage output. --- util/size_regression.sh | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/util/size_regression.sh b/util/size_regression.sh index 4c999542009c..7fc2e1a7c3ff 100755 --- a/util/size_regression.sh +++ b/util/size_regression.sh @@ -9,16 +9,13 @@ ignore_ref="master" unset skip_zero function usage() { - echo "Usage: $(basename "$0") [-j ] [-s ] [-d ] [-n] planck/rev6:default" - echo " -j : change the number of threads to execute with" - echo " defaults to \`$job_count\`" - echo " -s : use source commit, branch, tag, or sha1 to start the search" - echo " defaults to \`$source_ref\`" - echo " -d : use destination commit, branch, tag, or sha1 to end the search" - echo " defaults to \`$dest_ref\`" - echo " -i : the branch to ignore refs from" - echo " defaults to \`$ignore_ref\`" - echo " -n : skips printing changes if the delta is zero" + echo "Usage: $(basename "$0") [-h] [-j ] [-s ] [-d ] [-n] planck/rev6:default" + echo " -h : Shows this usage page." + echo " -j : Change the number of threads to execute with. Defaults to \`$job_count\`." + echo " -s : Use source commit, branch, tag, or sha1 to start the search. Defaults to \`$source_ref\`." + echo " -d : Use destination commit, branch, tag, or sha1 to end the search. Defaults to \`$dest_ref\`." + echo " -i : The branch to ignore refs from. Defaults to \`$ignore_ref\`." + echo " -n : Skips printing changes if the delta is zero." exit 1 } From 653c3532db138afdd2a606f7d59e9a85e4646e33 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Sat, 27 Nov 2021 09:06:43 +1100 Subject: [PATCH 8/8] Copyright header. --- util/size_regression.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/size_regression.sh b/util/size_regression.sh index 7fc2e1a7c3ff..988d1d9b5bed 100755 --- a/util/size_regression.sh +++ b/util/size_regression.sh @@ -1,5 +1,8 @@ #!/bin/bash +# Copyright 2021 Nick Brassel (@tzarc) +# SPDX-License-Identifier: GPL-2.0-or-later + set -eEuo pipefail job_count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)