aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2021-11-27 09:11:03 +1100
committerGitHub <noreply@github.com>2021-11-27 09:11:03 +1100
commitb04f66f2452494206673323c9495ea6a56c0cb06 (patch)
treec82c3ef299cc794f14294ea250275aa61e88f4ad
parent08b7f8b30a61a59ed52dba5d0b306ebaeb627095 (diff)
downloadqmk_firmware-b04f66f2452494206673323c9495ea6a56c0cb06.tar.gz
qmk_firmware-b04f66f2452494206673323c9495ea6a56c0cb06.zip
Add script for performing compilation size regression investigations. (#15303)
* Add script for performing compilation size regression investigations. * Print deltas * Correct scoping. * Concurrency control * Job count control, skip zeros (unless no build output), fix usage. * Add usage under -h arg. * Updated usage output. * Copyright header.
-rwxr-xr-xutil/size_regression.sh79
1 files changed, 79 insertions, 0 deletions
diff --git a/util/size_regression.sh b/util/size_regression.sh
new file mode 100755
index 000000000..988d1d9b5
--- /dev/null
+++ b/util/size_regression.sh
@@ -0,0 +1,79 @@
1#!/bin/bash
2
3# Copyright 2021 Nick Brassel (@tzarc)
4# SPDX-License-Identifier: GPL-2.0-or-later
5
6set -eEuo pipefail
7
8job_count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
9source_ref="0.11.0"
10dest_ref="develop"
11ignore_ref="master"
12unset skip_zero
13
14function usage() {
15 echo "Usage: $(basename "$0") [-h] [-j <jobs>] [-s <source>] [-d <dest>] [-n] planck/rev6:default"
16 echo " -h : Shows this usage page."
17 echo " -j <threads> : Change the number of threads to execute with. Defaults to \`$job_count\`."
18 echo " -s <source> : Use source commit, branch, tag, or sha1 to start the search. Defaults to \`$source_ref\`."
19 echo " -d <dest> : Use destination commit, branch, tag, or sha1 to end the search. Defaults to \`$dest_ref\`."
20 echo " -i <ignore> : The branch to ignore refs from. Defaults to \`$ignore_ref\`."
21 echo " -n : Skips printing changes if the delta is zero."
22 exit 1
23}
24
25if [[ ${#} -eq 0 ]]; then
26 usage
27fi
28
29while getopts "hj:s:d:i:n" opt "$@" ; do
30 case "$opt" in
31 h) usage; exit 0;;
32 j) job_count="${OPTARG:-}";;
33 s) source_ref="${OPTARG:-}";;
34 d) dest_ref="${OPTARG:-}";;
35 i) ignore_ref="${OPTARG:-}";;
36 n) skip_zero=1;;
37 \?) usage >&2; exit 1;;
38 esac
39done
40
41# Work out the target board
42shift $((OPTIND-1))
43keyboard_target=$1
44
45last_size=0
46last_line=""
47function build_executor() {
48 git rev-list --oneline --no-merges ${source_ref}...${dest_ref} ^${ignore_ref} | while IFS= read -r line ; do
49 revision=$(echo $line | cut -d' ' -f1)
50
51 make distclean >/dev/null 2>&1
52 git checkout $revision >/dev/null 2>&1 || { echo "Failed to check out revision ${revision}" >&2 ; exit 1 ; }
53 make -j${job_count} $keyboard_target >/dev/null 2>&1 || true
54 file_size=$(arm-none-eabi-size .build/*.elf 2>/dev/null | awk '/elf/ {print $1}' 2>/dev/null || true)
55
56 if [[ "$last_size" == 0 ]] ; then last_size=$file_size ; fi
57 if [[ -z "$file_size" ]] ; then file_size=0 ; fi
58
59 if [[ -n "$last_line" ]] ; then
60 size_delta=$(( $last_size - $file_size ))
61 if { [[ -n "${skip_zero:-}" ]] && [[ $size_delta -ne 0 ]] ; } || [[ $file_size -eq 0 ]] ; then
62 printf "Size: %8d, delta: %+6d -- %s\n" "$last_size" "$size_delta" "$last_line"
63 fi
64 fi
65
66 last_size=$file_size
67 last_line=$line
68 done
69
70 if [ -n "$last_line" ] ; then
71 size_delta=0
72 printf "Size: %8d, delta: %+6d -- %s\n" "$last_size" "$size_delta" "$last_line"
73 fi
74}
75
76# The actual execution of all the builds needs to be the last command in the entire script
77# - During builds, this script file will disappear, so we need the entire script to be
78# loaded into the script interpreter at the time of execution. Do not refactor.
79build_executor