From e2a245bb4294a9c9d477600fcb046d61a3ed39e5 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 30 Mar 2021 20:05:44 -0400 Subject: [PATCH] tests: benchmark: use cpu-bound workload, calculate average and std.dev. Signed-off-by: Mathieu Desnoyers Change-Id: If5cd9d920dd0cfe0e235b5386359080bc99efbb2 --- tests/benchmark/bench.c | 20 +++++++----------- tests/benchmark/test_benchmark | 38 +++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/tests/benchmark/bench.c b/tests/benchmark/bench.c index 517bfb73..77f53a15 100644 --- a/tests/benchmark/bench.c +++ b/tests/benchmark/bench.c @@ -27,6 +27,7 @@ #include #include #include +#include #ifdef TRACING #define TRACEPOINT_DEFINE @@ -38,28 +39,23 @@ static unsigned long nr_events; void do_stuff(void) { - int v; - FILE *file; - - v = 1; - - file = fopen("/dev/null", "a"); - fprintf(file, "%d", v); - fclose(file); - time(NULL); + int i; +#ifdef TRACING + int v = 50; +#endif + for (i = 0; i < 100; i++) + cmm_barrier(); #ifdef TRACING tracepoint(ust_tests_benchmark, tpbench, v); #endif - } - void *function(void *arg) { unsigned long i; - for(i = 0; i < nr_events; i++) { + for (i = 0; i < nr_events; i++) { do_stuff(); } return NULL; diff --git a/tests/benchmark/test_benchmark b/tests/benchmark/test_benchmark index 9cffcbc3..6f0dd7b4 100755 --- a/tests/benchmark/test_benchmark +++ b/tests/benchmark/test_benchmark @@ -6,7 +6,7 @@ source $TESTDIR/utils/tap.sh plan_tests 1 -: ${ITERS:=20} +: ${ITERS:=10} : ${NR_EVENTS:=7000000} : ${NR_CPUS:=1} @@ -25,12 +25,8 @@ 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 - if [[ $EUID -eq 0 ]]; then - echo 3 >/proc/sys/vm/drop_caches - fi - time_notrace="$time_notrace+$(sh -c "$CMD_NOTRACING")" + time_notrace[i]=$(sh -c "$CMD_NOTRACING") done @@ -39,12 +35,8 @@ lttng -q create --snapshot lttng -q enable-event -u -a lttng -q start -time_trace=0 for i in $(seq $ITERS); do - if [[ $EUID -eq 0 ]]; then - echo 3 >/proc/sys/vm/drop_caches - fi - time_trace="$time_trace+$(sh -c "$CMD_TRACING")" + time_trace[i]=$(sh -c "$CMD_TRACING") done lttng -q stop @@ -52,9 +44,27 @@ lttng -q destroy killall lttng-sessiond pass "Trace benchmark" -S_PER_EVENT=$(echo "( ($time_trace) - ($time_notrace) ) / $ITERS / $NR_EVENTS" | bc -l) -NS_PER_EVENT=$(echo "$S_PER_EVENT * 1000000000" | bc -l) + +avg_delta=0 +for i in $(seq $ITERS); do + delta[$i]=$(echo "( ((${time_trace[$i]}) - (${time_notrace[$i]})) / $NR_EVENTS)" | bc -l) + avg_delta=$(echo "(${avg_delta} + ${delta[$i]})" | bc -l) +done +avg_delta=$(echo "(${avg_delta} / $ITERS)" | bc -l) + +std_dev=0 +for i in $(seq $ITERS); do + dev[$i]=$(echo "(( (${delta[$i]}) - (${avg_delta}) ) ^ 2)" | bc -l) + std_dev=$(echo "( (${std_dev}) + (${dev[i]}) )" | bc -l) +done +std_dev=$(echo "( (${std_dev}) / $ITERS )" | bc -l) +std_dev=$(echo "(sqrt(${std_dev}))" | bc -l) + +NS_PER_EVENT=$(echo "($avg_delta * 1000000000)" | bc -l) # Remove fractions NS_PER_EVENT=${NS_PER_EVENT%%.*} -diag "Average tracing overhead per event is ${NS_PER_EVENT}ns" +STD_DEV_NS_PER_EVENT=$(echo "($std_dev * 1000000000)" | bc -l) +STD_DEV_NS_PER_EVENT=${STD_DEV_NS_PER_EVENT%%.*} + +diag "Average tracing overhead per event is ${NS_PER_EVENT}ns, std.dev.: ${STD_DEV_NS_PER_EVENT}ns" -- 2.34.1