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 00:05:44 +0000 (20:05 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: If5cd9d920dd0cfe0e235b5386359080bc99efbb2

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

index 1626fd2beeb7998db7a9d755cd942570689a1faf..c23f07c3d0153278efed3b44a8de1fd6d59c9e50 100644 (file)
@@ -12,6 +12,7 @@
 #include <unistd.h>
 #include <sched.h>
 #include <time.h>
+#include <urcu/compiler.h>
 
 #ifdef TRACING
 #define TRACEPOINT_DEFINE
@@ -23,28 +24,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 1fa009ef3df9f53be50de70f72733fa47945ef0d..334785b648c81d9d17894961e08391ff98f08688 100755 (executable)
@@ -8,7 +8,7 @@ source $TESTDIR/utils/tap.sh
 
 plan_tests 1
 
-: ${ITERS:=20}
+: ${ITERS:=10}
 : ${NR_EVENTS:=7000000}
 : ${NR_CPUS:=1}
 
@@ -27,12 +27,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
 
 
@@ -41,12 +37,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
@@ -54,9 +46,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.026904 seconds and 4 git commands to generate.