Skip to content
Snippets Groups Projects
Commit 53ccd4c8 authored by Jan Waller's avatar Jan Waller
Browse files

support exchange of BenchmarkingThread

parent 5487755b
No related branches found
No related tags found
No related merge requests found
...@@ -63,10 +63,11 @@ public final class Benchmark { ...@@ -63,10 +63,11 @@ public final class Benchmark {
// 2. Initialize Threads and Classes // 2. Initialize Threads and Classes
final CountDownLatch doneSignal = new CountDownLatch(Benchmark.totalThreads); final CountDownLatch doneSignal = new CountDownLatch(Benchmark.totalThreads);
final BenchmarkingThread[] threads = new BenchmarkingThread[Benchmark.totalThreads]; final BenchmarkingThread[] benchmarkingThreads = new BenchmarkingThread[Benchmark.totalThreads];
final Thread[] threads = new Thread[Benchmark.totalThreads];
for (int i = 0; i < Benchmark.totalThreads; i++) { for (int i = 0; i < Benchmark.totalThreads; i++) {
threads[i] = new BenchmarkingThread(Benchmark.mc, Benchmark.totalCalls, Benchmark.methodTime, Benchmark.recursionDepth, doneSignal); benchmarkingThreads[i] = new BenchmarkingThreadNano(Benchmark.mc, Benchmark.totalCalls, Benchmark.methodTime, Benchmark.recursionDepth, doneSignal);
threads[i].setName(String.valueOf(i + 1)); threads[i] = new Thread(benchmarkingThreads[i], String.valueOf(i + 1));
} }
if (!quickstart) { if (!quickstart) {
for (int l = 0; l < 4; l++) { for (int l = 0; l < 4; l++) {
...@@ -108,7 +109,7 @@ public final class Benchmark { ...@@ -108,7 +109,7 @@ public final class Benchmark {
// CSV Format: configuration;order_index;Thread-ID;duration_nsec // CSV Format: configuration;order_index;Thread-ID;duration_nsec
long[] timings; long[] timings;
for (int h = 0; h < Benchmark.totalThreads; h++) { for (int h = 0; h < Benchmark.totalThreads; h++) {
timings = threads[h].getTimings(); timings = benchmarkingThreads[h].getTimings();
for (int i = 0; i < Benchmark.totalCalls; i++) { for (int i = 0; i < Benchmark.totalCalls; i++) {
Benchmark.ps.println(threads[h].getName() + ";" + timings[i]); Benchmark.ps.println(threads[h].getName() + ";" + timings[i]);
} }
...@@ -141,6 +142,9 @@ public final class Benchmark { ...@@ -141,6 +142,9 @@ public final class Benchmark {
cmdlOpts.addOption(OptionBuilder.withLongOpt("application").withArgName("classname").hasArg(true).isRequired(false) cmdlOpts.addOption(OptionBuilder.withLongOpt("application").withArgName("classname").hasArg(true).isRequired(false)
.withDescription("Class implementing the MonitoredClass interface.").withValueSeparator('=') .withDescription("Class implementing the MonitoredClass interface.").withValueSeparator('=')
.create("a")); .create("a"));
cmdlOpts.addOption(OptionBuilder.withLongOpt("benchmarkthread").withArgName("classname").hasArg(true).isRequired(false)
.withDescription("Class implementing the BenchmarkingThread interface.").withValueSeparator('=')
.create("b"));
try { try {
CommandLine cmdl = null; CommandLine cmdl = null;
final CommandLineParser cmdlParser = new BasicParser(); final CommandLineParser cmdlParser = new BasicParser();
......
...@@ -16,52 +16,10 @@ ...@@ -16,52 +16,10 @@
package mooBench.benchmark; package mooBench.benchmark;
import java.util.concurrent.CountDownLatch;
import mooBench.monitoredApplication.MonitoredClass;
/** /**
* @author Jan Waller * @author Jan Waller
*/ */
public final class BenchmarkingThread extends Thread { public interface BenchmarkingThread extends Runnable {
private final MonitoredClass mc;
private final CountDownLatch doneSignal;
private final int totalCalls;
private final long methodTime;
private final int recursionDepth;
private final long[] timings;
public BenchmarkingThread(final MonitoredClass mc, final int totalCalls, final long methodTime, final int recursionDepth, final CountDownLatch doneSignal) {
super();
this.mc = mc;
this.doneSignal = doneSignal;
this.totalCalls = totalCalls;
this.methodTime = methodTime;
this.recursionDepth = recursionDepth;
this.timings = new long[totalCalls];
}
public final long[] getTimings() {
synchronized (this) {
return this.timings;
}
}
@Override
public final void run() {
long start_ns;
long stop_ns;
for (int i = 0; i < this.totalCalls; i++) {
start_ns = System.nanoTime();
this.mc.monitoredMethod(this.methodTime, this.recursionDepth);
stop_ns = System.nanoTime();
this.timings[i] = stop_ns - start_ns;
if ((i % 100000) == 0) {
System.out.println(i); // NOPMD (System.out)
}
}
this.doneSignal.countDown();
}
public abstract long[] getTimings();
} }
/***************************************************************************
* Copyright 2014 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package mooBench.benchmark;
import java.util.concurrent.CountDownLatch;
import mooBench.monitoredApplication.MonitoredClass;
/**
* @author Jan Waller
*/
public final class BenchmarkingThreadNano implements BenchmarkingThread {
private final MonitoredClass mc;
private final CountDownLatch doneSignal;
private final int totalCalls;
private final long methodTime;
private final int recursionDepth;
private final long[] timings;
public BenchmarkingThreadNano(final MonitoredClass mc, final int totalCalls, final long methodTime, final int recursionDepth, final CountDownLatch doneSignal) {
this.mc = mc;
this.doneSignal = doneSignal;
this.totalCalls = totalCalls;
this.methodTime = methodTime;
this.recursionDepth = recursionDepth;
this.timings = new long[totalCalls];
}
public final long[] getTimings() {
synchronized (this) {
return this.timings;
}
}
public final void run() {
long start_ns;
long stop_ns;
for (int i = 0; i < this.totalCalls; i++) {
start_ns = System.nanoTime();
this.mc.monitoredMethod(this.methodTime, this.recursionDepth);
stop_ns = System.nanoTime();
this.timings[i] = stop_ns - start_ns;
if ((i % 100000) == 0) {
System.out.println(i); // NOPMD (System.out)
}
}
this.doneSignal.countDown();
}
}
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