Search in sources :

Example 1 with Result

use of org.apache.tez.analyzer.Result in project tez by apache.

the class TezAnalyzerBase method printResults.

public void printResults() throws TezException {
    Result result = getResult();
    if (result instanceof CSVResult) {
        String[] headers = ((CSVResult) result).getHeaders();
        StringBuilder formatBuilder = new StringBuilder();
        int size = Math.max(MIN_COL_WIDTH, SEPARATOR_WIDTH / headers.length);
        for (int i = 0; i < headers.length; i++) {
            formatBuilder.append("%-").append(size).append("s ");
        }
        String format = formatBuilder.toString();
        StringBuilder sep = new StringBuilder();
        for (int i = 0; i < SEPARATOR_WIDTH; i++) {
            sep.append("-");
        }
        String separator = sep.toString();
        LOG.debug(separator);
        LOG.debug(String.format(format.toString(), (String[]) headers));
        LOG.debug(separator);
        Iterator<String[]> recordsIterator = ((CSVResult) result).getRecordsIterator();
        while (recordsIterator.hasNext()) {
            String line = String.format(format, (String[]) recordsIterator.next());
            LOG.debug(line);
        }
        LOG.debug(separator);
    }
}
Also used : CSVResult(org.apache.tez.analyzer.CSVResult) Result(org.apache.tez.analyzer.Result) CSVResult(org.apache.tez.analyzer.CSVResult)

Example 2 with Result

use of org.apache.tez.analyzer.Result in project tez by apache.

the class TezAnalyzerBase method run.

@Override
public int run(String[] args) throws Exception {
    // Parse downloaded contents
    CommandLine cmdLine = null;
    try {
        cmdLine = new GnuParser().parse(buildOptions(), args);
    } catch (ParseException e) {
        System.err.println("Invalid options on command line");
        printUsage();
        return -1;
    }
    saveResults = cmdLine.hasOption(SAVE_RESULTS);
    if (cmdLine.hasOption(HELP)) {
        printUsage();
        return 0;
    }
    outputDir = cmdLine.getOptionValue(OUTPUT_DIR);
    if (outputDir == null) {
        outputDir = System.getProperty("user.dir");
    }
    File file = null;
    if (cmdLine.hasOption(EVENT_FILE_NAME)) {
        file = new File(cmdLine.getOptionValue(EVENT_FILE_NAME));
    }
    String dagId = cmdLine.getOptionValue(DAG_ID);
    DagInfo dagInfo = null;
    if (file == null) {
        if (cmdLine.hasOption(FROM_SIMPLE_HISTORY)) {
            System.err.println("Event file name must be specified when using simple history");
            printUsage();
            return -2;
        }
        // using ATS - try to download directly
        String[] importArgs = { "--dagId=" + dagId, "--downloadDir=" + outputDir };
        int result = ATSImportTool.process(importArgs);
        if (result != 0) {
            System.err.println("Error downloading data from ATS");
            return -3;
        }
        // Parse ATS data and verify results
        // Parse downloaded contents
        file = new File(outputDir + Path.SEPARATOR + dagId + ".zip");
    }
    Preconditions.checkState(file != null);
    if (!cmdLine.hasOption(FROM_SIMPLE_HISTORY)) {
        ATSFileParser parser = new ATSFileParser(file);
        dagInfo = parser.getDAGData(dagId);
    } else {
        SimpleHistoryParser parser = new SimpleHistoryParser(file);
        dagInfo = parser.getDAGData(dagId);
    }
    Preconditions.checkState(dagInfo.getDagId().equals(dagId));
    analyze(dagInfo);
    Result result = getResult();
    if (saveResults && (result instanceof CSVResult)) {
        String fileName = outputDir + File.separator + this.getClass().getName() + "_" + dagInfo.getDagId() + ".csv";
        ((CSVResult) result).dumpToFile(fileName);
        LOG.info("Saved results in " + fileName);
    }
    return 0;
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) DagInfo(org.apache.tez.history.parser.datamodel.DagInfo) ATSFileParser(org.apache.tez.history.parser.ATSFileParser) SimpleHistoryParser(org.apache.tez.history.parser.SimpleHistoryParser) CSVResult(org.apache.tez.analyzer.CSVResult) GnuParser(org.apache.commons.cli.GnuParser) ParseException(org.apache.commons.cli.ParseException) File(java.io.File) Result(org.apache.tez.analyzer.Result) CSVResult(org.apache.tez.analyzer.CSVResult)

Aggregations

CSVResult (org.apache.tez.analyzer.CSVResult)2 Result (org.apache.tez.analyzer.Result)2 File (java.io.File)1 CommandLine (org.apache.commons.cli.CommandLine)1 GnuParser (org.apache.commons.cli.GnuParser)1 ParseException (org.apache.commons.cli.ParseException)1 ATSFileParser (org.apache.tez.history.parser.ATSFileParser)1 SimpleHistoryParser (org.apache.tez.history.parser.SimpleHistoryParser)1 DagInfo (org.apache.tez.history.parser.datamodel.DagInfo)1