diff options
author | Nick Brassel <nick@tzarc.org> | 2021-11-27 09:11:03 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-27 09:11:03 +1100 |
commit | b04f66f2452494206673323c9495ea6a56c0cb06 (patch) | |
tree | c82c3ef299cc794f14294ea250275aa61e88f4ad | |
parent | 08b7f8b30a61a59ed52dba5d0b306ebaeb627095 (diff) | |
download | qmk_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-x | util/size_regression.sh | 79 |
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 | |||
6 | set -eEuo pipefail | ||
7 | |||
8 | job_count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2) | ||
9 | source_ref="0.11.0" | ||
10 | dest_ref="develop" | ||
11 | ignore_ref="master" | ||
12 | unset skip_zero | ||
13 | |||
14 | function 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 | |||
25 | if [[ ${#} -eq 0 ]]; then | ||
26 | usage | ||
27 | fi | ||
28 | |||
29 | while 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 | ||
39 | done | ||
40 | |||
41 | # Work out the target board | ||
42 | shift $((OPTIND-1)) | ||
43 | keyboard_target=$1 | ||
44 | |||
45 | last_size=0 | ||
46 | last_line="" | ||
47 | function 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. | ||
79 | build_executor | ||