forked from kieker-monitoring/moobench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common-functions.sh
executable file
·298 lines (267 loc) · 6.27 KB
/
common-functions.sh
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/bash
#
# Common functions used in scripts.
#
# ensure the script is sourced
if [ "${BASH_SOURCE[0]}" -ef "$0" ]
then
echo "Hey, you should source this script, not execute it!"
exit 1
fi
#
# functions
#
function getSum {
awk '{sum += $1; square += $1^2} END {print "Average: "sum/NR" Standard Deviation: "sqrt(square / NR - (sum/NR)^2)" Count: "NR}'
}
## Clean up raw results
function cleanupResults() {
zip -jqr ${RESULTS_DIR}/results.zip ${RAWFN}*
rm -f ${RAWFN}*
[ -f ${DATA_DIR}/nohup.out ] && cp ${DATA_DIR}/nohup.out ${RESULTS_DIR}
[ -f ${DATA_DIR}/nohup.out ] && > ${DATA_DIR}/nohup.out
}
function createRLabels() {
# Create R labels
LABELS=""
for I in "${TITLE[@]}"
do
title="$I"
if [ "$LABELS" == "" ] ; then
LABELS="\"$title\""
else
LABELS="${LABELS}, \"$title\""
fi
done
echo $LABELS
}
## Generate Results file
function runStatistics() {
if [ "${TOTAL_NUM_OF_CALLS}" == 1 ] ; then
export SKIP=0
else
export SKIP=${TOTAL_NUM_OF_CALLS}/2
fi
INDICES=$(echo $MOOBENCH_CONFIGURATIONS | tr " " ",")
echo "Indices: $INDICES"
R --vanilla --silent << EOF
results_fn="${RAWFN}"
out_yaml_fn="${RESULTS_DIR}/results.yaml"
configs.loop=${NUM_OF_LOOPS}
configs.recursion=${RECURSION_DEPTH}
configs.labels=c($LABELS)
configs.framework_name="${FRAMEWORK_NAME}"
configs.indices=c($INDICES)
results.count=${TOTAL_NUM_OF_CALLS}
results.skip=${SKIP}
source("${RSCRIPT_PATH}")
EOF
}
function startZipkin {
if [ ! -d "${BASE_DIR}/zipkin" ] || [ ! -f "${BASE_DIR}/zipkin/zipkin.jar" ]
then
mkdir -p "${BASE_DIR}/zipkin"
cd "${BASE_DIR}/zipkin"
curl -sSL https://zipkin.io/quickstart.sh | bash -s
else
cd "${BASE_DIR}/zipkin"
fi
java -Xmx6g -jar "${BASE_DIR}/zipkin/zipkin.jar" &> "${BASE_DIR}/zipkin/zipkin.txt" &
pid=$!
sleep 5
cd "${BASE_DIR}"
}
function periodicallyCurlPrometheus {
PROMETHEUS_PORT=9464
sleep 5
while [ true ]
do
echo "Curling for prometheus simulation..."
curl localhost:$PROMETHEUS_PORT/metrics
sleep 15
done
}
function startPrometheus {
periodicallyCurlPrometheus &
pid=$!
}
function stopBackgroundProcess {
kill $pid
}
function writeConfiguration() {
uname -a > "${RESULTS_DIR}/configuration.txt"
"${JAVA_BIN}" "${JAVA_ARGS}" -version 2>> "${RESULTS_DIR}/configuration.txt"
cat << EOF >> "${RESULTS_DIR}/configuration.txt"
JAVA_ARGS: ${JAVA_ARGS}
Runtime: circa ${TIME} seconds
SLEEP_TIME=${SLEEP_TIME}
NUM_OF_LOOPS=${NUM_OF_LOOPS}
TOTAL_NUM_OF_CALLS=${TOTAL_NUM_OF_CALLS}
METHOD_TIME=${METHOD_TIME}
THREADS=${THREADS}
RECURSION_DEPTH=${RECURSION_DEPTH}
EOF
sync
}
function printIntermediaryResults {
loop="$1"
for index in $MOOBENCH_CONFIGURATIONS
do
RESULT_FILE="${RAWFN}-${loop}-${RECURSION_DEPTH}-${index}.csv"
checkFile result "${RESULT_FILE}"
raw_length=`cat "${RESULT_FILE}" | wc -l`
if [ "${raw_length}" == "0" ] ; then
error "Result file '${RESULT_FILE}' is empty."
exit 1
fi
CALLS_AFTER_WARMUP=$(($raw_length / 2))
info_n "Intermediary results "${TITLE[$index]}" (in ns) "
cat "${RESULT_FILE}" | awk -F';' '{print $2}' | getSum | tr "\n" " "
tail -n $CALLS_AFTER_WARMUP "${RESULT_FILE}" | awk -F';' '{print $2}' | getSum
done
}
function checkMoobenchConfiguration {
for configurationId in $MOOBENCH_CONFIGURATIONS
do
echo "Checking: $configurationId"
label="${TITLE[$configurationId]}"
echo "Label: $label"
if [ -z "$label" ]
then
echo "Configuration is not defined: $configurationId"
exit 1
fi
done
}
#
# reporting
#
export RED='\033[1;31m'
export WHITE='\033[1;37m'
export YELLOW='\033[1;33m'
export NC='\033[0m'
if [ "$BATCH_MODE" == "yes" ] ; then
export ERROR="[error]"
export WARNING="[warning]"
export INFO="[info]"
export DEBUG_INFO="[debug]"
else
export ERROR="${RED}[error]${NC}"
export WARNING="${YELLOW}[warning]${NC}"
export INFO="${WHITE}[info]${NC}"
export DEBUG_INFO="${WHITE}[debug]${NC}"
fi
function error() {
echo -e "${ERROR} $@"
if [ "${_STOP_ON_ERROR}" == "true" ] ; then
exit 1
fi
}
function warn() {
echo -e "${WARNING} $@"
}
function info() {
echo -e "${INFO} $@"
}
function info_n() {
echo -n -e "${INFO} $@"
}
function debug() {
if [ "${DEBUG}" == "yes" ] ; then
echo -e "${DEBUG_INFO} $@"
fi
}
# $1 = NAME, $2 = EXECUTABLE
function checkExecutable() {
if [ "$2" == "" ] ; then
error "$1 variable for executable not set."
exit 1
fi
if [ ! -x "$2" ] ; then
error "$1 not found at: $2"
exit 1
fi
}
# $1 = NAME, $2 = FILE
function checkFile() {
if [ "$2" == "" ] ; then
error "$1 variable for file not set."
exit 1
fi
if [ ! -f "$2" ] ; then
if [ "$3" == "clean" ] ; then
touch "$2"
else
error "$1 not found at: $2"
exit 1
fi
else
if [ "$3" == "clean" ] ; then
info "$1 recreated, now empty"
rm -f "$2"
touch "$2"
fi
fi
}
# $1 = NAME, $2 = FILE
function checkDirectory() {
if [ "$2" == "" ] ; then
error "$1 directory variable not set."
exit 1
fi
if [ ! -d "$2" ] ; then
if [ "$3" == "create" ] || [ "$3" == "recreate" ] ; then
info "$1: directory does not exist, creating it"
mkdir -p "$2"
else
error "$1: directory $2 does not exist."
exit 1
fi
else
if [ "$3" == "recreate" ] ; then
info "$1: exists, recreating it"
rm -rf "$2"
mkdir -p "$2"
fi
fi
}
function showParameter() {
info "FRAMEWORK_NAME ${FRAMEWORK_NAME}"
info "MOOBENCH_CONFIGURATIONS ${MOOBENCH_CONFIGURATIONS}"
info "RESULTS_DIR ${RESULTS_DIR}"
info "RAWFN ${RAWFN}"
info "JAVA_BIN ${JAVA_BIN}"
info "SLEEP_TIME ${SLEEP_TIME}"
info "NUM_OF_LOOPS ${NUM_OF_LOOPS}"
info "THREADS ${THREADS}"
info "RECURSION_DEPTH ${RECURSION_DEPTH}"
info "TOTAL_NUM_OF_CALLS ${TOTAL_NUM_OF_CALLS}"
info "METHOD_TIME ${METHOD_TIME}"
info "DEBUG ${DEBUG}"
}
FRAMEWORK_NAME=$(basename -- "${BASE_DIR}")
RESULTS_DIR="${BASE_DIR}/results-$FRAMEWORK_NAME"
RAWFN="${RESULTS_DIR}/raw"
# Initialize all unset parameters
if [ -z $SLEEP_TIME ]; then
SLEEP_TIME=30 ## 30
fi
if [ -z $NUM_OF_LOOPS ]; then
NUM_OF_LOOPS=10 ## 10
fi
if [ -z $THREADS ]; then
THREADS=1 ## 1
fi
if [ -z $RECURSION_DEPTH ]; then
RECURSION_DEPTH=10 ## 10
fi
if [ -z $TOTAL_NUM_OF_CALLS ]; then
TOTAL_NUM_OF_CALLS=2000000 ## 2000000
fi
if [ -z $METHOD_TIME ]; then
METHOD_TIME=0 ## 500000
fi
if [ -z $DEBUG ]; then
DEBUG=false ## false
fi
# end