changeset 305:578b0b6a25d9

doFork() to return multiple results.
author shade
date Thu, 05 Dec 2013 12:46:39 +0400
parents 6fcaa4228b4f
children 5eef9dda8fc7
files jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkClient.java jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkServer.java jmh-core/src/main/java/org/openjdk/jmh/link/frames/ResultsFrame.java jmh-core/src/main/java/org/openjdk/jmh/runner/ForkedRunner.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashMultimap.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashsetMultimap.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/Multimap.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreeMultimap.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreesetMultimap.java
diffstat 10 files changed, 51 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkClient.java	Thu Dec 05 11:37:00 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkClient.java	Thu Dec 05 12:46:39 2013 +0400
@@ -34,6 +34,7 @@
 import org.openjdk.jmh.runner.ActionPlan;
 import org.openjdk.jmh.runner.BenchmarkRecord;
 import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.util.internal.Multimap;
 
 import java.io.IOException;
 import java.io.ObjectInputStream;
@@ -83,8 +84,8 @@
         clientSocket.close();
     }
 
-    public void pushResults(BenchmarkRecord record, BenchResult result) throws IOException {
-        oos.writeObject(new ResultsFrame(record, result));
+    public void pushResults(Multimap<BenchmarkRecord, BenchResult> res) throws IOException {
+        oos.writeObject(new ResultsFrame(res));
         oos.flush();
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkServer.java	Thu Dec 05 11:37:00 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkServer.java	Thu Dec 05 12:46:39 2013 +0400
@@ -33,7 +33,10 @@
 import org.openjdk.jmh.logic.results.BenchResult;
 import org.openjdk.jmh.output.format.OutputFormat;
 import org.openjdk.jmh.runner.ActionPlan;
+import org.openjdk.jmh.runner.BenchmarkRecord;
 import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.util.internal.HashMultimap;
+import org.openjdk.jmh.util.internal.Multimap;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -68,7 +71,7 @@
     private final Set<String> forbidden;
     private final Acceptor acceptor;
     private final AtomicReference<Handler> handler;
-    private final AtomicReference<BenchResult> result;
+    private final AtomicReference<Multimap<BenchmarkRecord, BenchResult>> results;
     private final AtomicReference<ActionPlan> plan;
 
     public BinaryLinkServer(Options opts, OutputFormat out) throws IOException {
@@ -95,7 +98,7 @@
         acceptor.start();
 
         handler = new AtomicReference<Handler>();
-        result = new AtomicReference<BenchResult>();
+        results = new AtomicReference<Multimap<BenchmarkRecord, BenchResult>>(new HashMultimap<BenchmarkRecord, BenchResult>());
         plan = new AtomicReference<ActionPlan>();
     }
 
@@ -128,8 +131,8 @@
         }
     }
 
-    public BenchResult getResult() {
-        BenchResult res = result.getAndSet(null);
+    public Multimap<BenchmarkRecord, BenchResult> getResults() {
+        Multimap<BenchmarkRecord, BenchResult> res = results.getAndSet(new HashMultimap<BenchmarkRecord, BenchResult>());
         if (res != null) {
             return res;
         } else {
@@ -252,9 +255,7 @@
         }
 
         private void handleResults(ResultsFrame obj) {
-            if (!result.compareAndSet(null, obj.getResult())) {
-                throw new IllegalStateException("The result has been already set.");
-            }
+            results.get().merge(obj.getRes());
         }
 
         private void handleInfra(InfraFrame req) throws IOException {
--- a/jmh-core/src/main/java/org/openjdk/jmh/link/frames/ResultsFrame.java	Thu Dec 05 11:37:00 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/link/frames/ResultsFrame.java	Thu Dec 05 12:46:39 2013 +0400
@@ -26,23 +26,18 @@
 
 import org.openjdk.jmh.logic.results.BenchResult;
 import org.openjdk.jmh.runner.BenchmarkRecord;
+import org.openjdk.jmh.util.internal.Multimap;
 
 import java.io.Serializable;
 
 public class ResultsFrame implements Serializable {
-    private final BenchmarkRecord record;
-    private final BenchResult result;
+    private final Multimap<BenchmarkRecord, BenchResult> res;
 
-    public ResultsFrame(BenchmarkRecord record, BenchResult result) {
-        this.record = record;
-        this.result = result;
+    public ResultsFrame(Multimap<BenchmarkRecord, BenchResult> res) {
+        this.res = res;
     }
 
-    public BenchmarkRecord getRecord() {
-        return record;
-    }
-
-    public BenchResult getResult() {
-        return result;
+    public Multimap<BenchmarkRecord, BenchResult> getRes() {
+        return res;
     }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/ForkedRunner.java	Thu Dec 05 11:37:00 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/ForkedRunner.java	Thu Dec 05 12:46:39 2013 +0400
@@ -50,11 +50,7 @@
         ActionPlan actionPlan = link.requestPlan();
 
         Multimap<BenchmarkRecord,BenchResult> res = runBenchmarks(true, actionPlan);
-        for (BenchmarkRecord br : res.keys()) {
-            for (BenchResult r : res.get(br)) {
-                link.pushResults(br, r);
-            }
-        }
+        link.pushResults(res);
 
         out.flush();
         out.close();
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Thu Dec 05 11:37:00 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Thu Dec 05 12:46:39 2013 +0400
@@ -342,8 +342,8 @@
                 out.verbosePrintln("Forking " + forkCount + " times using command: " + Arrays.toString(commandString));
                 for (int i = 0; i < forkCount; i++) {
                     out.println("# Fork: " + (i + 1) + " of " + forkCount);
-                    BenchResult result = doFork(server, commandString);
-                    results.put(benchmark, result);
+                    Multimap<BenchmarkRecord, BenchResult> result = doFork(server, commandString);
+                    results.merge(result);
                 }
 
         } catch (IOException e) {
@@ -358,7 +358,7 @@
     }
 
 
-    private BenchResult doFork(BinaryLinkServer reader, String[] commandString) {
+    private Multimap<BenchmarkRecord, BenchResult> doFork(BinaryLinkServer reader, String[] commandString) {
         try {
             Process p = Runtime.getRuntime().exec(commandString);
 
@@ -391,7 +391,7 @@
             out.exception(ex);
         }
 
-        return reader.getResult();
+        return reader.getResults();
     }
 
     /**
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashMultimap.java	Thu Dec 05 11:37:00 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashMultimap.java	Thu Dec 05 12:46:39 2013 +0400
@@ -93,4 +93,11 @@
     public void remove(K key) {
         map.remove(key);
     }
+
+    @Override
+    public void merge(Multimap<K, V> other) {
+        for (K k : other.keys()) {
+            putAll(k, other.get(k));
+        }
+    }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashsetMultimap.java	Thu Dec 05 11:37:00 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashsetMultimap.java	Thu Dec 05 12:46:39 2013 +0400
@@ -94,4 +94,11 @@
     public void remove(K key) {
         map.remove(key);
     }
+
+    @Override
+    public void merge(Multimap<K, V> other) {
+        for (K k : other.keys()) {
+            putAll(k, other.get(k));
+        }
+    }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/Multimap.java	Thu Dec 05 11:37:00 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/Multimap.java	Thu Dec 05 12:46:39 2013 +0400
@@ -78,4 +78,5 @@
 
     void remove(K key);
 
+    void merge(Multimap<K, V> other);
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreeMultimap.java	Thu Dec 05 11:37:00 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreeMultimap.java	Thu Dec 05 12:46:39 2013 +0400
@@ -93,4 +93,11 @@
     public void remove(K key) {
         map.remove(key);
     }
+
+    @Override
+    public void merge(Multimap<K, V> other) {
+        for (K k : other.keys()) {
+            putAll(k, other.get(k));
+        }
+    }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreesetMultimap.java	Thu Dec 05 11:37:00 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreesetMultimap.java	Thu Dec 05 12:46:39 2013 +0400
@@ -94,4 +94,11 @@
     public void remove(K key) {
         map.remove(key);
     }
+
+    @Override
+    public void merge(Multimap<K, V> other) {
+        for (K k : other.keys()) {
+            putAll(k, other.get(k));
+        }
+    }
 }