1 /* 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 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; 26 27 import org.openjdk.jmh.runner.*; 28 import org.openjdk.jmh.runner.options.CommandLineOptionException; 29 import org.openjdk.jmh.runner.options.CommandLineOptions; 30 import org.openjdk.jmh.runner.options.VerboseMode; 31 32 import java.io.IOException; 33 34 /** 35 * Main program entry point 36 */ 37 public class Main { 38 39 public static void main(String[] argv) throws RunnerException, IOException { 40 try { 41 CommandLineOptions cmdOptions = new CommandLineOptions(argv); 42 43 Runner runner = new Runner(cmdOptions); 44 45 if (cmdOptions.shouldHelp()) { 46 cmdOptions.showHelp(); 47 return; 48 } 49 50 if (cmdOptions.shouldList()) { 51 runner.list(); 52 return; 53 } 54 55 if (cmdOptions.shouldListProfilers()) { 56 cmdOptions.listProfilers(); 57 return; 58 } 59 60 if (cmdOptions.shouldListResultFormats()) { 61 cmdOptions.listResultFormats(); 62 return; 63 } 64 65 try { 66 runner.run(); 67 } catch (NoBenchmarksException e) { 68 System.err.println("No matching benchmarks. Miss-spelled regexp?"); 69 70 if (cmdOptions.verbosity().orElse(Defaults.VERBOSITY) != VerboseMode.EXTRA) { 71 System.err.println("Use " + VerboseMode.EXTRA + " verbose mode to debug the pattern matching."); 72 } else { 73 runner.list(); 74 } 75 System.exit(1); 76 } catch (ProfilersFailedException e) { 77 // This is not exactly an error, set non-zero exit code 78 System.err.println(e.getMessage()); 79 System.exit(1); 80 } catch (RunnerException e) { 81 System.err.print("ERROR: "); 82 e.printStackTrace(System.err); 83 System.exit(1); 84 } 85 86 } catch (CommandLineOptionException e) { 87 System.err.println("Error parsing command line:"); 88 System.err.println(" " + e.getMessage()); 89 System.exit(1); 90 } 91 } 92 93 }