Debian Codegraph @

script/benchmark/tools/percentiles.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 GRANULARITY="${BENCHMARK_PERCENTILES_GRANULARITY:-}"
44 if [ "${GRANULARITY}" == "" ] ; then
45 GRANULARITY="10"
46 fi
47
48 # Ensure we use the exact same number of samples among benchmarks
49 MINSAMPLES=
50 for IMGNAME in "${IMAGES[@]}" ; do
51 for MODE in "${MODES[@]}"; do
52 THEMIN=$(min_samples "${JSON}" "${IMGNAME}" "${MODE}")
53 if [ "${MINSAMPLES}" == "" ] ; then
54 MINSAMPLES="${THEMIN}"
55 fi
56 MINSAMPLES=$(echo "${MINSAMPLES} ${THEMIN}" | tr ' ' '\n' | sort -n | head -1)
57 done
58 done
59
60 function template {
61 local GRAPHFILE="${1}"
62 local IMGNAME="${2}"
63 local MODE="${3}"
64 local OPERATION="${4}"
65 local SAMPLES="${5}"
66
67 cat <<EOF
68 set output '${GRAPHFILE}'
69 set title "${OPERATION} of ${IMGNAME}/${MODE} (${SAMPLES}samples)"
70 set terminal png size 500, 375
71 set boxwidth 0.5 relative
72 set style fill solid 1.0 border -1
73 set xlabel 'percentile'
74 set ylabel 'time[sec]'
75 EOF
76 }
77
78 RAWDATADIR="${DATADIR}raw/"
79 PLTDATADIR="${DATADIR}plt/"
80 IMGDATADIR="${DATADIR}png/"
81 CSVDATADIR="${DATADIR}csv/"
82 mkdir "${RAWDATADIR}" "${PLTDATADIR}" "${IMGDATADIR}" "${CSVDATADIR}"
83 for IMGNAME in "${IMAGES[@]}" ; do
84 echo "Processing: ${IMGNAME}"
85 IMAGE=$(echo "${IMGNAME}" | sed 's|[/:]|-|g')
86 CSVFILE="${CSVDATADIR}result-${IMAGE}.csv"
87 echo "image,mode,operation,percentile,time" > "${CSVFILE}"
88 for MODE in "${MODES[@]}"; do
89 for OPERATION in "pull" "create" "run" ; do
90 DATAFILE="${RAWDATADIR}${IMAGE}-${MODE}-${OPERATION}.dat"
91 PLTFILE="${PLTDATADIR}result-${IMAGE}-${MODE}-${OPERATION}.plt"
92 template "${IMGDATADIR}result-${IMAGE}-${MODE}-${OPERATION}.png" \
93 "${IMGNAME}" "${MODE}" "${OPERATION}" "${MINSAMPLES}" > "${PLTFILE}"
94 for PCTL in $(seq 0 "${GRANULARITY}" 100) ; do
95 TIME=$(PERCENTILE=${PCTL} percentile "${JSON}" "${MINSAMPLES}" "${IMGNAME}" "${MODE}" "elapsed_${OPERATION}")
96 echo "${PCTL} ${TIME}" >> "${DATAFILE}"
97 echo "${IMGNAME},${MODE},${OPERATION},${PCTL},${TIME}" >> "${CSVFILE}"
98 done
99 echo 'plot "'"${DATAFILE}"'" using 0:2:xtic(1) with boxes lw 1 lc rgb "black" notitle' >> "${PLTFILE}"
100 gnuplot "${PLTFILE}"
101 done
102 done
103 done