bachelor-thesis/chapters/thesis/appendix02_timing.sh

107 lines
2.6 KiB
Bash
Raw Normal View History

2024-04-18 00:51:19 +02:00
#!/bin/bash
#
# Activate Bash Strict Mode
set -euo pipefail
2024-07-10 00:22:25 +02:00
2024-04-18 00:51:19 +02:00
main() {
{
2024-07-25 00:48:07 +02:00
local maxLen=0
2024-04-18 00:51:19 +02:00
for url in ${@:2}; do
2024-07-25 00:48:07 +02:00
local size=${#url}
if [[ $size -gt $maxLen ]]
then maxLen=$size
fi
done
printf "%-${maxLen}s %+4s %+5s %+9s %+9s %+9s %+9s\n" "URL" "Runs" "StDev" "Min (ms)" "Avg (ms)" "Max (ms)" "1st (ms)"
for url in ${@:2}; do
get_statistics $url $1 $maxLen
2024-04-18 00:51:19 +02:00
done
} #| column -s $'\t' -t
}
get_statistics() {
# Initialice the variables
2024-07-25 00:48:07 +02:00
local first=-1
2024-04-18 00:51:19 +02:00
local min=1000000000
local max=0
local dur=0
2024-04-18 20:20:16 +02:00
local durQ=0
2024-07-10 00:22:25 +02:00
local spin=0
local spiner=('-' '\' '|' '/')
2024-07-25 00:48:07 +02:00
printf "%-${maxLen}s " $1
#echo -ne "$1\t "
2024-04-18 00:51:19 +02:00
# repeat for the defined counts the url calling
for i in $(seq 1 $2); do
2024-07-10 00:22:25 +02:00
echo -ne "\b${spiner[$spin]}"
spin=$(( (spin+1) % 4 ))
2024-04-18 00:51:19 +02:00
local gp=$(($(get_posts $1)/1000000)) # from ns to ms
2024-07-25 00:48:07 +02:00
if [[ $first -lt 0 ]]
then first=$gp
fi
2024-04-18 00:51:19 +02:00
if [[ $gp -gt $max ]]
then max=$gp
fi
if [[ $gp -lt $min ]]
then min=$gp
fi
dur=$(( $dur + $gp ))
2024-04-18 20:20:16 +02:00
durQ=$(( $durQ + $(($gp * $gp)) ))
2024-04-18 00:51:19 +02:00
done
2024-04-18 20:20:16 +02:00
local avg=$(($dur/$2))
local avgPow=$(($avg * $avg))
local stdev=$( echo "sqrt(($durQ / $2) - $avgPow)" | bc )
2024-04-18 00:51:19 +02:00
# output the statistic values
2024-07-25 00:48:07 +02:00
printf "\b%+4s %+5s %+9s %+9s %+9s %+9s\n" $2 $stdev $min $avg $max $first
#echo -e "\b$2\t$stdev\t$min\t$avg\t$max\t$first"
2024-04-18 00:51:19 +02:00
}
get_posts() {
# Call the url with measure time
local start=$(date +%s%N)
curl --silent --show-error $1 > /dev/null
local stop=$(date +%s%N)
local dur=$(($stop-$start))
echo $dur
}
2024-07-10 00:22:25 +02:00
print_process() {
ps -C java --no-headers --format "pid %cpu %mem rss pss cmd" |\
awk 'BEGIN { printf "%6s %5s %4s %13s %13s %-50s\n", "pid", "%cpu", "%mem", "rss Mb", "pss Mb", "cmd"}
{hr=$4/1024; hp=$5/1024; printf("%6i %5.1f %4.1f %13.2f %13.2f %s\n", $1, $2, $3,hr, hp, $6) }'
}
2024-08-16 22:13:36 +02:00
print_docker_process() {
sudo docker stats --no-stream
}
2024-04-18 00:51:19 +02:00
# the main domain
2024-07-10 00:22:25 +02:00
#hostname="https://briefedition.wedekind.h-da.de"
hostname="http://localhost:8080/WedekindJSF-1.0.0"
2024-04-18 00:51:19 +02:00
# the Array of the Urls
url_arr=(
"$hostname/index.xhtml"
2024-08-19 21:00:19 +02:00
#"$hostname/view/document/list.xhtml"
"$hostname/view/document/listsearch.xhtml"
2024-08-02 00:06:57 +02:00
#"$hostname/view/correspondent/list.xhtml"
2024-07-10 00:22:25 +02:00
#"$hostname/view/person/list.xhtml"
2024-04-18 00:51:19 +02:00
)
2024-07-10 00:22:25 +02:00
2024-08-16 22:13:36 +02:00
#print_process
print_docker_process
2024-07-10 00:22:25 +02:00
echo ""
2024-04-18 00:51:19 +02:00
# Execute all the URLs for 10 rounds
main 10 ${url_arr[@]}
2024-07-10 00:22:25 +02:00
echo ""
2024-08-16 22:13:36 +02:00
##print_process
print_docker_process