changeset 163:ca3102a6f220

Print secondary results in OutputFormat.
author shade
date Thu, 29 Aug 2013 20:20:24 +0400
parents 215073a11ca8
children e0d0ab023d09
files jmh-core/src/main/java/org/openjdk/jmh/logic/results/IterationData.java jmh-core/src/main/java/org/openjdk/jmh/output/format/CsvFormat.java jmh-core/src/main/java/org/openjdk/jmh/output/format/PrettyPrintFormat.java jmh-core/src/main/java/org/openjdk/jmh/output/format/TextReportFormat.java
diffstat 4 files changed, 51 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/logic/results/IterationData.java	Thu Aug 29 19:24:08 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/logic/results/IterationData.java	Thu Aug 29 20:20:24 2013 +0400
@@ -32,6 +32,7 @@
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
@@ -76,16 +77,30 @@
         }
     }
 
-    public List<Result> getPrimaryResults() {
+    public List<Result> getRawPrimaryResults() {
         return primaryResults;
     }
 
+    public Multimap<String, Result> getRawSecondaryResults() {
+        return secondaryResults;
+    }
+
+    public Map<String, Result> getSecondaryResults() {
+        Map<String, Result> answer = new TreeMap<String, Result>();
+        for (String label : secondaryResults.keys()) {
+            Collection<Result> results = secondaryResults.get(label);
+
+            Result next = results.iterator().next();
+
+            @SuppressWarnings("unchecked")
+            Aggregator<Result> aggregator = next.getIterationAggregator();
+            Result result = aggregator.aggregate(results);
+            answer.put(label, result);
+        }
+        return answer;
+    }
+
     public Result getPrimaryResult() {
-        Multimap<String, Result> results = new TreeMultimap<String, Result>();
-        for (Result r : primaryResults) {
-            results.put(r.getLabel(), r);
-        }
-
         Result next = primaryResults.iterator().next();
 
         @SuppressWarnings("unchecked")
@@ -121,36 +136,4 @@
         return scoreUnit;
     }
 
-    public String toPrintable() {
-        return getPrimaryResult().toString();
-//        if (primaryResults.size() > 1) {
-//            boolean first = true;
-//            StringBuilder sb = new StringBuilder();
-//            String unit = "";
-//            for (Map.Entry<String, Result> res : primaryResults.entrySet()) {
-//                if (!first) {
-//                    sb.append(", ");
-//                }
-//                first = false;
-//
-//                // rough estimate
-//                int threads = primaryResults.get(res.getKey()).size();
-//
-//                sb.append(res.getKey());
-//                sb.append("{t=").append(threads).append("}");
-//                sb.append(" = ");
-//                sb.append(res.getValue().toPrintableScore());
-//
-//                unit = res.getValue().getScoreUnit();
-//            }
-//            sb.append(" ");
-//            sb.append(unit);
-//            return sb.toString();
-//        } else if (result.size() == 1) {
-//            return result.values().iterator().next().toString();
-//        } else {
-//            return "N/A";
-//        }
-    }
-
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/format/CsvFormat.java	Thu Aug 29 19:24:08 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/format/CsvFormat.java	Thu Aug 29 20:20:24 2013 +0400
@@ -59,7 +59,7 @@
         out.print(convertDouble(data.getPrimaryResult().getScore()) + DELIMITER);
         out.print(params.getThreads() + DELIMITER + data.getScoreUnit() + DELIMITER);
 
-        for (Result r : data.getPrimaryResults()) {
+        for (Result r : data.getRawPrimaryResults()) {
             out.print(convertDouble(r.getScore()) + DELIMITER);
         }
         out.println();
@@ -109,7 +109,7 @@
     public void detailedResults(BenchmarkRecord name, IterationParams params, int iteration, IterationData data) {
         int count = 0;
 
-        for (Result result : data.getPrimaryResults()) {
+        for (Result result : data.getRawPrimaryResults()) {
             out.print(convertDouble(result.getScore()));
             out.print(DELIMITER);
             count++;
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/format/PrettyPrintFormat.java	Thu Aug 29 19:24:08 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/format/PrettyPrintFormat.java	Thu Aug 29 20:20:24 2013 +0400
@@ -39,6 +39,7 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * PrettyPrint implementation of OutputFormat.
@@ -53,7 +54,30 @@
 
     @Override
     public void iterationResult(BenchmarkRecord name, IterationParams params, int iteration, IterationType type, IterationData data, Collection<ProfilerResult> profiles) {
-        out.print(String.format("%s", data.toPrintable()));
+        StringBuilder sb = new StringBuilder();
+        sb.append(data.getPrimaryResult().toString());
+
+        if (type == IterationType.MEASUREMENT) {
+            int prefixLen = String.format("Iteration %3d (%s in %d %s): ", iteration,
+                    params.getTime(), params.getThreads(), getThreadsString(params.getThreads())).length();
+
+            Map<String, Result> secondary = data.getSecondaryResults();
+            if (!secondary.isEmpty()) {
+                sb.append("\n");
+                for (Map.Entry<String, Result> res : secondary.entrySet()) {
+                    // rough estimate
+                    int threads = data.getRawSecondaryResults().get(res.getKey()).size();
+
+                    sb.append(String.format("%" + prefixLen + "s", ""));
+                    sb.append("  \"").append(res.getKey()).append("\": ");
+                    sb.append(res.getValue().toString());
+                    sb.append(" (").append(threads).append(" threads)");
+                    sb.append("\n");
+                }
+            }
+        }
+
+        out.print(String.format("%s", sb.toString()));
 
         // also print out profiler information
         if (type == IterationType.MEASUREMENT) {
@@ -157,7 +181,7 @@
         out.print("Results per thread: [");
 
         boolean first = true;
-        for (Result result : data.getPrimaryResults()) {
+        for (Result result : data.getRawPrimaryResults()) {
             if (!first) {
                 out.print(", ");
             }
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/format/TextReportFormat.java	Thu Aug 29 19:24:08 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/format/TextReportFormat.java	Thu Aug 29 20:20:24 2013 +0400
@@ -92,7 +92,7 @@
             if (results != null) {
                 List<Result> iResults = new ArrayList<Result>();
                 for (IterationData res : results) {
-                    iResults.addAll(res.getPrimaryResults());
+                    iResults.addAll(res.getRawPrimaryResults());
                 }
 
                 if (!iResults.isEmpty()) {
@@ -129,7 +129,7 @@
             if (results != null) {
                 List<Result> iResults = new ArrayList<Result>();
                 for (IterationData res : results) {
-                    iResults.addAll(res.getPrimaryResults());
+                    iResults.addAll(res.getRawPrimaryResults());
                 }
 
                 if (!iResults.isEmpty()) {