Skip to content

Commit

Permalink
benchmark.sh: fix QA problems
Browse files Browse the repository at this point in the history
- Use mktemp for secure tmpdir handling
- Fix issues found by shellcheck

Signed-off-by: Andrew Savchenko <bircoph@gmail.com>
  • Loading branch information
bircoph committed May 18, 2019
1 parent 391584e commit 7c21359
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions doc/devel/thread-splitting/benchmark.sh
Expand Up @@ -2,6 +2,7 @@

RUN_TIMES=27

tmpdir=$(mktemp --tmpdir -d clsync-hl-bench.XXXXXXXXXX)

configuration() {
git checkout -- configuration.h
Expand All @@ -11,17 +12,17 @@ configuration() {
}

configure() {
./configure -C $@ >/dev/null 2>/dev/null || ./configure $@ || exit -1
./configure -C "$@" >/dev/null 2>/dev/null || ./configure "$@" || exit -1
}

run() {
time ./clsync -Mso -S'doc/devel/thread-splitting/benchmark-synchandler.so' --have-recursive-sync --max-iterations 1 -W ~/clsync-test $@ || exit -1
time ./clsync -Mso -S'doc/devel/thread-splitting/benchmark-synchandler.so' --have-recursive-sync --max-iterations 1 -W ~/clsync-test "$@" || exit -1
}

benchmark() {
make clean all
HL_INITIAL=$(awk '{if ($2 == "HL_LOCK_TRIES_INITIAL") print $3}' < configuration.h)
HL_AUTO=$(gcc -x c - -o /tmp/hl_auto.bin.$$ << 'EOF'
HL_AUTO=$(gcc -x c - -o "$tmpdir/hl_auto.bin" << 'EOF'
#include <stdio.h>
#include "configuration.h"
int main() {
Expand All @@ -33,21 +34,20 @@ int main() {
return 0;
}
EOF
/tmp/hl_auto.bin.$$
rm -f /tmp/hl_auto.bin.$$
"$tmpdir/hl_auto.bin"
rm -f "$tmpdir/hl_auto.bin"
)
CONFIGURE=$(awk '{if ($2 == "./configure") {$1=""; $2="";print $0; exit}}' < config.log)
hash="$@|$CONFIGURE"
hash="$*|$CONFIGURE"
if [[ "$HL_AUTO" == "auto" ]]; then
hash="$hash|$HL_AUTO"
else
hash="$hash|$HL_INITIAL"
fi
rm -f /tmp/benchmark.{,err}log-"$hash"
i=0
while [[ "$i" -lt "$RUN_TIMES" ]]; do
run -d1 $@ >>/tmp/benchmark.log-"$hash" 2>> /tmp/benchmark.errlog-"$hash"
i=$[ $i + 1 ]
run -d1 "$@" >> "$tmpdir/benchmark.log-$hash" 2>> "$tmpdir/benchmark.errlog-$hash"
i=$(( i + 1 ))
done
}

Expand Down Expand Up @@ -75,7 +75,7 @@ interval=1;
while [[ "$interval" -le "2147483648" ]]; do
configuration 's|SLEEP_SECONDS.*$|SLEEP_SECONDS 0|g' 's|#define HL_LOCK_TRIES_AUTO|//#define HL_LOCK_TRIES_AUTO|g' "s|HL_LOCK_TRIES_INITIAL.*$|HL_LOCK_TRIES_INITIAL $interval|g"
benchmark --thread-splitting
interval=$[ $interval * 2 ]
interval=$(( interval * 2 ))
done

rm -f doc/devel/thread-splitting/benchmark-synchandler.so

0 comments on commit 7c21359

Please sign in to comment.