-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.sh
executable file
·130 lines (105 loc) · 3.15 KB
/
bench.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
#!/usr/bin/env bash
set -o errexit
set -o pipefail
usage() { echo "Usage: $0 <all|tcpdump|app-ioref|app-statet|tcpdump_tcpdump|app_tcpdump-ioref|app_tcpdump-statet> [-s <1|10|100>] [-q] [-b <benchmark binary path>] [-- <app options>]" 1>&2; exit 1; }
bench=$1
[ -z "$bench" ] && usage
[ "$bench" == all -o "$bench" == tcpdump -o "$bench" == app-ioref -o "$bench" == app-statet -o "$bench" == tcpdump_tcpdump -o "$bench" == app_tcpdump-ioref -o "$bench" == app_tcpdump-statet ] || usage
shift
while getopts "s:b:qh-" o; do
case "${o}" in
s)
len=${OPTARG}
((len == 1 || len == 10 || len == 100)) || usage
;;
b)
bbpath=${OPTARG}
;;
q)
quiet="-q"
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
[ -z "$len" ] && len=10
[ -z "$bbpath" ] && bbpath=$(cabal list-bin bench:pcap-replicator)
# echo "bench = ${bench}"
# echo "len = ${len}"
# echo "quiet = ${quiet}"
# echo "bbpath = ${bbpath}"
# echo "rest = $@"
# exit 0
if [ "$quiet" = "-q" ]
then
exec > /tmp/debug.log
exec 2>&1
fi
app_args="$@"
the_pcap1=~/opt/haskell/rws/the1.pcap
packets=1000000
the_pcap10=~/opt/haskell/rws/the10.pcap
packets10=10000000
the_pcap100=~/opt/haskell/rws/the100.pcap
packets100=100000000
the_pcap=~/opt/haskell/rws/the${len}.pcap
packets=$(( $len * 1000 * 1000))
echo "runnning benchmark $bench with $packets packets"
title() {
echo
echo ======= $1
}
# https://unix.stackexchange.com/questions/472117/how-can-i-run-multiple-pv-commands-in-parallel
par() {
title "$@"
xargs -P 2 -I {} bash -c "{}"
}
function waitport() { cx=0; while ! ss -ntHl '( sport = :8091 )' | grep -q . -a $cx -ne 1000 ]; do sleep .000001; cx=$(($cx +1)); done; }
appbin() {
local app=$1
app_bin_rel_path_template="/x/pcap-replicator-_the_app_/opt/build/pcap-replicator-_the_app_/pcap-replicator-_the_app_"
app_bin_rel_path="${app_bin_rel_path_template//_the_app_/$app}"
echo $bbpath | sed "s,/b/.*,$app_bin_rel_path,"
}
#title "cat"
#time cat $the_pcap100 | pv -rt > /dev/null
#title "pv"
#time pv -rt $the_pcap100 > /dev/null
b_tcpdump() {
title "tcpdump"
pv -rt $the_pcap | /usr/bin/time -v tcpdump -nnr - --count >> /tmp/debug.log 2>&1
}
b_app() {
local app=$1
title "$app"
/usr/bin/time -v $(appbin $app) -1 $app_args "pv -rt $the_pcap"
}
b_tcpdump_tcpdump() {
par "tcpdump + tcpdump" <<EOF
pv -rtc -N server $the_pcap | tcpdump -nnr - -w - | nc -Nl 8091
cx=0; while ! ss -ntHl \'( sport = :8091 )\' | grep -q . && [ \$cx -ne 1000 ]; do sleep .000001; cx=\$\(\(\$cx +1)); done; time nc -d localhost 8091 | pv -rtc -N client | tcpdump -nnr - --count
EOF
}
b_app_tcpdump() {
local app=$1
par "$app + tcpdump" <<EOF
$(appbin $app) -1 "$app_args" \"sleep .1; time pv -rtc -N server $the_pcap\"
cx=0; while ! ss -ntHl \'( sport = :8091 )\' | grep -q . && [ \$cx -ne 1000 ]; do sleep .000001; cx=\$\(\(\$cx +1)); done; time nc -d localhost 8091 | pv -rtc -N client | tcpdump -nnr - --count
EOF
}
case $bench in
all)
b_tcpdump
b_app ioref
b_app statet
b_tcpdump_tcpdump
b_app_tcpdump ioref
b_app_tcpdump statet
;;
*)
b_${bench/-/ }
;;
esac
exit 0