File: repobench

package info (click to toggle)
reposurgeon 4.38-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,500 kB
  • sloc: sh: 4,832; makefile: 514; python: 485; lisp: 115; awk: 91; ruby: 19
file content (153 lines) | stat: -rwxr-xr-x 4,133 bytes parent folder | download | duplicates (3)
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
#!/bin/bash
#
##repobench - generate or render reposurgeon profiling results
##
## usage: repobench [-h] [-c cmd] [-p datafiles] [-o datafiles] [-s runtime|heap|highwater] [dumpfile min step max]

command=""
datfile=""
display=no
style=runtime
while getopts c:hops: opt
do
    case $opt in
	c) command="$OPTARG";;
	o) display=yes; svg=yes;;
	p) display=yes; svg=no;;
	s) style=$OPTARG;;
	*) grep '^##' "${0}" | sed -e 's/##//'
	   exit 0;;
    esac
done
shift $((OPTIND - 1))

reposurgeon="$(dirname "${0}")/reposurgeon"

function alphaonly {
    echo -n "${*}" | tr -cs '[:lower:]' '_'
}

if [ $# = 4 ] && [ "${display}" = no ]
then
    function run {
	datfile="${1}"	# The output benchmark data
	logfile="${2}"	# The logfile for the conversion
	dump="${3}"		# The dump to be read in
	readlimit="${4}"	# The nmber of revisions to read
	"${reposurgeon}" "logfile ${logfile}" \
			 "readlimit ${readlimit}" \
			 "${command}" \
			 "read <${dump}" \
			 "profile bench" >>"${datfile}"
    }

    dump="${1}"
    min="${2}"
    step="${3}"
    max="${4}"

    # This really shouldn't be run outside of the reposurgeon
    # repository, but we set up a fallback just in case
    rev="$(git describe HEAD 2>/dev/null)"
    if [ "$rev" = "" ]
    then
	# shellcheck disable=SC2046
	set -- $(reposurgeon --version)
	rev=$2
    fi

    datfile="$(basename "${dump}")_${rev}.dat"
    for readlimit in $(seq "${min}" "${step}" "${max}"); do
	logfile="$(basename "${dump}")_${rev}_${readlimit}.log"
	# Flush all disk VM caches so the data file has to be reread
	sudo sh -c 'echo 3 >/proc/sys/vm/drop_caches'
	run "${datfile}" "${logfile}" "${dump}" "${readlimit}"
	if [ $? == 1 ]	# In this context, means we got EOF before readlimit
	then
	    break
	fi
    done
    echo "Results are in ${datfile}"
    exit 0
fi

if [ "${display}" = yes ]
then
    case "${style}" in
	runtime) idx=2; title="running time";;
	heap) idx=3; title="heap size";;
	highwater) idx=4; title="total memory";;
	*)
	    echo "Unknown plot type ${style}" >&2
	    exit 1
	    ;;
    esac
fi

if [ "${display}" = yes ] && [ "$2" = "" ]
then
    datfile=${datfile:-$1}
    if [ ! -f "$datfile" ]
    then
	echo "File ${datfile} is missing." >&2
	exit 1
    fi

    cat >/tmp/plotme$$ <<EOF
set key top lmargin
set xlabel "number of revisions read in by reposurgeon"
set ylabel "${style}"
f(x) = a*x + b
g(x) = c*x**2 + d*x + e
fit f(x) file using 1:$idx via a,b
fit g(x) file using 1:$idx via c,d,e
plot file u 1:$idx title "$title" lw 2, \
     f(x) title "linear fit" lw 2, \
     g(x) title "quadratic fit" lw 2
EOF

    # The actual plotting
    if [ "${svg}" = yes ]
    then
	# You could use the non-SVG mode to view the graph, and then
	# use the viewer to save an svg file. However, that has some
	# drawbacks; in particular the size of the graph will be fixed
	# rather than dynamic, which means that it won't resize to
	# your browser window.
	name="$(alphaonly "${title}")_from_$(alphaonly "${datfile}")"
	gnuplot --persist -e "file='${datfile}'; set terminal svg size 1920,1080 dynamic mouse standalone name '${name}'" /tmp/plotme$$
    else
	gnuplot --persist -e "file='${datfile}'" /tmp/plotme$$ -
    fi
    rm -f /tmp/plotme$$
    exit 0
fi

if [ "${display}" = yes ] && [ "$2" != "" ]
then
    # We have: Multiple benchmark-data files corresponding to different
    # revisions.  We want: A merged plot extracting a selected statistic
    # from all of them for comparative graphing.
    cat >/tmp/plotme$$ <<EOF
set key top lmargin
set title "comparative ${title}"
set xlabel "number of revisions read in by reposurgeon"
set ylabel "${style}"
plot for [i=1:words(files)] word(files, i) using 1:${idx} title word(files, i) noenhanced lw 2
EOF
    # The actual plotting
    if [ "${svg}" = yes ]
    then
	name="comparative_$(alphaonly "${title}")"
	gnuplot --persist -e "files='$*'; set terminal svg size 1920,1080 dynamic mouse standalone name '${name}'" /tmp/plotme$$
    else
	gnuplot --persist -e "files='$*'" /tmp/plotme$$ -
    fi
    rm -f /tmp/plotme$$
    exit 0
fi

# Fall through to usage description
grep '^##' "${0}" | sed -e 's/##//'

# end