Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 91e1acfa378435e77704a23e8dd363e84a6a4cb6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package org.eclipse.team.tests.ccvs.ui.logformatter;

/*
 * (c) Copyright IBM Corp. 2000, 2002.
 * All Rights Reserved.
 */

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;

import org.xml.sax.SAXException;

public class PrintSummaryMain {
	public static void main(String[] args) {
		Parser parser = new Parser();
		if (! parser.parse(args)) {
			System.err.println("Usage: <log file> [-out <file>] [-csv] [-raw]");
			System.err.println("  -out <file> : specify the output file, default is console");
			System.err.println("  -csv        : produce comma separated values data");
			System.err.println("  -raw        : do not merge results from successive iterations");
			return;
		}
		try {
			PrintStream ps = System.out;
			try {
				if (parser.outputFile != null) ps = new PrintStream(new BufferedOutputStream(new FileOutputStream(parser.outputFile)));
				printLog(ps, parser.logFile, parser.csv, parser.raw);
			} finally {
				if (ps != System.out) ps.close();
			}
		} catch (Exception e) {
			System.err.println("An error occurred:");
			e.printStackTrace();
			return;
		}
	}

	private static void printLog(PrintStream ps, File logFile, boolean csv, boolean raw)
		throws IOException, SAXException {
		// read and merge the log
		RootEntry root = LogEntry.readLog(logFile);
		if (! raw) {
			MergeRunsVisitor mergeVisitor = new MergeRunsVisitor(null);
			root.accept(mergeVisitor);
			root = mergeVisitor.getMergedRoot();
		}

		// format options
		StringBuffer options = new StringBuffer();
		if (raw) options.append("-raw ");

		// format log file
		if (csv) {
			DelimitedValuesWriter writer = new DelimitedValuesWriter(ps, ",", true /*quoted*/);
			// print header
			writer.printRecord(new String[] { "Log File", logFile.toString() });
			writer.printRecord(new String[] { "Generated", root.getTimestamp() });
			writer.printRecord(new String[] { "SDK Build", root.getSDKBuildId() });
			writer.endRecord();
			writer.printRecord(new String[] { "Options", "'" + options.toString() });
			writer.endRecord();
			writer.printRecord(new String[] { "Case", "Group", "Task",
				"Runs", "Avg. (ms)", "95% C.I. (ms)", "95% C.I. (%)", "Results (ms)" });
			// print quoted CSV data
			PrintCSVSummaryVisitor visitor = new PrintCSVSummaryVisitor(writer);
			root.accept(visitor);
		} else {
			// print header
			ps.println("=== LOG SUMMARY ===");
			ps.println("File: " + logFile);
			ps.println("  Generated: " + root.getTimestamp());
			ps.println("  SDK Build: " + root.getSDKBuildId());
			ps.println("Options: " + options.toString());
			ps.println();
			// print the log summary
			root.accept(new PrintTextSummaryVisitor(ps));
		}
	}
	
	private static class Parser extends ArgumentParser {
		public File logFile = null;
		public File outputFile = null;
		public boolean csv = false;
		public boolean raw = false;

		protected boolean handleFinished() {
			return logFile != null;
		}
		protected boolean handleArgument(int index, String arg) {
			if (index == 0) {
				logFile = new File(arg);
			} else {
				return false;
			}
			return true;
		}
		protected boolean handleOption(String option, String arg) {
			if ("-out".equals(option)) {
				if (arg == null) return false;
				outputFile = new File(arg);
			} else if ("-csv".equals(option)) {
				if (arg != null) return false;
				csv = true;
			} else if ("-raw".equals(option)) {
				if (arg != null) return false;
				raw = true;
			} else {
				return false;
			}
			return true;
		}
	}
}

Back to the top