changeset 139:b3932d6c6377

Cleanup Runner.
author shade
date Fri, 23 Aug 2013 13:06:43 +0400
parents f357993710a8
children 18ce82926141
files jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java
diffstat 2 files changed, 51 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Fri Aug 23 12:32:13 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Fri Aug 23 13:06:43 2013 +0400
@@ -33,6 +33,7 @@
 import org.openjdk.jmh.runner.parameters.Defaults;
 import org.openjdk.jmh.util.AnnotationUtils;
 import org.openjdk.jmh.util.InputStreamDrainer;
+import org.openjdk.jmh.util.Utils;
 
 import java.io.BufferedOutputStream;
 import java.io.File;
@@ -62,17 +63,13 @@
     /** Class holding all our runtime options/arguments */
     private final HarnessOptions options;
 
-    /**
-     * Main constructor.
-     * @param options
-     */
     public Runner(HarnessOptions options) {
         super(options, createOutputFormat(options));
         this.options = options;
     }
 
     /** Setup helper method, creates OutputFormat according to argv options. */
-    public static OutputFormat createOutputFormat(HarnessOptions options) {
+    private static OutputFormat createOutputFormat(HarnessOptions options) {
         PrintStream out;
         // setup OutputFormat singleton
         if (options.getOutput() == null) {
@@ -154,11 +151,8 @@
     }
 
     /**
-     * Run specified warmup microbenchmarks prior to running
-     * any requested mircobenchmarks.
-     * currently valid only for non-external JVM runs
-     * @param benchmarks
-     * @param list
+     * Run specified warmup microbenchmarks prior to running any requested mircobenchmarks.
+     * TODO: Currently valid only for non-external JVM runs
      */
     private void runBulkWarmupBenchmarks(Set<BenchmarkRecord> benchmarks, MicroBenchmarkList list) {
         out.startRun();
@@ -255,9 +249,7 @@
     }
 
     /**
-     * tests if the benchmark has the mandatory fork annotation
-     * @param benchmark
-     * @return
+     * Tests if the benchmark has the fork annotation
      */
     private int benchForks(BenchmarkRecord benchmark) {
         Method m = MicroBenchmarkHandlers.findBenchmarkMethod(benchmark);
@@ -274,9 +266,7 @@
      */
     private void runSeparateMicroBenchmark(BinaryOutputFormatReader reader, BenchmarkRecord benchmark, String host, int port) {
 
-        /*
-         * Running microbenchmark in separate JVM requires to read some options from annotations.
-         */
+        // Running microbenchmark in separate JVM requires to read some options from annotations.
 
         final Method benchmarkMethod = MicroBenchmarkHandlers.findBenchmarkMethod(benchmark);
         Fork forkAnnotation = benchmarkMethod.getAnnotation(Fork.class);
@@ -301,33 +291,20 @@
         int forkCount = decideForks(options.getForkCount(), benchForks(benchmark));
         int warmupForkCount = decideWarmupForks(options.getWarmupForkCount(), forkAnnotation);
         if (warmupForkCount > 0) {
-            String[] warmupForkCheat = concat(commandString, new String[]{"-wi", "1", "-i", "0"});
-            if (warmupForkCount == 1) {
-                out.verbosePrintln("Warmup forking using command: " + Arrays.toString(warmupForkCheat));
-            } else {
-                out.verbosePrintln("Warmup forking " + warmupForkCount + " times using command: " + Arrays.toString(warmupForkCheat));
-            }
+            String[] warmupForkCheat = Utils.concat(commandString, new String[]{"-wi", "1", "-i", "0"});
+            out.verbosePrintln("Warmup forking " + warmupForkCount + " times using command: " + Arrays.toString(warmupForkCheat));
             for (int i = 0; i < warmupForkCount; i++) {
                 doFork(reader, warmupForkCheat);
             }
         }
-        if (forkCount == 1) {
-            out.verbosePrintln("Forking using command: " + Arrays.toString(commandString));
-        } else {
-            out.verbosePrintln("Forking " + forkCount + " times using command: " + Arrays.toString(commandString));
-        }
-        for (int i = 0; i < forkCount; i++) { // TODO should we report fork number somehow?
+
+        // TODO: should we report fork number somehow?
+        out.verbosePrintln("Forking " + forkCount + " times using command: " + Arrays.toString(commandString));
+        for (int i = 0; i < forkCount; i++) {
             doFork(reader, commandString);
         }
     }
 
-    public String[] concat(String[] t1, String[] t2) {
-        String[] r = new String[t1.length + t2.length];
-        System.arraycopy(t1, 0, r, 0, t1.length);
-        System.arraycopy(t2, 0, r, t1.length, t2.length);
-        return r;
-    }
-
     private void doFork(BinaryOutputFormatReader reader, String[] commandString) {
         try {
             Process p = Runtime.getRuntime().exec(commandString);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java	Fri Aug 23 13:06:43 2013 +0400
@@ -0,0 +1,39 @@
+/*
+ * 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.util;
+
+public class Utils {
+
+    private Utils() {
+
+    }
+
+    public static String[] concat(String[] t1, String[] t2) {
+        String[] r = new String[t1.length + t2.length];
+        System.arraycopy(t1, 0, r, 0, t1.length);
+        System.arraycopy(t2, 0, r, t1.length, t2.length);
+        return r;
+    }
+}