From 2add38b463899ace3a5910b3cb29299d06804ac5 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 30 Mar 2021 16:33:26 -0400 Subject: [PATCH] tests: improve benchmark script 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 Change-Id: Ia7844f3a52821da972b24bf9f39158c24329f63a --- tests/benchmark/test_benchmark | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/benchmark/test_benchmark b/tests/benchmark/test_benchmark index c55e3027..9cffcbc3 100755 --- a/tests/benchmark/test_benchmark +++ b/tests/benchmark/test_benchmark @@ -15,28 +15,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" -- 2.34.1