Add benchmarks for old LTTng-JUL API vs. new one
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 21 Jul 2015 20:12:53 +0000 (16:12 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 21 Jul 2015 23:50:06 +0000 (19:50 -0400)
Also move the tests in subpackages.

19 files changed:
.classpath
.project
.settings/org.eclipse.jdt.core.prefs
src/org/lttng/ust/agent/jul/benchmarks/AbstractJulBenchmark.java [deleted file]
src/org/lttng/ust/agent/jul/benchmarks/DummyHandlerBenchmark.java [deleted file]
src/org/lttng/ust/agent/jul/benchmarks/FileHandlerBenchmark.java [deleted file]
src/org/lttng/ust/agent/jul/benchmarks/LttngJulHandlerTracingDisabledBenchmark.java [deleted file]
src/org/lttng/ust/agent/jul/benchmarks/LttngJulHandlerTracingEnabledBenchmark.java [deleted file]
src/org/lttng/ust/agent/jul/benchmarks/NoHandlerBenchmark.java [deleted file]
src/org/lttng/ust/agent/jul/benchmarks/RunAllTests.java
src/org/lttng/ust/agent/jul/benchmarks/handler/AbstractJulBenchmark.java [new file with mode: 0644]
src/org/lttng/ust/agent/jul/benchmarks/handler/DummyHandlerBenchmark.java [new file with mode: 0644]
src/org/lttng/ust/agent/jul/benchmarks/handler/FileHandlerBenchmark.java [new file with mode: 0644]
src/org/lttng/ust/agent/jul/benchmarks/handler/NoHandlerBenchmark.java [new file with mode: 0644]
src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java [new file with mode: 0644]
src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java [new file with mode: 0644]
src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java [new file with mode: 0644]
src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java [new file with mode: 0644]
src/org/lttng/ust/agent/jul/benchmarks/utils/LttngSessionControl.java [new file with mode: 0644]

index bf7cf4ea0a2761aeabc1eccb50f6456a1c357e8d..0b8166efaf87e7ff0a16b107191ee5635b6a03b1 100644 (file)
@@ -4,5 +4,6 @@
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
        <classpathentry combineaccessrules="false" kind="src" path="/lttng-ust-agent-jul"/>
        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/lttng-ust-agent-common"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
index b0299dbe7631bd85179c8571c7b86da2b28dc7b4..1b1828ebc85adb5a804f18aca61ec7f28cddf9d9 100644 (file)
--- a/.project
+++ b/.project
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-       <name>test</name>
+       <name>lttng-ust-agent-jul-benchmarks</name>
        <comment></comment>
        <projects>
        </projects>
index 53d2118b381b128b00eff7c0bc0ac41687448c85..3b5cbc1af1b86f777a908fbaafa07422107f8d7a 100644 (file)
@@ -365,7 +365,7 @@ org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constan
 org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
 org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
 org.eclipse.jdt.core.formatter.join_lines_in_comments=true
-org.eclipse.jdt.core.formatter.join_wrapped_lines=true
+org.eclipse.jdt.core.formatter.join_wrapped_lines=false
 org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
 org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
 org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/AbstractJulBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/AbstractJulBenchmark.java
deleted file mode 100644 (file)
index 01c213b..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-package org.lttng.ust.agent.jul.benchmarks;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public abstract class AbstractJulBenchmark {
-
-    // ------------------------------------------------------------------------
-    // Configurable test parameters
-    // ------------------------------------------------------------------------
-
-    /** Nb of runs per test, result will be averaged */
-    private static final int NB_RUNS = 10;
-
-    /** Trace/log events per run */
-    private static final int NB_ITER = 100000;
-
-    /** Which tests to run (for different number of threads) */
-    private static final int[] NB_THREADS = {1, 1, 2, 3, 4, 5, 6, 7, 8};
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    private Logger logger;
-    protected Handler handler;
-
-    // ------------------------------------------------------------------------
-    // Maintenance methods
-    // ------------------------------------------------------------------------
-
-    @Before
-    public void setup() {
-        /* Set up the logger */
-        logger = Logger.getLogger("Test logger");
-        logger.setUseParentHandlers(false);
-        logger.setLevel(Level.ALL);
-
-        /* Sub-classes' @Before will setup the Handler */
-    }
-
-    @After
-    public void teardown() {
-        logger.removeHandler(handler);
-        if (handler != null) {
-            handler.close();
-        }
-        handler = null;
-        logger = null;
-    }
-
-    // ------------------------------------------------------------------------
-    // Test methods
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void runBenchmark() {
-        if (handler != null) {
-            logger.addHandler(handler);
-        }
-
-        System.out.println();
-        System.out.println("Running benchmark: " + this.getClass().getCanonicalName());
-        for (int i : NB_THREADS) {
-            runTest(logger, i);
-        }
-    }
-
-    private static void runTest(Logger log, int nbThreads) {
-        long start, end, average, total = 0;
-        for (int i = 0; i < NB_RUNS; i++) {
-            Runner runner = new Runner(nbThreads, NB_ITER, log);
-
-            start = System.nanoTime();
-            runner.run();
-            end = System.nanoTime();
-
-            total += (end - start);
-        }
-        average = total / NB_RUNS;
-        System.out.println(nbThreads + " threads, average = " + average / NB_ITER + " ns/event");
-    }
-
-    // ------------------------------------------------------------------------
-    // Helper classes
-    // ------------------------------------------------------------------------
-
-    private static class Runner implements Runnable {
-
-        private final List<Worker> workers = new LinkedList<>();
-        private final List<Thread> workerThreads = new LinkedList<>();
-
-        public Runner(int nbThreads, int nbIter, Logger log) {
-
-            for (int id = 0; id < nbThreads; id++) {
-                Worker curWorker = new Worker(id, nbIter, log);
-                workers.add(curWorker);
-                workerThreads.add(new Thread(curWorker, "worker " + id));
-            }
-        }
-
-        @Override
-        public void run() {
-            for (Thread curThread : workerThreads) {
-                curThread.start();
-            }
-
-            for (Thread curThread : workerThreads) {
-                try {
-                    curThread.join();
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
-                }
-            }
-        }
-
-        private static class Worker implements Runnable {
-
-            private final Logger log;
-            private final int threadId;
-            private final int nbIter;
-
-            public Worker(int threadId, int nbIter, Logger log) {
-                this.log = log;
-                this.threadId = threadId;
-                this.nbIter = nbIter;
-            }
-
-            @Override
-            public void run() {
-                for (int i = 0; i < nbIter; i++) {
-                    log.info("Thread " + threadId + ", iteration " + i);
-                }
-            }
-
-        }
-    }
-}
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/DummyHandlerBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/DummyHandlerBenchmark.java
deleted file mode 100644 (file)
index 0bf2f59..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.lttng.ust.agent.jul.benchmarks;
-
-import java.util.logging.Handler;
-import java.util.logging.LogRecord;
-
-import org.junit.Before;
-
-public class DummyHandlerBenchmark extends AbstractJulBenchmark {
-
-    @Before
-    public void testSetup() {
-        handler = new DummyHandler();
-    }
-
-    private static class DummyHandler extends Handler {
-
-        public DummyHandler() {
-            super();
-        }
-
-        @Override
-        public void close() throws SecurityException {}
-
-        @Override
-        public void flush() {}
-
-        @Override
-        public void publish(LogRecord record) {}
-
-    }
-}
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/FileHandlerBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/FileHandlerBenchmark.java
deleted file mode 100644 (file)
index 91a0419..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-package org.lttng.ust.agent.jul.benchmarks;
-
-import java.io.IOException;
-import java.util.logging.FileHandler;
-import java.util.logging.SimpleFormatter;
-
-import org.junit.Before;
-
-public class FileHandlerBenchmark extends AbstractJulBenchmark {
-
-    @Before
-    public void testSetup() throws SecurityException, IOException {
-        handler = new FileHandler("/tmp/log", false);
-        handler.setFormatter(new SimpleFormatter());
-    }
-}
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/LttngJulHandlerTracingDisabledBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/LttngJulHandlerTracingDisabledBenchmark.java
deleted file mode 100644 (file)
index 22106b6..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.lttng.ust.agent.jul.benchmarks;
-
-import static org.junit.Assert.assertFalse;
-
-import org.junit.Before;
-import org.lttng.ust.agent.jul.LTTngLogHandler;
-import org.lttng.ust.agent.jul.LttngJulRootAgent;
-
-public class LttngJulHandlerTracingDisabledBenchmark extends AbstractJulBenchmark {
-
-    @Before
-    public void testSetup() {
-        handler = new LTTngLogHandler(true);
-
-        assertFalse(LttngJulRootAgent.getInstance().listEnabledEvents().iterator().hasNext());
-    }
-}
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/LttngJulHandlerTracingEnabledBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/LttngJulHandlerTracingEnabledBenchmark.java
deleted file mode 100644 (file)
index 506c7ab..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.lttng.ust.agent.jul.benchmarks;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Before;
-import org.lttng.ust.agent.jul.LTTngLogHandler;
-import org.lttng.ust.agent.jul.LttngJulRootAgent;
-
-public class LttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark {
-
-    @Before
-    public void testSetup() {
-        handler = new LTTngLogHandler(true);
-
-        LttngJulRootAgent agent = LttngJulRootAgent.getInstance();
-        agent.enableEvent("*");
-        assertTrue(agent.listEnabledEvents().iterator().hasNext());
-    }
-}
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/NoHandlerBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/NoHandlerBenchmark.java
deleted file mode 100644 (file)
index ec569af..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-package org.lttng.ust.agent.jul.benchmarks;
-
-public class NoHandlerBenchmark extends AbstractJulBenchmark {
-
-    /* Do not setup any handler */
-}
index 0f61c039f0f9c485adafb7297ecd4e6e07989c8c..42ce901bd595c039212c29cf72feca34cc3c47f1 100644 (file)
@@ -5,11 +5,13 @@ import org.junit.runners.Suite;
 
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
-    DummyHandlerBenchmark.class,
-    FileHandlerBenchmark.class,
-    LttngJulHandlerTracingDisabledBenchmark.class,
-    LttngJulHandlerTracingEnabledBenchmark.class,
-    NoHandlerBenchmark.class
+    org.lttng.ust.agent.jul.benchmarks.handler.NoHandlerBenchmark.class,
+    org.lttng.ust.agent.jul.benchmarks.handler.DummyHandlerBenchmark.class,
+    org.lttng.ust.agent.jul.benchmarks.handler.FileHandlerBenchmark.class,
+    org.lttng.ust.agent.jul.benchmarks.handler.lttng.LttngJulHandlerTracingDisabledBenchmark.class,
+    org.lttng.ust.agent.jul.benchmarks.handler.lttng.LttngJulHandlerTracingEnabledBenchmark.class,
+    org.lttng.ust.agent.jul.benchmarks.handler.lttng.old.OldLttngJulHandlerTracingDisabledBenchmark.class,
+    org.lttng.ust.agent.jul.benchmarks.handler.lttng.old.OldLttngJulHandlerTracingEnabledBenchmark.class
 })
 public class RunAllTests {
 }
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/AbstractJulBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/handler/AbstractJulBenchmark.java
new file mode 100644 (file)
index 0000000..0f51012
--- /dev/null
@@ -0,0 +1,145 @@
+package org.lttng.ust.agent.jul.benchmarks.handler;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public abstract class AbstractJulBenchmark {
+
+    // ------------------------------------------------------------------------
+    // Configurable test parameters
+    // ------------------------------------------------------------------------
+
+    /** Nb of runs per test, result will be averaged */
+    private static final int NB_RUNS = 10;
+
+    /** Trace/log events per run */
+    private static final int NB_ITER = 100000;
+
+    /** Which tests to run (for different number of threads) */
+    private static final int[] NB_THREADS = {1, 1, 2, 3, 4, 5, 6, 7, 8};
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    protected Logger logger;
+    protected Handler handler;
+
+    // ------------------------------------------------------------------------
+    // Maintenance methods
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void setup() {
+        /* Set up the logger */
+        logger = Logger.getLogger("Test logger");
+        logger.setUseParentHandlers(false);
+        logger.setLevel(Level.ALL);
+
+        /* Sub-classes' @Before will setup the Handler */
+    }
+
+    @After
+    public void teardown() {
+        if (handler != null) {
+            logger.removeHandler(handler);
+            handler.close();
+        }
+        handler = null;
+        logger = null;
+    }
+
+    // ------------------------------------------------------------------------
+    // Test methods
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void runBenchmark() {
+        if (handler != null) {
+            logger.addHandler(handler);
+        }
+
+        System.out.println();
+        System.out.println("Running benchmark: " + this.getClass().getCanonicalName());
+        for (int i : NB_THREADS) {
+            runTest(logger, i);
+        }
+    }
+
+    private static void runTest(Logger log, int nbThreads) {
+        long start, end, average, total = 0;
+        for (int i = 0; i < NB_RUNS; i++) {
+            Runner runner = new Runner(nbThreads, NB_ITER, log);
+
+            start = System.nanoTime();
+            runner.run();
+            end = System.nanoTime();
+
+            total += (end - start);
+        }
+        average = total / NB_RUNS;
+        System.out.println(nbThreads + " threads, average = " + average / NB_ITER + " ns/event");
+    }
+
+    // ------------------------------------------------------------------------
+    // Helper classes
+    // ------------------------------------------------------------------------
+
+    private static class Runner implements Runnable {
+
+        private final List<Worker> workers = new LinkedList<>();
+        private final List<Thread> workerThreads = new LinkedList<>();
+
+        public Runner(int nbThreads, int nbIter, Logger log) {
+
+            for (int id = 0; id < nbThreads; id++) {
+                Worker curWorker = new Worker(id, nbIter, log);
+                workers.add(curWorker);
+                workerThreads.add(new Thread(curWorker, "worker " + id));
+            }
+        }
+
+        @Override
+        public void run() {
+            for (Thread curThread : workerThreads) {
+                curThread.start();
+            }
+
+            for (Thread curThread : workerThreads) {
+                try {
+                    curThread.join();
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+
+        private static class Worker implements Runnable {
+
+            private final Logger log;
+            private final int threadId;
+            private final int nbIter;
+
+            public Worker(int threadId, int nbIter, Logger log) {
+                this.log = log;
+                this.threadId = threadId;
+                this.nbIter = nbIter;
+            }
+
+            @Override
+            public void run() {
+                for (int i = 0; i < nbIter; i++) {
+                    log.info("Thread " + threadId + ", iteration " + i);
+                }
+            }
+
+        }
+    }
+}
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/DummyHandlerBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/handler/DummyHandlerBenchmark.java
new file mode 100644 (file)
index 0000000..5675f9b
--- /dev/null
@@ -0,0 +1,31 @@
+package org.lttng.ust.agent.jul.benchmarks.handler;
+
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+
+import org.junit.Before;
+
+public class DummyHandlerBenchmark extends AbstractJulBenchmark {
+
+    @Before
+    public void testSetup() {
+        handler = new DummyHandler();
+    }
+
+    private static class DummyHandler extends Handler {
+
+        public DummyHandler() {
+            super();
+        }
+
+        @Override
+        public void close() throws SecurityException {}
+
+        @Override
+        public void flush() {}
+
+        @Override
+        public void publish(LogRecord record) {}
+
+    }
+}
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/FileHandlerBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/handler/FileHandlerBenchmark.java
new file mode 100644 (file)
index 0000000..203316d
--- /dev/null
@@ -0,0 +1,16 @@
+package org.lttng.ust.agent.jul.benchmarks.handler;
+
+import java.io.IOException;
+import java.util.logging.FileHandler;
+import java.util.logging.SimpleFormatter;
+
+import org.junit.Before;
+
+public class FileHandlerBenchmark extends AbstractJulBenchmark {
+
+    @Before
+    public void testSetup() throws SecurityException, IOException {
+        handler = new FileHandler("/tmp/log", false);
+        handler.setFormatter(new SimpleFormatter());
+    }
+}
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/NoHandlerBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/handler/NoHandlerBenchmark.java
new file mode 100644 (file)
index 0000000..3d1aab4
--- /dev/null
@@ -0,0 +1,6 @@
+package org.lttng.ust.agent.jul.benchmarks.handler;
+
+public class NoHandlerBenchmark extends AbstractJulBenchmark {
+
+    /* Do not setup any handler */
+}
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java
new file mode 100644 (file)
index 0000000..cd7a59a
--- /dev/null
@@ -0,0 +1,27 @@
+package org.lttng.ust.agent.jul.benchmarks.handler.lttng;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.lttng.ust.agent.jul.LTTngLogHandler;
+import org.lttng.ust.agent.jul.benchmarks.handler.AbstractJulBenchmark;
+import org.lttng.ust.agent.jul.benchmarks.utils.LttngSessionControl;
+
+public class LttngJulHandlerTracingDisabledBenchmark extends AbstractJulBenchmark {
+
+    @Before
+    public void testSetup() throws IOException {
+        handler = new LTTngLogHandler(true);
+
+        assertTrue(LttngSessionControl.setupJulSessionNoEvents());
+    }
+
+    @After
+    public void testTeardown() {
+        assertTrue(LttngSessionControl.stopSession());
+        assertTrue(LttngSessionControl.destroySession());
+    }
+}
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java
new file mode 100644 (file)
index 0000000..d3db3c8
--- /dev/null
@@ -0,0 +1,27 @@
+package org.lttng.ust.agent.jul.benchmarks.handler.lttng;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.lttng.ust.agent.jul.LTTngLogHandler;
+import org.lttng.ust.agent.jul.benchmarks.handler.AbstractJulBenchmark;
+import org.lttng.ust.agent.jul.benchmarks.utils.LttngSessionControl;
+
+public class LttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark {
+
+    @Before
+    public void testSetup() throws IOException {
+        handler = new LTTngLogHandler(true);
+
+        assertTrue(LttngSessionControl.setupJulSessionAllEvents());
+    }
+
+    @After
+    public void testTeardown() {
+        assertTrue(LttngSessionControl.stopSession());
+        assertTrue(LttngSessionControl.destroySession());
+    }
+}
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java
new file mode 100644 (file)
index 0000000..a7afc03
--- /dev/null
@@ -0,0 +1,32 @@
+package org.lttng.ust.agent.jul.benchmarks.handler.lttng.old;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.lttng.ust.agent.LTTngAgent;
+import org.lttng.ust.agent.jul.benchmarks.handler.AbstractJulBenchmark;
+import org.lttng.ust.agent.jul.benchmarks.utils.LttngSessionControl;
+
+@SuppressWarnings("deprecation")
+public class OldLttngJulHandlerTracingDisabledBenchmark extends AbstractJulBenchmark {
+
+    private LTTngAgent agent;
+
+    @Before
+    public void testSetup() throws IOException {
+        agent = LTTngAgent.getLTTngAgent();
+
+        assertTrue(LttngSessionControl.setupJulSessionNoEvents());
+    }
+
+    @After
+    public void testTeardown() {
+        assertTrue(LttngSessionControl.stopSession());
+        assertTrue(LttngSessionControl.destroySession());
+
+        agent.dispose();
+    }
+}
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java
new file mode 100644 (file)
index 0000000..28851a4
--- /dev/null
@@ -0,0 +1,62 @@
+package org.lttng.ust.agent.jul.benchmarks.handler.lttng.old;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+
+import org.junit.After;
+import org.junit.Before;
+import org.lttng.ust.agent.LTTngAgent;
+import org.lttng.ust.agent.jul.LTTngJUL;
+import org.lttng.ust.agent.jul.LTTngLogHandler;
+import org.lttng.ust.agent.jul.benchmarks.handler.AbstractJulBenchmark;
+import org.lttng.ust.agent.jul.benchmarks.utils.LttngSessionControl;
+
+@SuppressWarnings("deprecation")
+public class OldLttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark {
+
+    private LTTngAgent agent;
+    private LTTngLogHandler oldHandler;
+
+    @Before
+    public void testSetup() throws IOException {
+        agent = LTTngAgent.getLTTngAgent();
+
+        /*
+         * The "old API" works by attaching a handler managed by the agent to
+         * the root JUL logger. This causes problem here, because we use
+         * logger.setUserParentHandler(false), which does not trigger the
+         * handler as would be expected.
+         *
+         * Instead we will retrieve this handler through reflection, and attach
+         * it to our own logger here for the duration of the test.
+         */
+        try {
+            Field julRootField = LTTngAgent.class.getDeclaredField("julRoot");
+            julRootField.setAccessible(true);
+            LTTngJUL lf = (LTTngJUL) julRootField.get(null); // static field
+
+            Field handlerField = LTTngJUL.class.getDeclaredField("handler");
+            handlerField.setAccessible(true);
+            oldHandler = (LTTngLogHandler) handlerField.get(lf);
+
+            logger.addHandler(oldHandler);
+
+        } catch (ReflectiveOperationException e) {
+            fail();
+        }
+
+        assertTrue(LttngSessionControl.setupJulSessionAllEvents());
+    }
+
+    @After
+    public void testTeardown() {
+        assertTrue(LttngSessionControl.stopSession());
+        assertTrue(LttngSessionControl.destroySession());
+
+        logger.removeHandler(oldHandler);
+        agent.dispose();
+    }
+}
diff --git a/src/org/lttng/ust/agent/jul/benchmarks/utils/LttngSessionControl.java b/src/org/lttng/ust/agent/jul/benchmarks/utils/LttngSessionControl.java
new file mode 100644 (file)
index 0000000..8407be0
--- /dev/null
@@ -0,0 +1,66 @@
+package org.lttng.ust.agent.jul.benchmarks.utils;
+
+import java.io.IOException;
+import java.lang.ProcessBuilder.Redirect;
+
+public final class LttngSessionControl {
+
+    private LttngSessionControl() {}
+
+    public static boolean setupJulSessionNoEvents() {
+        return executeCommands(new String[][] {
+                { "lttng", "create" },
+                /*
+                 * We have to enable a channel for 'lttng start' to work.
+                 * However, we cannot enable a channel directly, see
+                 * https://bugs.lttng.org/issues/894 . Instead we will enable an
+                 * event we know does not exist
+                 */
+                { "lttng", "enable-event", "-j", "non-event" },
+                { "lttng", "start" }
+        });
+    }
+
+    public static boolean setupJulSessionAllEvents() {
+        return executeCommands(new String[][] {
+                { "lttng", "create" },
+                { "lttng", "enable-event", "-j", "-a" },
+                { "lttng", "start" }
+        });
+    }
+
+    public static boolean stopSession() {
+        return executeCommand(new String[] { "lttng", "stop" });
+    }
+
+    public static boolean destroySession() {
+        return executeCommand(new String[] { "lttng", "destroy" });
+    }
+
+    private static boolean executeCommands(String [][] commands) {
+        for (String[] command : commands) {
+            if (executeCommand(command) == false) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static void main(String[] args) {
+        executeCommand(new String[] {"ls", "-l"});
+    }
+
+    private static boolean executeCommand(String[] command) {
+        try {
+            ProcessBuilder builder = new ProcessBuilder(command);
+            builder.redirectErrorStream(true);
+            builder.redirectOutput(Redirect.INHERIT);
+
+            Process p = builder.start();
+            int ret = p.waitFor();
+            return (ret == 0);
+        } catch (IOException | InterruptedException e) {
+            return false;
+        }
+    }
+}
This page took 0.035642 seconds and 4 git commands to generate.