diff --git a/src/mooBench/benchmark/Benchmark.java b/src/mooBench/benchmark/Benchmark.java index bccf6421bb9379a803d01d468e1dfac895165a21..810ca66f708c6bc4afa26dc8dff1606d4faa8990 100644 --- a/src/mooBench/benchmark/Benchmark.java +++ b/src/mooBench/benchmark/Benchmark.java @@ -63,10 +63,11 @@ public final class Benchmark { // 2. Initialize Threads and Classes 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++) { - threads[i] = new BenchmarkingThread(Benchmark.mc, Benchmark.totalCalls, Benchmark.methodTime, Benchmark.recursionDepth, doneSignal); - threads[i].setName(String.valueOf(i + 1)); + benchmarkingThreads[i] = new BenchmarkingThreadNano(Benchmark.mc, Benchmark.totalCalls, Benchmark.methodTime, Benchmark.recursionDepth, doneSignal); + threads[i] = new Thread(benchmarkingThreads[i], String.valueOf(i + 1)); } if (!quickstart) { for (int l = 0; l < 4; l++) { @@ -108,7 +109,7 @@ public final class Benchmark { // CSV Format: configuration;order_index;Thread-ID;duration_nsec long[] timings; for (int h = 0; h < Benchmark.totalThreads; h++) { - timings = threads[h].getTimings(); + timings = benchmarkingThreads[h].getTimings(); for (int i = 0; i < Benchmark.totalCalls; i++) { Benchmark.ps.println(threads[h].getName() + ";" + timings[i]); } @@ -141,6 +142,9 @@ public final class Benchmark { cmdlOpts.addOption(OptionBuilder.withLongOpt("application").withArgName("classname").hasArg(true).isRequired(false) .withDescription("Class implementing the MonitoredClass interface.").withValueSeparator('=') .create("a")); + cmdlOpts.addOption(OptionBuilder.withLongOpt("benchmarkthread").withArgName("classname").hasArg(true).isRequired(false) + .withDescription("Class implementing the BenchmarkingThread interface.").withValueSeparator('=') + .create("b")); try { CommandLine cmdl = null; final CommandLineParser cmdlParser = new BasicParser(); diff --git a/src/mooBench/benchmark/BenchmarkingThread.java b/src/mooBench/benchmark/BenchmarkingThread.java index 354fcd59b1caed548123686dabffca74950dfe76..16bcda3a989e03fab14cee136087dcfb3084d1de 100644 --- a/src/mooBench/benchmark/BenchmarkingThread.java +++ b/src/mooBench/benchmark/BenchmarkingThread.java @@ -16,52 +16,10 @@ package mooBench.benchmark; -import java.util.concurrent.CountDownLatch; - -import mooBench.monitoredApplication.MonitoredClass; - /** * @author Jan Waller */ -public final class BenchmarkingThread extends Thread { - - 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 interface BenchmarkingThread extends Runnable { + public abstract long[] getTimings(); } diff --git a/src/mooBench/benchmark/BenchmarkingThreadNano.java b/src/mooBench/benchmark/BenchmarkingThreadNano.java new file mode 100644 index 0000000000000000000000000000000000000000..936c549d7fc10bc9cb748d7181e21efbb9670baa --- /dev/null +++ b/src/mooBench/benchmark/BenchmarkingThreadNano.java @@ -0,0 +1,65 @@ +/*************************************************************************** + * 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(); + } + +}