1402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/******************************************************************************* 2402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Copyright (c) 2000, 2009 IBM Corporation and others. 3402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * All rights reserved. This program and the accompanying materials 4402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * are made available under the terms of the Eclipse Public License v1.0 5402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * which accompanies this distribution, and is available at 6402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * http://www.eclipse.org/legal/epl-v10.html 7402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 8402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Contributors: 9402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * IBM Corporation - initial API and implementation 10402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *******************************************************************************/ 11402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpackage org.eclipse.test.performance.ui; 12402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 13402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.io.PrintStream; 14402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.util.ArrayList; 15402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.util.Collections; 16402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.util.List; 17402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 18402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.data.Dim; 19402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.db.BuildResults; 20402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.db.ConfigResults; 21402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.db.DB_Results; 22402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.utils.Util; 23402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 24402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/** 25402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Class used to fill details file of scenario builds data. 26402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @see ScenarioData 27402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */ 28402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic class RawDataTable { 29402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 30402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll private ConfigResults configResults; 31402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll private List buildPrefixes; 32402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll private PrintStream stream; 33402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll private Dim[] dimensions = DB_Results.getResultsDimensions(); 34402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll private boolean debug = false; 35402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 36402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollprivate RawDataTable(ConfigResults results, PrintStream ps) { 37402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.configResults = results; 38402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream = ps; 39402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll} 40402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 41402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic RawDataTable(ConfigResults results, List prefixes, PrintStream ps) { 42402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this(results, ps); 43402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.buildPrefixes = prefixes; 44402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll} 45402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic RawDataTable(ConfigResults results, String baselinePrefix, PrintStream ps) { 46402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this(results, ps); 47402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.buildPrefixes = new ArrayList(); 48402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.buildPrefixes.add(baselinePrefix); 49402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll} 50402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 51402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/** 52402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Print all build data to the current stream. 53402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */ 54402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic void print(){ 55402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<table border=\"1\">"); 56402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll printSummary(); 57402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll printDetails(); 58402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</table>\n"); 59402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll} 60402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 61402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* 62402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Print table columns headers. 63402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */ 64402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollprivate void printColumnHeaders() { 65402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll StringBuffer buffer = new StringBuffer(); 66402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll int length = this.dimensions.length; 67402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll for (int i=0; i<length; i++) { 68402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll buffer.append("<td><b>"); 69402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll buffer.append(this.dimensions[i].getName()); 70402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll buffer.append("</b></td>"); 71402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll } 72402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print(buffer.toString()); 73402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll} 74402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 75402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* 76402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Print all build results in the table. 77402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */ 78402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollprivate void printDetails() { 79402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<tr><td><b>Build ID</b></td>"); 80402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll printColumnHeaders(); 81402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</tr>\n"); 82402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 83402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll List builds = this.configResults.getBuildsMatchingPrefixes(this.buildPrefixes); 84402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll Collections.reverse(builds); 85402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll int size = builds.size(); 86402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll for (int i=0; i<size; i++) { 87402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll BuildResults buildResults = (BuildResults) builds.get(i); 88402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<tr><td>"); 89402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print(buildResults.getName()); 90402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</td>"); 91402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll int dimLength = this.dimensions.length; 92402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll for (int d=0; d<dimLength; d++) { 93402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll Dim dimension = this.dimensions[d]; 94402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll int dim_id = dimension.getId(); 95402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll double value = buildResults.getValue(dim_id); 96402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll printDimTitle(dimension.getName()); 97402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll String displayValue = dimension.getDisplayValue(value); 98402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print(displayValue); 99402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll if (this.debug) System.out.print("\t"+displayValue); 100402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</td>"); 101402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll } 102402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll if (this.debug) System.out.println(); 103402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</tr>\n"); 104402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll } 105402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll if (this.debug) System.out.println("\n"); 106402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll} 107402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 108402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* 109402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Print summary on top of the table. 110402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */ 111402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollprivate void printSummary() { 112402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<tr><td><b>Stats</b></td>"); 113402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll printColumnHeaders(); 114402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</tr>\n"); 115402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 116402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll int length = this.dimensions.length; 117402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll double[][] dimStats = new double[length][]; 118402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll for (int i=0; i<length; i++) { 119402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll dimStats[i] = this.configResults.getStatistics(this.buildPrefixes, this.dimensions[i].getId()); 120402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll } 121402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 122402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<tr><td>#BUILDS SAMPLED</td>"); 123402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll for (int i=0; i<length; i++) { 124402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll String dimName = this.dimensions[i].getName(); 125402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll printDimTitle(dimName); 126402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print((int)dimStats[i][0]); 127402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</td>"); 128402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll } 129402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</tr>\n"); 130402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<tr><td>MEAN</td>"); 131402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll printRowDoubles(dimStats, 1); 132402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</tr>\n"); 133402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<tr><td>STD DEV</td>"); 134402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll printRowDoubles(dimStats, 2); 135402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</tr>\n"); 136402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<tr><td>COEF. VAR</td>"); 137402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll printRowDoubles(dimStats, 3); 138402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</tr>\n"); 139402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 140402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll // Blank line 141402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<tr>"); 142402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll for (int i=0; i<length+1; i++){ 143402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<td> </td>"); 144402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll } 145402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</tr>\n"); 146402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll} 147402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 148402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* 149402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Print values in table row. 150402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */ 151402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollprivate void printRowDoubles(double[][] stats, int idx) { 152402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll int length = this.dimensions.length; 153402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll for (int i=0; i<length; i++) { 154402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll double value = stats[i][idx]; 155402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll String dimName = this.dimensions[i].getName(); 156402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll if (idx == 3) { 157402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll if (value > 0.1 && value < 0.2) { 158402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<td bgcolor=\"yellow\" title=\""); 159402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll } else if (value >= 0.2) { 160402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<td bgcolor=\"FF9900\" title=\""); 161402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll } else { 162402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<td title=\""); 163402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll } 164402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print(dimName); 165402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("\">"); 166402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print(Util.PERCENTAGE_FORMAT.format(value)); 167402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</td>"); 168402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll } else { 169402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll printDimTitle(dimName); 170402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print(this.dimensions[i].getDisplayValue(value)); 171402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("</td>"); 172402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll } 173402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll } 174402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll} 175402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll 176402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* 177402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Print dim title inside value reference. 178402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * TODO (frederic) See if this title is really necessary 179402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */ 180402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollprivate void printDimTitle(String dimName) { 181402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("<td title=\""); 182402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print(dimName); 183402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll this.stream.print("\">"); 184402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll} 185402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll} 186