jmh-core/src/main/java/org/openjdk/jmh/runner/format/TextReportFormat.java

Print this page




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package org.openjdk.jmh.runner.format;
  26 
  27 import org.openjdk.jmh.annotations.Mode;
  28 import org.openjdk.jmh.infra.BenchmarkParams;
  29 import org.openjdk.jmh.infra.IterationParams;
  30 import org.openjdk.jmh.results.BenchmarkResult;
  31 import org.openjdk.jmh.results.IterationResult;
  32 import org.openjdk.jmh.results.Result;
  33 import org.openjdk.jmh.results.RunResult;
  34 import org.openjdk.jmh.results.format.ResultFormatFactory;
  35 import org.openjdk.jmh.results.format.ResultFormatType;
  36 import org.openjdk.jmh.runner.IterationType;

  37 import org.openjdk.jmh.runner.options.VerboseMode;
  38 
  39 import java.io.PrintStream;
  40 import java.io.PrintWriter;
  41 import java.util.Collection;
  42 import java.util.Map;

  43 
  44 /**
  45  * TextReportFormat implementation of OutputFormat.
  46  */
  47 class TextReportFormat extends AbstractOutputFormat {
  48 
  49     public TextReportFormat(PrintStream out, VerboseMode verbose) {
  50         super(out, verbose);
  51     }
  52 
  53     @Override
  54     public void startBenchmark(BenchmarkParams params) {
  55         if (params.getWarmup().getCount() > 0) {
  56             out.println("# Warmup: " + params.getWarmup().getCount() + " iterations, " +
  57                     params.getWarmup().getTime() + " each" +
  58                     (params.getWarmup().getBatchSize() <= 1 ? "" : ", " + params.getWarmup().getBatchSize() + " calls per op"));

  59         } else {
  60             out.println("# Warmup: <none>");
  61         }
  62 
  63         if (params.getMeasurement().getCount() > 0) {
  64             out.println("# Measurement: " + params.getMeasurement().getCount() + " iterations, " +
  65                     params.getMeasurement().getTime() + " each" +
  66                     (params.getMeasurement().getBatchSize() <= 1 ? "" : ", " + params.getMeasurement().getBatchSize() + " calls per op"));

  67         } else {
  68             out.println("# Measurement: <none>");
  69         }
  70 





  71         out.println("# Threads: " + params.getThreads() + " " + getThreadsString(params.getThreads()) +
  72                 (params.shouldSynchIterations() ?
  73                         ", will synchronize iterations" :
  74                         (params.getMode() == Mode.SingleShotTime) ? "" : ", ***WARNING: Synchronize iterations are disabled!***"));

  75         out.println("# Benchmark mode: " + params.getMode().longLabel());
  76         out.println("# Benchmark: " + params.getBenchmark());
  77         if (!params.getParamsKeys().isEmpty()) {
  78             String s = "";
  79             boolean isFirst = true;
  80             for (String k : params.getParamsKeys()) {
  81                 if (isFirst) {
  82                     isFirst = false;
  83                 } else {
  84                     s += ", ";
  85                 }
  86                 s += k + " = " + params.getParam(k);
  87             }
  88             out.println("# Parameters: (" + s + ")");
  89         }
  90     }
  91 
  92     @Override
  93     public void iteration(BenchmarkParams benchmarkParams, IterationParams params, int iteration) {
  94         switch (params.getType()) {




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package org.openjdk.jmh.runner.format;
  26 
  27 import org.openjdk.jmh.annotations.Mode;
  28 import org.openjdk.jmh.infra.BenchmarkParams;
  29 import org.openjdk.jmh.infra.IterationParams;
  30 import org.openjdk.jmh.results.BenchmarkResult;
  31 import org.openjdk.jmh.results.IterationResult;
  32 import org.openjdk.jmh.results.Result;
  33 import org.openjdk.jmh.results.RunResult;
  34 import org.openjdk.jmh.results.format.ResultFormatFactory;
  35 import org.openjdk.jmh.results.format.ResultFormatType;
  36 import org.openjdk.jmh.runner.IterationType;
  37 import org.openjdk.jmh.runner.options.TimeValue;
  38 import org.openjdk.jmh.runner.options.VerboseMode;
  39 
  40 import java.io.PrintStream;
  41 import java.io.PrintWriter;
  42 import java.util.Collection;
  43 import java.util.Map;
  44 import java.util.concurrent.TimeUnit;
  45 
  46 /**
  47  * TextReportFormat implementation of OutputFormat.
  48  */
  49 class TextReportFormat extends AbstractOutputFormat {
  50 
  51     public TextReportFormat(PrintStream out, VerboseMode verbose) {
  52         super(out, verbose);
  53     }
  54 
  55     @Override
  56     public void startBenchmark(BenchmarkParams params) {
  57         IterationParams warmup = params.getWarmup();
  58         if (warmup.getCount() > 0) {
  59             out.println("# Warmup: " + warmup.getCount() + " iterations, " +
  60                     warmup.getTime() + " each" +
  61                     (warmup.getBatchSize() <= 1 ? "" : ", " + warmup.getBatchSize() + " calls per op"));
  62         } else {
  63             out.println("# Warmup: <none>");
  64         }
  65 
  66         IterationParams measurement = params.getMeasurement();
  67         if (measurement.getCount() > 0) {
  68             out.println("# Measurement: " + measurement.getCount() + " iterations, " +
  69                     measurement.getTime() + " each" +
  70                     (measurement.getBatchSize() <= 1 ? "" : ", " + measurement.getBatchSize() + " calls per op"));
  71         } else {
  72             out.println("# Measurement: <none>");
  73         }
  74 
  75         TimeValue timeout = params.getTimeout();
  76         boolean timeoutWarning = (timeout.convertTo(TimeUnit.NANOSECONDS) <= measurement.getTime().convertTo(TimeUnit.NANOSECONDS)) ||
  77                 (timeout.convertTo(TimeUnit.NANOSECONDS) <= warmup.getTime().convertTo(TimeUnit.NANOSECONDS));
  78         out.println("# Timeout: " + timeout + " per iteration" + (timeoutWarning ? ", ***WARNING: The timeout might be too low!***" : ""));
  79 
  80         out.println("# Threads: " + params.getThreads() + " " + getThreadsString(params.getThreads()) +
  81                 (params.shouldSynchIterations() ?
  82                         ", will synchronize iterations" :
  83                         (params.getMode() == Mode.SingleShotTime) ? "" : ", ***WARNING: Synchronize iterations are disabled!***"));
  84 
  85         out.println("# Benchmark mode: " + params.getMode().longLabel());
  86         out.println("# Benchmark: " + params.getBenchmark());
  87         if (!params.getParamsKeys().isEmpty()) {
  88             String s = "";
  89             boolean isFirst = true;
  90             for (String k : params.getParamsKeys()) {
  91                 if (isFirst) {
  92                     isFirst = false;
  93                 } else {
  94                     s += ", ";
  95                 }
  96                 s += k + " = " + params.getParam(k);
  97             }
  98             out.println("# Parameters: (" + s + ")");
  99         }
 100     }
 101 
 102     @Override
 103     public void iteration(BenchmarkParams benchmarkParams, IterationParams params, int iteration) {
 104         switch (params.getType()) {