Skip to content
Snippets Groups Projects
Commit a35d7a42 authored by Christian Wulf's avatar Christian Wulf
Browse files

added MooBenchStarter with first test using it

parent 453dac68
No related branches found
No related tags found
No related merge requests found
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();
}
}
......@@ -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 {
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment