forked from chazy/kvmperf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-all.sh
executable file
·545 lines (460 loc) · 11 KB
/
run-all.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
#!/bin/bash
source setup.sh
HOST_DIR=""
GUEST_DIR=""
GUEST_ALIVE=0
APACHE_STARTED=""
MYSQL_STARTED=""
POWER_PID=0
DO_POWER=0
echo "" > /tmp/kvmperf.log
trap 'early_exit; exit;' SIGINT SIGQUIT
early_exit()
{
echo ""
if [[ -n "$HOST_DIR" ]]; then
echo -n "Removing temporary directory on the host..."
$SSSH root@$HOST "umount $HOST_DIR/ram"
ssh root@$HOST "rm -rf $HOST_DIR"
echo "done"
fi
if [[ -n "$GUEST_DIR" ]]; then
echo -n "Removing temporary directory on the guest"
$SSSH root@$GUEST1 "umount $GUEST_DIR/ram"
ssh root@$GUEST1 "rm -rf $GUEST_DIR"
echo "done"
fi
if [[ -n "$APACHE_STARTED" ]]; then
echo -n "Stopping service apache2 on $APACHE_STARTED..."
$SSH 2>/dev/null 1>/dev/null root@$APACHE_STARTED "service apache2 stop"
echo "done"
fi
if [[ -n "$MYSQL_STARTED" ]]; then
echo -n "Stopping service mysql on $MYSQL_STARTED..."
$SSH 2>/dev/null 1>/dev/null root@$MYSQL_STARTED "service mysql stop"
echo "done"
fi
if [[ $GUEST_ALIVE == 1 ]]; then
echo -n "Shutting down VM..."
shutdown_guest
echo "done"
fi
if [[ ! $POWER_PID == 0 && "$TESTARCH" == "arm" ]]; then
echo -n "Shutting down power probe..."
$SSH root@$POWERHOST "pkill -SIGINT arm-probe"
sleep 1
kill $POWER_PID
POWER_PID=0
fi
echo "Exiting!"
exit 1
}
function start_guest()
{
GUEST_ALIVE=1
sleep 1
echo "Starting guest with command: $START_VM_COMMAND" | tee -a $LOGFILE
ssh -f root@$HOST 2>&1 >>$LOGFILE "sync; echo 3 > /proc/sys/vm/drop_caches"
sleep 5
ssh -f root@$HOST 2>&1 >>$LOGFILE "$START_VM_COMMAND"
if [[ ! $? == 0 ]]; then
echo "Error starting guest - check logfile!" >&2
return 1
fi
return 0
}
function shutdown_guest()
{
GUEST_ALIVE=0
echo "Shutting down guest" 2>&1 | tee -a $LOGFILE
ssh root@$GUEST1 "halt -p"
sleep 20
ssh root@$HOST "$SHUTDOWN_VM_COMMAND" 2>&1 | tee -a $LOGFILE
sleep 1
if [[ -n "$VM_CONSOLE" ]]; then
$SCP root@$HOST:$VM_CONSOLE /tmp/.
echo "VM Console:" >> $LOGFILE
cat /tmp/$(basename $VM_CONSOLE) >> $LOGFILE
fi
}
function wait_for_remote()
{
remote=$1
echo "Waiting for $remote to become alive" >> $LOGFILE
wait=1
timeout=120
while [[ $wait == 1 && $timeout -gt 0 ]]; do
ping -q -c 1 $remote > /dev/null
wait=$?
sleep 1
timeout=$(($timeout - 1))
done
if [[ $timeout == 0 ]]; then
return 1
else
sleep 20
return 0
fi
}
function set_remote_dir()
{
remote_dir="$1"
if [[ $GUEST_ALIVE == 0 ]]; then
HOST_DIR="$remote_dir"
else
GUEST_DIR="$remote_dir"
fi
}
#
# Run with common_test <unit under test> <dns/ip of machine> [<tool> ...]
#
function common_test()
{
uut="$1" # unit under test
remote="$2" # dns/ip for machine to test
shift 2
cmdname="$uut.sh"
rand=$RANDOM
remote_dir=/tmp/${uut}_${rand}
set_remote_dir "$remote_dir"
# Create remote directory, upload common scripts and tools
echo "Uploading common scripts and tools to $remote_dir" | tee -a $LOGFILE
ssh root@$remote "mkdir $remote_dir"
$SCP ".localconf" root@$remote:$remote_dir/.
$SCP "tests/common.sh" root@$remote:$remote_dir/.
$SCP "tests/power.sh" root@$remote:$remote_dir/.
$SCP "tests/$cmdname" root@$remote:$remote_dir/.
while [[ -n $1 ]]; do
file=`basename $1`
scp -q "$TOOLS/$file" root@$remote:$remote_dir/.
shift 1
done
if [[ $DO_POWER == 1 ]]; then
echo "Measuring power for $uut on $remote" | tee -a $LOGFILE
echo "DO_POWER=1" > /tmp/powerconf
echo "POWEROUT=\"$remote_dir\"" >> /tmp/powerconf
$SCP /tmp/powerconf root@$remote:$remote_dir/powerconf
fi
# Actually run the test command
rm -f /tmp/time.txt
echo "Going to actually run the test" | tee -a $LOGFILE
remote_cmd=""\
"chmod a+x $remote_dir/$cmdname && "\
"cd $remote_dir && "\
"./$cmdname"
$SSH -t root@$remote "$remote_cmd" 2>&1 | tee -a $LOGFILE
if [[ $? == 255 ]]; then
early_exit
fi
# Get time stats
echo "Downloading time stats" | tee -a $LOGFILE
$SCP root@$remote:$remote_dir/time.txt /tmp/time.txt
tr '\n' '\t' < /tmp/time.txt | tee -a $LOGFILE
echo "" | tee -a $LOGFILE
# Output in nice format as well
echo -en " $uut (${remote})\t" >> $OUTFILE
cat /tmp/time.txt | tr '\n' '\t' | tr '\r' ' ' >> $OUTFILE
echo "" >> $OUTFILE
# Get power stats
if [[ $DO_POWER == 1 ]]; then
rm -f /tmp/power.values.*
echo "Downloading power stats" | tee -a $LOGFILE
$SCP root@$remote:$remote_dir/power.values.* /tmp/.
echo -en " $uut (${remote} - power)\t" >> $OUTFILE
for powerfile in `ls -1 /tmp/power.values.*`; do
piter=`basename "$powefile" | awk -F . '{print $NF}'`
cat $powerfile | ./avg >> $OUTFILE
echo -en "\t" >> $OUTFILE
done
echo "" >> $OUTFILE
fi
# Clean up
echo "Cleaning up" | tee -a $LOGFILE
ssh root@$remote "umount $remote_dir/ram 2>/dev/null" | tee -a $LOGFILE
ssh root@$remote "rm -rf $remote_dir" | tee -a $LOGFILE
set_remote_dir ""
}
###########################################################################
# Here follows hackbench results
#
function hackbench_test()
{
common_test "$1" "$2" hackbench
}
function kernel_compile_test()
{
common_test "$1" "$2"
}
function untar_test()
{
common_test "$1" "$2"
}
function curl1k_test()
{
common_test "$1" "$2"
}
function curl1g_test()
{
common_test "$1" "$2"
}
function dd_write_test()
{
common_test "$1" "$2"
}
function dd_read_test()
{
uut="$1" # unit under test
remote="$2" # dns/ip for machine to test
ORIG_OUTFILE="$OUTFILE"
OUTFILE=/tmp/.results
echo -en " $uut (${remote})\t" >> $ORIG_OUTFILE
common_test "$1_prepare" "$2"
if [[ $GUEST_ALIVE == 0 ]]; then
for i in `seq 1 $REPTS`; do
ssh root@$remote "sync"
ssh root@$remote " sudo bash -c 'echo 3 > /proc/sys/vm/drop_caches'"
rm "$OUTFILE"
common_test "$1" "$2"
echo "================= reading content from $OUTFILE ============="
cat "$OUTFILE"
cat "$OUTFILE" | awk '{ print $3 }' | tr '\n' '\t' >> "$ORIG_OUTFILE"
ssh root@$remote "sync"
ssh root@$remote " sudo bash -c 'echo 3 > /proc/sys/vm/drop_caches'"
done
else
# VM must be rebooted between each run here
for i in `seq 1 $REPTS`; do
shutdown_guest
rm "$OUTFILE"
ssh root@$remote "sync"
ssh root@$remote " sudo bash -c 'echo 3 > /proc/sys/vm/drop_caches'"
start_guest
if [[ ! $? == 0 ]]; then
echo "Error starting guest - check logfile!" >&2
return 1
fi
wait_for_remote $GUEST1
if [[ ! $? == 0 ]]; then
echo "Guest didn't respond in a timely manner - check logfile!" >&2
return 1
fi
sleep 20
common_test "$1" "$2"
echo "================= reading content from $OUTFILE ============="
cat "$OUTFILE"
cat "$OUTFILE" | awk '{ print $3 }' | tr '\n' '\t' >> "$ORIG_OUTFILE"
done
fi
ssh root@$remote "rm -f /root/foo"
OUTFILE="$ORIG_OUTFILE"
echo "" >> $OUTFILE
}
function dd_rw_test()
{
common_test "$1" "$2"
}
function memcached_test()
{
uut="$1" # unit under test
remote="$2" # dns/ip for machine to test
MEMCACHED=libmemcached-1.0.15
# Make sure memcached and memslap are installed
$SCP tools/$MEMCACHED.tar.gz root@$remote:/tmp/$MEMCACHED.tar.gz
ssh root@$remote "cat > /tmp/i.sh && chmod a+x /tmp/i.sh && /tmp/i.sh" < tests/memcached_install.sh | \
tee -a $LOGFILE
common_test "$uut" "$remote"
ssh root@$remote "service memcached stop" | tee -a $LOGFILE
}
function fake_test()
{
common_test "$1" "$2"
}
function ws_arm_test()
{
common_test "$1" "$2" guest-driver vmexit-guest
}
function ws_x86_test()
{
common_test "$1" "$2" qemu-system-x86_64 vmexit.flat en-us common modifiers \
tools_x86/*.bin tools_x86/*.rom
}
source tests/apache-remote.sh
source tests/mysql.sh
##########################################################################
# Test Harness
#
TESTS="hackbench untar curl1k curl1g apache mysql dd_rw kernel_compile memcached ws_arm ws_x86"
GUEST_ONLY_TESTS=""
HOST_ONLY_TESTS="ws_arm ws_x86"
ARM_ONLY_TESTS="ws_arm"
x86_ONLY_TESTS="ws_x86"
fn_exists()
{
type $1 2>/dev/null | grep -q 'is a function' 1> /dev/null 2>&1
}
function belongsto()
{
ARR=( $2 )
for _X in ${ARR[@]}; do
if [[ "$_X" == "$1" ]]; then
return 1
fi
done
return 0
}
is_guest_only()
{
belongsto $1 "$GUEST_ONLY_TESTS"
return $?
}
is_host_only()
{
belongsto $1 "$HOST_ONLY_TESTS"
return $?
}
is_arm_only()
{
belongsto $1 "$ARM_ONLY_TESTS"
return $?
}
is_x86_only()
{
belongsto $1 "$x86_ONLY_TESTS"
return $?
}
function run_test
{
TEST="$1"
RUN_IN_GUEST=1
RUN_ON_HOST=1
is_arm_only $TEST
ARM_ONLY=$?
is_x86_only $TEST
X86_ONLY=$?
if [[ "$TESTARCH" == "x86" && $ARM_ONLY == 1 ]]; then
echo "Skipping ARM-only test: $TEST"
return 1
elif [[ "$TESTARCH" == "arm" && $X86_ONLY == 1 ]]; then
echo "Skipping x86-only test: $TEST"
return 1
fi
is_host_only "$TEST"
if [[ $? == 1 ]]; then
RUN_IN_GUEST=0
fi
is_guest_only "$TEST"
if [[ $? == 1 ]]; then
RUN_ON_HOST=0
fi
if ! fn_exists "${TEST}_test"; then
echo "Test function ${TEST}_test not defined!"
return 1
fi
echo "($TEST):" | tee -a $LOGFILE
# Run test on native side (unless a guest-only test)
if [[ $RUN_ON_HOST == 1 ]]; then
echo -en "native:\t" | tee -a $LOGFILE
eval "${TEST}_test $TEST $HOST"
fi
if [[ $RUN_IN_GUEST == 1 ]]; then
start_guest
if [[ ! $? == 0 ]]; then
echo "Error starting guest - check logfile!" >&2
return 1
fi
wait_for_remote $GUEST1
if [[ ! $? == 0 ]]; then
echo "Guest didn't respond in a timely manner - check logfile!" >&2
return 1
fi
echo -en " kvm:\t"
eval "${TEST}_test $TEST $GUEST1"
shutdown_guest $GUEST1
fi
return 0
}
usage() {
U=""
if [[ -n "$1" ]]; then
U="${U}$1\n\n"
fi
U="${U}Usage: $0 [options] [test-names] \n\n"
U="${U}Options:\n"
U="$U --host-only: Only run test(s) on host\n"
U="$U --guest-only: Only run test(s) on VM guests\n"
U="$U --power: Also measure power of runs\n"
U="$U -h | --help: Show this message\n"
U="$U\n"
U="${U}Available tests are:\n"
U="$U $TESTS\n"
echo -e "$U" >&2
}
HONLY=0
GONLY=0
while :
do
case "$1" in
--host-only)
if [[ $GONLY == 1 ]]; then
usage "error: $1 conflicts with --guest-only"
exit 1
fi
HONLY=1
shift 1
;;
--guest-only)
if [[ $HONLY == 1 ]]; then
usage "error: $1 conflicts with --host-only"
exit 1
fi
GONLY=1
shift 1
;;
--power)
DO_POWER=1
shift 1
;;
-h | --help)
usage
exit 0
;;
--) # End of all options
shift
break
;;
-*) # Unknown option
usage "Error: Unknown option: $1"
exit 1
;;
*)
if [[ -n "$1" ]]; then
TESTS="$@"
fi
shift 1
break
;;
esac
done
#TODO: Don't allow a host-only test to become a guest-only test... eh.
if [[ $HONLY == 1 ]]; then
HOST_ONLY_TESTS="$TESTS"
elif [[ $GONLY == 1 ]]; then
GUEST_ONLY_TESTS="$TESTS"
fi
echo "Outputting results to $OUTFILE"
echo -e "\n" >> $OUTFILE
echo -n "Performing KVM benchmarks (" >> $OUTFILE
date | tr '\n' ')' >> $OUTFILE
echo >> $OUTFILE
__i=1
TESTS=( $TESTS )
total=$(( ${#TESTS[@]} + ${#HOST_TESTS[@]} ))
for TEST in ${TESTS[@]}; do
echo "============================================" | tee -a $LOGFILE
echo -n "Test $__i of $total " | tee -a $LOGFILE
run_test "$TEST"
echo "============================================" | tee -a $LOGFILE
echo -e "\n\n" | tee -a $LOGFILE
__i=$(($__i+1))
done
echo "Done. Results in: $OUTFILE"