Added
Link Here
|
1 |
package org.eclipse.test.internal.performance; |
2 |
|
3 |
import java.io.BufferedReader; |
4 |
import java.io.FileReader; |
5 |
import java.io.FileWriter; |
6 |
import java.io.PrintWriter; |
7 |
import java.util.Iterator; |
8 |
import java.util.Map; |
9 |
import java.util.TreeMap; |
10 |
|
11 |
public class GenHtml { |
12 |
private Map perfBaseline; |
13 |
private Map perfRun; |
14 |
private DimHeaders header; |
15 |
|
16 |
static class DimHeaders { |
17 |
public DimHeaders(String systemTime, String elapsedTime, |
18 |
String scenarioName, String scenarioTest) { |
19 |
this.systemTime = systemTime; |
20 |
this.elapsedTime = elapsedTime; |
21 |
this.scenarioName = scenarioName; |
22 |
this.scenarioTest = scenarioTest; |
23 |
} |
24 |
|
25 |
String systemTime; |
26 |
String elapsedTime; |
27 |
String scenarioName; |
28 |
String scenarioTest; |
29 |
} |
30 |
|
31 |
static class Dim { |
32 |
public Dim(int s, int e, String sc) { |
33 |
systemTime = s; |
34 |
elapsedTime = e; |
35 |
scenario = sc; |
36 |
} |
37 |
|
38 |
int systemTime; |
39 |
int elapsedTime; |
40 |
String scenario; |
41 |
} |
42 |
|
43 |
/** |
44 |
* @param args |
45 |
*/ |
46 |
public static void main(String[] args) { |
47 |
if (args.length != 3) { |
48 |
System.out.println(GenHtml.class.getName() |
49 |
+ ": <baselineTSV> <latestTSV> <output.html>"); |
50 |
return; |
51 |
} |
52 |
try { |
53 |
GenHtml html = new GenHtml(); |
54 |
html.read(args); |
55 |
html.write(args); |
56 |
} catch (Exception e) { |
57 |
e.printStackTrace(); |
58 |
} |
59 |
} |
60 |
|
61 |
public void write(String[] args) throws Exception { |
62 |
PrintWriter out = new PrintWriter(new FileWriter(args[2])); |
63 |
writeHeader(out, args[0], args[1]); |
64 |
Iterator tests = perfRun.keySet().iterator(); |
65 |
while (tests.hasNext()) { |
66 |
String test = (String) tests.next(); |
67 |
String[] testInfo = test.split("#"); |
68 |
Dim d350 = (Dim) perfRun.get(test); |
69 |
Dim d33x = (Dim) perfBaseline.get(test); |
70 |
if (d350 == null || d33x == null) { |
71 |
continue; |
72 |
} |
73 |
int per = ((d33x.elapsedTime - d350.elapsedTime) * 100) |
74 |
/ d33x.elapsedTime; |
75 |
String colour = " bgcolor=\"#66FF00\""; |
76 |
if (per < -5) { |
77 |
colour = " bgcolor=\"#FF0033\""; |
78 |
} else if (per < 0) { |
79 |
colour = " bgcolor=\"#FFFF66\""; |
80 |
} |
81 |
out.print("<tr><td>"); |
82 |
out.print(testInfo.length == 1 ? testInfo[0] : testInfo[1]); |
83 |
out.print("</td><td align=\"right\">" + d33x.elapsedTime |
84 |
+ "</td><td align=\"right\">" + d350.elapsedTime |
85 |
+ "</td><td align=\"right\"" + colour + ">" + per |
86 |
+ "%</td><td>"); |
87 |
out.print(testInfo.length == 1 ? "Not Specified" : testInfo[0]); |
88 |
out.println("</td></tr>"); |
89 |
} |
90 |
writeFooter(out); |
91 |
out.close(); |
92 |
|
93 |
} |
94 |
|
95 |
private void writeFooter(PrintWriter out) { |
96 |
out.println("</table>\n\n</body></html>"); |
97 |
} |
98 |
|
99 |
public void read(String[] args) throws Exception { |
100 |
perfBaseline = load(args[0]); |
101 |
perfRun = load(args[1]); |
102 |
} |
103 |
|
104 |
private void writeHeader(PrintWriter out, String baseline, String run) { |
105 |
out.print("<html>\n<head>\n<title>"); |
106 |
out.print(baseline); |
107 |
out.print(" vs "); |
108 |
out.print(run); |
109 |
out.print("</title>\n</head>\n<body>\n<h1>"); |
110 |
out.print(baseline); |
111 |
out.print(" vs "); |
112 |
out.print(run); |
113 |
out.print("</h1>\n<table border=\"1\"><tr><th>"); |
114 |
out.print(header.scenarioName); |
115 |
out.print("</th>\n<th>"); |
116 |
out.print(header.elapsedTime + " baseline"); |
117 |
out.print("</th>\n<th>"); |
118 |
out.print(header.elapsedTime + " run"); |
119 |
out.print("</th>\n<th>"); |
120 |
out.print(header.elapsedTime + " %"); |
121 |
out.print("</th>\n<th>"); |
122 |
out.print(header.scenarioTest); |
123 |
out.print("</th>\n</tr>"); |
124 |
} |
125 |
|
126 |
public Map load(String filename) throws Exception { |
127 |
TreeMap testMap = new TreeMap(); |
128 |
BufferedReader perfReader = new BufferedReader(new FileReader(filename)); |
129 |
String line; |
130 |
while ((line = perfReader.readLine()) != null) { |
131 |
String[] columns = line.split("\t"); |
132 |
if (columns.length > 11) { |
133 |
if ("System Time".equals(columns[0])) { |
134 |
if (header == null) { |
135 |
header = new DimHeaders(columns[0], columns[3], |
136 |
"Scenario Name", "Scenario Test"); |
137 |
} |
138 |
continue; |
139 |
} |
140 |
Dim d = new Dim(Integer.parseInt(columns[0]), Integer |
141 |
.parseInt(columns[3]), columns[11]); |
142 |
testMap.put(d.scenario, d); |
143 |
} |
144 |
} |
145 |
return testMap; |
146 |
} |
147 |
} |