Also move the tests in subpackages.
<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>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>test</name>
+ <name>lttng-ust-agent-jul-benchmarks</name>
<comment></comment>
<projects>
</projects>
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
+++ /dev/null
-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);
- }
- }
-
- }
- }
-}
+++ /dev/null
-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) {}
-
- }
-}
+++ /dev/null
-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());
- }
-}
+++ /dev/null
-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());
- }
-}
+++ /dev/null
-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());
- }
-}
+++ /dev/null
-package org.lttng.ust.agent.jul.benchmarks;
-
-public class NoHandlerBenchmark extends AbstractJulBenchmark {
-
- /* Do not setup any handler */
-}
@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 {
}
--- /dev/null
+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);
+ }
+ }
+
+ }
+ }
+}
--- /dev/null
+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) {}
+
+ }
+}
--- /dev/null
+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());
+ }
+}
--- /dev/null
+package org.lttng.ust.agent.jul.benchmarks.handler;
+
+public class NoHandlerBenchmark extends AbstractJulBenchmark {
+
+ /* Do not setup any handler */
+}
--- /dev/null
+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());
+ }
+}
--- /dev/null
+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());
+ }
+}
--- /dev/null
+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();
+ }
+}
--- /dev/null
+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();
+ }
+}
--- /dev/null
+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;
+ }
+ }
+}