From a35d7a42696ef43408e18d51595f266beaad10d3 Mon Sep 17 00:00:00 2001 From: Christian Wulf <chw@informatik.uni-kiel.de> Date: Tue, 19 Aug 2014 05:28:29 +0200 Subject: [PATCH] added MooBenchStarter with first test using it --- src/main/java/util/MooBenchStarter.java | 31 +++++++++++ .../examples/kiekerdays/KiekerLoadDriver.java | 17 ++++-- ...TraceReductionAnalysisWithThreadsTest.java | 53 ++++++++++++++++--- 3 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 src/main/java/util/MooBenchStarter.java diff --git a/src/main/java/util/MooBenchStarter.java b/src/main/java/util/MooBenchStarter.java new file mode 100644 index 00000000..6a5a42eb --- /dev/null +++ b/src/main/java/util/MooBenchStarter.java @@ -0,0 +1,31 @@ +package util; + +import java.io.File; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +public class MooBenchStarter { + + private final File execDir; + + public MooBenchStarter() { + this.execDir = new File("scripts/MooBench-cmd"); + System.out.println("execDir: " + this.execDir.getAbsolutePath()); + } + + public void start(final int runs, final long calls) throws IOException { + List<String> command = new LinkedList<String>(); + command.add("cmd"); + command.add("/c"); + command.add("start"); + command.add("/D"); + command.add(this.execDir.getAbsolutePath()); + command.add("Load Driver"); + command.add("startMooBench.cmd"); + command.add(String.valueOf(runs)); + command.add(String.valueOf(calls)); + + new ProcessBuilder(command).start(); + } +} diff --git a/src/test/java/teetime/variant/methodcallWithPorts/examples/kiekerdays/KiekerLoadDriver.java b/src/test/java/teetime/variant/methodcallWithPorts/examples/kiekerdays/KiekerLoadDriver.java index 133b83c5..ba836104 100644 --- a/src/test/java/teetime/variant/methodcallWithPorts/examples/kiekerdays/KiekerLoadDriver.java +++ b/src/test/java/teetime/variant/methodcallWithPorts/examples/kiekerdays/KiekerLoadDriver.java @@ -2,9 +2,11 @@ package teetime.variant.methodcallWithPorts.examples.kiekerdays; import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; @@ -123,8 +125,13 @@ public class KiekerLoadDriver { final int runs = Integer.parseInt(args[2]); KiekerLoadDriver kiekerLoadDriver = new KiekerLoadDriver(directory); - kiekerLoadDriver.timings = new long[runs]; - Collection<IMonitoringRecord> records = kiekerLoadDriver.load(); + kiekerLoadDriver.start(runs); + kiekerLoadDriver.writeTimingsToFile(outputFile); + } + + public void start(final int runs) throws IOException { + this.timings = new long[runs]; + Collection<IMonitoringRecord> records = this.load(); final Registry<String> stringRegistry = new Registry<String>(); ByteBuffer recordBuffer = ByteBuffer.allocateDirect(Short.MAX_VALUE); @@ -165,7 +172,7 @@ public class KiekerLoadDriver { long start_ns = System.nanoTime(); int writtenBytes = socketChannel.write(recordBuffer); long stop_ns = System.nanoTime(); - kiekerLoadDriver.timings[i] = stop_ns - start_ns; + this.timings[i] = stop_ns - start_ns; if ((i % 100000) == 0) { System.out.println(i); // NOPMD (System.out) } @@ -181,10 +188,12 @@ public class KiekerLoadDriver { } finally { recordReceiver.close(); } + } + public void writeTimingsToFile(final File outputFile) throws UnsupportedEncodingException, FileNotFoundException { PrintStream ps = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFile), 8192 * 8), false, "UTF-8"); try { - for (long timing : kiekerLoadDriver.timings) { + for (long timing : this.timings) { ps.println("0;" + timing); } } finally { diff --git a/src/test/java/teetime/variant/methodcallWithPorts/examples/traceReductionWithThreads/ChwWorkTcpTraceReductionAnalysisWithThreadsTest.java b/src/test/java/teetime/variant/methodcallWithPorts/examples/traceReductionWithThreads/ChwWorkTcpTraceReductionAnalysisWithThreadsTest.java index 11aaa5b6..7db26144 100644 --- a/src/test/java/teetime/variant/methodcallWithPorts/examples/traceReductionWithThreads/ChwWorkTcpTraceReductionAnalysisWithThreadsTest.java +++ b/src/test/java/teetime/variant/methodcallWithPorts/examples/traceReductionWithThreads/ChwWorkTcpTraceReductionAnalysisWithThreadsTest.java @@ -17,23 +17,26 @@ package teetime.variant.methodcallWithPorts.examples.traceReductionWithThreads; import static org.junit.Assert.assertEquals; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import teetime.util.ListUtil; import teetime.util.StopWatch; +import util.MooBenchStarter; import util.StatisticsUtil; /** * @author Christian Wulf - * + * * @since 1.10 */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) @@ -42,8 +45,15 @@ public class ChwWorkTcpTraceReductionAnalysisWithThreadsTest { private static final int EXPECTED_NUM_TRACES = 1000000; private static final int EXPECTED_NUM_SAME_TRACES = 1; + private static MooBenchStarter mooBenchStarter; + private StopWatch stopWatch; + @BeforeClass + public static void beforeClass() { + mooBenchStarter = new MooBenchStarter(); + } + @Before public void before() { this.stopWatch = new StopWatch(); @@ -56,18 +66,36 @@ public class ChwWorkTcpTraceReductionAnalysisWithThreadsTest { } @Test - public void performAnalysisWith1Thread() { - this.performAnalysis(1); + public void performAnalysisWith1Thread() throws InterruptedException, IOException { + Runnable runnable = new Runnable() { + @Override + public void run() { + ChwWorkTcpTraceReductionAnalysisWithThreadsTest.this.performAnalysis(1); + } + }; + this.startTest(runnable); } @Test - public void performAnalysisWith2Threads() { - this.performAnalysis(2); + public void performAnalysisWith2Threads() throws InterruptedException, IOException { + Runnable runnable = new Runnable() { + @Override + public void run() { + ChwWorkTcpTraceReductionAnalysisWithThreadsTest.this.performAnalysis(2); + } + }; + this.startTest(runnable); } @Test - public void performAnalysisWith4Threads() { - this.performAnalysis(4); + public void performAnalysisWith4Threads() throws InterruptedException, IOException { + Runnable runnable = new Runnable() { + @Override + public void run() { + ChwWorkTcpTraceReductionAnalysisWithThreadsTest.this.performAnalysis(4); + } + }; + this.startTest(runnable); } void performAnalysis(final int numWorkerThreads) { @@ -107,6 +135,17 @@ public class ChwWorkTcpTraceReductionAnalysisWithThreadsTest { assertEquals("#traces", EXPECTED_NUM_SAME_TRACES, analysis.getNumTraces()); } + private void startTest(final Runnable runnable) throws InterruptedException, IOException { + Thread thread = new Thread(runnable); + thread.start(); + + Thread.sleep(1000); + + mooBenchStarter.start(1, EXPECTED_NUM_TRACES); + + thread.join(); + } + public static void main(final String[] args) { ChwWorkTcpTraceReductionAnalysisWithThreadsTest analysis = new ChwWorkTcpTraceReductionAnalysisWithThreadsTest(); analysis.before(); -- GitLab