common-functions.sh 3.21 KB
Newer Older
1
#!/bin/bash
Antoine Kaufmann's avatar
Antoine Kaufmann committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Copyright 2021 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

24
25

average() {
26
    awk '{s+=$1}END{printf ("%f", NR?s/NR:"NaN")}'
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
}

min() {
    awk 'BEGIN{x="NaN"}{x=(x=="NaN" || $1<x ? $1 : x)}END{print x}'
}

max() {
    awk 'BEGIN{x="NaN"}{x=(x=="NaN" || $1>x ? $1 : x)}END{print x}'
}

exp_durations() {
    for e in ../experiments/out/$1/*/
    do
        [ ! -f $e/endtime ] && continue
        start="$(date --date "`head -n 1 $e/starttime`" +%s)"
        end="$(date --date "`tail -n 1 $e/endtime`" +%s)"
        echo $(($end - $start))
    done
}

nopaxos_avglatencies() {
    for f in ../experiments/out/$1/*/qemu.c0.log \
        ../experiments/out/$1/*/gem5.c0.log
    do
        [ ! -f $f ] && continue

        grep "Average latency is" $f | sed 's/.*latency is \([0-9]*\) ns.*/\1/'
    done
}
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


iperf_tputs() {
    for d in ../experiments/out/$1/*/
    do
        [ ! -d $d ] && continue

        tputs="0"
        for f in $d/qemu.*.log $d/gem5.*.log
        do
            [ ! -f $f ] && continue
            [[ "`basename $f`" = *.a.log ]] && continue

            tp="`grep -e '^\[SUM\]' $f | sed \
                -e 's:.*Bytes\s*\([0-9\.]*\)\s*Kbits/sec:\1:' \
                -e 's:.*Bytes\s*\([0-9\.]*\)\s*Mbits/sec:\1 * 1000:' \
                -e 's:.*Bytes\s*\([0-9\.]*\)\s*Gbits/sec:\1 * 1000000:' | \
                sed -e s/
//`"
            [ "$tp" = "" ] && continue
            tputs="$tputs + `echo \"scale=2; $tp\" | bc`"
        done
        echo "scale=2; $tputs" | bc
    done
}

iperf_server_tputs() {
    for d in ../experiments/out/$1/*/
    do
        [ ! -d $d ] && continue

        tputs="0"
        for f in $d/qemu.a.log $d/gem5.a.log
        do
            [ ! -f $f ] && continue

            tp="`grep 'bits/sec' $f | sed \
                -e 's:.*Bytes\s*\([0-9\.]*\)\s*Kbits/sec.*:\1:' \
                -e 's:.*Bytes\s*\([0-9\.]*\)\s*Mbits/sec.*:\1 * 1000:' \
                -e 's:.*Bytes\s*\([0-9\.]*\)\s*Gbits/sec.*:\1 * 1000000:' | \
                sed -e s/
//`"
            [ "$tp" = "" ] && continue
            tputs="$tputs + `echo \"scale=2; $tp\" | bc`"
        done
        echo "scale=2; $tputs" | bc
    done
}