Debian Codegraph @

script/benchmark/tools/plot.sh

raw
1 #!/bin/bash
2
3 # Copyright The containerd Authors.
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8
9 # http://www.apache.org/licenses/LICENSE-2.0
10
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 set -euo pipefail
18
19 JSON="$(mktemp)"
20 cat > "${JSON}"
21
22 CONTEXT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/"
23 source "${CONTEXT}/util.sh"
24
25 if [ "${1}" == "" ] ; then
26 echo "Specify directory for output"
27 exit 1
28 fi
29
30 DATADIR="${1}/"
31 echo "output into: ${DATADIR}"
32
33 MODES=( ${TARGET_MODES:-} )
34 if [ ${#MODES[@]} -eq 0 ] ; then
35 MODES=("legacy" "estargz-noopt" "estargz" "zstdchunked")
36 fi
37
38 IMAGES=( ${TARGET_IMAGES:-} )
39 if [ ${#IMAGES[@]} -eq 0 ] ; then
40 IMAGES=( $(cat "${JSON}" | jq -r '[ .[] | select(.mode=="'${MODES[0]}'").repo ] | unique[]') )
41 fi
42
43 # Ensure we use the exact same number of samples among benchmarks
44 MINSAMPLES=
45 for IMGNAME in "${IMAGES[@]}" ; do
46 for MODE in "${MODES[@]}"; do
47 THEMIN=$(min_samples "${JSON}" "${IMGNAME}" "${MODE}")
48 if [ "${MINSAMPLES}" == "" ] ; then
49 MINSAMPLES="${THEMIN}"
50 fi
51 MINSAMPLES=$(echo "${MINSAMPLES} ${THEMIN}" | tr ' ' '\n' | sort -n | head -1)
52 done
53 done
54
55 PLTFILE_ALL="${DATADIR}result.plt"
56 GRAPHFILE_ALL="${DATADIR}result.png"
57
58 cat <<EOF > "${PLTFILE_ALL}"
59 set output '${GRAPHFILE_ALL}'
60 set title "Time to take for starting up containers(${PERCENTILE} pctl., ${MINSAMPLES} samples)"
61 set terminal png size 1000, 750
62 set style data histogram
63 set style histogram rowstack gap 1
64 set style fill solid 1.0 border -1
65 set key autotitle columnheader
66 set xtics rotate by -45
67 set ylabel 'time[sec]'
68 set lmargin 10
69 set rmargin 5
70 set tmargin 5
71 set bmargin 7
72 plot \\
73 EOF
74
75 NOTITLE=
76 INDEX=1
77 for IMGNAME in "${IMAGES[@]}" ; do
78 echo "[${INDEX}]Processing: ${IMGNAME}"
79 IMAGE=$(echo "${IMGNAME}" | sed 's|[/:]|-|g')
80 DATAFILE="${DATADIR}${IMAGE}.dat"
81 SUFFIX=', \'
82 if [ ${INDEX} -eq ${#IMAGES[@]} ] ; then
83 SUFFIX=''
84 fi
85 echo "mode pull create run" > "${DATAFILE}"
86 for MODE in "${MODES[@]}"; do
87 PULLTIME=$(percentile "${JSON}" "${MINSAMPLES}" "${IMGNAME}" "${MODE}" "elapsed_pull")
88 CREATETIME=$(percentile "${JSON}" "${MINSAMPLES}" "${IMGNAME}" "${MODE}" "elapsed_create")
89 RUNTIME=$(percentile "${JSON}" "${MINSAMPLES}" "${IMGNAME}" "${MODE}" "elapsed_run")
90
91 echo "${MODE} ${PULLTIME} ${CREATETIME} ${RUNTIME}" >> "${DATAFILE}"
92 done
93
94 echo 'newhistogram "'"${IMAGE}"'", "'"${DATAFILE}"'" u 2:xtic(1) fs pattern 1 lt -1 '"${NOTITLE}"', "" u 3 fs pattern 2 lt -1 '"${NOTITLE}"', "" u 4 fs pattern 3 lt -1 '"${NOTITLE}""${SUFFIX}" \
95 >> "${PLTFILE_ALL}"
96 NOTITLE=notitle
97 ((INDEX+=1))
98 done
99
100 gnuplot "${PLTFILE_ALL}"