changeset 132:ced67a356973

Fold OutputFormat.warmupIteration into OutputFormat.iteration
author shade
date Wed, 21 Aug 2013 20:39:43 +0400
parents 59b8ba356d64
children e908157a6c14
files jmh-core/src/main/java/org/openjdk/jmh/output/format/CsvFormat.java jmh-core/src/main/java/org/openjdk/jmh/output/format/IterationType.java jmh-core/src/main/java/org/openjdk/jmh/output/format/OutputFormat.java jmh-core/src/main/java/org/openjdk/jmh/output/format/PrettyPrintFormat.java jmh-core/src/main/java/org/openjdk/jmh/output/format/SilentFormat.java jmh-core/src/main/java/org/openjdk/jmh/output/format/TextReportFormat.java jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java
diffstat 8 files changed, 85 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/format/CsvFormat.java	Wed Aug 21 20:25:57 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/format/CsvFormat.java	Wed Aug 21 20:39:43 2013 +0400
@@ -52,7 +52,9 @@
     }
 
     @Override
-    public void iterationResult(BenchmarkRecord name, int iteration, int thread, IterationResult result, Collection<ProfilerResult> profiles) {
+    public void iterationResult(BenchmarkRecord name, int iteration, IterationType type, int thread, IterationResult result, Collection<ProfilerResult> profiles) {
+        if (type != IterationType.MEASUREMENT) return;
+
         out.print(name + DELIMITER + iteration + DELIMITER);
         for (Result r : result.getResult().values()) {
             out.print(convertDouble(r.getScore()) + DELIMITER);
@@ -96,17 +98,7 @@
     }
 
     @Override
-    public void iteration(BenchmarkRecord benchmark, int iteration, int threads, TimeValue runTime) {
-        // don't print anything
-    }
-
-    @Override
-    public void warmupIteration(BenchmarkRecord benchmark, int iteration, int threads, TimeValue warmupTime) {
-        // don't print anything
-    }
-
-    @Override
-    public void warmupIterationResult(BenchmarkRecord benchmark, int iteration, int thread, IterationResult result) {
+    public void iteration(BenchmarkRecord benchmark, int iteration, IterationType type, int threads, TimeValue runTime) {
         // don't print anything
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/format/IterationType.java	Wed Aug 21 20:39:43 2013 +0400
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.output.format;
+
+public enum IterationType {
+    WARMUP,
+    MEASUREMENT,
+}
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/format/OutputFormat.java	Wed Aug 21 20:25:57 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/format/OutputFormat.java	Wed Aug 21 20:39:43 2013 +0400
@@ -45,26 +45,6 @@
 public interface OutputFormat {
 
     /**
-     * Format for warmup output.
-     *
-     * @param benchmark benchmark name
-     * @param iteration Warmup Iteration Number (1..N)
-     * @param threads   Number of threads we executed on
-     * @param warmupTime Time to spend per iteration
-     */
-    public void warmupIteration(BenchmarkRecord benchmark, int iteration, int threads, TimeValue warmupTime);
-
-    /**
-     * Format for end-of-warmup-iteration.
-     *
-     * @param benchmark benchmark name
-     * @param iteration iteration-number
-     * @param thread    amount of threads used
-     * @param result    result of iteration
-     */
-    public void warmupIterationResult(BenchmarkRecord benchmark, int iteration, int thread, IterationResult result);
-
-    /**
      * Format for iteration start.
      *
      * @param benchmark benchmark name
@@ -72,7 +52,7 @@
      * @param threads threads to run
      * @param runTime time to spend per iteration
      */
-    public void iteration(BenchmarkRecord benchmark, int iteration, int threads, TimeValue runTime);
+    public void iteration(BenchmarkRecord benchmark, int iteration, IterationType type, int threads, TimeValue runTime);
 
     /**
      * Format for end-of-iteration.
@@ -83,7 +63,7 @@
      * @param result    result of iteration
      * @param profiles  profiler results
      */
-    public void iterationResult(BenchmarkRecord name, int iteration, int thread, IterationResult result, Collection<ProfilerResult> profiles);
+    public void iterationResult(BenchmarkRecord name, int iteration, IterationType type, int thread, IterationResult result, Collection<ProfilerResult> profiles);
 
     /**
      * Format for start-of-benchmark output.
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/format/PrettyPrintFormat.java	Wed Aug 21 20:25:57 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/format/PrettyPrintFormat.java	Wed Aug 21 20:39:43 2013 +0400
@@ -53,24 +53,28 @@
     }
 
     @Override
-    public void iterationResult(BenchmarkRecord name, int iteration, int thread, IterationResult result, Collection<ProfilerResult> profiles) {
-        boolean firstProfiler = true;
-        out.print(String.format("%s", result.toPrintable()));
-        for (ProfilerResult profRes : profiles) {
-            if (profRes.hasData()) {
-                if (firstProfiler) {
-                    out.println("");
-                    firstProfiler = false;
+    public void iterationResult(BenchmarkRecord name, int iteration, IterationType type, int thread, IterationResult result, Collection<ProfilerResult> profiles) {
+        out.println(String.format("%s", result.toPrintable()));
+
+        if (type == IterationType.MEASUREMENT) {
+            boolean firstProfiler = true;
+            out.print(String.format("%s", result.toPrintable()));
+            for (ProfilerResult profRes : profiles) {
+                if (profRes.hasData()) {
+                    if (firstProfiler) {
+                        out.println("");
+                        firstProfiler = false;
+                    }
+                    String prefix = profRes.getProfilerName();
+                    for (String line : profRes.toString().split("\n")) {
+                        out.print(String.format("%12s | %s\n", prefix, line));
+                        prefix = "";
+                    }
+                    out.print(String.format("%12s |\n", ""));
                 }
-                String prefix = profRes.getProfilerName();
-                for (String line : profRes.toString().split("\n")) {
-                    out.print(String.format("%12s | %s\n", prefix, line));
-                    prefix = "";
-                }
-                out.print(String.format("%12s |\n", ""));
             }
+            out.println("");
         }
-        out.println("");
         out.flush();
     }
 
@@ -132,22 +136,19 @@
     }
 
     @Override
-    public void iteration(BenchmarkRecord benchmark, int iteration, int threads, TimeValue timeValue) {
-        out.print(String.format("Iteration %3d (%s in %d %s): ", iteration,
-                timeValue, threads, getThreadsString(threads)));
-        out.flush();
-    }
-
-    @Override
-    public void warmupIteration(BenchmarkRecord benchmark, int iteration, int threads, TimeValue timeValue) {
-        out.print(String.format("# Warmup Iteration %3d (%s in %d %s): ", iteration,
-                timeValue, threads, getThreadsString(threads)));
-        out.flush();
-    }
-
-    @Override
-    public void warmupIterationResult(BenchmarkRecord benchmark, int iteration, int thread, IterationResult result) {
-        out.println(String.format("%s", result.toPrintable()));
+    public void iteration(BenchmarkRecord benchmark, int iteration, IterationType type, int threads, TimeValue timeValue) {
+        switch (type) {
+            case WARMUP:
+                out.print(String.format("# Warmup Iteration %3d (%s in %d %s): ", iteration,
+                        timeValue, threads, getThreadsString(threads)));
+                break;
+            case MEASUREMENT:
+                out.print(String.format("Iteration %3d (%s in %d %s): ", iteration,
+                        timeValue, threads, getThreadsString(threads)));
+                break;
+            default:
+                throw new IllegalStateException("Unknown iteration type: " + type);
+        }
         out.flush();
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/format/SilentFormat.java	Wed Aug 21 20:25:57 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/format/SilentFormat.java	Wed Aug 21 20:39:43 2013 +0400
@@ -54,11 +54,6 @@
     }
 
     @Override
-    public void warmupIteration(BenchmarkRecord benchmark, int iteration, int threads, TimeValue warmupTime) {
-
-    }
-
-    @Override
     public void startBenchmark(BenchmarkRecord name, MicroBenchmarkParameters mbParams, boolean verbose) {
 
     }
@@ -74,17 +69,13 @@
     }
 
     @Override
-    public void iteration(BenchmarkRecord benchmark, int iteration, int threads, TimeValue runTime) {
+    public void iteration(BenchmarkRecord benchmark, int iteration, IterationType type, int threads, TimeValue runTime) {
 
     }
 
     @Override
-    public void iterationResult(BenchmarkRecord name, int iteration, int thread, IterationResult result, Collection<ProfilerResult> profiles) {
+    public void iterationResult(BenchmarkRecord name, int iteration, IterationType type, int thread, IterationResult result, Collection<ProfilerResult> profiles) {
 
     }
 
-    @Override
-    public void warmupIterationResult(BenchmarkRecord benchmark, int iteration, int thread, IterationResult result) {
-    }
-
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/format/TextReportFormat.java	Wed Aug 21 20:25:57 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/format/TextReportFormat.java	Wed Aug 21 20:39:43 2013 +0400
@@ -68,9 +68,11 @@
     }
 
     @Override
-    public void iterationResult(BenchmarkRecord name, int iteration, int thread, IterationResult result, Collection<ProfilerResult> profiles) {
-        super.iterationResult(name, iteration, thread, result, profiles);
-        benchmarkResults.put(new BenchmarkIdentifier(name, thread), result);
+    public void iterationResult(BenchmarkRecord name, int iteration, IterationType type, int thread, IterationResult result, Collection<ProfilerResult> profiles) {
+        super.iterationResult(name, iteration, type, thread, result, profiles);
+        if (type == IterationType.MEASUREMENT) {
+            benchmarkResults.put(new BenchmarkIdentifier(name, thread), result);
+        }
     }
 
     @Override
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Wed Aug 21 20:25:57 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Wed Aug 21 20:39:43 2013 +0400
@@ -27,6 +27,7 @@
 import org.openjdk.jmh.logic.results.IterationData;
 import org.openjdk.jmh.logic.results.Result;
 import org.openjdk.jmh.logic.results.internal.RunResult;
+import org.openjdk.jmh.output.format.IterationType;
 import org.openjdk.jmh.output.format.OutputFormat;
 import org.openjdk.jmh.runner.options.BaseOptions;
 import org.openjdk.jmh.runner.parameters.IterationParams;
@@ -86,10 +87,10 @@
                     out.verbosePrintln("System.gc() executed");
                 }
 
-                out.warmupIteration(handler.getBenchmark(), i, executionParams.getThreads(), warmupParams.getTime());
+                out.iteration(handler.getBenchmark(), i, IterationType.WARMUP, executionParams.getThreads(), warmupParams.getTime());
                 boolean isLastIteration = false; // warmup is never the last iteration
                 IterationData iterData = handler.runIteration(executionParams.getThreads(), warmupParams.getTime(), isLastIteration).setWarmup();
-                out.warmupIterationResult(handler.getBenchmark(), i, options.getThreads(), iterData.getAggregatedResult());
+                out.iterationResult(handler.getBenchmark(), i, IterationType.WARMUP, options.getThreads(), iterData.getAggregatedResult(), iterData.getProfilerResults());
             }
 
             IterationParams measureParams = executionParams.getIteration();
@@ -100,7 +101,7 @@
                 }
 
                 // run benchmark iteration
-                out.iteration(handler.getBenchmark(), i, executionParams.getThreads(), measureParams.getTime());
+                out.iteration(handler.getBenchmark(), i, IterationType.MEASUREMENT, executionParams.getThreads(), measureParams.getTime());
 
                 boolean isLastIteration = (i == measureParams.getCount());
                 IterationData iterData = handler.runIteration(executionParams.getThreads(), measureParams.getTime(), isLastIteration);
@@ -109,7 +110,7 @@
                 if (iterData.isResultsEmpty()) {
                     out.println("WARNING: No results returned, benchmark payload threw exception?");
                 } else {
-                    out.iterationResult(handler.getBenchmark(), i, executionParams.getThreads(), iterData.getAggregatedResult(), iterData.getProfilerResults());
+                    out.iterationResult(handler.getBenchmark(), i, IterationType.MEASUREMENT, executionParams.getThreads(), iterData.getAggregatedResult(), iterData.getProfilerResults());
 
                     if (options.shouldOutputDetailedResults()) {
                         out.detailedResults(handler.getBenchmark(), i, executionParams.getThreads(), iterData.getAggregatedResult());
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Wed Aug 21 20:25:57 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Wed Aug 21 20:39:43 2013 +0400
@@ -29,6 +29,7 @@
 import org.openjdk.jmh.logic.results.IterationData;
 import org.openjdk.jmh.logic.results.internal.RunResult;
 import org.openjdk.jmh.output.OutputFormatFactory;
+import org.openjdk.jmh.output.format.IterationType;
 import org.openjdk.jmh.output.format.OutputFormat;
 import org.openjdk.jmh.output.format.internal.BinaryOutputFormatReader;
 import org.openjdk.jmh.runner.options.HarnessOptions;
@@ -441,7 +442,7 @@
                     }
 
                     // run benchmark iteration
-                    out.warmupIteration(handler.getBenchmark(), i, executionParams.getThreads(), p.getTime());
+                    out.iteration(handler.getBenchmark(), i, IterationType.WARMUP, executionParams.getThreads(), p.getTime());
 
                     boolean isLastIteration = (i == p.getCount());
                     IterationData iterData = handler.runIteration(executionParams.getThreads(), p.getTime(), isLastIteration);
@@ -451,7 +452,7 @@
                         out.println("WARNING: No results returned, benchmark payload threw exception?");
                     } else {
                         // print out score for this iteration
-                        out.warmupIterationResult(handler.getBenchmark(), i, executionParams.getThreads(), iterData.getAggregatedResult());
+                        out.iterationResult(handler.getBenchmark(), i, IterationType.WARMUP, executionParams.getThreads(), iterData.getAggregatedResult(), iterData.getProfilerResults());
                     }
                 }
             } else {
@@ -463,7 +464,7 @@
                     }
 
                     // run benchmark iteration
-                    out.iteration(handler.getBenchmark(), i, executionParams.getThreads(), p.getTime());
+                    out.iteration(handler.getBenchmark(), i, IterationType.MEASUREMENT, executionParams.getThreads(), p.getTime());
 
                     boolean isLastIteration = (i == p.getCount());
                     IterationData iterData = handler.runIteration(executionParams.getThreads(), p.getTime(), isLastIteration);
@@ -476,7 +477,7 @@
                         allResults.add(iterData);
 
                         // print out score for this iteration
-                        out.iterationResult(handler.getBenchmark(), i, options.getThreads(), iterData.getAggregatedResult(), iterData.getProfilerResults());
+                        out.iterationResult(handler.getBenchmark(), i, IterationType.MEASUREMENT, options.getThreads(), iterData.getAggregatedResult(), iterData.getProfilerResults());
                     }
                 }
             }