changeset 210:a38d89ed91ce

Rework the run/benchmark properties aggregation.
author shade
date Wed, 23 Oct 2013 21:55:29 +0400
parents 1d5924d127bc
children cd800437c7de
files jmh-core/src/main/java/org/openjdk/jmh/logic/results/BenchResult.java jmh-core/src/main/java/org/openjdk/jmh/logic/results/RunResult.java
diffstat 2 files changed, 64 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/logic/results/BenchResult.java	Wed Oct 23 20:13:56 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/logic/results/BenchResult.java	Wed Oct 23 21:55:29 2013 +0400
@@ -24,6 +24,8 @@
  */
 package org.openjdk.jmh.logic.results;
 
+import org.openjdk.jmh.runner.BenchmarkRecord;
+import org.openjdk.jmh.runner.parameters.IterationParams;
 import org.openjdk.jmh.util.internal.HashMultimap;
 import org.openjdk.jmh.util.internal.Multimap;
 
@@ -44,9 +46,32 @@
     private static final long serialVersionUID = 6467912427356048369L;
 
     private final Collection<IterationResult> iterationResults;
+    private final BenchmarkRecord benchmark;
+    private final IterationParams params;
 
     public BenchResult(Collection<IterationResult> data) {
         this.iterationResults = data;
+
+        BenchmarkRecord myRecord = null;
+        IterationParams myParams = null;
+
+        for (IterationResult ir : data) {
+            BenchmarkRecord record = ir.getBenchmark();
+            IterationParams params = ir.getParams();
+            if (myRecord != null && !record.equals(myRecord)) {
+                throw new IllegalStateException("Aggregating the iteration results from different benchmarks");
+            } else {
+                myRecord = record;
+            }
+
+            if (myParams != null && !params.equals(myParams)) {
+                throw new IllegalStateException("Aggregating the iteration results from different benchmarks");
+            } else {
+                myParams = params;
+            }
+        }
+        this.benchmark = myRecord;
+        this.params = myParams;
     }
 
     public Collection<IterationResult> getRawIterationResults() {
@@ -99,4 +124,11 @@
         return getPrimaryResult().getScoreUnit();
     }
 
+    public BenchmarkRecord getBenchmark() {
+        return benchmark;
+    }
+
+    public IterationParams getParams() {
+        return params;
+    }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/logic/results/RunResult.java	Wed Oct 23 20:13:56 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/logic/results/RunResult.java	Wed Oct 23 21:55:29 2013 +0400
@@ -24,6 +24,8 @@
  */
 package org.openjdk.jmh.logic.results;
 
+import org.openjdk.jmh.runner.BenchmarkRecord;
+import org.openjdk.jmh.runner.parameters.IterationParams;
 import org.openjdk.jmh.runner.parameters.TimeValue;
 import org.openjdk.jmh.util.internal.HashMultimap;
 import org.openjdk.jmh.util.internal.Multimap;
@@ -46,9 +48,34 @@
     private static final long serialVersionUID = 6467912427356048369L;
 
     private final Collection<BenchResult> benchResults;
+    private final BenchmarkRecord benchmark;
+    private final IterationParams params;
 
     public RunResult(Collection<BenchResult> data) {
         this.benchResults = data;
+
+        BenchmarkRecord myRecord = null;
+        IterationParams myParams = null;
+
+        for (BenchResult br : data) {
+            BenchmarkRecord record = br.getBenchmark();
+            IterationParams params = br.getParams();
+
+            if (myRecord != null && !record.equals(myRecord)) {
+                throw new IllegalStateException("Aggregating the benchmark results from different benchmarks");
+            } else {
+                myRecord = record;
+            }
+
+            if (myParams != null && !params.equals(myParams)) {
+                throw new IllegalStateException("Aggregating the benchmark results from different benchmarks");
+            } else {
+                myParams = params;
+            }
+        }
+
+        this.benchmark = myRecord;
+        this.params = myParams;
     }
 
     public Collection<BenchResult> getRawBenchResults() {
@@ -106,11 +133,14 @@
     }
 
     public int getThreads() {
-        return getRawBenchResults().iterator().next().getRawIterationResults().iterator().next().getParams().getThreads();
+        return params.getThreads();
     }
 
     public TimeValue getTime() {
-        return getRawBenchResults().iterator().next().getRawIterationResults().iterator().next().getParams().getTime();
+        return params.getTime();
     }
 
+    public BenchmarkRecord getBenchmark() {
+        return benchmark;
+    }
 }