xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
+ <prerequisites>
+ <maven>3.0</maven>
+ </prerequisites>
+
<groupId>org.lttng.ust.agent</groupId>
<artifactId>lttng-ust-agent-tests</artifactId>
<version>1.0.0</version>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.1</version>
+ <version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</plugins>
</build>
+ <profiles>
+ <profile>
+ <id>benchmark</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.18.1</version>
+ <configuration>
+ <includes>
+ <include>**/*Benchmark.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
</project>
+++ /dev/null
-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<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.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) {}
-
- }
-}
+++ /dev/null
-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);
- }
-}
--- /dev/null
+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<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.benchmarks.jul.handler;
-
-public class NoHandlerBenchmark extends AbstractJulBenchmark {
-
- /* Do not setup any handler */
-}
--- /dev/null
+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) {}
+
+ }
+}
--- /dev/null
+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);
+ }
+}
--- /dev/null
+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 */
+}
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;
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;
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;
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;