changeset 116:e5450f2db884

Implicit ".*" for benchmark selection from the command line.
author shade
date Fri, 16 Aug 2013 18:39:06 +0400
parents 7c137a6d33e4
children 65b09f85aee3
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/HarnessOptions.java jmh-core/src/test/java/org/openjdk/jmh/TestMain.java
diffstat 4 files changed, 51 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/Main.java	Fri Aug 16 18:12:35 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/Main.java	Fri Aug 16 18:39:06 2013 +0400
@@ -47,63 +47,59 @@
     public static void main(String[] argv) {
         HarnessOptions cmdOptions = HarnessOptions.newInstance();
 
-        if (argv.length == 0) {
-            cmdOptions.printUsage("Print help");
-        } else {
-            try {
-                cmdOptions.parseArguments(argv);
+        try {
+            cmdOptions.parseArguments(argv);
 
-                // list output formats?
-                if (cmdOptions.shouldListFormats()) {
-                    StringBuilder sb = new StringBuilder();
+            // list output formats?
+            if (cmdOptions.shouldListFormats()) {
+                StringBuilder sb = new StringBuilder();
 
-                    for (OutputFormatType f : OutputFormatType.values()) {
-                        sb.append(f.toString().toLowerCase());
-                        sb.append(", ");
+                for (OutputFormatType f : OutputFormatType.values()) {
+                    sb.append(f.toString().toLowerCase());
+                    sb.append(", ");
+                }
+                sb.setLength(sb.length() - 2);
+
+                System.out.println("Available formats: " + sb.toString());
+                return;
+            }
+
+            // list available profilers?
+            if (cmdOptions.shouldListProfilers()) {
+                StringBuilder sb = new StringBuilder();
+                for (String s : ProfilerFactory.getAvailableProfilers()) {
+                    if (ProfilerFactory.isSupported(s)) {
+                        sb.append(String.format("%10s: %s\n", s, ProfilerFactory.getDescription(s)));
                     }
-                    sb.setLength(sb.length() - 2);
-
-                    System.out.println("Available formats: " + sb.toString());
-                    return;
+                }
+                if (!sb.toString().isEmpty()) {
+                    System.out.println("Supported profilers:\n" + sb.toString());
                 }
 
-                // list available profilers?
-                if (cmdOptions.shouldListProfilers()) {
-                    StringBuilder sb = new StringBuilder();
-                    for (String s : ProfilerFactory.getAvailableProfilers()) {
-                        if (ProfilerFactory.isSupported(s)) {
-                            sb.append(String.format("%10s: %s\n", s, ProfilerFactory.getDescription(s)));
-                        }
+                sb = new StringBuilder();
+                for (String s : ProfilerFactory.getAvailableProfilers()) {
+                    if (!ProfilerFactory.isSupported(s)) {
+                        sb.append(String.format("%10s: %s\n", s, ProfilerFactory.getDescription(s)));
                     }
-                    if (!sb.toString().isEmpty()) {
-                        System.out.println("Supported profilers:\n" + sb.toString());
-                    }
-
-                    sb = new StringBuilder();
-                    for (String s : ProfilerFactory.getAvailableProfilers()) {
-                        if (!ProfilerFactory.isSupported(s)) {
-                            sb.append(String.format("%10s: %s\n", s, ProfilerFactory.getDescription(s)));
-                        }
-                    }
-
-                    if (!sb.toString().isEmpty()) {
-                        System.out.println("Unsupported profilers:\n" + sb.toString());
-                    }
-                    return;
                 }
 
-                if (cmdOptions.shouldHelp()) {
-                    cmdOptions.printUsage("Displaying help");
-                    return;
+                if (!sb.toString().isEmpty()) {
+                    System.out.println("Unsupported profilers:\n" + sb.toString());
                 }
+                return;
+            }
 
-                Runner runner = new Runner(cmdOptions);
-                runner.run(MicroBenchmarkList.defaultList());
-            } catch (CmdLineException ex) {
-                cmdOptions.printUsage(ex.getMessage());
-            } catch (RunnerException e) {
-                cmdOptions.printUsage(e.getMessage());
+            if (cmdOptions.shouldHelp()) {
+                cmdOptions.printUsage("Displaying help");
+                return;
             }
+
+            Runner runner = new Runner(cmdOptions);
+            runner.run(MicroBenchmarkList.defaultList());
+        } catch (CmdLineException ex) {
+            cmdOptions.printUsage(ex.getMessage());
+        } catch (RunnerException e) {
+            cmdOptions.printUsage(e.getMessage());
         }
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Fri Aug 16 18:12:35 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Fri Aug 16 18:39:06 2013 +0400
@@ -130,18 +130,9 @@
 
     /** Main entry point */
     public void run(MicroBenchmarkList list) throws RunnerException {
-        Set<BenchmarkRecord> benchmarks;
+        Set<BenchmarkRecord> benchmarks = list.find(out, options.getRegexps(), options.getExcludes());
 
-        // get a list of benchmarks
-        if (options.getRegexps().isEmpty()) {
-            out.println("No regexp to match against benchmarks was given. Use -h for help or \".*\" for every benchmark.");
-            out.flush();
-            benchmarks = Collections.emptySet();
-        } else {
-            benchmarks = list.find(out, options.getRegexps(), options.getExcludes());
-        }
-
-        if (benchmarks.isEmpty() && !options.getRegexps().isEmpty()) {
+        if (benchmarks.isEmpty()) {
             out.println("No matching benchmarks. Miss-spelled regexp? Use -v for verbose output.");
             out.flush();
         }
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/HarnessOptions.java	Fri Aug 16 18:12:35 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/HarnessOptions.java	Fri Aug 16 18:39:06 2013 +0400
@@ -132,7 +132,7 @@
      */
     public void printUsage(String message) {
         System.err.println(message);
-        System.err.println("Usage: [options] <benchmark regexp> <benchmark regexp>");
+        System.err.println("Usage: [options] [benchmark regexp]*");
         parser.printUsage(System.err);
     }
 
@@ -260,7 +260,12 @@
      * @return the value
      */
     public List<String> getRegexps() {
-        return regexps;
+        if (!regexps.isEmpty()) {
+            return regexps;
+        } else {
+            // assume user requested all benchmarks
+            return Collections.singletonList(".*");
+        }
     }
 
     /**
--- a/jmh-core/src/test/java/org/openjdk/jmh/TestMain.java	Fri Aug 16 18:12:35 2013 +0400
+++ b/jmh-core/src/test/java/org/openjdk/jmh/TestMain.java	Fri Aug 16 18:39:06 2013 +0400
@@ -54,21 +54,6 @@
         baos.close();
     }
 
-
-    @Test
-    public void testNoArgs() throws Exception {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        PrintStream tmp = System.err;
-
-        System.setErr(new PrintStream(baos));
-        Main.main(new String[] {});
-        System.setErr(tmp);
-
-        String s = baos.toString();
-        assertTrue(s, s.contains("Usage: [options]"));
-        baos.close();
-    }
-
     @Test
     public void testHelp() throws Exception {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();