changeset 78:9d9133e41e4c

Accept multiple -bm options.
author shade
date Tue, 04 Jun 2013 14:46:43 +0400
parents be430c14ada0
children f1383f50315b
files jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkRecord.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/BaseOptions.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/handlers/BenchmarkModeTypeOptionHandler.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/handlers/BenchmarkTypeOptionHandler.java
diffstat 5 files changed, 91 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkRecord.java	Tue Jun 04 14:04:46 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkRecord.java	Tue Jun 04 14:46:43 2013 +0400
@@ -32,7 +32,7 @@
 
     private final String userName;
     private final String generatedName;
-    private Mode mode;
+    private final Mode mode;
 
     public BenchmarkRecord(String userName, String generatedName, Mode mode) {
         this.userName = userName;
@@ -92,10 +92,6 @@
         return userName;
     }
 
-    public void setMode(Mode mode) {
-        this.mode = mode;
-    }
-
     public Mode getMode() {
         return mode;
     }
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Tue Jun 04 14:04:46 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Tue Jun 04 14:46:43 2013 +0400
@@ -171,15 +171,22 @@
             }
         }
 
-        // override the benchmark type
-        if (options.getBenchType() != null) {
+        // override the benchmark types;
+        // this may yield new benchmark records
+        List<BenchmarkRecord> newBenchmarks = new ArrayList<BenchmarkRecord>();
+        if (options.getBenchModes() != null) {
             for (BenchmarkRecord br : benchmarks) {
-                br.setMode(options.getBenchType());
+                for (Mode m : options.getBenchModes()) {
+                    newBenchmarks.add(br.cloneWith(m));
+                }
+
             }
         }
 
+        benchmarks.clear();
+        benchmarks.addAll(newBenchmarks);
+
         // clone with all the modes
-        List<BenchmarkRecord> newBenchmarks = new ArrayList<BenchmarkRecord>();
         for (BenchmarkRecord br : benchmarks) {
             if (br.getMode() == Mode.All) {
                 for (Mode mode : Mode.values()) {
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/BaseOptions.java	Tue Jun 04 14:04:46 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/BaseOptions.java	Tue Jun 04 14:46:43 2013 +0400
@@ -27,7 +27,7 @@
 import org.kohsuke.args4j.Option;
 import org.openjdk.jmh.annotations.Mode;
 import org.openjdk.jmh.profile.ProfilerFactory;
-import org.openjdk.jmh.runner.options.handlers.BenchmarkTypeOptionHandler;
+import org.openjdk.jmh.runner.options.handlers.BenchmarkModeTypeOptionHandler;
 import org.openjdk.jmh.runner.options.handlers.BooleanOptionHandler;
 import org.openjdk.jmh.runner.options.handlers.ProfilersOptionHandler;
 import org.openjdk.jmh.runner.options.handlers.ThreadCountsOptionHandler;
@@ -38,6 +38,7 @@
 
 import java.lang.reflect.Field;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.EnumSet;
@@ -81,8 +82,8 @@
     @Option(name = "-w", aliases = {"--warmup"}, metaVar = "TIME", usage = "Run time for warmup iterations. Result not used when calculating score. Examples 100s, 200ms; defaults to " + Defaults.WARMUP_TIME_SECS + "", handler = TimeValueOptionHandler.class)
     protected TimeValue warmupTime = null;
 
-    @Option(name = "-bt", aliases = {"--type"}, metaVar = "TYPE", usage = "Benchmark type", handler = BenchmarkTypeOptionHandler.class)
-    protected Mode benchType = null;
+    @Option(name = "-bm", aliases = {"--mode"}, multiValued = false, metaVar = "MODE", usage = "Benchmark mode", handler = BenchmarkModeTypeOptionHandler.class)
+    protected List<Mode> benchMode = null;
 
     @Option(name = "-t", aliases = {"--threads"}, usage = "Number of threads to run the microbenchmark with. Special value \"max\" or 0 will use Runtime.availableProcessors()", handler = ThreadsOptionHandler.class)
     protected int threads = -1;
@@ -468,7 +469,7 @@
         return profilers;
     }
 
-    public Mode getBenchType() {
-        return benchType;
+    public Collection<Mode> getBenchModes() {
+        return benchMode;
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/handlers/BenchmarkModeTypeOptionHandler.java	Tue Jun 04 14:46:43 2013 +0400
@@ -0,0 +1,73 @@
+/**
+ * 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.runner.options.handlers;
+
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.OptionDef;
+import org.kohsuke.args4j.spi.OptionHandler;
+import org.kohsuke.args4j.spi.Parameters;
+import org.kohsuke.args4j.spi.Setter;
+import org.openjdk.jmh.annotations.Mode;
+
+/**
+ * OptionHandler for Mode options.
+ */
+public class BenchmarkModeTypeOptionHandler extends OptionHandler<Mode> {
+
+    /**
+     * Constructor
+     *
+     * @param parser CmdLineParser parent
+     * @param option Run-time copy of the Option
+     * @param setter Setter to feed back the value
+     */
+    public BenchmarkModeTypeOptionHandler(CmdLineParser parser, OptionDef option, Setter<Mode> setter) {
+        super(parser, option, setter);
+    }
+
+    @Override
+    public int parseArguments(Parameters params) throws CmdLineException {
+        if (params.size() > 0) {
+            String param = params.getParameter(0);
+            try {
+                String[] modes = param.split(",");
+                for (String c : modes) {
+                    Mode value = Mode.deepValueOf(c);
+                    setter.addValue(value);
+                }
+                return 1;
+            } catch (Exception e) {
+                throw new CmdLineException(owner, e.getMessage());
+            }
+        }
+        return 0;
+    }
+
+    @Override
+    public String getDefaultMetaVariable() {
+        return "MODE";
+    }
+}
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/handlers/BenchmarkTypeOptionHandler.java	Tue Jun 04 14:04:46 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,70 +0,0 @@
-/**
- * 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.runner.options.handlers;
-
-import org.kohsuke.args4j.CmdLineException;
-import org.kohsuke.args4j.CmdLineParser;
-import org.kohsuke.args4j.OptionDef;
-import org.kohsuke.args4j.spi.OptionHandler;
-import org.kohsuke.args4j.spi.Parameters;
-import org.kohsuke.args4j.spi.Setter;
-import org.openjdk.jmh.annotations.Mode;
-
-/**
- * OptionHandler for Mode options.
- */
-public class BenchmarkTypeOptionHandler extends OptionHandler<Mode> {
-
-    /**
-     * Constructor
-     *
-     * @param parser CmdLineParser parent
-     * @param option Run-time copy of the Option
-     * @param setter Setter to feed back the value
-     */
-    public BenchmarkTypeOptionHandler(CmdLineParser parser, OptionDef option, Setter<Mode> setter) {
-        super(parser, option, setter);
-    }
-
-    @Override
-    public int parseArguments(Parameters params) throws CmdLineException {
-        if (params.size() > 0) {
-            String param = params.getParameter(0);
-            try {
-                Mode value = Mode.deepValueOf(param);
-                setter.addValue(value);
-                return 1;
-            } catch (Exception e) {
-                throw new CmdLineException(owner, e.getMessage());
-            }
-        }
-        return 0;
-    }
-
-    @Override
-    public String getDefaultMetaVariable() {
-        return "TYPE";
-    }
-}