changeset 408:5740a1770694

@Params should manifest in JSON report.
author shade
date Tue, 18 Feb 2014 18:00:36 +0400
parents d349049dc58b
children 433a268f4a26
files jmh-core/src/main/java/org/openjdk/jmh/output/results/JSONResultFormat.java jmh-core/src/main/java/org/openjdk/jmh/runner/ActualParams.java jmh-core/src/test/java/org/openjdk/jmh/output/results/ResultFormatTest.java jmh-core/src/test/resources/org/openjdk/jmh/output/results/output-golden.json
diffstat 4 files changed, 73 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/results/JSONResultFormat.java	Tue Feb 18 17:32:08 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/results/JSONResultFormat.java	Tue Feb 18 18:00:36 2014 +0400
@@ -27,6 +27,7 @@
 import org.openjdk.jmh.logic.results.BenchResult;
 import org.openjdk.jmh.logic.results.Result;
 import org.openjdk.jmh.logic.results.RunResult;
+import org.openjdk.jmh.runner.ActualParams;
 import org.openjdk.jmh.runner.BenchmarkRecord;
 import org.openjdk.jmh.util.internal.Statistics;
 
@@ -71,6 +72,13 @@
                 pw.println("\"warmupTime\" : \"" + runResult.getParams().getWarmup().getTime() + "\",");
                 pw.println("\"measurementIterations\" : " + runResult.getParams().getMeasurement().getCount() + ",");
                 pw.println("\"measurementTime\" : \"" + runResult.getParams().getMeasurement().getTime() + "\",");
+
+                if (!br.getActualParams().isEmpty()) {
+                    pw.println("\"params\" : {");
+                    pw.println(emitParams(br.getActualParams()));
+                    pw.println("},");
+                }
+
                 pw.println("\"primaryMetric\" : {");
                 pw.println("\"score\" : " + emit(runResult.getPrimaryResult().getScore()) + ",");
                 pw.println("\"scoreError\" : " + emit(runResult.getPrimaryResult().getStatistics().getMeanErrorAt(0.999)) + ",");
@@ -137,6 +145,21 @@
         }
     }
 
+    private String emitParams(ActualParams params) {
+        StringBuilder sb = new StringBuilder();
+        boolean isFirst = true;
+        for (String k : params.keys()) {
+            if (isFirst) {
+                isFirst = false;
+            } else {
+                sb.append(", ");
+            }
+            sb.append("\"").append(k).append("\" : ");
+            sb.append("\"").append(params.get(k)).append("\"");
+        }
+        return sb.toString();
+    }
+
     private String emitPercentiles(Statistics stats) {
         StringBuilder sb = new StringBuilder();
         sb.append("\"scorePercentiles\" : {");
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/ActualParams.java	Tue Feb 18 17:32:08 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/ActualParams.java	Tue Feb 18 18:00:36 2014 +0400
@@ -25,6 +25,7 @@
 package org.openjdk.jmh.runner;
 
 import java.io.Serializable;
+import java.util.Collection;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
@@ -99,4 +100,12 @@
     public ActualParams copy() {
         return new ActualParams(params);
     }
+
+    public boolean isEmpty() {
+        return params.isEmpty();
+    }
+
+    public Collection<String> keys() {
+        return params.keySet();
+    }
 }
--- a/jmh-core/src/test/java/org/openjdk/jmh/output/results/ResultFormatTest.java	Tue Feb 18 17:32:08 2014 +0400
+++ b/jmh-core/src/test/java/org/openjdk/jmh/output/results/ResultFormatTest.java	Tue Feb 18 18:00:36 2014 +0400
@@ -32,6 +32,7 @@
 import org.openjdk.jmh.logic.results.ResultRole;
 import org.openjdk.jmh.logic.results.RunResult;
 import org.openjdk.jmh.logic.results.ThroughputResult;
+import org.openjdk.jmh.runner.ActualParams;
 import org.openjdk.jmh.runner.BenchmarkRecord;
 import org.openjdk.jmh.runner.parameters.BenchmarkParams;
 import org.openjdk.jmh.runner.parameters.TimeValue;
@@ -59,6 +60,11 @@
         Random r = new Random(12345);
         for (int b = 0; b < r.nextInt(10); b++) {
             BenchmarkRecord record = new BenchmarkRecord("benchmark_" + b, JSONResultFormat.class.getName() + ".benchmark_" + b, Mode.AverageTime);
+            ActualParams ps = new ActualParams();
+            for (int p = 0; p < 5; p++) {
+                ps.put("param" + p, "value" + p);
+            }
+            record = record.cloneWith(ps);
             BenchmarkParams params = new BenchmarkParams(false,
                     r.nextInt(1000),
                     new int[]{ r.nextInt(1000) },
--- a/jmh-core/src/test/resources/org/openjdk/jmh/output/results/output-golden.json	Tue Feb 18 17:32:08 2014 +0400
+++ b/jmh-core/src/test/resources/org/openjdk/jmh/output/results/output-golden.json	Tue Feb 18 18:00:36 2014 +0400
@@ -8,6 +8,13 @@
         "warmupTime" : "375 s",
         "measurementIterations" : 802,
         "measurementTime" : "501 s",
+        "params" : {
+            "param0" : "value0",
+            "param1" : "value1",
+            "param2" : "value2",
+            "param3" : "value3",
+            "param4" : "value4"
+        },
         "primaryMetric" : {
             "score" : 528.8571333333333,
             "scoreError" : 278.1419529743147,
@@ -174,6 +181,13 @@
         "warmupTime" : "409 s",
         "measurementIterations" : 55,
         "measurementTime" : "398 s",
+        "params" : {
+            "param0" : "value0",
+            "param1" : "value1",
+            "param2" : "value2",
+            "param3" : "value3",
+            "param4" : "value4"
+        },
         "primaryMetric" : {
             "score" : 439.0,
             "scoreError" : "NaN",
@@ -265,6 +279,13 @@
         "warmupTime" : "105 s",
         "measurementIterations" : 461,
         "measurementTime" : "96 s",
+        "params" : {
+            "param0" : "value0",
+            "param1" : "value1",
+            "param2" : "value2",
+            "param3" : "value3",
+            "param4" : "value4"
+        },
         "primaryMetric" : {
             "score" : 545.0,
             "scoreError" : 553.3366994253071,
@@ -386,6 +407,13 @@
         "warmupTime" : "207 s",
         "measurementIterations" : 857,
         "measurementTime" : "438 s",
+        "params" : {
+            "param0" : "value0",
+            "param1" : "value1",
+            "param2" : "value2",
+            "param3" : "value3",
+            "param4" : "value4"
+        },
         "primaryMetric" : {
             "score" : 417.57141666666666,
             "scoreError" : 362.81396705929166,
@@ -534,6 +562,13 @@
         "warmupTime" : "651 s",
         "measurementIterations" : 16,
         "measurementTime" : "763 s",
+        "params" : {
+            "param0" : "value0",
+            "param1" : "value1",
+            "param2" : "value2",
+            "param3" : "value3",
+            "param4" : "value4"
+        },
         "primaryMetric" : {
             "score" : 956.0,
             "scoreError" : "NaN",