001 package jp.osdl.jbento2.analyzer;
002
003 import java.util.Iterator;
004 import org.apache.commons.cli.*;
005
006 public class GCAnalyzerCli {
007
008 public static void main(String[] args) throws Exception {
009 Options options = new Options();
010 options.addOption(OptionBuilder.withArgName("source file").hasArg()
011 .withDescription("source file.").withLongOpt("source").create(
012 "f"));
013 options.addOption(OptionBuilder.withArgName("dest file").hasArg()
014 .withDescription("dest file.").withLongOpt("dest").create("d"));
015 options.addOption(OptionBuilder.withArgName("start time").hasArg()
016 .withDescription("start time[HH:mm:ss]").withLongOpt("start")
017 .create("s"));
018 options.addOption("h", "help", false, "display help");
019
020 options.addOption(OptionBuilder.withArgName("skip time").hasArg()
021 .withDescription("skip time[sec]").withLongOpt("skip")
022 .create("k"));
023
024 options.addOption(OptionBuilder.withArgName("mean time").hasArg()
025 .withDescription("mean time[sec]").withLongOpt("mean")
026 .create("m"));
027
028 CommandLineParser parser = new PosixParser();
029 CommandLine line = null;
030 try {
031 line = parser.parse(options, args);
032 } catch (ParseException ex) {
033 throw ex;
034 }
035
036 if (line.hasOption("h")
037 || (line.getOptions().length == 0 && line.getArgs().length == 0)) {
038 HelpFormatter formatter = new HelpFormatter();
039 formatter.printHelp("GCAnalyzerCli", options, true);
040 return;
041 }
042
043 GCAnalyzer analyzer = new GCAnalyzer();
044
045 for (Iterator it = line.iterator(); it.hasNext();) {
046 Option o = (Option) it.next();
047 String longOpt = o.getLongOpt();
048 if (longOpt.equals("source")) {
049 analyzer.setSrc(o.getValue());
050 } else if (longOpt.equals("dest")) {
051 analyzer.setDest(o.getValue());
052 } else if (longOpt.equals("start")) {
053 analyzer.setStartTime(o.getValue());
054 } else if (longOpt.equals("skip")) {
055 analyzer.setRampUpMillis(Long.parseLong(o.getValue()));
056 } else if (longOpt.equals("mean")) {
057 analyzer.setDurationMillis(Long.parseLong(o.getValue()));
058 }
059 }
060
061 if (analyzer.getSrc() == null) {
062 if (line.getArgs().length < 1) {
063 throw new MissingOptionException("source does not specified.");
064 } else {
065 analyzer.setSrc(line.getArgs()[0]);
066 }
067 }
068
069 analyzer.analyze();
070 }
071 }