]> git.ipfire.org Git - thirdparty/git.git/blame - t/perf/run
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / perf / run
CommitLineData
342e9ef2
TR
1#!/bin/sh
2
8796b307
CC
3die () {
4 echo >&2 "error: $*"
5 exit 1
6}
7
8while [ $# -gt 0 ]; do
9 arg="$1"
10 case "$arg" in
11 --)
12 break ;;
342e9ef2 13 --help)
8796b307
CC
14 echo "usage: $0 [--config file] [--subsection subsec] [other_git_tree...] [--] [test_scripts]"
15 exit 0 ;;
e3d5e120
CC
16 --config)
17 shift
18 GIT_PERF_CONFIG_FILE=$(cd "$(dirname "$1")"; pwd)/$(basename "$1")
19 export GIT_PERF_CONFIG_FILE
20 shift ;;
8796b307
CC
21 --subsection)
22 shift
23 GIT_PERF_SUBSECTION="$1"
24 export GIT_PERF_SUBSECTION
25 shift ;;
26 --*)
27 die "unrecognised option: '$arg'" ;;
28 *)
29 break ;;
30 esac
31done
342e9ef2
TR
32
33run_one_dir () {
34 if test $# -eq 0; then
35 set -- p????-*.sh
36 fi
37 echo "=== Running $# tests in ${GIT_TEST_INSTALLED:-this tree} ==="
38 for t in "$@"; do
39 ./$t $GIT_TEST_OPTS
40 done
41}
42
43unpack_git_rev () {
44 rev=$1
b11ad029 45 echo "=== Unpacking $rev in build/$rev ==="
342e9ef2
TR
46 mkdir -p build/$rev
47 (cd "$(git rev-parse --show-cdup)" && git archive --format=tar $rev) |
48 (cd build/$rev && tar x)
49}
e6b71539 50
342e9ef2
TR
51build_git_rev () {
52 rev=$1
ffdd0107 53 name="$2"
cd5c2812
KS
54 for config in config.mak config.mak.autogen config.status
55 do
56 if test -e "../../$config"
57 then
58 cp "../../$config" "build/$rev/"
59 fi
60 done
ffdd0107 61 echo "=== Building $rev ($name) ==="
88b6197d
ÆAB
62 (
63 cd build/$rev &&
64 if test -n "$GIT_PERF_MAKE_COMMAND"
65 then
66 sh -c "$GIT_PERF_MAKE_COMMAND"
67 else
68 make $GIT_PERF_MAKE_OPTS
69 fi
70 ) || die "failed to build revision '$mydir'"
342e9ef2
TR
71}
72
df0f5021
ÆAB
73set_git_test_installed () {
74 mydir=$1
75
76 mydir_abs=$(cd $mydir && pwd)
f9d65b04 77 mydir_abs_wrappers="$mydir_abs/bin-wrappers"
df0f5021
ÆAB
78 if test -d "$mydir_abs_wrappers"
79 then
80 GIT_TEST_INSTALLED=$mydir_abs_wrappers
81 else
82 # Older versions of git lacked bin-wrappers;
83 # fallback to the files in the root.
84 GIT_TEST_INSTALLED=$mydir_abs
85 fi
86 export GIT_TEST_INSTALLED
82b7eb23
ÆAB
87 PERF_SET_GIT_TEST_INSTALLED=true
88 export PERF_SET_GIT_TEST_INSTALLED
df0f5021
ÆAB
89}
90
342e9ef2
TR
91run_dirs_helper () {
92 mydir=${1%/}
93 shift
94 while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
95 shift
96 done
97 if test $# -gt 0 -a "$1" = --; then
98 shift
99 fi
df0f5021
ÆAB
100
101 PERF_RESULTS_PREFIX=
102 if test "$mydir" = "."
103 then
104 unset GIT_TEST_INSTALLED
105 elif test -d "$mydir"
106 then
fab80ee7 107 PERF_RESULTS_PREFIX=bindir$(cd $mydir && printf "%s" "$(pwd)" | tr -c "[a-zA-Z0-9]" "_").
df0f5021
ÆAB
108 set_git_test_installed "$mydir"
109 else
342e9ef2
TR
110 rev=$(git rev-parse --verify "$mydir" 2>/dev/null) ||
111 die "'$mydir' is neither a directory nor a valid revision"
112 if [ ! -d build/$rev ]; then
113 unpack_git_rev $rev
114 fi
ffdd0107 115 build_git_rev $rev "$mydir"
342e9ef2 116 mydir=build/$rev
90e38154 117
df0f5021
ÆAB
118 PERF_RESULTS_PREFIX=build_$rev.
119 set_git_test_installed "$mydir"
342e9ef2 120 fi
df0f5021
ÆAB
121 export PERF_RESULTS_PREFIX
122
342e9ef2
TR
123 run_one_dir "$@"
124}
125
126run_dirs () {
127 while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
128 run_dirs_helper "$@"
129 shift
130 done
131}
132
2638441e
CC
133get_subsections () {
134 section="$1"
135 test -z "$GIT_PERF_CONFIG_FILE" && return
136 git config -f "$GIT_PERF_CONFIG_FILE" --name-only --get-regex "$section\..*\.[^.]+" |
137 sed -e "s/$section\.\(.*\)\..*/\1/" | sort | uniq
138}
139
e6b71539
CC
140get_var_from_env_or_config () {
141 env_var="$1"
9ba95ed2
CC
142 conf_sec="$2"
143 conf_var="$3"
3ae7d2b0 144 conf_opts="$4" # optional
e6b71539
CC
145
146 # Do nothing if the env variable is already set
147 eval "test -z \"\${$env_var+x}\"" || return
148
9ba95ed2
CC
149 test -z "$GIT_PERF_CONFIG_FILE" && return
150
e6b71539 151 # Check if the variable is in the config file
9ba95ed2
CC
152 if test -n "$GIT_PERF_SUBSECTION"
153 then
154 var="$conf_sec.$GIT_PERF_SUBSECTION.$conf_var"
3ae7d2b0 155 conf_value=$(git config $conf_opts -f "$GIT_PERF_CONFIG_FILE" "$var") &&
9ba95ed2
CC
156 eval "$env_var=\"$conf_value\"" && return
157 fi
158 var="$conf_sec.$conf_var"
3ae7d2b0 159 conf_value=$(git config $conf_opts -f "$GIT_PERF_CONFIG_FILE" "$var") &&
53ba2c79 160 eval "$env_var=\"$conf_value\""
e6b71539
CC
161}
162
afda85c2 163run_subsection () {
53ba2c79
RS
164 get_var_from_env_or_config "GIT_PERF_REPEAT_COUNT" "perf" "repeatCount" "--int"
165 : ${GIT_PERF_REPEAT_COUNT:=3}
afda85c2 166 export GIT_PERF_REPEAT_COUNT
e6b71539 167
afda85c2
CC
168 get_var_from_env_or_config "GIT_PERF_DIRS_OR_REVS" "perf" "dirsOrRevs"
169 set -- $GIT_PERF_DIRS_OR_REVS "$@"
91c4339e 170
afda85c2
CC
171 get_var_from_env_or_config "GIT_PERF_MAKE_COMMAND" "perf" "makeCommand"
172 get_var_from_env_or_config "GIT_PERF_MAKE_OPTS" "perf" "makeOpts"
948e22e2 173
ba1b117e
VD
174 get_var_from_env_or_config "GIT_PERF_USE_SCALAR" "perf" "useScalar" "--bool"
175 export GIT_PERF_USE_SCALAR
176
19cf57a9
CC
177 get_var_from_env_or_config "GIT_PERF_REPO_NAME" "perf" "repoName"
178 export GIT_PERF_REPO_NAME
179
afda85c2
CC
180 GIT_PERF_AGGREGATING_LATER=t
181 export GIT_PERF_AGGREGATING_LATER
182
183 if test $# = 0 -o "$1" = -- -o -f "$1"; then
184 set -- . "$@"
185 fi
186
5d6bb930
CC
187 codespeed_opt=
188 test "$GIT_PERF_CODESPEED_OUTPUT" = "true" && codespeed_opt="--codespeed"
189
afda85c2 190 run_dirs "$@"
fccec20f
CC
191
192 if test -z "$GIT_PERF_SEND_TO_CODESPEED"
193 then
3663e590 194 ./aggregate.perl --results-dir="$TEST_RESULTS_DIR" $codespeed_opt "$@"
fccec20f 195 else
3663e590
PS
196 json_res_file=""$TEST_RESULTS_DIR"/$GIT_PERF_SUBSECTION/aggregate.json"
197 ./aggregate.perl --results-dir="$TEST_RESULTS_DIR" --codespeed "$@" | tee "$json_res_file"
fccec20f
CC
198 send_data_url="$GIT_PERF_SEND_TO_CODESPEED/result/add/json/"
199 curl -v --request POST --data-urlencode "json=$(cat "$json_res_file")" "$send_data_url"
200 fi
afda85c2 201}
342e9ef2 202
5d6bb930 203get_var_from_env_or_config "GIT_PERF_CODESPEED_OUTPUT" "perf" "codespeedOutput" "--bool"
fccec20f 204get_var_from_env_or_config "GIT_PERF_SEND_TO_CODESPEED" "perf" "sendToCodespeed"
5d6bb930 205
342e9ef2
TR
206cd "$(dirname $0)"
207. ../../GIT-BUILD-OPTIONS
208
3663e590
PS
209if test -n "$TEST_OUTPUT_DIRECTORY"
210then
211 TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results"
212else
213 TEST_RESULTS_DIR=test-results
214fi
215
216mkdir -p "$TEST_RESULTS_DIR"
217get_subsections "perf" >"$TEST_RESULTS_DIR"/run_subsections.names
afda85c2 218
3663e590 219if test $(wc -l <"$TEST_RESULTS_DIR"/run_subsections.names) -eq 0
afda85c2 220then
8796b307
CC
221 if test -n "$GIT_PERF_SUBSECTION"
222 then
223 if test -n "$GIT_PERF_CONFIG_FILE"
224 then
225 die "no subsections are defined in config file '$GIT_PERF_CONFIG_FILE'"
226 else
227 die "subsection '$GIT_PERF_SUBSECTION' defined without a config file"
228 fi
229 fi
afda85c2
CC
230 (
231 run_subsection "$@"
232 )
8796b307
CC
233elif test -n "$GIT_PERF_SUBSECTION"
234then
81580fa0 235 grep -E "^$GIT_PERF_SUBSECTION\$" "$TEST_RESULTS_DIR"/run_subsections.names >/dev/null ||
8796b307
CC
236 die "subsection '$GIT_PERF_SUBSECTION' not found in '$GIT_PERF_CONFIG_FILE'"
237
81580fa0 238 grep -E "^$GIT_PERF_SUBSECTION\$" "$TEST_RESULTS_DIR"/run_subsections.names | while read -r subsec
8796b307
CC
239 do
240 (
241 GIT_PERF_SUBSECTION="$subsec"
242 export GIT_PERF_SUBSECTION
243 echo "======== Run for subsection '$GIT_PERF_SUBSECTION' ========"
244 run_subsection "$@"
245 )
246 done
afda85c2
CC
247else
248 while read -r subsec
249 do
250 (
251 GIT_PERF_SUBSECTION="$subsec"
252 export GIT_PERF_SUBSECTION
253 echo "======== Run for subsection '$GIT_PERF_SUBSECTION' ========"
254 run_subsection "$@"
255 )
3663e590 256 done <"$TEST_RESULTS_DIR"/run_subsections.names
342e9ef2 257fi