changeset 892:8a02e092fb3c

runners: print the result aggregated over multiple forks, reformat the output.
author shade
date Thu, 03 Jul 2014 14:29:15 +0400
parents 925af64108f1
children f8c2b0671f99
files jmh-core/src/main/java/org/openjdk/jmh/results/RunResult.java jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java
diffstat 3 files changed, 28 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/results/RunResult.java	Wed Jul 02 23:10:43 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/results/RunResult.java	Thu Jul 03 14:29:15 2014 +0400
@@ -66,18 +66,20 @@
     }
 
     public Result getPrimaryResult() {
-         return getFakeResult().getPrimaryResult();
+         return getAggregatedResult().getPrimaryResult();
     }
 
     public Map<String, Result> getSecondaryResults() {
-        return getFakeResult().getSecondaryResults();
+        return getAggregatedResult().getSecondaryResults();
     }
 
     /**
-     * Implementation note: RunResult tries to aggregate BenchmarkResult as if
-     * the underlying iterations are aggregated in the single run.
+     * Return the benchmark result, as if all iterations from all sub-benchmark results
+     * were merged in a single result.
+     *
+     * @return merged benchmark result
      */
-    private BenchmarkResult getFakeResult() {
+    public BenchmarkResult getAggregatedResult() {
         Collection<IterationResult> results = new ArrayList<IterationResult>();
         for (BenchmarkResult r : benchmarkResults) {
             for (IterationResult ir : r.getIterationResults()) {
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Wed Jul 02 23:10:43 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Thu Jul 03 14:29:15 2014 +0400
@@ -78,7 +78,7 @@
             ActionMode mode = action.getMode();
 
             if (!forked) {
-                beforeBenchmark();
+                etaBeforeBenchmark();
                 out.startBenchmark(params);
                 out.println("# Fork: N/A, test runs in the existing VM");
             }
@@ -119,7 +119,7 @@
             }
 
             if (!forked) {
-                afterBenchmark(params);
+                etaAfterBenchmark(params);
                 out.endBenchmark(r);
             }
         }
@@ -127,14 +127,14 @@
         return results;
     }
 
-    protected void afterBenchmark(BenchmarkParams params) {
+    protected void etaAfterBenchmark(BenchmarkParams params) {
         long current = System.nanoTime();
         projectedRunningTime += estimateTimeSingleFork(params);
         actualRunningTime += (current - benchmarkStart);
         benchmarkStart = current;
     }
 
-    protected void beforeBenchmarks(Collection<ActionPlan> plans) {
+    protected void etaBeforeBenchmarks(Collection<ActionPlan> plans) {
         projectedTotalTime = 0;
         for (ActionPlan plan : plans) {
             for (Action act : plan.getActions()) {
@@ -161,7 +161,7 @@
         return estimatedTime;
     }
 
-    protected void beforeBenchmark() {
+    protected void etaBeforeBenchmark() {
         if (benchmarkStart == 0) {
             benchmarkStart = System.nanoTime();
         }
@@ -177,7 +177,7 @@
         out.println(String.format("# Run progress: %.2f%% complete, ETA %s", partsDone * 100, formatDuration(totalETA)));
     }
 
-    protected void afterBenchmarks() {
+    protected void etaAfterBenchmarks() {
         out.println(String.format("# Run complete. Total time: %s", formatDuration(actualRunningTime)));
         out.println("");
     }
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Wed Jul 02 23:10:43 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Thu Jul 03 14:29:15 2014 +0400
@@ -434,7 +434,7 @@
         Multimap<BenchmarkParams, BenchmarkResult> results = new TreeMultimap<BenchmarkParams, BenchmarkResult>();
         List<ActionPlan> plan = getActionPlans(benchmarks);
 
-        beforeBenchmarks(plan);
+        etaBeforeBenchmarks(plan);
 
         try {
             for (ActionPlan r : plan) {
@@ -455,7 +455,7 @@
                 }
             }
 
-            afterBenchmarks();
+            etaAfterBenchmarks();
 
             SortedSet<RunResult> runResults = mergeRunResults(results);
             out.endRun(runResults);
@@ -516,15 +516,17 @@
 
             String jvm = options.getJvm().orElse(getDefaultJvm());
 
+            out.println("# VM invoker: " + jvm);
+            out.println("# VM options: " + opts);
+            out.startBenchmark(params);
+            out.println("");
+
             int forkCount = params.getForks();
             int warmupForkCount = params.getWarmupForks();
             if (warmupForkCount > 0) {
                 out.verbosePrintln("Warmup forking " + warmupForkCount + " times using command: " + Arrays.toString(commandString));
                 for (int i = 0; i < warmupForkCount; i++) {
-                    beforeBenchmark();
-                    out.startBenchmark(params);
-                    out.println("# VM invoker: " + jvm);
-                    out.println("# VM options: " + opts);
+                    etaBeforeBenchmark();
                     out.println("# Warmup Fork: " + (i + 1) + " of " + warmupForkCount);
 
                     File stdErr = FileUtils.tempFile("stderr");
@@ -532,18 +534,14 @@
 
                     doFork(server, commandString, stdOut, stdErr, printOut, printErr);
 
-                    out.endBenchmark(null);
-                    afterBenchmark(params);
+                    etaAfterBenchmark(params);
+                    out.println("");
                 }
             }
 
             out.verbosePrintln("Forking " + forkCount + " times using command: " + Arrays.toString(commandString));
             for (int i = 0; i < forkCount; i++) {
-                beforeBenchmark();
-                out.startBenchmark(params);
-
-                out.println("# VM invoker: " + jvm);
-                out.println("# VM options: " + opts);
+                etaBeforeBenchmark();
                 out.println("# Fork: " + (i + 1) + " of " + forkCount);
 
                 File stdErr = FileUtils.tempFile("stderr");
@@ -581,16 +579,11 @@
                 }
 
                 results.merge(result);
-                afterBenchmark(params);
+                etaAfterBenchmark(params);
+                out.println("");
+            }
 
-                // we have only a single benchmark, which will produce only a single result
-                // TODO: clean up doFork() to return only a single value
-                BenchmarkResult r = null;
-                if (result.values().size() == 1) {
-                    r = result.values().iterator().next();
-                }
-                out.endBenchmark(r);
-            }
+            out.endBenchmark(new RunResult(results.get(params)).getAggregatedResult());
 
         } catch (IOException e) {
             throw new IllegalStateException(e);