changeset 418:b33c145ad8d8

@Param values should be printed properly in text report.
author shade
date Thu, 20 Feb 2014 16:15:56 +0400
parents cb6358cfb6c5
children 5b8de0f72c4f
files jmh-core/src/main/java/org/openjdk/jmh/output/format/TextReportFormat.java
diffstat 1 files changed, 45 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/format/TextReportFormat.java	Thu Feb 20 13:00:38 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/format/TextReportFormat.java	Thu Feb 20 16:15:56 2014 +0400
@@ -39,7 +39,10 @@
 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 /**
  * TextReportFormat implementation of OutputFormat.
@@ -161,9 +164,9 @@
         Collection<String> benchNames = new ArrayList<String>();
         for (BenchmarkRecord key : runResults.keySet()) {
             RunResult runResult = runResults.get(key);
-            benchNames.add(key.getUsername() + mixActualParams(key));
+            benchNames.add(key.getUsername());
             for (String label : runResult.getSecondaryResults().keySet()) {
-                benchNames.add(key.getUsername() + ":" + label + mixActualParams(key));
+                benchNames.add(key.getUsername() + ":" + label);
             }
         }
 
@@ -176,14 +179,41 @@
         }
         nameLen += 2;
 
-        out.printf("%-" + nameLen + "s %6s %9s %12s %12s %8s%n",
-                "Benchmark", "Mode", "Samples", "Mean", "Mean error", "Units");
+        Map<String, Integer> paramLengths = new HashMap<String, Integer>();
+        SortedSet<String> params = new TreeSet<String>();
+        for (BenchmarkRecord br : runResults.keySet()) {
+            if (br.getActualParams() != null) {
+                for (String k : br.getActualParams().keys()) {
+                    params.add(k);
+                    Integer len = paramLengths.get(k);
+                    if (len == null) {
+                        len = ("(" + k + ")").length();
+                    }
+                    paramLengths.put(k, Math.max(len, br.getActualParam(k).length()));
+                }
+            }
+        }
+
+        out.printf("%-" + nameLen + "s ", "Benchmark");
+        for (String k : params) {
+            out.printf("%" + paramLengths.get(k) + "s ", "(" + k + ")");
+        }
+
+        out.printf("%6s %9s %12s %12s %8s%n",
+                    "Mode", "Samples", "Mean", "Mean error", "Units");
         for (BenchmarkRecord key : runResults.keySet()) {
             RunResult res = runResults.get(key);
             {
                 Statistics stats = res.getPrimaryResult().getStatistics();
-                out.printf("%-" + nameLen + "s %6s %9d %12.3f %12.3f %8s%n",
-                        benchPrefixes.get(key.getUsername() + mixActualParams(key)),
+                out.printf("%-" + nameLen + "s ",
+                        benchPrefixes.get(key.getUsername()));
+
+                for (String k : params) {
+                    String v = key.getActualParam(k);
+                    out.printf("%" + paramLengths.get(k) + "s ", (v == null) ? "N/A" : v);
+                }
+
+                out.printf("%6s %9d %12.3f %12.3f %8s%n",
                         key.getMode().shortLabel(),
                         stats.getN(),
                         stats.getMean(), stats.getMeanErrorAt(0.999),
@@ -193,8 +223,15 @@
             for (String label : res.getSecondaryResults().keySet()) {
                 Statistics stats = res.getSecondaryResults().get(label).getStatistics();
 
-                out.printf("%-" + nameLen + "s %6s %9d %12.3f %12.3f %8s%n",
-                        benchPrefixes.get(key.getUsername() + ":" + label + mixActualParams(key)),
+                out.printf("%-" + nameLen + "s ",
+                        benchPrefixes.get(key.getUsername() + ":" + label));
+
+                for (String k : params) {
+                    String v = key.getActualParam(k);
+                    out.printf("%" + paramLengths.get(k) + "s ", (v == null) ? "N/A" : v);
+                }
+
+                out.printf("%6s %9d %12.3f %12.3f %8s%n",
                         key.getMode().shortLabel(),
                         stats.getN(),
                         stats.getMean(), stats.getMeanErrorAt(0.999),
@@ -203,8 +240,4 @@
         }
     }
 
-    private static String mixActualParams(BenchmarkRecord key) {
-        return (key.getActualParams() == null ? "" : " " + key.getActualParams().toString());
-    }
-
 }