-
Notifications
You must be signed in to change notification settings - Fork 66
/
BasicResultsTable.java
365 lines (320 loc) · 15.3 KB
/
BasicResultsTable.java
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/*******************************************************************************
* Copyright (c) 2022 Samantha Dawley and others.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: Samantha Dawley - initial API and implementation
*******************************************************************************/
package org.eclipse.test.performance;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.Set;
import java.util.HashMap;
import java.util.ArrayList;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.test.internal.performance.data.ResultsData;
public class BasicResultsTable implements IApplication{
private static String CURRENT_BUILD, BASELINE_BUILD=null;
private static ArrayList<Path> inputFiles = new ArrayList<Path>();
private static Path phpTemplateFile = null;
private static String EOL = System.lineSeparator();
private static String buildDirectory = "";
@Override
public Object start(IApplicationContext context) {
String[] args = (String[]) context.getArguments().get("application.args");
//DEBUG
if (args.length > 0) {
System.out.println("\n\t= = Raw arguments ('application.args') passed to performance import application: = =");
for (String arg : args) {
System.out.println("\t\t>" + arg + "<");
}
}
//Stuff
run(args);
return this.EXIT_OK;
}
@Override
public void stop() {
// Do nothing
}
public static void run(String[] args) {
parse(args);
//Initialize results data
ResultsData results = new ResultsData(CURRENT_BUILD, BASELINE_BUILD);
try {
// import data
System.out.println("INFO: Start importing " + inputFiles.size() + " performance data files.");
for (Path inputFile : inputFiles) {
results.importData(inputFile);
}
} catch (Exception ex) {
System.out.println("Performance data import failed with exception!" + ex);
System.exit(1);
}
//Sort all scenarios into components, then make html file per component
Set<String> scenarioIDs = results.getCurrentScenarios();
ArrayList<String> usedComponents = new ArrayList<String>();
//group scenarios by component for making tables
HashMap<String, ArrayList<String>> componentMap = new HashMap<String, ArrayList<String>>();
//get components from scenario name, for simplicity I'm just grabing everthing before .test/.tests but eventually should be mapped to actual components
for (String scenarioID : scenarioIDs) {
String[] scenarioParts = scenarioID.split("\\.");
String scenarioComponent = "";
for (String part : scenarioParts) {
if (part.equals("tests")) {
break;
}
//stw is different
if (part.equals("test")) {
break;
}
scenarioComponent = scenarioComponent + part + ".";
}
//trim final .
scenarioComponent = scenarioComponent.substring(0, scenarioComponent.length()-1);
//check if component in used components list
if (usedComponents.contains(scenarioComponent)) {
//Update HashMap entry, add scenario to components list
ArrayList<String> componentScenarios = componentMap.get(scenarioComponent);
componentScenarios.add(scenarioID);
componentMap.replace(scenarioComponent, componentScenarios);
} else {
//Add component to used components and make new entry into HashMap
ArrayList<String> componentScenarios = new ArrayList<String>();
componentScenarios.add(scenarioID);
componentMap.put(scenarioComponent, componentScenarios);
usedComponents.add(scenarioComponent);
}
}
//for checking if a test has a baseline to reference
Set<String> baselineScenarios = results.getBaselineScenarios();
//Make component html files
for (String component : usedComponents) {
ArrayList<String> scenarioList = componentMap.get(component);
scenarioList.sort(String::compareToIgnoreCase);
//set up html string
String htmlString = "";
//htmlString = htmlString + EOL + "<h2>Performance of " + component + ": " + CURRENT_BUILD + " relative to " + BASELINE_BUILD + "</h2>" + EOL;
//htmlString = htmlString + EOL + "<a href=\"performance.php?fp_type=0\">Back to global results</a>" + EOL;
htmlString = htmlString + EOL + "<h3>All " + scenarioList.size() + " scenarios:</h3>" + EOL;
htmlString = htmlString + EOL + "<p>Times are given in milliseconds.</p>" + EOL;
htmlString = htmlString + "<table border=\"1\">" + EOL + "<tr>" + EOL;
htmlString = htmlString + "<td><h4>Class</h4></td>" + EOL;
htmlString = htmlString + "<td><h4>Name</h4></td>" + EOL;
htmlString = htmlString + "<td><h4>Elapsed Process (Current)</h4></td>" + EOL;
htmlString = htmlString + "<td><h4>Elapsed Process (Baseline)</h4></td>" + EOL;
htmlString = htmlString + "<td><h4>Difference</h4></td>" + EOL;
htmlString = htmlString + "<td><h4>CPU Time (Current)</h4></td>" + EOL;
htmlString = htmlString + "<td><h4>CPU Time (Baseline)</h4>" + EOL;
htmlString = htmlString + "<td><h4>Difference</h4>" + EOL;
for (String scenario : scenarioList) {
String[] scenarioParts = null;
String componentClass = null;
String componentName = null;
//swt is different
if (scenario.contains("swt")) {
scenarioParts = scenario.split("\\.");
componentName = scenarioParts[scenarioParts.length - 1];
for (int i=0; i < (scenarioParts.length - 1); i++ ) {
componentClass = componentClass + scenarioParts[i] + ".";
}
//trim final .
componentClass = componentClass.substring(0, componentClass.length()-1);
} else {
scenarioParts = scenario.split("#");
componentClass = scenarioParts[0];
componentName = scenarioParts[1];
}
double[] currentData = results.getData("current", scenario);
String elapsedCurrent = String.valueOf(currentData[0]);
String cpuCurrent = String.valueOf(currentData[1]);
String elapsedBaseline = "N/A";
String cpuBaseline = "N/A";
String elapsedPercent = "N/A";
String cpuPercent = "N/A";
String elapsedColor = "#4CE600";
String cpuColor = "#4CE600";
if (baselineScenarios.contains(scenario)) {
double[] baselineData = results.getData("baseline", scenario);
elapsedBaseline = String.valueOf(baselineData[0]);
cpuBaseline = String.valueOf(baselineData[1]);
double elapsedDifference = baselineData[0] - currentData[0];
double cpuDifference = baselineData[1] - currentData[1];
double elapsedPercentValue = Math.abs(elapsedDifference / baselineData[0]) * 100;
double cpuPercentValue = Math.abs(cpuDifference / baselineData[1]) * 100;
elapsedPercent = String.format("%.2f", elapsedPercentValue) + "%";
cpuPercent = String.format("%.2f", cpuPercentValue) + "%";
if (elapsedDifference < 0) {
elapsedColor = "D7191C";
}
if (cpuDifference < 0) {
cpuColor = "D7191C";
}
}
htmlString = htmlString + "<tr>" + EOL;
htmlString = htmlString + "<td>" + componentClass + EOL;
htmlString = htmlString + "<td>" + componentName + EOL;
htmlString = htmlString + "<td>" + elapsedCurrent + EOL;
htmlString = htmlString + "<td>" + elapsedBaseline + EOL;
htmlString = htmlString + "<td bgcolor=\"" + elapsedColor + "\">" + elapsedPercent + EOL;
htmlString = htmlString + "<td>" + cpuCurrent + EOL;
htmlString = htmlString + "<td>" + cpuBaseline + EOL;
htmlString = htmlString + "<td bgcolor=\"" + cpuColor + "\">" + cpuPercent + EOL;
}
htmlString = htmlString + "</table>" + EOL;
//create file
String outputFileName = buildDirectory + "/" + component + "_BasicTable.html";
File outputFile = new File(outputFileName);
try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile))){
outputStream.write(htmlString.getBytes());
}
catch (final FileNotFoundException ex) {
System.err.println("ERROR: File not found exception while writing: " + outputFile.getPath());
System.exit(1);
}
catch (final IOException ex) {
System.err.println("ERROR: IOException writing: " + outputFile.getPath());
System.exit(1);
}
}
//make basicResultsIndex.html file
String htmlString = "";
htmlString = htmlString + EOL;
for (String component : usedComponents) {
htmlString = htmlString + "<a href=\"./basicPerformance.php/" +
"?name=" + component +
"&build=" + CURRENT_BUILD +
"&baseline=" + BASELINE_BUILD +
"\">" + component + "*</a><br>" + EOL;
}
//create file
String outputFileName = buildDirectory + "/BasicResultsIndex.html";
File outputFile = new File(outputFileName);
try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile))){
outputStream.write(htmlString.getBytes());
}
catch (final FileNotFoundException ex) {
System.err.println("ERROR: File not found exception while writing: " + outputFile.getPath());
System.exit(1);
}
catch (final IOException ex) {
System.err.println("ERROR: IOException writing: " + outputFile.getPath());
System.exit(1);
}
//copy basicPerformance.php from templatefiles
String phpFileName = buildDirectory + "/basicPerformance.php";
File phpFile = new File(phpFileName);
try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(phpFile))){
outputStream.write(Files.readAllBytes(phpTemplateFile));
}
catch (final FileNotFoundException ex) {
System.err.println(EOL + "ERROR: File not found exception while writing: " + phpFile.getPath());
System.exit(1);
}
catch (final IOException ex) {
System.err.println(EOL + "ERROR: IOException writing: " + phpFile.getPath());
System.exit(1);
}
}
//args = baseline, current build, input file array
private static void parse(String[] args) {
if (args.length == 0) {
printUsage();
}
int i = 0;
while (i < args.length) {
String arg = args[i];
if (arg.equals("-current")){
CURRENT_BUILD = args[i+1];
if (CURRENT_BUILD.startsWith("-")) {
System.out.println("Missing value for "+arg+" parameter");
printUsage();
}
i++;
i++;
continue;
}
if (arg.equals("-baseline")){
BASELINE_BUILD = args[i+1];
if (BASELINE_BUILD.startsWith("-")) {
System.out.println("Missing value for "+arg+" parameter");
printUsage();
}
i++;
i++;
continue;
}
if (arg.equals("-buildDirectory")){
buildDirectory = args[i+1];
if (buildDirectory.startsWith("-")) {
System.out.println("Missing value for "+arg+" parameter");
printUsage();
}
i++;
i++;
continue;
}
if (arg.equals("-phpFile")){
String inputFile = args[i+1];
if (inputFile.startsWith("-")) {
System.out.println("Missing value for "+arg+" parameter");
printUsage();
}
//check real file
Path inputFilePath = Paths.get(inputFile);
if (Files.isReadable(inputFilePath)) {
phpTemplateFile = inputFilePath;
} else {
System.err.println("ERROR: invalid input argument. Cannot read file: " + inputFile);
}
i++;
i++;
continue;
}
if (arg.equals("-inputFiles")){
for (int j=1; j < 5; j++) {
String inputFile = args[i+j];
if (inputFile.startsWith("-")) {
System.out.println("Missing value for "+arg+" parameter");
printUsage();
}
//check real file
//Path inputFilePath = Paths.get(buildDirectory + "/" + inputFile);
Path inputFilePath = Paths.get(inputFile);
if (Files.isReadable(inputFilePath)) {
inputFiles.add(inputFilePath);
} else {
System.err.println("ERROR: invalid input argument. Cannot read file: " + inputFile);
}
}
i = i+5;
continue;
}
System.err.println("ERROR: Unrecognized argument (arg) found, with value of >" + arg + "<");
i++;
continue;
}
}
private static void printUsage() {
System.out.println(
"Usage:\n" +
"-baseline: Build id for the baseline build.\n" +
"-current: Build id for the current build.\n" +
"-buildDirectory: Directory of performance.php file, usually /home/data/httpd/download.eclipse.org/eclipse/downloads/drops4/${BUILD_ID}/performance.\n" +
"-phpFile: Location of the basicPerformance.php file, also known as template file.\n" +
"-inputFiles: List of the dat files from which to extract performance data (will grab the next 4 args as filenames).\n"
);
System.exit(1);
}
}