benchmark tool
authorDouglas Santos <douglas.santos@polymtl.ca>
Thu, 18 Mar 2010 21:45:50 +0000 (17:45 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 23 Mar 2010 05:41:13 +0000 (01:41 -0400)
tests/benchmark/Makefile [new file with mode: 0644]
tests/benchmark/README [new file with mode: 0644]
tests/benchmark/bench.c [new file with mode: 0644]
tests/benchmark/install [new file with mode: 0755]
tests/benchmark/run [new file with mode: 0755]

diff --git a/tests/benchmark/Makefile b/tests/benchmark/Makefile
new file mode 100644 (file)
index 0000000..b2922ce
--- /dev/null
@@ -0,0 +1,14 @@
+CC=gcc
+CFLAGS=-O3 -Wall
+LFLAGS=-lpthread -lust
+
+all: bench1 bench2
+
+bench1:
+       $(CC) $(CFLAGS) $(LFLAGS) -o bench1 bench.c
+bench2:
+       $(CC) $(CFLAGS) $(LFLAGS) -DMARKER -o bench2 bench.c
+
+
+clean:
+       rm -f *.o bench1 bench2
diff --git a/tests/benchmark/README b/tests/benchmark/README
new file mode 100644 (file)
index 0000000..8a9321d
--- /dev/null
@@ -0,0 +1,9 @@
+UST Benchmark
+
+INSTALLATION INSTRUCTIONS:
+
+  - run ./install  to install and compile UST/benchmark
+  - run ./run  to perform the benchmark
+
+
+The trace files will be automatically saved at $HOME/.usttraces
diff --git a/tests/benchmark/bench.c b/tests/benchmark/bench.c
new file mode 100644 (file)
index 0000000..ec08130
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * bench.c
+ *
+ * LTTng Userspace Tracer (UST) - benchmark tool
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sched.h>
+#include <ust/marker.h>
+
+static int nr_cpus;
+static unsigned long nr_events;
+pthread_mutex_t        mutex = PTHREAD_MUTEX_INITIALIZER;
+
+void do_stuff(void)
+{
+       int v;
+       FILE *file;
+       int lock;
+
+       v = 1;
+
+       lock = pthread_mutex_lock(&mutex);
+       file = fopen("/tmp/bench.txt", "a");
+       fprintf(file, "%d", v);
+       fclose(file);
+       lock = pthread_mutex_unlock(&mutex);
+
+#ifdef MARKER
+       trace_mark(ust, event, "event %d", v);
+#endif
+
+}
+
+
+void *function(void *arg)
+{
+       unsigned long i;
+
+       for(i = 0; i < nr_events; i++) {
+               do_stuff();
+       }
+       return NULL;
+}
+
+
+void usage(char **argv) {
+       printf("Usage: %s nr_cpus nr_events\n", argv[0]);
+}
+
+
+int main(int argc, char **argv)
+{
+       void *retval;
+       int i;
+
+       if (argc < 3) {
+               usage(argv);
+               exit(1);
+       }
+
+       nr_cpus = atoi(argv[1]);
+       printf("using %d processor(s)\n", nr_cpus);
+
+       nr_events = atol(argv[2]);
+       printf("using %ld events per cpu\n", nr_events);
+
+       pthread_t thread[nr_cpus];
+       for (i = 0; i < nr_cpus; i++) {
+               if (pthread_create(&thread[i], NULL, function, NULL)) {
+                       fprintf(stderr, "thread create %d failed\n", i);
+                       exit(1);
+               }
+       }
+
+       for (i = 0; i < nr_cpus; i++) {
+               if (pthread_join(thread[i], &retval)) {
+                       fprintf(stderr, "thread join %d failed\n", i);
+                       exit(1);
+               }
+       }
+       return 0;
+}
diff --git a/tests/benchmark/install b/tests/benchmark/install
new file mode 100755 (executable)
index 0000000..a66405d
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/bash
+#
+# install ust
+
+# compile and install UST
+cd ../../
+make clean
+CFLAGS=-O3 ./configure
+make
+sudo make install
+sudo ldconfig
+
+# compile benchmark
+cd tests/benchmark
+make clean && make
diff --git a/tests/benchmark/run b/tests/benchmark/run
new file mode 100755 (executable)
index 0000000..dfc1125
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# run ust benchmark
+#
+
+echo "ust benchmark"
+
+NR_EVENTS=2000000
+NR_CPUS=2
+echo "using $NR_CPUS processor(s)"
+echo "using $NR_EVENTS events per cpu"
+
+
+rm -f /tmp/bench.txt
+# without markers
+echo ">running without markers"
+t1=$(/usr/bin/time -f%e usttrace ./bench1 $NR_CPUS $NR_EVENTS 2>&1 1> /dev/null)
+echo " time=$t1 sec"
+
+
+rm -f /tmp/bench.txt
+# with markers
+echo ">running with markers activated"
+t2=$(/usr/bin/time -f%e usttrace ./bench2 $NR_CPUS $NR_EVENTS 2>&1 1> /dev/null)
+echo " time=$t2 sec"
+
+
+#penalty = t2 - t1
+echo
+penalty=$(echo "$t2 - $t1;" | bc)
+echo "time penalty=$penalty sec"
+
+#event = penalty / (nr_events * nr_cpus)
+event=$(echo "scale=8; ($penalty / ($NR_EVENTS * $NR_CPUS));" | bc)
+echo "time penalty per event=$event sec"
+
+rm -f /tmp/bench.txt
This page took 0.028816 seconds and 4 git commands to generate.