Example usage for org.apache.commons.collections15.map ListOrderedMap ListOrderedMap

List of usage examples for org.apache.commons.collections15.map ListOrderedMap ListOrderedMap

Introduction

In this page you can find the example usage for org.apache.commons.collections15.map ListOrderedMap ListOrderedMap.

Prototype

public ListOrderedMap() 

Source Link

Document

Constructs a new empty ListOrderedMap that decorates a HashMap.

Usage

From source file:lu.lippmann.cdb.common.gui.MultiPanel.java

public static final void main(String[] args) {
    int w = 1024, h = 768;

    JPanel panel1 = new JPanel();
    panel1.setToolTipText("Panel 1");
    JPanel panel2 = new JPanel();
    panel2.setToolTipText("Panel 2");
    JPanel panel3 = new JPanel();
    panel3.setToolTipText("Panel 3");
    JPanel panel4 = new JPanel();
    panel4.setToolTipText("Panel 4");
    JPanel panel5 = new JPanel();
    panel5.setToolTipText("Panel 5");

    final ListOrderedMap<JComponent, Integer> mapPanels = new ListOrderedMap<JComponent, Integer>();

    //add in increasing order or in the order you want to maintain ...
    mapPanels.put(panel4, 5);//www .  j ava 2  s  .co  m
    mapPanels.put(panel5, 5);
    mapPanels.put(panel3, 10);
    mapPanels.put(panel1, 30);
    mapPanels.put(panel2, 50);

    MultiPanel mp = new MultiPanel(mapPanels, w, h, false);
    JFrame f = new JFrame("MultiPanel test");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(w, h);
    f.getContentPane().add(mp);
    f.setVisible(true);
}

From source file:edu.brown.benchmark.seats.util.GenerateHistograms.java

public static void main(String[] vargs) throws Exception {
    ArgumentsParser args = ArgumentsParser.load(vargs);

    File csv_path = new File(args.getOptParam(0));
    File output_path = new File(args.getOptParam(1));

    GenerateHistograms gh = GenerateHistograms.generate(csv_path);

    Map<String, Object> m = new ListOrderedMap<String, Object>();
    m.put("Airport Codes", gh.flights_per_airport.size());
    m.put("Airlines", gh.flights_per_airline.getValueCount());
    m.put("Departure Times", gh.flights_per_time.getValueCount());
    LOG.info(StringUtil.formatMaps(m));/*from w w w  .  j av a 2  s.c  om*/

    System.err.println(StringUtil.join("\n", gh.flights_per_airport.keySet()));

    Map<String, Histogram<?>> histograms = new HashMap<String, Histogram<?>>();
    histograms.put(SEATSConstants.HISTOGRAM_FLIGHTS_PER_DEPART_TIMES, gh.flights_per_time);
    // histograms.put(SEATSConstants.HISTOGRAM_FLIGHTS_PER_AIRLINE, gh.flights_per_airline);
    histograms.put(SEATSConstants.HISTOGRAM_FLIGHTS_PER_AIRPORT,
            SEATSHistogramUtil.collapseAirportFlights(gh.flights_per_airport));

    for (Entry<String, Histogram<?>> e : histograms.entrySet()) {
        File output_file = new File(output_path.getAbsolutePath() + "/" + e.getKey() + ".histogram");
        LOG.info(String.format("Writing out %s data to '%s' [samples=%d, values=%d]", e.getKey(), output_file,
                e.getValue().getSampleCount(), e.getValue().getValueCount()));
        e.getValue().save(output_file);
    } // FOR
}

From source file:edu.brown.benchmark.seats.util.GenerateHistograms.java

public static GenerateHistograms generate(File input) throws Exception {
    GenerateHistograms gh = new GenerateHistograms();

    final ListOrderedMap<String, Integer> columns_xref = new ListOrderedMap<String, Integer>();
    CSVReader reader = new CSVReader(FileUtil.getReader(input));
    String row[] = null;//  w w w. j a  v a  2 s  .c o m
    boolean first = true;
    while ((row = reader.readNext()) != null) {
        if (first) {
            for (int i = 0; i < row.length; i++) {
                columns_xref.put(row[i].toUpperCase(), i);
            } // FOR
            first = false;
            continue;
        }
        if (row[0].equalsIgnoreCase("Year"))
            continue;

        String airline_code = row[columns_xref.get("UNIQUECARRIER")];
        String depart_airport_code = row[columns_xref.get("ORIGIN")];
        String arrival_airport_code = row[columns_xref.get("DEST")];
        String depart_time = row[columns_xref.get("CRSDEPTIME")];

        // Flights Per Airline
        gh.flights_per_airline.put(airline_code);

        // Flights Per Time
        // Convert the time into "HH:MM" and round to the nearest 15 minutes
        int hour = Integer.parseInt(depart_time.substring(0, 2));
        int minute = Integer.parseInt(depart_time.substring(2, 4));
        minute = (minute / 15) * 15;
        gh.flights_per_time.put(String.format("%02d:%02d", hour, minute));

        // Flights Per Airport
        // DepartAirport -> Histogram<ArrivalAirport>
        ObjectHistogram<String> h = gh.flights_per_airport.get(depart_airport_code);
        if (h == null) {
            h = new ObjectHistogram<String>();
            gh.flights_per_airport.put(depart_airport_code, h);
        }
        h.put(arrival_airport_code);
    } // WHILE
    reader.close();
    return (gh);
}

From source file:edu.brown.benchmark.ResultsPrinter.java

@Override
public String formatFinalResults(BenchmarkResults results) {
    StringBuilder sb = new StringBuilder();
    FinalResult fr = new FinalResult(results);

    final int width = 100;
    sb.append(String.format("\n%s\n", StringUtil.header("BENCHMARK RESULTS", "=", width)));

    StringBuilder inner = new StringBuilder();
    inner.append(String.format(RESULT_FORMAT + " txn/s", fr.getTotalTxnPerSecond())).append(" [")
            .append(String.format("min:" + RESULT_FORMAT, fr.getMinTxnPerSecond())).append(" / ")
            .append(String.format("max:" + RESULT_FORMAT, fr.getMaxTxnPerSecond())).append(" / ")
            .append(String.format("stddev:" + RESULT_FORMAT, fr.getStandardDeviationTxnPerSecond()))
            .append("]\n\n");

    Map<String, Object> m = new ListOrderedMap<String, Object>();
    m.put("Execution Time", String.format("%d ms", fr.getDuration()));
    m.put("Total Transactions", fr.getTotalTxnCount());
    m.put("Throughput", inner.toString());

    sb.append(StringUtil.formatMaps(m));

    Collection<String> txnNames = fr.getTransactionNames();
    Collection<String> clientNames = fr.getClientNames();
    int num_rows = txnNames.size() + (this.output_clients ? clientNames.size() + 1 : 0);
    Object rows[][] = new String[num_rows][COL_FORMATS.length];
    int row_idx = 0;

    for (String txnName : txnNames) {
        EntityResult er = fr.getTransactionResult(txnName);
        assert (er != null);
        int col_idx = 0;
        rows[row_idx][col_idx++] = String.format(COL_FORMATS[col_idx - 1], txnName);
        rows[row_idx][col_idx++] = String.format(COL_FORMATS[col_idx - 1], er.getTxnCount());
        rows[row_idx][col_idx++] = String.format(COL_FORMATS[col_idx - 1], er.getTxnPercentage());
        rows[row_idx][col_idx++] = String.format(COL_FORMATS[col_idx - 1], er.getTxnPerMilli());
        rows[row_idx][col_idx++] = String.format(COL_FORMATS[col_idx - 1], er.getTxnPerSecond());
        row_idx++;/*from   ww w .jav  a2 s .  c o  m*/
    } // FOR

    if (output_clients) {
        rows[row_idx][0] = "\nBreakdown by client:";
        for (int i = 1; i < COL_FORMATS.length; i++) {
            rows[row_idx][i] = "";
        } // FOR
        row_idx++;

        for (String clientName : clientNames) {
            EntityResult er = fr.getClientResult(clientName);
            assert (er != null);
            int col_idx = 0;
            rows[row_idx][col_idx++] = String.format(COL_FORMATS[col_idx - 1], clientName);
            rows[row_idx][col_idx++] = String.format(COL_FORMATS[col_idx - 1], er.getTxnCount());
            rows[row_idx][col_idx++] = String.format(COL_FORMATS[col_idx - 1], er.getTxnPercentage());
            rows[row_idx][col_idx++] = String.format(COL_FORMATS[col_idx - 1], er.getTxnPerMilli());
            rows[row_idx][col_idx++] = String.format(COL_FORMATS[col_idx - 1], er.getTxnPerSecond());
            row_idx++;
        } // FOR
    }
    sb.append(TableUtil.table(rows));
    sb.append(String.format("\n%s\n", StringUtil.repeat("=", width)));

    if (output_basepartitions) {
        sb.append("Transaction Base Partitions:\n");
        Histogram<Integer> h = results.getBasePartitions();
        Map<Integer, String> labels = new HashMap<Integer, String>();
        for (Integer p : h.values()) {
            labels.put(p, String.format("Partition %02d", p));
        } // FOR
        h.setDebugLabels(labels);
        sb.append(h.toString((int) (width * 0.75)));
        sb.append(String.format("\n%s\n", StringUtil.repeat("=", width)));
    }

    return (sb.toString());
}

From source file:com.oltpbenchmark.DBWorkload.java

/**
 * @param args/*from  ww  w.  ja  v  a 2 s . c o  m*/
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    // Initialize log4j
    String log4jPath = System.getProperty("log4j.configuration");
    if (log4jPath != null) {
        org.apache.log4j.PropertyConfigurator.configure(log4jPath);
    } else {
        throw new RuntimeException("Missing log4j.properties file");
    }

    // create the command line parser
    CommandLineParser parser = new PosixParser();
    XMLConfiguration pluginConfig = null;
    try {
        pluginConfig = new XMLConfiguration("config/plugin.xml");
    } catch (ConfigurationException e1) {
        LOG.info("Plugin configuration file config/plugin.xml is missing");
        e1.printStackTrace();
    }
    pluginConfig.setExpressionEngine(new XPathExpressionEngine());
    Options options = new Options();
    options.addOption("b", "bench", true,
            "[required] Benchmark class. Currently supported: " + pluginConfig.getList("/plugin//@name"));
    options.addOption("c", "config", true, "[required] Workload configuration file");
    options.addOption(null, "create", true, "Initialize the database for this benchmark");
    options.addOption(null, "clear", true, "Clear all records in the database for this benchmark");
    options.addOption(null, "load", true, "Load data using the benchmark's data loader");
    options.addOption(null, "execute", true, "Execute the benchmark workload");
    options.addOption(null, "runscript", true, "Run an SQL script");
    options.addOption(null, "upload", true, "Upload the result");

    options.addOption("v", "verbose", false, "Display Messages");
    options.addOption("h", "help", false, "Print this help");
    options.addOption("s", "sample", true, "Sampling window");
    options.addOption("ss", false, "Verbose Sampling per Transaction");
    options.addOption("o", "output", true, "Output file (default System.out)");
    options.addOption("d", "directory", true,
            "Base directory for the result files, default is current directory");
    options.addOption("t", "timestamp", false,
            "Each result file is prepended with a timestamp for the beginning of the experiment");
    options.addOption(null, "histograms", false, "Print txn histograms");
    options.addOption(null, "dialects-export", true, "Export benchmark SQL to a dialects file");

    // parse the command line arguments
    CommandLine argsLine = parser.parse(options, args);
    if (argsLine.hasOption("h")) {
        printUsage(options);
        return;
    } else if (argsLine.hasOption("c") == false) {
        LOG.error("Missing Configuration file");
        printUsage(options);
        return;
    } else if (argsLine.hasOption("b") == false) {
        LOG.fatal("Missing Benchmark Class to load");
        printUsage(options);
        return;
    }

    // If an output directory is used, store the information
    String outputDirectory = "";
    if (argsLine.hasOption("d")) {
        outputDirectory = argsLine.getOptionValue("d");
    }

    String timestampValue = "";
    if (argsLine.hasOption("t")) {
        timestampValue = String.valueOf(TimeUtil.getCurrentTime().getTime()) + "_";
    }

    //       -------------------------------------------------------------------
    //        GET PLUGIN LIST
    //       -------------------------------------------------------------------

    String plugins = argsLine.getOptionValue("b");

    String[] pluginList = plugins.split(",");
    List<BenchmarkModule> benchList = new ArrayList<BenchmarkModule>();

    // Use this list for filtering of the output
    List<TransactionType> activeTXTypes = new ArrayList<TransactionType>();

    String configFile = argsLine.getOptionValue("c");
    XMLConfiguration xmlConfig = new XMLConfiguration(configFile);
    xmlConfig.setExpressionEngine(new XPathExpressionEngine());
    int lastTxnId = 0;

    for (String plugin : pluginList) {

        // ----------------------------------------------------------------
        // WORKLOAD CONFIGURATION
        // ----------------------------------------------------------------

        String pluginTest = "";

        pluginTest = "[@bench='" + plugin + "']";

        WorkloadConfiguration wrkld = new WorkloadConfiguration();
        wrkld.setBenchmarkName(plugin);
        wrkld.setXmlConfig(xmlConfig);
        wrkld.setDBType(DatabaseType.get(xmlConfig.getString("dbtype")));
        wrkld.setDBDriver(xmlConfig.getString("driver"));
        wrkld.setDBConnection(xmlConfig.getString("DBUrl"));
        wrkld.setDBName(xmlConfig.getString("DBName"));
        wrkld.setDBUsername(xmlConfig.getString("username"));
        wrkld.setDBPassword(xmlConfig.getString("password"));
        int terminals = xmlConfig.getInt("terminals[not(@bench)]", 0);
        terminals = xmlConfig.getInt("terminals" + pluginTest, terminals);
        wrkld.setTerminals(terminals);
        wrkld.setIsolationMode(xmlConfig.getString("isolation", "TRANSACTION_SERIALIZABLE"));
        wrkld.setScaleFactor(xmlConfig.getDouble("scalefactor", 1.0));
        wrkld.setRecordAbortMessages(xmlConfig.getBoolean("recordabortmessages", false));

        int size = xmlConfig.configurationsAt("/works/work").size();
        for (int i = 1; i < size + 1; i++) {
            SubnodeConfiguration work = xmlConfig.configurationAt("works/work[" + i + "]");
            List<String> weight_strings;

            // use a workaround if there multiple workloads or single
            // attributed workload
            if (pluginList.length > 1 || work.containsKey("weights[@bench]")) {
                weight_strings = get_weights(plugin, work);
            } else {
                weight_strings = work.getList("weights[not(@bench)]");
            }
            int rate = 1;
            boolean rateLimited = true;
            boolean disabled = false;

            // can be "disabled", "unlimited" or a number
            String rate_string;
            rate_string = work.getString("rate[not(@bench)]", "");
            rate_string = work.getString("rate" + pluginTest, rate_string);
            if (rate_string.equals(RATE_DISABLED)) {
                disabled = true;
            } else if (rate_string.equals(RATE_UNLIMITED)) {
                rateLimited = false;
            } else if (rate_string.isEmpty()) {
                LOG.fatal(String.format("Please specify the rate for phase %d and workload %s", i, plugin));
                System.exit(-1);
            } else {
                try {
                    rate = Integer.parseInt(rate_string);
                    if (rate < 1) {
                        LOG.fatal("Rate limit must be at least 1. Use unlimited or disabled values instead.");
                        System.exit(-1);
                    }
                } catch (NumberFormatException e) {
                    LOG.fatal(String.format("Rate string must be '%s', '%s' or a number", RATE_DISABLED,
                            RATE_UNLIMITED));
                    System.exit(-1);
                }
            }
            Phase.Arrival arrival = Phase.Arrival.REGULAR;
            String arrive = work.getString("@arrival", "regular");
            if (arrive.toUpperCase().equals("POISSON"))
                arrival = Phase.Arrival.POISSON;

            int activeTerminals;
            activeTerminals = work.getInt("active_terminals[not(@bench)]", terminals);
            activeTerminals = work.getInt("active_terminals" + pluginTest, activeTerminals);
            if (activeTerminals > terminals) {
                System.out.println("Configuration error in work " + i + ": number of active terminals" + ""
                        + "is bigger than the total number of terminals");
                System.exit(-1);
            }
            wrkld.addWork(work.getInt("/time"), rate, weight_strings, rateLimited, disabled, activeTerminals,
                    arrival);
        } // FOR

        int numTxnTypes = xmlConfig.configurationsAt("transactiontypes" + pluginTest + "/transactiontype")
                .size();
        if (numTxnTypes == 0 && pluginList.length == 1) {
            //if it is a single workload run, <transactiontypes /> w/o attribute is used
            pluginTest = "[not(@bench)]";
            numTxnTypes = xmlConfig.configurationsAt("transactiontypes" + pluginTest + "/transactiontype")
                    .size();
        }
        wrkld.setNumTxnTypes(numTxnTypes);

        // CHECKING INPUT PHASES
        int j = 0;
        for (Phase p : wrkld.getAllPhases()) {
            j++;
            if (p.getWeightCount() != wrkld.getNumTxnTypes()) {
                LOG.fatal(String.format(
                        "Configuration files is inconsistent, phase %d contains %d weights but you defined %d transaction types",
                        j, p.getWeightCount(), wrkld.getNumTxnTypes()));
                System.exit(-1);
            }
        } // FOR

        // Generate the dialect map
        wrkld.init();

        assert (wrkld.getNumTxnTypes() >= 0);
        assert (xmlConfig != null);

        // ----------------------------------------------------------------
        // BENCHMARK MODULE
        // ----------------------------------------------------------------

        String classname = pluginConfig.getString("/plugin[@name='" + plugin + "']");

        if (classname == null) {
            throw new ParseException("Plugin " + plugin + " is undefined in config/plugin.xml");
        }
        BenchmarkModule bench = ClassUtil.newInstance(classname, new Object[] { wrkld },
                new Class<?>[] { WorkloadConfiguration.class });
        assert (benchList.get(0) != null);

        Map<String, Object> initDebug = new ListOrderedMap<String, Object>();
        initDebug.put("Benchmark", String.format("%s {%s}", plugin.toUpperCase(), classname));
        initDebug.put("Configuration", configFile);
        initDebug.put("Type", wrkld.getDBType());
        initDebug.put("Driver", wrkld.getDBDriver());
        initDebug.put("URL", wrkld.getDBConnection());
        initDebug.put("Isolation", xmlConfig.getString("isolation", "TRANSACTION_SERIALIZABLE [DEFAULT]"));
        initDebug.put("Scale Factor", wrkld.getScaleFactor());
        INIT_LOG.info(SINGLE_LINE + "\n\n" + StringUtil.formatMaps(initDebug));
        INIT_LOG.info(SINGLE_LINE);

        // Load TransactionTypes
        List<TransactionType> ttypes = new ArrayList<TransactionType>();

        // Always add an INVALID type for Carlo
        ttypes.add(TransactionType.INVALID);
        int txnIdOffset = lastTxnId;
        for (int i = 1; i < wrkld.getNumTxnTypes() + 1; i++) {
            String key = "transactiontypes" + pluginTest + "/transactiontype[" + i + "]";
            String txnName = xmlConfig.getString(key + "/name");
            int txnId = i + 1;
            if (xmlConfig.containsKey(key + "/id")) {
                txnId = xmlConfig.getInt(key + "/id");
            }
            TransactionType tmpType = bench.initTransactionType(txnName, txnId + txnIdOffset);
            // Keep a reference for filtering
            activeTXTypes.add(tmpType);
            // Add a reference for the active TTypes in this benchmark
            ttypes.add(tmpType);
            lastTxnId = i;
        } // FOR
        TransactionTypes tt = new TransactionTypes(ttypes);
        wrkld.setTransTypes(tt);
        LOG.debug("Using the following transaction types: " + tt);

        benchList.add(bench);
    }

    // Export StatementDialects
    if (isBooleanOptionSet(argsLine, "dialects-export")) {
        BenchmarkModule bench = benchList.get(0);
        if (bench.getStatementDialects() != null) {
            LOG.info("Exporting StatementDialects for " + bench);
            String xml = bench.getStatementDialects().export(bench.getWorkloadConfiguration().getDBType(),
                    bench.getProcedures().values());
            System.out.println(xml);
            System.exit(0);
        }
        throw new RuntimeException("No StatementDialects is available for " + bench);
    }

    @Deprecated
    boolean verbose = argsLine.hasOption("v");

    // Create the Benchmark's Database
    if (isBooleanOptionSet(argsLine, "create")) {
        for (BenchmarkModule benchmark : benchList) {
            CREATE_LOG.info("Creating new " + benchmark.getBenchmarkName().toUpperCase() + " database...");
            runCreator(benchmark, verbose);
            CREATE_LOG.info("Finished!");
            CREATE_LOG.info(SINGLE_LINE);
        }
    } else if (CREATE_LOG.isDebugEnabled()) {
        CREATE_LOG.debug("Skipping creating benchmark database tables");
        CREATE_LOG.info(SINGLE_LINE);
    }

    // Clear the Benchmark's Database
    if (isBooleanOptionSet(argsLine, "clear")) {
        for (BenchmarkModule benchmark : benchList) {
            CREATE_LOG.info("Resetting " + benchmark.getBenchmarkName().toUpperCase() + " database...");
            benchmark.clearDatabase();
            CREATE_LOG.info("Finished!");
            CREATE_LOG.info(SINGLE_LINE);
        }
    } else if (CREATE_LOG.isDebugEnabled()) {
        CREATE_LOG.debug("Skipping creating benchmark database tables");
        CREATE_LOG.info(SINGLE_LINE);
    }

    // Execute Loader
    if (isBooleanOptionSet(argsLine, "load")) {
        for (BenchmarkModule benchmark : benchList) {
            LOAD_LOG.info("Loading data into " + benchmark.getBenchmarkName().toUpperCase() + " database...");
            runLoader(benchmark, verbose);
            LOAD_LOG.info("Finished!");
            LOAD_LOG.info(SINGLE_LINE);
        }
    } else if (LOAD_LOG.isDebugEnabled()) {
        LOAD_LOG.debug("Skipping loading benchmark database records");
        LOAD_LOG.info(SINGLE_LINE);
    }

    // Execute a Script
    if (argsLine.hasOption("runscript")) {
        for (BenchmarkModule benchmark : benchList) {
            String script = argsLine.getOptionValue("runscript");
            SCRIPT_LOG.info("Running a SQL script: " + script);
            runScript(benchmark, script);
            SCRIPT_LOG.info("Finished!");
            SCRIPT_LOG.info(SINGLE_LINE);
        }
    }

    // Execute Workload
    if (isBooleanOptionSet(argsLine, "execute")) {
        // Bombs away!
        Results r = null;
        try {
            r = runWorkload(benchList, verbose);
        } catch (Throwable ex) {
            LOG.error("Unexpected error when running benchmarks.", ex);
            System.exit(1);
        }
        assert (r != null);

        PrintStream ps = System.out;
        PrintStream rs = System.out;
        ResultUploader ru = new ResultUploader(r, xmlConfig, argsLine);

        if (argsLine.hasOption("o")) {
            // Check if directory needs to be created
            if (outputDirectory.length() > 0) {
                FileUtil.makeDirIfNotExists(outputDirectory.split("/"));
            }

            // Build the complex path
            String baseFile = timestampValue + argsLine.getOptionValue("o");

            // Increment the filename for new results
            String nextName = FileUtil.getNextFilename(FileUtil.joinPath(outputDirectory, baseFile + ".res"));
            ps = new PrintStream(new File(nextName));
            EXEC_LOG.info("Output into file: " + nextName);

            nextName = FileUtil.getNextFilename(FileUtil.joinPath(outputDirectory, baseFile + ".raw"));
            rs = new PrintStream(new File(nextName));
            EXEC_LOG.info("Output Raw data into file: " + nextName);

            nextName = FileUtil.getNextFilename(FileUtil.joinPath(outputDirectory, baseFile + ".summary"));
            PrintStream ss = new PrintStream(new File(nextName));
            EXEC_LOG.info("Output summary data into file: " + nextName);
            ru.writeSummary(ss);
            ss.close();

            nextName = FileUtil.getNextFilename(FileUtil.joinPath(outputDirectory, baseFile + ".db.cnf"));
            ss = new PrintStream(new File(nextName));
            EXEC_LOG.info("Output db config into file: " + nextName);
            ru.writeDBParameters(ss);
            ss.close();

            nextName = FileUtil.getNextFilename(FileUtil.joinPath(outputDirectory, baseFile + ".ben.cnf"));
            ss = new PrintStream(new File(nextName));
            EXEC_LOG.info("Output benchmark config into file: " + nextName);
            ru.writeBenchmarkConf(ss);
            ss.close();
        } else if (EXEC_LOG.isDebugEnabled()) {
            EXEC_LOG.debug("No output file specified");
        }

        if (argsLine.hasOption("s")) {
            int windowSize = Integer.parseInt(argsLine.getOptionValue("s"));
            EXEC_LOG.info("Grouped into Buckets of " + windowSize + " seconds");
            r.writeCSV(windowSize, ps);

            if (isBooleanOptionSet(argsLine, "upload")) {
                ru.uploadResult();
            }

            // Allow more detailed reporting by transaction to make it easier to check
            if (argsLine.hasOption("ss")) {

                for (TransactionType t : activeTXTypes) {
                    PrintStream ts = ps;

                    if (ts != System.out) {
                        // Get the actual filename for the output
                        String baseFile = timestampValue + argsLine.getOptionValue("o") + "_" + t.getName();
                        String prepended = outputDirectory + timestampValue;
                        String nextName = FileUtil
                                .getNextFilename(FileUtil.joinPath(outputDirectory, baseFile + ".res"));
                        ts = new PrintStream(new File(nextName));
                        r.writeCSV(windowSize, ts, t);
                        ts.close();
                    }
                }
            }
        } else if (EXEC_LOG.isDebugEnabled()) {
            EXEC_LOG.warn("No bucket size specified");
        }
        if (argsLine.hasOption("histograms")) {
            EXEC_LOG.info(SINGLE_LINE);
            EXEC_LOG.info("Completed Transactions:\n" + r.getTransactionSuccessHistogram() + "\n");
            EXEC_LOG.info("Aborted Transactions:\n" + r.getTransactionAbortHistogram() + "\n");
            EXEC_LOG.info("Rejected Transactions:\n" + r.getTransactionRetryHistogram());
            EXEC_LOG.info("Unexpected Errors:\n" + r.getTransactionErrorHistogram());
            if (r.getTransactionAbortMessageHistogram().isEmpty() == false)
                EXEC_LOG.info(
                        "User Aborts:\n" + StringUtil.formatMaps(r.getTransactionAbortMessageHistogram()));
        } else if (EXEC_LOG.isDebugEnabled()) {
            EXEC_LOG.warn("No bucket size specified");
        }

        r.writeAllCSVAbsoluteTiming(rs);

        ps.close();
        rs.close();
    } else {
        EXEC_LOG.info("Skipping benchmark workload execution");
    }
}

From source file:edu.brown.statistics.AbstractStatistics.java

protected String debug(Database catalog_db, Enum<?> elements[]) {
    Map<String, Object> m = new ListOrderedMap<String, Object>();
    try {//from w w w .j  a  v a 2  s .  co m
        Class<?> statsClass = this.getClass();
        for (Enum<?> element : elements) {
            Field field = statsClass.getDeclaredField(element.toString().toLowerCase());
            Object value = field.get(this);

            if (field.getClass().isAssignableFrom(SortedMap.class)) {
                SortedMap<?, ?> orig_value = (SortedMap<?, ?>) value;
                Map<String, Object> inner_m = new ListOrderedMap<String, Object>();
                for (Object inner_key : orig_value.keySet()) {
                    Object inner_val = orig_value.get(inner_key);
                    if (inner_val instanceof AbstractStatistics<?>) {
                        inner_val = ((AbstractStatistics<?>) inner_val).debug(catalog_db);
                    }
                    inner_m.put(inner_key.toString(), inner_val);
                } // FOR
                value = StringUtil.formatMaps(inner_m);
            }
            m.put(element.toString(), value);
        } // FOR
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(1);
    }
    return (String.format("%s\n%s", this.getCatalogItem(catalog_db),
            StringUtil.prefix(StringUtil.formatMaps(m), DEBUG_SPACER)));
}

From source file:com.oltpbenchmark.benchmarks.auctionmark.util.LoaderItemInfo.java

@Override
public String toString() {
    Class<?> hints_class = this.getClass();
    ListOrderedMap<String, Object> m = new ListOrderedMap<String, Object>();
    for (Field f : hints_class.getDeclaredFields()) {
        String key = f.getName().toUpperCase();
        Object val = null;
        try {/* w  w  w . ja  va2s.  co m*/
            val = f.get(this);
        } catch (IllegalAccessException ex) {
            val = ex.getMessage();
        }
        m.put(key, val);
    } // FOR
    return (StringUtil.formatMaps(m));
}

From source file:lu.lippmann.cdb.datasetview.tabs.WeightedMapOfDecisionTreesTabView.java

/**
 * {@inheritDoc}/*from   w  ww .  j a  v a  2  s . c o  m*/
 */
@Override
public void update0(final Instances dataSet) throws Exception {
    if (this.mp != null)
        this.panel.remove(this.mp);

    if (this.cl != null)
        this.slider.removeChangeListener(cl);
    //if (this.cl!=null) this.slider.removeChangeListener(cl);

    this.cl = new ChangeListener() {
        @Override
        public void stateChanged(final ChangeEvent e) {
            if (!slider.getValueIsAdjusting()) {
                dtFactory = new J48DecisionTreeFactory(slider.getValue() / 100d, false);
                update(dataSet);
            }
        }
    };
    this.slider.addChangeListener(cl);

    final double frameWidth = this.panel.getSize().getWidth() * 0.95d;
    final double frameHeight = this.panel.getSize().getHeight() * 0.95d;

    final ListOrderedMap<JComponent, Integer> mapPanels = new ListOrderedMap<JComponent, Integer>();

    final String oldSelected;
    if (this.attrSelectionCombo.getSelectedItem() == null) {
        oldSelected = dataSet.classAttribute().name();
    } else {
        final Attribute oldAttr = dataSet.attribute(this.attrSelectionCombo.getSelectedItem().toString());
        if (oldAttr != null) {
            oldSelected = oldAttr.name();
        } else {
            oldSelected = dataSet.classAttribute().name();
        }
    }
    final int idx = dataSet.attribute(oldSelected).index();
    final Set<Object> presentValues = WekaDataStatsUtil.getNominalRepartition(dataSet, idx).keySet();
    for (final Object o : presentValues) {
        final Instances part = WekaDataProcessingUtil.filterDataSetOnNominalValue(dataSet, idx, o.toString());
        final DecisionTree dti = dtFactory.buildDecisionTree(part);

        final int ratio = 100 * part.numInstances() / dataSet.numInstances();
        final GraphView myGraph = DecisionTreeToGraphViewHelper.buildGraphView(dti, eventPublisher,
                commandDispatcher);
        myGraph.hideSharedLabel();
        myGraph.addMetaInfo("size=" + dti.getSize(), "");
        myGraph.addMetaInfo("depth=" + dti.getDepth(), "");
        myGraph.addMetaInfo("err=" + FormatterUtil.DECIMAL_FORMAT.format(100d * dti.getErrorRate()) + "%", "");

        final JButton openInEditorButton = new JButton("Edit");
        openInEditorButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                GraphUtil.importDecisionTreeInEditor(dtFactory, part, applicationContext, eventPublisher,
                        commandDispatcher);
            }
        });
        myGraph.addMetaInfoComponent(openInEditorButton);

        myGraph.fitGraphToSubPanel(frameWidth - 10 * presentValues.size(), frameHeight - 10, ratio);
        mapPanels.put((JComponent) myGraph, ratio);

    }
    this.mp = new MultiPanel(mapPanels, (int) frameWidth, (int) frameHeight,
            this.withWeightCheckBox.isSelected());

    this.panel.add(this.mp, BorderLayout.CENTER);

    if (this.attrSelectionCombo.getActionListeners().length > 0) {
        this.attrSelectionCombo.removeActionListener(attrSelectionComboListener);
    }
    if (this.withWeightCheckBox.getActionListeners().length > 0) {
        this.withWeightCheckBox.removeActionListener(attrSelectionComboListener);
    }

    this.attrSelectionCombo.removeAllItems();
    for (final Attribute attr : WekaDataStatsUtil.getNominalAttributesList(dataSet)) {
        this.attrSelectionCombo.addItem(attr.name());
    }
    this.attrSelectionCombo.setSelectedItem(oldSelected);

    this.attrSelectionComboListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            update(dataSet);
        }
    };
    this.attrSelectionCombo.addActionListener(attrSelectionComboListener);
    this.withWeightCheckBox.addActionListener(attrSelectionComboListener);

}

From source file:com.oltpbenchmark.multitenancy.MuTeBench.java

/**
 * @param args/*  ww  w  .  j  a va 2  s. c o  m*/
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    String duration = null;
    String scenarioFile = null;

    // -------------------------------------------------------------------
    // INITIALIZE LOGGING
    // -------------------------------------------------------------------
    String log4jPath = System.getProperty("log4j.configuration");
    if (log4jPath != null) {
        org.apache.log4j.PropertyConfigurator.configure(log4jPath);
    } else {
        throw new RuntimeException("Missing log4j.properties file");
    }

    // -------------------------------------------------------------------
    // PARSE COMMAND LINE PARAMETERS
    // -------------------------------------------------------------------
    CommandLineParser parser = new PosixParser();
    XMLConfiguration pluginConfig = null;
    try {
        pluginConfig = new XMLConfiguration("config/plugin.xml");
    } catch (ConfigurationException e1) {
        LOG.info("Plugin configuration file config/plugin.xml is missing");
        e1.printStackTrace();
    }
    pluginConfig.setExpressionEngine(new XPathExpressionEngine());
    Options options = new Options();
    options.addOption("s", "scenario", true, "[required] Workload scenario file");
    options.addOption("a", "analysis-buckets", true, "sampling buckets for result aggregation");
    options.addOption("r", "runtime", true,
            "maximum runtime  (no events will be started after finishing runtime)");
    options.addOption("v", "verbose", false, "Display Messages");
    options.addOption("g", "gui", false, "Show controlling GUI");
    options.addOption("h", "help", false, "Print this help");
    options.addOption("o", "output", true, "Output file (default System.out)");
    options.addOption("b", "baseline", true, "Output files of previous baseline run");
    options.addOption(null, "histograms", false, "Print txn histograms");
    options.addOption("d", "dialects-export", true, "Export benchmark SQL to a dialects file");

    // parse the command line arguments
    CommandLine argsLine = parser.parse(options, args);
    if (argsLine.hasOption("h")) {
        printUsage(options);
        return;
    } else if (!argsLine.hasOption("scenario")) {
        INIT_LOG.fatal("Missing scenario description file");
        System.exit(-1);
    } else
        scenarioFile = argsLine.getOptionValue("scenario");
    if (argsLine.hasOption("r"))
        duration = argsLine.getOptionValue("r");
    if (argsLine.hasOption("runtime"))
        duration = argsLine.getOptionValue("runtime");

    // -------------------------------------------------------------------
    // CREATE TENANT SCHEDULE
    // -------------------------------------------------------------------
    INIT_LOG.info("Create schedule");
    Schedule schedule = new Schedule(duration, scenarioFile);
    HashMap<Integer, ScheduleEvents> tenantEvents = schedule.getTenantEvents();
    ArrayList<Integer> tenantList = schedule.getTenantList();

    List<BenchmarkModule> benchList = new ArrayList<BenchmarkModule>();

    for (int tenInd = 0; tenInd < tenantList.size(); tenInd++) {
        int tenantID = tenantList.get(tenInd);
        for (int tenEvent = 0; tenEvent < tenantEvents.get(tenantID).size(); tenEvent++) {

            BenchmarkSettings benchmarkSettings = (BenchmarkSettings) tenantEvents.get(tenantID)
                    .getBenchmarkSettings(tenEvent);

            // update benchmark Settings
            benchmarkSettings.setTenantID(tenantID);

            // -------------------------------------------------------------------
            // GET PLUGIN LIST
            // -------------------------------------------------------------------
            String plugins = benchmarkSettings.getBenchmark();
            String[] pluginList = plugins.split(",");

            String configFile = benchmarkSettings.getConfigFile();
            XMLConfiguration xmlConfig = new XMLConfiguration(configFile);
            xmlConfig.setExpressionEngine(new XPathExpressionEngine());
            int lastTxnId = 0;

            for (String plugin : pluginList) {

                // ----------------------------------------------------------------
                // WORKLOAD CONFIGURATION
                // ----------------------------------------------------------------

                String pluginTest = "";

                pluginTest = "[@bench='" + plugin + "']";

                WorkloadConfiguration wrkld = new WorkloadConfiguration();
                wrkld.setTenantId(tenantID);
                wrkld.setBenchmarkName(setTenantIDinString(plugin, tenantID));
                wrkld.setXmlConfig(xmlConfig);
                wrkld.setDBType(DatabaseType.get(setTenantIDinString(xmlConfig.getString("dbtype"), tenantID)));
                wrkld.setDBDriver(setTenantIDinString(xmlConfig.getString("driver"), tenantID));
                wrkld.setDBConnection(setTenantIDinString(xmlConfig.getString("DBUrl"), tenantID));
                wrkld.setDBName(setTenantIDinString(xmlConfig.getString("DBName"), tenantID));
                wrkld.setDBUsername(setTenantIDinString(xmlConfig.getString("username"), tenantID));
                wrkld.setDBPassword(setTenantIDinString(xmlConfig.getString("password"), tenantID));
                String terminalString = setTenantIDinString(xmlConfig.getString("terminals[not(@bench)]", "0"),
                        tenantID);
                int terminals = Integer.parseInt(xmlConfig.getString("terminals" + pluginTest, terminalString));
                wrkld.setTerminals(terminals);
                int taSize = Integer.parseInt(xmlConfig.getString("taSize", "1"));
                if (taSize < 0)
                    INIT_LOG.fatal("taSize must not be negative!");
                wrkld.setTaSize(taSize);
                wrkld.setProprietaryTaSyntax(xmlConfig.getBoolean("proprietaryTaSyntax", false));
                wrkld.setIsolationMode(setTenantIDinString(
                        xmlConfig.getString("isolation", "TRANSACTION_SERIALIZABLE"), tenantID));
                wrkld.setScaleFactor(Double
                        .parseDouble(setTenantIDinString(xmlConfig.getString("scalefactor", "1.0"), tenantID)));
                wrkld.setRecordAbortMessages(xmlConfig.getBoolean("recordabortmessages", false));

                int size = xmlConfig.configurationsAt("/works/work").size();

                for (int i = 1; i < size + 1; i++) {
                    SubnodeConfiguration work = xmlConfig.configurationAt("works/work[" + i + "]");
                    List<String> weight_strings;

                    // use a workaround if there multiple workloads or
                    // single
                    // attributed workload
                    if (pluginList.length > 1 || work.containsKey("weights[@bench]")) {
                        weight_strings = get_weights(plugin, work);
                    } else {
                        weight_strings = work.getList("weights[not(@bench)]");
                    }
                    int rate = 1;
                    boolean rateLimited = true;
                    boolean disabled = false;

                    // can be "disabled", "unlimited" or a number
                    String rate_string;
                    rate_string = setTenantIDinString(work.getString("rate[not(@bench)]", ""), tenantID);
                    rate_string = setTenantIDinString(work.getString("rate" + pluginTest, rate_string),
                            tenantID);
                    if (rate_string.equals(RATE_DISABLED)) {
                        disabled = true;
                    } else if (rate_string.equals(RATE_UNLIMITED)) {
                        rateLimited = false;
                    } else if (rate_string.isEmpty()) {
                        LOG.fatal(String.format(
                                "Tenant " + tenantID + ": Please specify the rate for phase %d and workload %s",
                                i, plugin));
                        System.exit(-1);
                    } else {
                        try {
                            rate = Integer.parseInt(rate_string);
                            if (rate < 1) {
                                LOG.fatal("Tenant " + tenantID
                                        + ": Rate limit must be at least 1. Use unlimited or disabled values instead.");
                                System.exit(-1);
                            }
                        } catch (NumberFormatException e) {
                            LOG.fatal(String.format(
                                    "Tenant " + tenantID + ": Rate string must be '%s', '%s' or a number",
                                    RATE_DISABLED, RATE_UNLIMITED));
                            System.exit(-1);
                        }
                    }
                    Phase.Arrival arrival = Phase.Arrival.REGULAR;
                    String arrive = setTenantIDinString(work.getString("@arrival", "regular"), tenantID);
                    if (arrive.toUpperCase().equals("POISSON"))
                        arrival = Phase.Arrival.POISSON;

                    int activeTerminals;
                    activeTerminals = Integer.parseInt(setTenantIDinString(
                            work.getString("active_terminals[not(@bench)]", String.valueOf(terminals)),
                            tenantID));
                    activeTerminals = Integer.parseInt(setTenantIDinString(
                            work.getString("active_terminals" + pluginTest, String.valueOf(activeTerminals)),
                            tenantID));
                    if (activeTerminals > terminals) {
                        LOG.fatal("Tenant " + tenantID + ": Configuration error in work " + i
                                + ": number of active terminals" + ""
                                + "is bigger than the total number of terminals");
                        System.exit(-1);
                    }
                    wrkld.addWork(Integer.parseInt(setTenantIDinString(work.getString("/time"), tenantID)),
                            rate, weight_strings, rateLimited, disabled, activeTerminals, arrival);
                } // FOR

                int numTxnTypes = xmlConfig
                        .configurationsAt("transactiontypes" + pluginTest + "/transactiontype").size();
                if (numTxnTypes == 0 && pluginList.length == 1) {
                    // if it is a single workload run, <transactiontypes />
                    // w/o attribute is used
                    pluginTest = "[not(@bench)]";
                    numTxnTypes = xmlConfig
                            .configurationsAt("transactiontypes" + pluginTest + "/transactiontype").size();
                }
                wrkld.setNumTxnTypes(numTxnTypes);

                // CHECKING INPUT PHASES
                int j = 0;
                for (Phase p : wrkld.getAllPhases()) {
                    j++;
                    if (p.getWeightCount() != wrkld.getNumTxnTypes()) {
                        LOG.fatal(String.format("Tenant " + tenantID
                                + ": Configuration files is inconsistent, phase %d contains %d weights but you defined %d transaction types",
                                j, p.getWeightCount(), wrkld.getNumTxnTypes()));
                        System.exit(-1);
                    }
                } // FOR

                // Generate the dialect map
                wrkld.init();

                assert (wrkld.getNumTxnTypes() >= 0);
                assert (xmlConfig != null);

                // ----------------------------------------------------------------
                // BENCHMARK MODULE
                // ----------------------------------------------------------------

                String classname = pluginConfig.getString("/plugin[@name='" + plugin + "']");

                if (classname == null) {
                    throw new ParseException("Plugin " + plugin + " is undefined in config/plugin.xml");
                }
                BenchmarkModule bench = ClassUtil.newInstance(classname, new Object[] { wrkld },
                        new Class<?>[] { WorkloadConfiguration.class });
                assert (benchList.get(0) != null);

                Map<String, Object> initDebug = new ListOrderedMap<String, Object>();
                initDebug.put("Benchmark", String.format("%s {%s}", plugin.toUpperCase(), classname));
                initDebug.put("Configuration", configFile);
                initDebug.put("Type", wrkld.getDBType());
                initDebug.put("Driver", wrkld.getDBDriver());
                initDebug.put("URL", wrkld.getDBConnection());
                initDebug.put("Isolation", setTenantIDinString(
                        xmlConfig.getString("isolation", "TRANSACTION_SERIALIZABLE [DEFAULT]"), tenantID));
                initDebug.put("Scale Factor", wrkld.getScaleFactor());
                INIT_LOG.info(SINGLE_LINE + "\n\n" + StringUtil.formatMaps(initDebug));
                INIT_LOG.info(SINGLE_LINE);

                // Load TransactionTypes
                List<TransactionType> ttypes = new ArrayList<TransactionType>();

                // Always add an INVALID type for Carlo
                ttypes.add(TransactionType.INVALID);
                int txnIdOffset = lastTxnId;
                for (int i = 1; i < wrkld.getNumTxnTypes() + 1; i++) {
                    String key = "transactiontypes" + pluginTest + "/transactiontype[" + i + "]";
                    String txnName = setTenantIDinString(xmlConfig.getString(key + "/name"), tenantID);
                    int txnId = i + 1;
                    if (xmlConfig.containsKey(key + "/id")) {
                        txnId = Integer
                                .parseInt(setTenantIDinString(xmlConfig.getString(key + "/id"), tenantID));
                    }
                    ttypes.add(bench.initTransactionType(txnName, txnId + txnIdOffset));
                    lastTxnId = i;
                } // FOR
                TransactionTypes tt = new TransactionTypes(ttypes);
                wrkld.setTransTypes(tt);
                if (benchmarkSettings.getBenchmarkSlaFile() != null)
                    wrkld.setSlaFromFile(benchmarkSettings.getBenchmarkSlaFile());
                LOG.debug("Tenant " + tenantID + ": Using the following transaction types: " + tt);

                bench.setTenantOffset(tenantEvents.get(tenantID).getTime(tenEvent));
                bench.setTenantID(tenantID);
                bench.setBenchmarkSettings(benchmarkSettings);
                benchList.add(bench);
            }
        }
    }
    // create result collector
    ResultCollector rCollector = new ResultCollector(tenantList);

    // execute benchmarks in parallel
    ArrayList<Thread> benchThreads = new ArrayList<Thread>();
    for (BenchmarkModule benchmark : benchList) {
        BenchmarkExecutor benchThread = new BenchmarkExecutor(benchmark, argsLine);
        Thread t = new Thread(benchThread);
        t.start();
        benchThreads.add(t);
        benchmark.getWorkloadConfiguration().setrCollector(rCollector);
    }

    // waiting for completion of all benchmarks
    for (Thread t : benchThreads) {
        t.join();
    }

    // print statistics
    int analysisBuckets = -1;
    if (argsLine.hasOption("analysis-buckets"))
        analysisBuckets = Integer.parseInt(argsLine.getOptionValue("analysis-buckets"));
    String output = null;
    if (argsLine.hasOption("o"))
        output = argsLine.getOptionValue("o");
    String baseline = null;
    if (argsLine.hasOption("b"))
        baseline = argsLine.getOptionValue("b");

    rCollector.printStatistics(output, analysisBuckets, argsLine.hasOption("histograms"), baseline);

    // create GUI
    if (argsLine.hasOption("g") && (!rCollector.getAllResults().isEmpty())) {
        try {
            Gui gui = new Gui(Integer.parseInt(argsLine.getOptionValue("analysis-buckets", "10")), rCollector,
                    output);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.oltpbenchmark.WorkloadConfiguration.java

@Override
public String toString() {
    Class<?> confClass = this.getClass();
    Map<String, Object> m = new ListOrderedMap<String, Object>();
    for (Field f : confClass.getDeclaredFields()) {
        Object obj = null;/*from  www .j ava 2  s  .c om*/
        try {
            obj = f.get(this);
        } catch (IllegalAccessException ex) {
            throw new RuntimeException(ex);
        }
        m.put(f.getName().toUpperCase(), obj);
    } // FOR
    return StringUtil.formatMaps(m);
}