-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbenchmark.sh
More file actions
executable file
·190 lines (149 loc) · 6.1 KB
/
benchmark.sh
File metadata and controls
executable file
·190 lines (149 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env bash
set -e
export LC_ALL=C
export PROJECT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [[ "$1" == "run" ]]; then
if [[ "$2" == "aws" ]]; then
INFRA_ENVIRONMENT="aws"
else
echo "Available environments: aws"
exit 1
fi
infra_count="$(ls 2>/dev/null -Ubad1 -- $PROJECT_ROOT/config/infra/$INFRA_ENVIRONMENT/*.ini | wc -l)"
infra_count="$(echo "$infra_count" | awk '{$1=$1;print}')"
if [ "$infra_count" -eq "0" ]; then
echo "The $PROJECT_ROOT/config/infra/$INFRA_ENVIRONMENT directory should contain at least one .ini file in order to be able to run the benchmark"
exit 1
fi
php_count="$(ls 2>/dev/null -Ubad1 -- $PROJECT_ROOT/config/php/*.ini | wc -l)"
php_count="$(echo "$php_count" | awk '{$1=$1;print}')"
if [ "$php_count" -eq "0" ]; then
echo "The $PROJECT_ROOT/config/php directory should contain at least one .ini file in order to be able to run the benchmark"
exit 1
fi
test_count="$(ls 2>/dev/null -Ubad1 -- $PROJECT_ROOT/config/test/*.ini | wc -l)"
test_count="$(echo "$test_count" | awk '{$1=$1;print}')"
if [ "$test_count" -eq "0" ]; then
echo "The $PROJECT_ROOT/config/test directory should contain at least one .ini file in order to be able to run the benchmark"
exit 1
fi
export N="${3:-1}"
NOW="$(TZ=UTC date +'%Y-%m-%d %H:%M:%S')"
export NOW
DRY_RUN="0";
if [[ "$4" == "dry-run" ]]; then
DRY_RUN="1"
fi
export DRY_RUN
RESULT_ROOT_DIR="${NOW//-/_}"
RESULT_ROOT_DIR="${RESULT_ROOT_DIR// /_}"
RESULT_ROOT_DIR="${RESULT_ROOT_DIR//:/_}"
RESULT_ROOT_DIR="$(echo "$NOW" | cut -c 1-4)/$RESULT_ROOT_DIR"
export RESULT_ROOT_DIR
export INFRA_ENVIRONMENT
for infra_config in $PROJECT_ROOT/config/infra/$INFRA_ENVIRONMENT/*.ini; do
source "$infra_config"
export $(cut -d= -f1 $infra_config)
$PROJECT_ROOT/bin/build.sh "local"
done
for php_config in $PROJECT_ROOT/config/php/*.ini; do
source "$php_config"
if [ -z "$PHP_BASE_ID" ]; then
export PHP_SOURCE_PATH="$PROJECT_ROOT/tmp/$PHP_ID"
else
export PHP_SOURCE_PATH="$PROJECT_ROOT/tmp/$PHP_BASE_ID"
fi
export "PHP_COMMITS_$PHP_ID=$(git -C "$PHP_SOURCE_PATH" rev-parse HEAD)"
done
for RUN in $(seq "$N"); do
export RUN
for infra_config in $PROJECT_ROOT/config/infra/$INFRA_ENVIRONMENT/*.ini; do
source "$infra_config"
export $(cut -d= -f1 $infra_config)
$PROJECT_ROOT/bin/provision.sh
done
done
elif [[ "$1" == "ssh" ]]; then
host_dns_file="$PROJECT_ROOT/tmp/host_dns.txt"
if [ ! -f "$host_dns_file" ]; then
echo "Instance is not yet running"
exit 1;
fi
private_key_file="$PROJECT_ROOT/tmp/ssh-key.pem"
if [ ! -f "$private_key_file" ]; then
echo "Instance is not yet running"
exit 1;
fi
host_dns="$(cat "$host_dns_file")"
ssh -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=no -o ConnectTimeout=10 -i "$private_key_file" "ec2-user@$host_dns" "$2"
elif [[ "$1" == "bisect" ]]; then
if [[ $# -ne 2 ]]; then
echo "Usage: ./benchmark.sh bisect <php_bisect_template_name>"
exit 1
fi
php_bisect_template_name="$2"
php_bisect_template_file="$PROJECT_ROOT/config/php/$php_bisect_template_name.bisect"
if [ ! -f "$php_bisect_template_file" ]; then
echo "The $php_bisect_template_file bisect template file doesn't exist"
exit 1;
fi
source "$php_bisect_template_file"
export $(cut -d= -f1 $php_bisect_template_file)
export PHP_SOURCE_PATH="$PROJECT_ROOT/tmp/$PHP_ID"
if [ ! -z "$PHP_COMMIT" ]; then
echo "The PHP_COMMIT config option is not supported"
exit 1;
fi
if ! [[ "$PHP_BISECT_PARTS" =~ ^[0-9]+$ ]] || [[ "$PHP_BISECT_PARTS" -lt 2 ]]; then
echo "PHP_BISECT_PARTS must be an integer >= 2"
exit 1
fi
if [ ! -d "$PHP_SOURCE_PATH" ]; then
$PROJECT_ROOT/build/script/php_source.sh "local"
else
git --git-dir="$PHP_SOURCE_PATH/.git" --work-tree="$PHP_SOURCE_PATH" fetch
fi
# Collect commits (oldest -> newest)
php_bisect_commits=()
php_bisect_commits+=("$PHP_BISECT_COMMIT_FROM")
while IFS= read -r commit; do
php_bisect_commits+=("$commit")
done < <(git --git-dir="$PHP_SOURCE_PATH/.git" --work-tree="$PHP_SOURCE_PATH" rev-list --ancestry-path --reverse "$PHP_BISECT_COMMIT_FROM..$PHP_BISECT_COMMIT_TO")
php_bisect_commits_total="${#php_bisect_commits[@]}"
if [[ "$php_bisect_commits_total" -lt "$PHP_BISECT_PARTS" ]]; then
echo "Not enough php_bisect_commits ($php_bisect_commits_total) for PHP_BISECT_PARTS=$PHP_BISECT_PARTS"
exit 1
fi
echo "Total php_bisect_commits: $php_bisect_commits_total"
echo "Generating $PHP_BISECT_PARTS checkpoints"
php_bisect_source_path="$PHP_SOURCE_PATH"
# Evenly distributed index
for ((i=0; i<$PHP_BISECT_PARTS; i++)); do
i_1="$((i + 1))"
index="$(( (i * (php_bisect_commits_total - 1) + ($PHP_BISECT_PARTS - 1) / 2) / ($PHP_BISECT_PARTS - 1) ))"
php_bisect_commit="${php_bisect_commits[$index]}"
php_bisect_ini_file="${php_bisect_template_file}_${i_1}.ini"
PHP_SOURCE_PATH="${php_bisect_source_path}_${i_1}"
cat <<EOF > "$php_bisect_ini_file"
PHP_NAME="$PHP_NAME ${i_1}"
PHP_ID=${PHP_ID}_${i_1}
PHP_BASE_ID=$PHP_BASE_ID
PHP_REPO=$PHP_REPO
PHP_BRANCH=$PHP_BRANCH
PHP_COMMIT=$php_bisect_commit
PHP_JIT=$PHP_JIT
EOF
echo "Created bisect config \"$PHP_NAME ${i_1}\" for commit $php_bisect_commit"
echo "Checking out source..."
rm -rf "$PHP_SOURCE_PATH"
cp -r "$php_bisect_source_path" "$PHP_SOURCE_PATH"
git --git-dir="$PHP_SOURCE_PATH/.git" --work-tree="$PHP_SOURCE_PATH" checkout --detach "$php_bisect_commit"
done
elif [[ "$1" == "help" ]]; then
echo "Usage: ./benchmark.sh run [environment] [runs] [dry-run]"
echo ""
echo "Available runners: aws"
else
echo 'Available subcommands: "run", "ssh", "bisect", "help"!'
exit 1
fi