tests: improve benchmark script
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 30 Mar 2021 20:33:26 +0000 (16:33 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 30 Mar 2021 20:33:26 +0000 (16:33 -0400)
Kill session daemon after script, conditionally drop caches if root
(else it is forbidden to do so), handle cleanup on trap, use snapshot
(flight recorder) tracing to benchmark ring buffer, output the result in
nanoseconds, removing trailing numbers after dot.

Before this, the test was pretty much always resulting in an output of
"0s" extra overhead due to truncation of significant numbers in the
output.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ia7844f3a52821da972b24bf9f39158c24329f63a

tests/benchmark/test_benchmark

index 42901bef0d05bb39e5e9995eeb0b5c659739cfdb..1fa009ef3df9f53be50de70f72733fa47945ef0d 100755 (executable)
@@ -17,28 +17,46 @@ plan_tests 1
 : ${PROG_NOTRACING:="./$CURDIR/bench1 $NR_CPUS $NR_EVENTS"}
 : ${PROG_TRACING:="./$CURDIR/bench2 $NR_CPUS $NR_EVENTS"}
 
+function signal_cleanup ()
+{
+       killall lttng-sessiond
+}
+
+trap signal_cleanup SIGTERM SIGINT
+
 CMD_NOTRACING="$TIME '$PROG_NOTRACING >/dev/null 2>&1'"
 CMD_TRACING="$TIME '$PROG_TRACING >/dev/null 2>&1'"
 
 time_notrace=0
 for i in $(seq $ITERS); do
-       echo 3 >/proc/sys/vm/drop_caches
+       if [[ $EUID -eq 0 ]]; then
+               echo 3 >/proc/sys/vm/drop_caches
+       fi
        time_notrace="$time_notrace+$(sh -c "$CMD_NOTRACING")"
 done
 
+
 lttng-sessiond -d --no-kernel
-lttng -q create
+lttng -q create --snapshot
 lttng -q enable-event -u -a
 lttng -q start
 
 time_trace=0
 for i in $(seq $ITERS); do
-       echo 3 >/proc/sys/vm/drop_caches
+       if [[ $EUID -eq 0 ]]; then
+               echo 3 >/proc/sys/vm/drop_caches
+       fi
        time_trace="$time_trace+$(sh -c "$CMD_TRACING")"
 done
 
 lttng -q stop
 lttng -q destroy
+killall lttng-sessiond
 
 pass "Trace benchmark"
-diag "Average tracing overhead per event is $(echo "scale=6;( ($time_trace) - ($time_notrace) ) / $ITERS / $NR_EVENTS" | bc -l)s"
+S_PER_EVENT=$(echo "( ($time_trace) - ($time_notrace) ) / $ITERS / $NR_EVENTS" | bc -l)
+NS_PER_EVENT=$(echo "$S_PER_EVENT * 1000000000" | bc -l)
+# Remove fractions
+NS_PER_EVENT=${NS_PER_EVENT%%.*}
+
+diag "Average tracing overhead per event is ${NS_PER_EVENT}ns"
This page took 0.025506 seconds and 4 git commands to generate.