Commit latest version
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 11 Jun 2012 02:08:17 +0000 (22:08 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 11 Jun 2012 02:08:17 +0000 (22:08 -0400)
.settings/org.eclipse.jdt.core.prefs
src/org/lttng/ust/tests/Benchmark.java
src/org/lttng/ust/tests/DummyHandler.java [new file with mode: 0644]
src/org/lttng/ust/tests/Runner.java
src/org/lttng/ust/tests/Worker.java

index e388939ec1bbf06554ebcda3cfbd301614623e2f..7341ab1683c4f1bd2f33bbd3d102ebf032569b57 100644 (file)
@@ -1,4 +1,3 @@
-#Thu May 03 13:20:10 EDT 2012
 eclipse.preferences.version=1
 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
index 45000ac944db833780b7f081b26434ab46a2566f..b435e40fbfa514105414bc59bd780d69c888bb33 100644 (file)
@@ -2,6 +2,7 @@ package org.lttng.ust.tests;
 
 import java.io.IOException;
 import java.util.logging.FileHandler;
+import java.util.logging.Handler;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.logging.SimpleFormatter;
@@ -10,28 +11,28 @@ import org.lttng.ust.LTTngUst;
 
 public class Benchmark {
 
+    /** Nb of runs per test, result will be averaged */
     private static final int NB_RUNS = 5;
-    private static final int NB_THREADS = 2;
-
-    /**
-     * @param args
-     * @throws IOException
-     * @throws SecurityException
-     */
-    public static void main(String[] args) throws SecurityException,
-            IOException {
-        Runner runner;
-        long start, end, average, total = 0;
 
-        final Logger log;
-        final FileHandler fh;
+    /** Trace/log events per run */
+    private static final int NB_ITER = 1000000;
+
+    /** Which tests to run (for different number of threads) */
+    private static final int[] nbThreads = {1, 1, 2, 3, 4, 5, 6, 7, 8};
+
+    private static Runner runner;
+    private static Logger log;
+
+    public static void main(String[] args) throws SecurityException, IOException {
+
+        final Handler fh;
 
         /* Set up the logger */
         log = Logger.getLogger("Test logger");
         log.setUseParentHandlers(false);
         fh = new FileHandler("/tmp/log", false);
         fh.setFormatter(new SimpleFormatter());
-        // log.addHandler(fh);
+//        log.addHandler(fh);
         log.setLevel(Level.ALL);
 
         /* Set up the tracer */
@@ -39,8 +40,16 @@ public class Benchmark {
         System.out.println("Press a key to start.");
         System.in.read();
 
+        for (int i : nbThreads) {
+            runTest(i);
+        }
+    }
+
+
+    private static void runTest(int nbThreads) throws SecurityException, IOException {
+        long start, end, average, total = 0;
         for (int i = 0; i < NB_RUNS; i++) {
-            runner = new Runner(NB_THREADS, log);
+            runner = new Runner(nbThreads, NB_ITER, log);
 
             start = System.nanoTime();
             runner.run();
@@ -49,7 +58,6 @@ public class Benchmark {
             total += (end - start);
         }
         average = total / NB_RUNS;
-        System.out.println("Average = " + average / 1000000 + " ms");
+        System.out.println(nbThreads + " threads, average = " + average / NB_ITER + " ns/event");
     }
-
 }
diff --git a/src/org/lttng/ust/tests/DummyHandler.java b/src/org/lttng/ust/tests/DummyHandler.java
new file mode 100644 (file)
index 0000000..601f06c
--- /dev/null
@@ -0,0 +1,21 @@
+package org.lttng.ust.tests;
+
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+
+public class DummyHandler extends Handler {
+
+    public DummyHandler() {
+        super();
+    }
+
+    @Override
+    public void close() throws SecurityException {}
+
+    @Override
+    public void flush() {}
+
+    @Override
+    public void publish(LogRecord record) {}
+
+}
index f9a08cecb478053609d3aabcfd30a59fd4d3e044..470e98f9d4054649ef83abff15ae569c549356dc 100644 (file)
@@ -3,28 +3,24 @@ package org.lttng.ust.tests;
 import java.io.IOException;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.logging.FileHandler;
-import java.util.logging.Handler;
-import java.util.logging.Level;
 import java.util.logging.Logger;
-import java.util.logging.SimpleFormatter;
 
 public class Runner implements Runnable {
 
     private final List<Worker> workers;
     private final List<Thread> workerThreads;
 
-    public Runner(int nbThreads, Logger log) throws SecurityException,
-            IOException {
+    public Runner(int nbThreads, int nbIter, Logger log)
+            throws SecurityException, IOException {
         Worker curWorker;
 
-        workers = new LinkedList<>();
-        workerThreads = new LinkedList<>();
+        this.workers = new LinkedList<>();
+        this.workerThreads = new LinkedList<>();
 
-        for (int i = 0; i < nbThreads; i++) {
-            curWorker = new Worker(i, log);
+        for (int id = 0; id < nbThreads; id++) {
+            curWorker = new Worker(id, nbIter, log);
             workers.add(curWorker);
-            workerThreads.add(new Thread(curWorker, "worker " + i));
+            workerThreads.add(new Thread(curWorker, "worker " + id));
         }
     }
 
index e608ac36b42c18f1bcf881420594c662928da802..736dddbad78e891148bb30673633d6463dd76e40 100644 (file)
@@ -7,23 +7,25 @@ import org.lttng.ust.LTTngUst;
 public class Worker implements Runnable {
 
     private final Logger log;
-    private final int threadNumber;
+    private final int threadId;
+    private final int nbIter;
     private long curCount;
 
-    public Worker(int nb, Logger log) {
+    public Worker(int threadId, int nbIter, Logger log) {
         this.log = log;
-        threadNumber = nb;
+        this.threadId = threadId;
+        this.nbIter = nbIter;
         curCount = 0;
     }
 
     @Override
     public void run() {
-        for (int i = 0; i < 10000; i++) {
-            // log.info("Thread " + threadNumber + ", iteration " + i);
-            LTTngUst.tracepointIntInt("Thread/Iteration", threadNumber, i);
+        for (int i = 0; i < nbIter; i++) {
+//            log.info("Thread " + threadId + ", iteration " + i);
+            LTTngUst.tracepointIntInt("Thread/Iteration", threadId, i);
             curCount += i;
         }
-        // System.out.println(curCount);
+//        System.out.println(curCount);
     }
 
 }
This page took 0.026239 seconds and 4 git commands to generate.