tests: benchmark: use cpu-bound workload, calculate average and std.dev.
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 31 Mar 2021 00:05:44 +0000 (20:05 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 31 Mar 2021 14:33:13 +0000 (10:33 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: If5cd9d920dd0cfe0e235b5386359080bc99efbb2

tests/benchmark/bench.c
tests/benchmark/test_benchmark

index 517bfb73078db7b74769b00f81143576dd723000..77f53a1532f9a977d149acde14c95974be0a2889 100644 (file)
@@ -27,6 +27,7 @@
 #include <unistd.h>
 #include <sched.h>
 #include <time.h>
+#include <urcu/compiler.h>
 
 #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;
index 9cffcbc3e6e38cf0569eda77692d8e8428984471..6f0dd7b49851cc106f03884fbf367f97e991c565 100755 (executable)
@@ -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"
This page took 0.026467 seconds and 4 git commands to generate.