changeset 1263:898b59ce36f8

7901484: New option to list benchmarks with parameters Contributed-by: Sergey Kuksenko <sergey.kuksenko@oracle.com>
author shade
date Thu, 13 Aug 2015 18:12:55 +0300
parents 3adb58795226
children 7073e1a4bee6
files jmh-core/src/main/java/org/openjdk/jmh/Main.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/CommandLineOptions.java
diffstat 3 files changed, 34 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/Main.java	Thu Aug 13 18:00:26 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/Main.java	Thu Aug 13 18:12:55 2015 +0300
@@ -52,6 +52,11 @@
                 return;
             }
 
+            if (cmdOptions.shouldListWithParams()) {
+                runner.listWithParams(cmdOptions);
+                return;
+            }
+
             if (cmdOptions.shouldListProfilers()) {
                 cmdOptions.listProfilers();
                 return;
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Thu Aug 13 18:00:26 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Thu Aug 13 18:12:55 2015 +0300
@@ -36,11 +36,9 @@
 import org.openjdk.jmh.runner.format.OutputFormat;
 import org.openjdk.jmh.runner.format.OutputFormatFactory;
 import org.openjdk.jmh.runner.link.BinaryLinkServer;
-import org.openjdk.jmh.runner.options.Options;
-import org.openjdk.jmh.runner.options.ProfilerConfig;
-import org.openjdk.jmh.runner.options.TimeValue;
-import org.openjdk.jmh.runner.options.VerboseMode;
+import org.openjdk.jmh.runner.options.*;
 import org.openjdk.jmh.util.*;
+import org.openjdk.jmh.util.Optional;
 
 import java.io.*;
 import java.lang.management.ManagementFactory;
@@ -127,6 +125,26 @@
     }
 
     /**
+     * Print matching benchmarks with parameters into output.
+     * @param options
+     */
+    public void listWithParams(CommandLineOptions options) {
+        Set<BenchmarkListEntry> benchmarks = list.find(out, options.getIncludes(), options.getExcludes());
+        out.println("Benchmarks: ");
+        for (BenchmarkListEntry benchmark : benchmarks) {
+            out.println(benchmark.getUsername());
+            Optional<Map<String, String[]>> params = benchmark.getParams();
+            if (params.hasValue()) {
+                for (Map.Entry<String, String[]> e : params.get().entrySet()) {
+                    String param = e.getKey();
+                    Collection<String> values = options.getParameter(param).orElse(Arrays.asList(e.getValue()));
+                    out.println("  param \"" + param + "\" = {" + Utils.join(values, ", ") + "}");
+                }
+            }
+        }
+    }
+
+    /**
      * Shortcut method for the single benchmark execution.
      * This method is handy when Options describe only the single benchmark to run.
      *
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/CommandLineOptions.java	Thu Aug 13 18:00:26 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/CommandLineOptions.java	Thu Aug 13 18:12:55 2015 +0300
@@ -75,6 +75,7 @@
     private final List<String> warmupMicros = new ArrayList<String>();
     private final Multimap<String, String> params = new HashMultimap<String, String>();
     private final boolean list;
+    private final boolean listWithParams;
     private final boolean listResultFormats;
     private final boolean help;
     private final boolean listProfilers;
@@ -197,6 +198,7 @@
                 .withRequiredArg().withValuesSeparatedBy(',').ofType(String.class).describedAs("regexp+");
 
         parser.accepts("l", "List matching benchmarks and exit.");
+        parser.accepts("lp", "List matching benchmarks with parameters and exit.");
         parser.accepts("lrf", "List result formats.");
         parser.accepts("lprof", "List profilers.");
         parser.accepts("h", "Display help.");
@@ -259,6 +261,7 @@
 
             help = set.has("h");
             list = set.has("l");
+            listWithParams = set.has("lp");
             listResultFormats = set.has("lrf");
             listProfilers = set.has("lprof");
 
@@ -404,6 +407,10 @@
         return list;
     }
 
+    public boolean shouldListWithParams() {
+        return listWithParams;
+    }
+
     public boolean shouldListResultFormats() {
         return listResultFormats;
     }