changeset 158:ee135e6ab5c0

Cleanup IterationData.
author shade
date Thu, 29 Aug 2013 16:49:13 +0400
parents 8ee765583a16
children 511a26839ce9
files jmh-core/src/main/java/org/openjdk/jmh/logic/results/IterationData.java jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java jmh-core/src/main/java/org/openjdk/jmh/runner/LoopMicroBenchmarkHandler.java jmh-core/src/main/java/org/openjdk/jmh/runner/MicroBenchmarkHandler.java
diffstat 4 files changed, 28 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/logic/results/IterationData.java	Wed Aug 28 18:43:34 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/logic/results/IterationData.java	Thu Aug 29 16:49:13 2013 +0400
@@ -24,9 +24,9 @@
  */
 package org.openjdk.jmh.logic.results;
 
-import org.openjdk.jmh.logic.results.internal.IterationResult;
 import org.openjdk.jmh.profile.ProfilerResult;
 import org.openjdk.jmh.runner.BenchmarkRecord;
+import org.openjdk.jmh.runner.parameters.IterationParams;
 import org.openjdk.jmh.runner.parameters.TimeValue;
 
 import java.util.ArrayList;
@@ -40,24 +40,19 @@
 public class IterationData {
 
     private final BenchmarkRecord benchmark;
+    private final IterationParams params;
     private final List<Result> perThreadResults;
     private final List<ProfilerResult> profilerResults;
-    private final int numThreads;
-    private final TimeValue runTime;
-    private IterationResult aggregated;
-    private boolean isWarmup;
 
-    public IterationData(BenchmarkRecord benchmark, int threadCount, TimeValue runTime) {
+    public IterationData(BenchmarkRecord benchmark, IterationParams params) {
         this.benchmark = benchmark;
-        this.numThreads = threadCount;
-        this.runTime = runTime;
-        this.perThreadResults = new ArrayList<Result>(threadCount);
+        this.params = params;
+        this.perThreadResults = new ArrayList<Result>(params.getThreads());
         this.profilerResults = new ArrayList<ProfilerResult>();
     }
 
     public void addResult(Result result) {
         perThreadResults.add(result);
-        aggregated = null;
     }
 
     public List<Result> getRawResults() {
@@ -68,36 +63,16 @@
         return perThreadResults.isEmpty();
     }
 
-    public IterationResult getAggregatedResult() {
-        if (aggregated == null) {
-            aggregated = new IterationResult(perThreadResults);
-        }
-        return aggregated;
-    }
-
-    public int getNumThreads() {
-        return numThreads;
-    }
-
-    public TimeValue getRuntime() {
-        return runTime;
-    }
-
     public void clearResults() {
         perThreadResults.clear();
     }
 
-    public boolean isWarmup() {
-        return isWarmup;
+    public BenchmarkRecord getBenchmark() {
+        return benchmark;
     }
 
-    public IterationData setWarmup() {
-        isWarmup = true;
-        return this;
-    }
-
-    public BenchmarkRecord getBenchmark() {
-        return benchmark;
+    public IterationParams getParams() {
+        return params;
     }
 
     public void addProfileResult(ProfilerResult profilerResult) {
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Wed Aug 28 18:43:34 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Thu Aug 29 16:49:13 2013 +0400
@@ -26,6 +26,7 @@
 
 import org.openjdk.jmh.logic.results.IterationData;
 import org.openjdk.jmh.logic.results.Result;
+import org.openjdk.jmh.logic.results.internal.IterationResult;
 import org.openjdk.jmh.logic.results.internal.RunResult;
 import org.openjdk.jmh.output.format.IterationType;
 import org.openjdk.jmh.output.format.OutputFormat;
@@ -99,8 +100,9 @@
 
             out.iteration(handler.getBenchmark(), i, IterationType.WARMUP, wp.getThreads(), wp.getTime());
             boolean isLastIteration = (executionParams.getIteration().getCount() == 0);
-            IterationData iterData = handler.runIteration(wp.getThreads(), wp.getTime(), isLastIteration).setWarmup();
-            out.iterationResult(handler.getBenchmark(), i, IterationType.WARMUP, options.getThreads(), iterData.getAggregatedResult(), iterData.getProfilerResults());
+            IterationData iterData = handler.runIteration(wp, isLastIteration);
+            IterationResult iterResult = new IterationResult(iterData.getRawResults());
+            out.iterationResult(handler.getBenchmark(), i, IterationType.WARMUP, options.getThreads(), iterResult, iterData.getProfilerResults());
         }
 
         // measurement
@@ -115,16 +117,17 @@
             out.iteration(handler.getBenchmark(), i, IterationType.MEASUREMENT, mp.getThreads(), mp.getTime());
 
             boolean isLastIteration = (i == mp.getCount());
-            IterationData iterData = handler.runIteration(mp.getThreads(), mp.getTime(), isLastIteration);
+            IterationData iterData = handler.runIteration(mp, isLastIteration);
 
             // might get an exception above, in which case the results list will be empty
             if (iterData.isResultsEmpty()) {
                 out.println("WARNING: No results returned, benchmark payload threw exception?");
             } else {
-                out.iterationResult(handler.getBenchmark(), i, IterationType.MEASUREMENT, mp.getThreads(), iterData.getAggregatedResult(), iterData.getProfilerResults());
+                IterationResult iterResult = new IterationResult(iterData.getRawResults());
+                out.iterationResult(handler.getBenchmark(), i, IterationType.MEASUREMENT, mp.getThreads(), iterResult, iterData.getProfilerResults());
 
                 if (options.shouldOutputDetailedResults()) {
-                    out.detailedResults(handler.getBenchmark(), i, mp.getThreads(), iterData.getAggregatedResult());
+                    out.detailedResults(handler.getBenchmark(), i, mp.getThreads(), iterResult);
                 }
 
                 allResults.add(iterData);
@@ -206,7 +209,8 @@
     protected static RunResult aggregateIterationData(List<IterationData> results) {
         List<Result> res = new ArrayList<Result>(results.size());
         for (IterationData itData : results) {
-            res.addAll(itData.getAggregatedResult().getResult().values());
+            IterationResult iterResult = new IterationResult(itData.getRawResults());
+            res.addAll(iterResult.getResult().values());
         }
         return new RunResult(res);
     }
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/LoopMicroBenchmarkHandler.java	Wed Aug 28 18:43:34 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/LoopMicroBenchmarkHandler.java	Thu Aug 29 16:49:13 2013 +0400
@@ -31,6 +31,7 @@
 import org.openjdk.jmh.logic.results.Result;
 import org.openjdk.jmh.output.format.OutputFormat;
 import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.parameters.IterationParams;
 import org.openjdk.jmh.runner.parameters.MicroBenchmarkParameters;
 import org.openjdk.jmh.runner.parameters.TimeValue;
 
@@ -71,12 +72,15 @@
      * {@inheritDoc}
      */
     @Override
-    public IterationData runIteration(int numThreads, TimeValue runtime, boolean last) {
+    public IterationData runIteration(IterationParams params, boolean last) {
+        int numThreads = params.getThreads();
+        TimeValue runtime = params.getTime();
+
         CountDownLatch preSetupBarrier = new CountDownLatch(numThreads);
         CountDownLatch preTearDownBarrier = new CountDownLatch(numThreads);
 
         // result object to accumulate the results in
-        IterationData iterationResults = new IterationData(microbenchmark, numThreads, runtime);
+        IterationData iterationResults = new IterationData(microbenchmark, params);
 
         InfraControl control = new InfraControl(numThreads, shouldSynchIterations, runtime, preSetupBarrier, preTearDownBarrier, last, timeUnit);
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/MicroBenchmarkHandler.java	Wed Aug 28 18:43:34 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/MicroBenchmarkHandler.java	Thu Aug 29 16:49:13 2013 +0400
@@ -25,6 +25,7 @@
 package org.openjdk.jmh.runner;
 
 import org.openjdk.jmh.logic.results.IterationData;
+import org.openjdk.jmh.runner.parameters.IterationParams;
 import org.openjdk.jmh.runner.parameters.TimeValue;
 
 /**
@@ -41,12 +42,11 @@
     /**
      * Runs an iteration on the handled benchmark.
      *
-     * @param threads How many thread to execute with for this iteration
-     * @param timeValue Duration of the iteration (some implementations may ignore this parameter)
+     * @param params  Iteration parameters
      * @param last    Should this iteration considered to be the last
      * @return IterationData
      */
-    public IterationData runIteration(int threads, TimeValue timeValue, boolean last);
+    public IterationData runIteration(IterationParams params, boolean last);
 
     /**
      * Do required shutdown actions. Actions may be: