From da8308fe655f5008237400e26160fab0792b7c1d Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Thu, 23 Jul 2015 11:22:44 -0400 Subject: [PATCH] Rename the project to a general ust-java-tests This can hold both unit/integration tests as well as benchmarks. Reshuffle the package names a bit to do so. Signed-off-by: Alexandre Montplaisir --- .project | 2 +- .../benchmarks/jul/RunAllBenchmarks.java | 17 ++ .../jul}/handler/AbstractJulBenchmark.java | 2 +- .../jul}/handler/DummyHandlerBenchmark.java | 2 +- .../jul}/handler/FileHandlerBenchmark.java | 2 +- .../jul}/handler/NoHandlerBenchmark.java | 2 +- ...tngJulHandlerTracingDisabledBenchmark.java | 13 +- ...ttngJulHandlerTracingEnabledBenchmark.java | 13 +- ...tngJulHandlerTracingDisabledBenchmark.java | 15 +- ...ttngJulHandlerTracingEnabledBenchmark.java | 35 ++-- .../integration/jul/JulEnabledEventsTest.java | 180 ++++++++++++++++++ .../ust/agent/jul/benchmarks/RunAllTests.java | 17 -- .../benchmarks/utils/LttngSessionControl.java | 66 ------- .../ust/agent/utils/LttngSessionControl.java | 174 +++++++++++++++++ 14 files changed, 412 insertions(+), 128 deletions(-) create mode 100644 src/org/lttng/ust/agent/benchmarks/jul/RunAllBenchmarks.java rename src/org/lttng/ust/agent/{jul/benchmarks => benchmarks/jul}/handler/AbstractJulBenchmark.java (98%) rename src/org/lttng/ust/agent/{jul/benchmarks => benchmarks/jul}/handler/DummyHandlerBenchmark.java (91%) rename src/org/lttng/ust/agent/{jul/benchmarks => benchmarks/jul}/handler/FileHandlerBenchmark.java (88%) rename src/org/lttng/ust/agent/{jul/benchmarks => benchmarks/jul}/handler/NoHandlerBenchmark.java (66%) rename src/org/lttng/ust/agent/{jul/benchmarks => benchmarks/jul}/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java (53%) rename src/org/lttng/ust/agent/{jul/benchmarks => benchmarks/jul}/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java (52%) rename src/org/lttng/ust/agent/{jul/benchmarks => benchmarks/jul}/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java (58%) rename src/org/lttng/ust/agent/{jul/benchmarks => benchmarks/jul}/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java (50%) create mode 100644 src/org/lttng/ust/agent/integration/jul/JulEnabledEventsTest.java delete mode 100644 src/org/lttng/ust/agent/jul/benchmarks/RunAllTests.java delete mode 100644 src/org/lttng/ust/agent/jul/benchmarks/utils/LttngSessionControl.java create mode 100644 src/org/lttng/ust/agent/utils/LttngSessionControl.java diff --git a/.project b/.project index 1b1828e..0617969 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - lttng-ust-agent-jul-benchmarks + ust-java-tests diff --git a/src/org/lttng/ust/agent/benchmarks/jul/RunAllBenchmarks.java b/src/org/lttng/ust/agent/benchmarks/jul/RunAllBenchmarks.java new file mode 100644 index 0000000..e8fa16d --- /dev/null +++ b/src/org/lttng/ust/agent/benchmarks/jul/RunAllBenchmarks.java @@ -0,0 +1,17 @@ +package org.lttng.ust.agent.benchmarks.jul; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + org.lttng.ust.agent.benchmarks.jul.handler.NoHandlerBenchmark.class, + org.lttng.ust.agent.benchmarks.jul.handler.DummyHandlerBenchmark.class, +// org.lttng.ust.agent.jul.benchmarks.handler.FileHandlerBenchmark.class, + org.lttng.ust.agent.benchmarks.jul.handler.lttng.LttngJulHandlerTracingDisabledBenchmark.class, + org.lttng.ust.agent.benchmarks.jul.handler.lttng.LttngJulHandlerTracingEnabledBenchmark.class, + org.lttng.ust.agent.benchmarks.jul.handler.lttng.old.OldLttngJulHandlerTracingDisabledBenchmark.class, + org.lttng.ust.agent.benchmarks.jul.handler.lttng.old.OldLttngJulHandlerTracingEnabledBenchmark.class +}) +public class RunAllBenchmarks { +} diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/AbstractJulBenchmark.java b/src/org/lttng/ust/agent/benchmarks/jul/handler/AbstractJulBenchmark.java similarity index 98% rename from src/org/lttng/ust/agent/jul/benchmarks/handler/AbstractJulBenchmark.java rename to src/org/lttng/ust/agent/benchmarks/jul/handler/AbstractJulBenchmark.java index 0f51012..a089e9d 100644 --- a/src/org/lttng/ust/agent/jul/benchmarks/handler/AbstractJulBenchmark.java +++ b/src/org/lttng/ust/agent/benchmarks/jul/handler/AbstractJulBenchmark.java @@ -1,4 +1,4 @@ -package org.lttng.ust.agent.jul.benchmarks.handler; +package org.lttng.ust.agent.benchmarks.jul.handler; import java.util.LinkedList; import java.util.List; diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/DummyHandlerBenchmark.java b/src/org/lttng/ust/agent/benchmarks/jul/handler/DummyHandlerBenchmark.java similarity index 91% rename from src/org/lttng/ust/agent/jul/benchmarks/handler/DummyHandlerBenchmark.java rename to src/org/lttng/ust/agent/benchmarks/jul/handler/DummyHandlerBenchmark.java index 5675f9b..d962b42 100644 --- a/src/org/lttng/ust/agent/jul/benchmarks/handler/DummyHandlerBenchmark.java +++ b/src/org/lttng/ust/agent/benchmarks/jul/handler/DummyHandlerBenchmark.java @@ -1,4 +1,4 @@ -package org.lttng.ust.agent.jul.benchmarks.handler; +package org.lttng.ust.agent.benchmarks.jul.handler; import java.util.logging.Handler; import java.util.logging.LogRecord; diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/FileHandlerBenchmark.java b/src/org/lttng/ust/agent/benchmarks/jul/handler/FileHandlerBenchmark.java similarity index 88% rename from src/org/lttng/ust/agent/jul/benchmarks/handler/FileHandlerBenchmark.java rename to src/org/lttng/ust/agent/benchmarks/jul/handler/FileHandlerBenchmark.java index 203316d..d6095aa 100644 --- a/src/org/lttng/ust/agent/jul/benchmarks/handler/FileHandlerBenchmark.java +++ b/src/org/lttng/ust/agent/benchmarks/jul/handler/FileHandlerBenchmark.java @@ -1,4 +1,4 @@ -package org.lttng.ust.agent.jul.benchmarks.handler; +package org.lttng.ust.agent.benchmarks.jul.handler; import java.io.IOException; import java.util.logging.FileHandler; diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/NoHandlerBenchmark.java b/src/org/lttng/ust/agent/benchmarks/jul/handler/NoHandlerBenchmark.java similarity index 66% rename from src/org/lttng/ust/agent/jul/benchmarks/handler/NoHandlerBenchmark.java rename to src/org/lttng/ust/agent/benchmarks/jul/handler/NoHandlerBenchmark.java index 3d1aab4..424b32e 100644 --- a/src/org/lttng/ust/agent/jul/benchmarks/handler/NoHandlerBenchmark.java +++ b/src/org/lttng/ust/agent/benchmarks/jul/handler/NoHandlerBenchmark.java @@ -1,4 +1,4 @@ -package org.lttng.ust.agent.jul.benchmarks.handler; +package org.lttng.ust.agent.benchmarks.jul.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/benchmarks/jul/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java similarity index 53% rename from src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java rename to src/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java index cd7a59a..690af1d 100644 --- a/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java +++ b/src/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java @@ -1,4 +1,4 @@ -package org.lttng.ust.agent.jul.benchmarks.handler.lttng; +package org.lttng.ust.agent.benchmarks.jul.handler.lttng; import static org.junit.Assert.assertTrue; @@ -6,17 +6,18 @@ 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; +import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark; +import org.lttng.ust.agent.jul.LttngLogHandler; +import org.lttng.ust.agent.utils.LttngSessionControl; +import org.lttng.ust.agent.utils.LttngSessionControl.Domain; public class LttngJulHandlerTracingDisabledBenchmark extends AbstractJulBenchmark { @Before public void testSetup() throws IOException { - handler = new LTTngLogHandler(true); + handler = new LttngLogHandler(); - assertTrue(LttngSessionControl.setupJulSessionNoEvents()); + assertTrue(LttngSessionControl.setupSession(null, Domain.JUL)); } @After diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java b/src/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java similarity index 52% rename from src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java rename to src/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java index d3db3c8..eb0514e 100644 --- a/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java +++ b/src/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java @@ -1,4 +1,4 @@ -package org.lttng.ust.agent.jul.benchmarks.handler.lttng; +package org.lttng.ust.agent.benchmarks.jul.handler.lttng; import static org.junit.Assert.assertTrue; @@ -6,17 +6,18 @@ 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; +import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark; +import org.lttng.ust.agent.jul.LttngLogHandler; +import org.lttng.ust.agent.utils.LttngSessionControl; +import org.lttng.ust.agent.utils.LttngSessionControl.Domain; public class LttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark { @Before public void testSetup() throws IOException { - handler = new LTTngLogHandler(true); + handler = new LttngLogHandler(); - assertTrue(LttngSessionControl.setupJulSessionAllEvents()); + assertTrue(LttngSessionControl.setupSessionAllEvents(null, Domain.JUL)); } @After diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java b/src/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java similarity index 58% rename from src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java rename to src/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java index a7afc03..c8cbe6e 100644 --- a/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java +++ b/src/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java @@ -1,4 +1,4 @@ -package org.lttng.ust.agent.jul.benchmarks.handler.lttng.old; +package org.lttng.ust.agent.benchmarks.jul.handler.lttng.old; import static org.junit.Assert.assertTrue; @@ -7,19 +7,18 @@ 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; +import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark; +import org.lttng.ust.agent.utils.LttngSessionControl; +import org.lttng.ust.agent.utils.LttngSessionControl.Domain; @SuppressWarnings("deprecation") public class OldLttngJulHandlerTracingDisabledBenchmark extends AbstractJulBenchmark { - private LTTngAgent agent; - @Before public void testSetup() throws IOException { - agent = LTTngAgent.getLTTngAgent(); + LTTngAgent.getLTTngAgent(); - assertTrue(LttngSessionControl.setupJulSessionNoEvents()); + assertTrue(LttngSessionControl.setupSession(null, Domain.JUL)); } @After @@ -27,6 +26,6 @@ public class OldLttngJulHandlerTracingDisabledBenchmark extends AbstractJulBench assertTrue(LttngSessionControl.stopSession()); assertTrue(LttngSessionControl.destroySession()); - agent.dispose(); + LTTngAgent.dispose(); } } diff --git a/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java b/src/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java similarity index 50% rename from src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java rename to src/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java index 28851a4..3e6636b 100644 --- a/src/org/lttng/ust/agent/jul/benchmarks/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java +++ b/src/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java @@ -1,4 +1,4 @@ -package org.lttng.ust.agent.jul.benchmarks.handler.lttng.old; +package org.lttng.ust.agent.benchmarks.jul.handler.lttng.old; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -9,24 +9,23 @@ 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; +import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark; +import org.lttng.ust.agent.jul.LttngLogHandler; +import org.lttng.ust.agent.utils.LttngSessionControl; +import org.lttng.ust.agent.utils.LttngSessionControl.Domain; @SuppressWarnings("deprecation") public class OldLttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark { - private LTTngAgent agent; - private LTTngLogHandler oldHandler; + private LttngLogHandler agentHandler; @Before public void testSetup() throws IOException { - agent = LTTngAgent.getLTTngAgent(); + LTTngAgent agentInstance = 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 + * the root JUL logger. This causes problems here, because we use * logger.setUserParentHandler(false), which does not trigger the * handler as would be expected. * @@ -34,21 +33,17 @@ public class OldLttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchm * 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 julHandlerField = LTTngAgent.class.getDeclaredField("julHandler"); + julHandlerField.setAccessible(true); + agentHandler = (LttngLogHandler) julHandlerField.get(agentInstance); - Field handlerField = LTTngJUL.class.getDeclaredField("handler"); - handlerField.setAccessible(true); - oldHandler = (LTTngLogHandler) handlerField.get(lf); - - logger.addHandler(oldHandler); + logger.addHandler(agentHandler); } catch (ReflectiveOperationException e) { fail(); } - assertTrue(LttngSessionControl.setupJulSessionAllEvents()); + assertTrue(LttngSessionControl.setupSessionAllEvents(null, Domain.JUL)); } @After @@ -56,7 +51,7 @@ public class OldLttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchm assertTrue(LttngSessionControl.stopSession()); assertTrue(LttngSessionControl.destroySession()); - logger.removeHandler(oldHandler); - agent.dispose(); + logger.removeHandler(agentHandler); + LTTngAgent.dispose(); } } diff --git a/src/org/lttng/ust/agent/integration/jul/JulEnabledEventsTest.java b/src/org/lttng/ust/agent/integration/jul/JulEnabledEventsTest.java new file mode 100644 index 0000000..27f033e --- /dev/null +++ b/src/org/lttng/ust/agent/integration/jul/JulEnabledEventsTest.java @@ -0,0 +1,180 @@ +package org.lttng.ust.agent.integration.jul; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + +import java.io.IOException; +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.BeforeClass; +import org.junit.Test; +import org.lttng.ust.agent.jul.LttngLogHandler; +import org.lttng.ust.agent.utils.LttngSessionControl; +import org.lttng.ust.agent.utils.LttngSessionControl.Domain; + +public class JulEnabledEventsTest { + + private static final Domain DOMAIN = Domain.JUL; + + private static final String EVENT_NAME_A = "EventA"; + private static final String EVENT_NAME_B = "EventAB"; + private static final String EVENT_NAME_C = "EventABC"; + private static final String EVENT_NAME_D = "EventABCD"; + + private Logger loggerA; + private Logger loggerB; + private Logger loggerC; + private Logger loggerD; + + private Handler handlerA; + private Handler handlerB; + private Handler handlerC; + + @BeforeClass + public static void classSetup() { + /* Skip tests if we can't find the JNI library or lttng-tools */ + try { + LttngLogHandler testHandler = new LttngLogHandler(); + testHandler.close(); + } catch (SecurityException | IOException e) { + assumeTrue(false); + } + + boolean ret1 = LttngSessionControl.setupSession(null, DOMAIN); + boolean ret2 = LttngSessionControl.stopSession(); + boolean ret3 = LttngSessionControl.destroySession(); + assumeTrue(ret1 && ret2 && ret3); + } + + @Before + public void setup() throws SecurityException, IOException { + loggerA = Logger.getLogger(EVENT_NAME_A); + loggerB = Logger.getLogger(EVENT_NAME_B); + loggerC = Logger.getLogger(EVENT_NAME_C); + loggerD = Logger.getLogger(EVENT_NAME_D); + + loggerA.setLevel(Level.ALL); + loggerB.setLevel(Level.ALL); + loggerC.setLevel(Level.ALL); + loggerD.setLevel(Level.ALL); + + handlerA = new LttngLogHandler(); + handlerB = new LttngLogHandler(); + handlerC = new LttngLogHandler(); + + loggerA.addHandler(handlerA); + loggerB.addHandler(handlerB); + loggerC.addHandler(handlerB); + } + + @After + public void teardown() { + loggerA.removeHandler(handlerA); + loggerB.removeHandler(handlerB); + loggerC.removeHandler(handlerC); + + handlerA.close(); + handlerB.close(); + handlerC.close(); + + loggerA = null; + loggerB = null; + loggerC = null; + loggerD = null; + handlerA = null; + handlerB = null; + handlerC = null; + } + + /** + * Test sending events on the Java side, but no events enabled in the + * tracing session. There should be nothing in the resulting trace. + */ + @Test + public void testNoEvents() { + assertTrue(LttngSessionControl.setupSession(null, DOMAIN)); + + send10Events(loggerA); + send10Events(loggerB); + send10Events(loggerC); + send10Events(loggerD); + + assertTrue(LttngSessionControl.stopSession()); + + List output = LttngSessionControl.viewSession(); + assertNotNull(output); + assertTrue(output.isEmpty()); + + assertTrue(LttngSessionControl.destroySession()); + } + + /** + * Test sending events on the Java side, and all events enabled in the + * tracing session. All handlers should have sent their events. + */ + @Test + public void testAllEvents() { + assertTrue(LttngSessionControl.setupSessionAllEvents(null, DOMAIN)); + + send10Events(loggerA); + send10Events(loggerB); + send10Events(loggerC); + send10Events(loggerD); + + assertTrue(LttngSessionControl.stopSession()); + + List output = LttngSessionControl.viewSession(); + assertNotNull(output); + assertEquals(20, output.size()); // loggerC has no handler attached + + assertTrue(LttngSessionControl.destroySession()); + } + + /** + * Test sending events on the Java side, with only some of them enabled in + * the tracing session. Only the subset that is enabled should be received. + */ + @Test + public void testSomeEvents() { + assertTrue(LttngSessionControl.setupSession(null, DOMAIN, + EVENT_NAME_A, EVENT_NAME_D)); + + send10Events(loggerA); + send10Events(loggerB); + send10Events(loggerC); + send10Events(loggerD); + + assertTrue(LttngSessionControl.stopSession()); + + List output = LttngSessionControl.viewSession(); + assertNotNull(output); + assertEquals(10, output.size()); // loggerC has no handler attached + + assertTrue(LttngSessionControl.destroySession()); + } + + private static void send10Events(Logger logger) { + String a = new String("a"); + Object[] params = {a, new String("b"), new Object()}; + + // Levels are FINE, FINER, FINEST, INFO, SEVERE, WARNING + logger.fine("A fine level message"); + logger.finer("A finer level message"); + logger.finest("A finest level message"); + logger.info("A info level message"); + logger.severe("A severe level message"); + logger.warning("A warning level message"); + logger.warning("Another warning level message"); + logger.log(Level.WARNING, "A warning message using Logger.log()"); + logger.log(Level.INFO, "A message with one parameter", a); + logger.log(Level.INFO, "A message with parameters", params); + } + +} diff --git a/src/org/lttng/ust/agent/jul/benchmarks/RunAllTests.java b/src/org/lttng/ust/agent/jul/benchmarks/RunAllTests.java deleted file mode 100644 index 42ce901..0000000 --- a/src/org/lttng/ust/agent/jul/benchmarks/RunAllTests.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.lttng.ust.agent.jul.benchmarks; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - 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/utils/LttngSessionControl.java b/src/org/lttng/ust/agent/jul/benchmarks/utils/LttngSessionControl.java deleted file mode 100644 index 8407be0..0000000 --- a/src/org/lttng/ust/agent/jul/benchmarks/utils/LttngSessionControl.java +++ /dev/null @@ -1,66 +0,0 @@ -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; - } - } -} diff --git a/src/org/lttng/ust/agent/utils/LttngSessionControl.java b/src/org/lttng/ust/agent/utils/LttngSessionControl.java new file mode 100644 index 0000000..48eacc5 --- /dev/null +++ b/src/org/lttng/ust/agent/utils/LttngSessionControl.java @@ -0,0 +1,174 @@ +package org.lttng.ust.agent.utils; + +import java.io.IOException; +import java.lang.ProcessBuilder.Redirect; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public final class LttngSessionControl { + + private LttngSessionControl() {} + + public enum Domain { + JUL("-j"), + LOG4J("-l"); + + private final String flag; + + private Domain(String flag) { + this.flag = flag; + } + + public String flag() { + return flag; + } + } + + // ------------------------------------------------------------------------ + // Public utility methods + // ------------------------------------------------------------------------ + + /** + * Setup a LTTng session by enabling certain events (or none). + * + * @param sessionName + * The name of the session to create. May be null to use the + * default one from lttng-tools. + * @param domain + * The tracing domain + * @param enabledEvents + * The list of events to enable. May be null or empty, to not + * enable any events. + * @return If the command executed successfully (return code = 0). + */ + public static boolean setupSession(String sessionName, Domain domain, String... enabledEvents) { + String[] createCommand = (sessionName == null ? + new String[] { "lttng", "create" } : + new String[] { "lttng", "create", sessionName} + ); + + String eventsToEnable = (enabledEvents == null || enabledEvents.length == 0 ? + /* + * 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 + */ + "non-event" : + Arrays.stream(enabledEvents).collect(Collectors.joining(",")) + ); + + return executeCommands(new String[][] { + createCommand, + { "lttng", "enable-event", domain.flag(), eventsToEnable}, + { "lttng", "start" } + }); + } + + /** + * Setup a LTTng session with all events enabled (lttng enable-event -a). + * + * @param sessionName + * The name of the session to create. May be null to use the + * default one from lttng-tools. + * @param domain + * The tracing domain + * @return If the command executed successfully (return code = 0). + */ + public static boolean setupSessionAllEvents(String sessionName, Domain domain) { + String[] createCommand = (sessionName == null ? + new String[] { "lttng", "create" } : + new String[] { "lttng", "create", sessionName} + ); + + return executeCommands(new String[][] { + createCommand, + { "lttng", "enable-event", domain.flag(), "-a" }, + { "lttng", "start" } + }); + } + + /** + * Stop the current tracing session + * + * @return If the command executed successfully (return code = 0). + */ + public static boolean stopSession() { + return executeCommand(new String[] { "lttng", "stop" }); + } + + public static List viewSession() { + return getOutputFromCommand(new String[] { "lttng", "view" }); + } + + /** + * Destroy the current tracing session + * + * @return If the command executed successfully (return code = 0). + */ + public static boolean destroySession() { + return executeCommand(new String[] { "lttng", "destroy" }); + } + + // ------------------------------------------------------------------------ + // Private helper methods + // ------------------------------------------------------------------------ + + private static boolean executeCommands(String [][] commands) { + for (String[] command : commands) { + if (executeCommand(command) == false) { + return false; + } + } + return true; + } + + /** + * Just to test the environment / stdout are working correctly + */ + 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; + } + } + + private static List getOutputFromCommand(String[] command) { + try { + Path tempFile = Files.createTempFile("test-output", null); + + ProcessBuilder builder = new ProcessBuilder(command); + builder.redirectErrorStream(true); + builder.redirectOutput(Redirect.to(tempFile.toFile())); + + Process p = builder.start(); + p.waitFor(); + + List lines = Files.readAllLines(tempFile); + Files.delete(tempFile); + + /* Also print the output to the console */ + lines.stream().forEach(s -> System.out.println(s)); + + return lines; + + } catch (IOException | InterruptedException e) { + return null; + } + } +} -- 2.39.5