-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
FeiWongReed
committed
Apr 28, 2015
1 parent
42f15b1
commit 1a7ad33
Showing
12 changed files
with
310 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
...test-utils-stress/src/main/java/org/nohope/test/stress/MultiInvocationStatCalculator.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...est-utils/test-utils-stress/src/main/java/org/nohope/test/stress/PreparedMeasurement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package org.nohope.test.stress; | ||
|
||
import org.nohope.test.stress.result.ActionResult; | ||
import org.nohope.test.stress.result.StressResult; | ||
import org.nohope.test.stress.util.Memory; | ||
import org.nohope.test.stress.util.MetricsAccumulator; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
final public class PreparedMeasurement { | ||
private final int threadsNumber; | ||
private final int cycleCount; | ||
private final Iterable<ExecutorService> executors; | ||
private final Iterable<? extends StatAccumulator> statAccumulators; | ||
private final List<Thread> threads; | ||
private final TimerResolution timerResolution; | ||
|
||
|
||
PreparedMeasurement(final TimerResolution resolution, final int threadsNumber, final int cycleCount, final Iterable<ExecutorService> executors, | ||
final Iterable<? extends StatAccumulator> statAccumulators, final List<Thread> threads) { | ||
this.timerResolution = resolution; | ||
this.threadsNumber = threadsNumber; | ||
this.cycleCount = cycleCount; | ||
this.executors = executors; | ||
this.statAccumulators = statAccumulators; | ||
this.threads = threads; | ||
} | ||
|
||
|
||
public int getThreadsNumber() { | ||
return threadsNumber; | ||
} | ||
|
||
|
||
public int getCycleCount() { | ||
return cycleCount; | ||
} | ||
|
||
|
||
public Iterable<ExecutorService> getExecutors() { | ||
return executors; | ||
} | ||
|
||
|
||
public Iterable<? extends StatAccumulator> getStatAccumulators() { | ||
return statAccumulators; | ||
} | ||
|
||
|
||
public List<Thread> getThreads() { | ||
return threads; | ||
} | ||
|
||
public StressResult perform() throws InterruptedException { | ||
return awaitResult(this); | ||
} | ||
|
||
private StressResult awaitResult(final PreparedMeasurement preparedMeasurement) throws InterruptedException { | ||
final MetricsAccumulator metrics = new MetricsAccumulator(); | ||
metrics.start(); | ||
|
||
final Memory memoryStart = Memory.getCurrent(); | ||
final long overallStart = timerResolution.currentTime(); | ||
|
||
preparedMeasurement.getThreads().forEach(java.lang.Thread::start); | ||
|
||
for (final Thread thread : preparedMeasurement.getThreads()) { | ||
thread.join(); | ||
} | ||
|
||
metrics.stop(); | ||
|
||
for (final ExecutorService service : preparedMeasurement.getExecutors()) { | ||
try { | ||
service.shutdown(); | ||
service.awaitTermination(Long.MAX_VALUE, TimeUnit.HOURS); | ||
} catch (final InterruptedException ignored) { | ||
} | ||
} | ||
|
||
final long overallEnd = timerResolution.currentTime(); | ||
final Memory memoryEnd = Memory.getCurrent(); | ||
|
||
final double runtime = overallEnd - overallStart; | ||
|
||
final Map<String, ActionResult> results = new HashMap<>(); | ||
for (final StatAccumulator stats : preparedMeasurement.getStatAccumulators()) { | ||
final ActionResult r = stats.getResult(); | ||
results.put(r.getName(), r); | ||
} | ||
|
||
return new StressResult(results, preparedMeasurement.getThreadsNumber(), preparedMeasurement.getCycleCount(), runtime, metrics.getMetrics(), memoryStart, memoryEnd); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.