From 86316987b44d0adfa063772b97b4ee31a61c88fc Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Tue, 21 Jul 2015 16:12:53 -0400 Subject: [PATCH] Add benchmarks for old LTTng-JUL API vs. new one Also move the tests in subpackages. --- .classpath | 1 + .project | 2 +- .settings/org.eclipse.jdt.core.prefs | 2 +- ...tngJulHandlerTracingDisabledBenchmark.java | 17 ----- ...ttngJulHandlerTracingEnabledBenchmark.java | 19 ------ .../ust/agent/jul/benchmarks/RunAllTests.java | 12 ++-- .../{ => handler}/AbstractJulBenchmark.java | 6 +- .../{ => handler}/DummyHandlerBenchmark.java | 2 +- .../{ => handler}/FileHandlerBenchmark.java | 2 +- .../{ => handler}/NoHandlerBenchmark.java | 2 +- ...tngJulHandlerTracingDisabledBenchmark.java | 27 ++++++++ ...ttngJulHandlerTracingEnabledBenchmark.java | 27 ++++++++ ...tngJulHandlerTracingDisabledBenchmark.java | 32 +++++++++ ...ttngJulHandlerTracingEnabledBenchmark.java | 62 +++++++++++++++++ .../benchmarks/utils/LttngSessionControl.java | 66 +++++++++++++++++++ 15 files changed, 230 insertions(+), 49 deletions(-) delete mode 100644 src/org/lttng/ust/agent/jul/benchmarks/LttngJulHandlerTracingDisabledBenchmark.java delete mode 100644 src/org/lttng/ust/agent/jul/benchmarks/LttngJulHandlerTracingEnabledBenchmark.java rename src/org/lttng/ust/agent/jul/benchmarks/{ => handler}/AbstractJulBenchmark.java (97%) rename src/org/lttng/ust/agent/jul/benchmarks/{ => handler}/DummyHandlerBenchmark.java (91%) rename src/org/lttng/ust/agent/jul/benchmarks/{ => handler}/FileHandlerBenchmark.java (88%) rename src/org/lttng/ust/agent/jul/benchmarks/{ => handler}/NoHandlerBenchmark.java (66%) create mode 100644 src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java create mode 100644 src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java create mode 100644 src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java create mode 100644 src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java create mode 100644 src/org/lttng/ust/agent/jul/benchmarks/utils/LttngSessionControl.java diff --git a/.classpath b/.classpath index bf7cf4e..0b8166e 100644 --- a/.classpath +++ b/.classpath @@ -4,5 +4,6 @@ + diff --git a/.project b/.project index b0299db..1b1828e 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - test + lttng-ust-agent-jul-benchmarks diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 53d2118..3b5cbc1 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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/LttngJulHandlerTracingDisabledBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/LttngJulHandlerTracingDisabledBenchmark.java deleted file mode 100644 index 22106b6..0000000 --- a/src/org/lttng/ust/agent/jul/benchmarks/LttngJulHandlerTracingDisabledBenchmark.java +++ /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 index 506c7ab..0000000 --- a/src/org/lttng/ust/agent/jul/benchmarks/LttngJulHandlerTracingEnabledBenchmark.java +++ /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/RunAllTests.java b/src/org/lttng/ust/agent/jul/benchmarks/RunAllTests.java index 0f61c03..42ce901 100644 --- a/src/org/lttng/ust/agent/jul/benchmarks/RunAllTests.java +++ b/src/org/lttng/ust/agent/jul/benchmarks/RunAllTests.java @@ -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/AbstractJulBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/handler/AbstractJulBenchmark.java similarity index 97% rename from src/org/lttng/ust/agent/jul/benchmarks/AbstractJulBenchmark.java rename to src/org/lttng/ust/agent/jul/benchmarks/handler/AbstractJulBenchmark.java index 01c213b..0f51012 100644 --- a/src/org/lttng/ust/agent/jul/benchmarks/AbstractJulBenchmark.java +++ b/src/org/lttng/ust/agent/jul/benchmarks/handler/AbstractJulBenchmark.java @@ -1,4 +1,4 @@ -package org.lttng.ust.agent.jul.benchmarks; +package org.lttng.ust.agent.jul.benchmarks.handler; import java.util.LinkedList; import java.util.List; @@ -29,7 +29,7 @@ public abstract class AbstractJulBenchmark { // Attributes // ------------------------------------------------------------------------ - private Logger logger; + protected Logger logger; protected Handler handler; // ------------------------------------------------------------------------ @@ -48,8 +48,8 @@ public abstract class AbstractJulBenchmark { @After public void teardown() { - logger.removeHandler(handler); if (handler != null) { + logger.removeHandler(handler); handler.close(); } handler = null; diff --git a/src/org/lttng/ust/agent/jul/benchmarks/DummyHandlerBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/handler/DummyHandlerBenchmark.java similarity index 91% rename from src/org/lttng/ust/agent/jul/benchmarks/DummyHandlerBenchmark.java rename to src/org/lttng/ust/agent/jul/benchmarks/handler/DummyHandlerBenchmark.java index 0bf2f59..5675f9b 100644 --- a/src/org/lttng/ust/agent/jul/benchmarks/DummyHandlerBenchmark.java +++ b/src/org/lttng/ust/agent/jul/benchmarks/handler/DummyHandlerBenchmark.java @@ -1,4 +1,4 @@ -package org.lttng.ust.agent.jul.benchmarks; +package org.lttng.ust.agent.jul.benchmarks.handler; import java.util.logging.Handler; import java.util.logging.LogRecord; diff --git a/src/org/lttng/ust/agent/jul/benchmarks/FileHandlerBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/handler/FileHandlerBenchmark.java similarity index 88% rename from src/org/lttng/ust/agent/jul/benchmarks/FileHandlerBenchmark.java rename to src/org/lttng/ust/agent/jul/benchmarks/handler/FileHandlerBenchmark.java index 91a0419..203316d 100644 --- a/src/org/lttng/ust/agent/jul/benchmarks/FileHandlerBenchmark.java +++ b/src/org/lttng/ust/agent/jul/benchmarks/handler/FileHandlerBenchmark.java @@ -1,4 +1,4 @@ -package org.lttng.ust.agent.jul.benchmarks; +package org.lttng.ust.agent.jul.benchmarks.handler; import java.io.IOException; import java.util.logging.FileHandler; diff --git a/src/org/lttng/ust/agent/jul/benchmarks/NoHandlerBenchmark.java b/src/org/lttng/ust/agent/jul/benchmarks/handler/NoHandlerBenchmark.java similarity index 66% rename from src/org/lttng/ust/agent/jul/benchmarks/NoHandlerBenchmark.java rename to src/org/lttng/ust/agent/jul/benchmarks/handler/NoHandlerBenchmark.java index ec569af..3d1aab4 100644 --- a/src/org/lttng/ust/agent/jul/benchmarks/NoHandlerBenchmark.java +++ b/src/org/lttng/ust/agent/jul/benchmarks/handler/NoHandlerBenchmark.java @@ -1,4 +1,4 @@ -package org.lttng.ust.agent.jul.benchmarks; +package org.lttng.ust.agent.jul.benchmarks.handler; public class NoHandlerBenchmark extends AbstractJulBenchmark { 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 index 0000000..cd7a59a --- /dev/null +++ b/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java @@ -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 index 0000000..d3db3c8 --- /dev/null +++ b/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java @@ -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 index 0000000..a7afc03 --- /dev/null +++ b/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java @@ -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 index 0000000..28851a4 --- /dev/null +++ b/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java @@ -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 index 0000000..8407be0 --- /dev/null +++ b/src/org/lttng/ust/agent/jul/benchmarks/utils/LttngSessionControl.java @@ -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; + } + } +} -- 2.34.1