From: Alexandre Montplaisir Date: Sat, 25 Jul 2015 06:51:34 +0000 (-0400) Subject: Actually add the profile to run the benchmarks X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d4e2e87c9bb9dfe32fa15aea16fc24b86a0fe661;p=lttng-ust-java-tests.git Actually add the profile to run the benchmarks Signed-off-by: Alexandre Montplaisir --- diff --git a/pom.xml b/pom.xml index e5ec790..fe19978 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 + + 3.0 + + org.lttng.ust.agent lttng-ust-agent-tests 1.0.0 @@ -82,7 +86,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 + 3.3 1.8 1.8 @@ -91,4 +95,24 @@ + + + benchmark + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18.1 + + + **/*Benchmark.java + + + + + + + + diff --git a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/AbstractJulBenchmark.java b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/AbstractJulBenchmark.java deleted file mode 100644 index a089e9d..0000000 --- a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/AbstractJulBenchmark.java +++ /dev/null @@ -1,145 +0,0 @@ -package org.lttng.ust.agent.benchmarks.jul.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 workers = new LinkedList<>(); - private final List 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/test/java/org/lttng/ust/agent/benchmarks/jul/handler/DummyHandlerBenchmark.java b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/DummyHandlerBenchmark.java deleted file mode 100644 index d962b42..0000000 --- a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/DummyHandlerBenchmark.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.lttng.ust.agent.benchmarks.jul.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/test/java/org/lttng/ust/agent/benchmarks/jul/handler/FileHandlerBenchmark.java b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/FileHandlerBenchmark.java deleted file mode 100644 index 167c741..0000000 --- a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/FileHandlerBenchmark.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.lttng.ust.agent.benchmarks.jul.handler; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.logging.FileHandler; -import java.util.logging.SimpleFormatter; - -import org.junit.After; -import org.junit.Before; - -public class FileHandlerBenchmark extends AbstractJulBenchmark { - - private Path outputFile; - - @Before - public void testSetup() throws SecurityException, IOException { - outputFile = Files.createTempFile(this.getClass().getSimpleName(), null); - - handler = new FileHandler(outputFile.toString(), false); - handler.setFormatter(new SimpleFormatter()); - } - - @After - public void testTeardown() throws IOException { - Files.deleteIfExists(outputFile); - } -} diff --git a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/JulHandlerBenchmarkBase.java b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/JulHandlerBenchmarkBase.java new file mode 100644 index 0000000..dbfd331 --- /dev/null +++ b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/JulHandlerBenchmarkBase.java @@ -0,0 +1,145 @@ +package org.lttng.ust.agent.benchmarks.jul.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 JulHandlerBenchmarkBase { + + // ------------------------------------------------------------------------ + // 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 workers = new LinkedList<>(); + private final List 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/test/java/org/lttng/ust/agent/benchmarks/jul/handler/NoHandlerBenchmark.java b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/NoHandlerBenchmark.java deleted file mode 100644 index 424b32e..0000000 --- a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/NoHandlerBenchmark.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.lttng.ust.agent.benchmarks.jul.handler; - -public class NoHandlerBenchmark extends AbstractJulBenchmark { - - /* Do not setup any handler */ -} diff --git a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/DummyHandlerBenchmark.java b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/DummyHandlerBenchmark.java new file mode 100644 index 0000000..cc867cb --- /dev/null +++ b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/DummyHandlerBenchmark.java @@ -0,0 +1,32 @@ +package org.lttng.ust.agent.benchmarks.jul.handler.builtin; + +import java.util.logging.Handler; +import java.util.logging.LogRecord; + +import org.junit.Before; +import org.lttng.ust.agent.benchmarks.jul.handler.JulHandlerBenchmarkBase; + +public class DummyHandlerBenchmark extends JulHandlerBenchmarkBase { + + @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/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/FileHandlerBenchmark.java b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/FileHandlerBenchmark.java new file mode 100644 index 0000000..41a8bae --- /dev/null +++ b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/FileHandlerBenchmark.java @@ -0,0 +1,29 @@ +package org.lttng.ust.agent.benchmarks.jul.handler.builtin; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.logging.FileHandler; +import java.util.logging.SimpleFormatter; + +import org.junit.After; +import org.junit.Before; +import org.lttng.ust.agent.benchmarks.jul.handler.JulHandlerBenchmarkBase; + +public class FileHandlerBenchmark extends JulHandlerBenchmarkBase { + + private Path outputFile; + + @Before + public void testSetup() throws SecurityException, IOException { + outputFile = Files.createTempFile(this.getClass().getSimpleName(), null); + + handler = new FileHandler(outputFile.toString(), false); + handler.setFormatter(new SimpleFormatter()); + } + + @After + public void testTeardown() throws IOException { + Files.deleteIfExists(outputFile); + } +} diff --git a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/NoHandlerBenchmark.java b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/NoHandlerBenchmark.java new file mode 100644 index 0000000..953e5ba --- /dev/null +++ b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/builtin/NoHandlerBenchmark.java @@ -0,0 +1,8 @@ +package org.lttng.ust.agent.benchmarks.jul.handler.builtin; + +import org.lttng.ust.agent.benchmarks.jul.handler.JulHandlerBenchmarkBase; + +public class NoHandlerBenchmark extends JulHandlerBenchmarkBase { + + /* Do not setup any handler */ +} diff --git a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java index 18f84d3..62f7ec5 100644 --- a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java +++ b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingDisabledBenchmark.java @@ -6,12 +6,12 @@ import java.io.IOException; import org.junit.After; import org.junit.Before; -import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark; +import org.lttng.ust.agent.benchmarks.jul.handler.JulHandlerBenchmarkBase; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.LttngSession; import org.lttng.ust.agent.utils.LttngSession.Domain; -public class LttngJulHandlerTracingDisabledBenchmark extends AbstractJulBenchmark { +public class LttngJulHandlerTracingDisabledBenchmark extends JulHandlerBenchmarkBase { private LttngSession session; diff --git a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java index 02c7b05..031c26e 100644 --- a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java +++ b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/LttngJulHandlerTracingEnabledBenchmark.java @@ -6,12 +6,12 @@ import java.io.IOException; import org.junit.After; import org.junit.Before; -import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark; +import org.lttng.ust.agent.benchmarks.jul.handler.JulHandlerBenchmarkBase; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.LttngSession; import org.lttng.ust.agent.utils.LttngSession.Domain; -public class LttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark { +public class LttngJulHandlerTracingEnabledBenchmark extends JulHandlerBenchmarkBase { private LttngSession session; diff --git a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java index 2978fe0..275e33d 100644 --- a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java +++ b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingDisabledBenchmark.java @@ -5,12 +5,12 @@ import static org.junit.Assert.assertTrue; import org.junit.After; import org.junit.Before; import org.lttng.ust.agent.LTTngAgent; -import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark; +import org.lttng.ust.agent.benchmarks.jul.handler.JulHandlerBenchmarkBase; import org.lttng.ust.agent.utils.LttngSession; import org.lttng.ust.agent.utils.LttngSession.Domain; @SuppressWarnings("deprecation") -public class OldLttngJulHandlerTracingDisabledBenchmark extends AbstractJulBenchmark { +public class OldLttngJulHandlerTracingDisabledBenchmark extends JulHandlerBenchmarkBase { private LttngSession session; diff --git a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java index c6cc49c..1e2ce4b 100644 --- a/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java +++ b/src/test/java/org/lttng/ust/agent/benchmarks/jul/handler/lttng/old/OldLttngJulHandlerTracingEnabledBenchmark.java @@ -8,13 +8,13 @@ import java.lang.reflect.Field; import org.junit.After; import org.junit.Before; import org.lttng.ust.agent.LTTngAgent; -import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark; +import org.lttng.ust.agent.benchmarks.jul.handler.JulHandlerBenchmarkBase; import org.lttng.ust.agent.jul.LttngLogHandler; import org.lttng.ust.agent.utils.LttngSession; import org.lttng.ust.agent.utils.LttngSession.Domain; @SuppressWarnings("deprecation") -public class OldLttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark { +public class OldLttngJulHandlerTracingEnabledBenchmark extends JulHandlerBenchmarkBase { private LttngSession session; private LttngLogHandler agentHandler;