/
benchmark.sh
executable file
·110 lines (76 loc) · 2.42 KB
/
benchmark.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
#! /bin/bash
set -o pipefail
# Global variables
bg_bench_pid=
start_time=
# collect_stats pid logname
collect_stats() {
local pid=$1
local logname=$2
while ps -q $pid --no-headers -o '%cpu vsz' | tr -d '\n' >> $logname; do
local current_time=$(date +"%s.%3N")
local temp=0$(echo "scale=3; $current_time - $start_time" | bc)
echo " $temp" >> $logname
sleep 0.1
done
}
# bench program logname
bench() {
local program=$1
local logname=$2
# ${program} >/dev/null 2>&1 &
${program} &
local pid=$!
collect_stats $pid $logname
}
# bg_bench program logname
bg_bench(){
local program=$1
local logname=$2
# ${program} >/dev/null 2>&1 &
${program} &
bg_bench_pid=$!
collect_stats $bg_bench_pid $logname &
}
bf=./bf
imperium=./omr/imperium/server/imperium_server
bf_program=../brainfuck/programs/mandelbrot.bf
script_dir="$(dirname $0)"
# Delete all the old files
rm -f \
client_only.log client_only.png \
imperium_client.log imperium_client.png \
imperium_server.log imperium_server.png \
imperium_client2.log imperium_client2.png \
imperium_server2.log imperium_server2.png
# Run without the server
echo Running Client Only
start_time=$(date +"%s.%3N")
bench "$bf $bf_program" client_only.log
gnuplot -c $script_dir/plot.gp client_only.log client_only.png
# Run with the server
echo Running Client+Server
echo Launching the server
start_time=$(date +"%s.%3N")
bg_bench "$imperium" imperium_server.log
# Must make sure the server is running before starting the client
sleep 2
echo Launching the client
bench "$bf --server 127.0.0.1:50055 $bf_program" imperium_client.log
kill "$bg_bench_pid"
gnuplot -c $script_dir/plot.gp imperium_client.log imperium_client.png
gnuplot -c $script_dir/plot.gp imperium_server.log imperium_server.png
# Run the client on the server twice in a row (caching)
echo Running Client+Server
echo Launching the server
start_time=$(date +"%s.%3N")
bg_bench "$imperium" imperium_server2.log
# Must make sure the server is running before starting the client
sleep 2
echo Launching the client
bench "$bf --server 127.0.0.1:50055 $bf_program" imperium_client2.log
echo Launching the client
bench "$bf --server 127.0.0.1:50055 $bf_program" imperium_client2.log
kill "$bg_bench_pid"
gnuplot -c $script_dir/plot.gp imperium_client2.log imperium_client2.png
gnuplot -c $script_dir/plot.gp imperium_server2.log imperium_server2.png