/******************************************************************************* * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.test.performance.ui; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import junit.framework.AssertionFailedError; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.ImageLoader; import org.eclipse.swt.widgets.Display; import org.eclipse.test.internal.performance.data.Dim; import org.eclipse.test.internal.performance.results.db.BuildResults; import org.eclipse.test.internal.performance.results.db.ComponentResults; import org.eclipse.test.internal.performance.results.db.ConfigResults; import org.eclipse.test.internal.performance.results.db.DB_Results; import org.eclipse.test.internal.performance.results.db.PerformanceResults; import org.eclipse.test.internal.performance.results.db.ScenarioResults; import org.eclipse.test.internal.performance.results.utils.Util; /** * Class used to print scenario all builds data. */ public class ScenarioData { private String baselinePrefix = null; private List pointsOfInterest; private List buildIDStreamPatterns; private File rootDir; private static final int GRAPH_WIDTH = 600; private static final int GRAPH_HEIGHT = 200; private Dim[] dimensions = DB_Results.getResultsDimensions(); /** * Summary of results for a scenario for a given build compared to a * reference. * * @param baselinePrefix The prefix of the baseline build names * @param pointsOfInterest A list of buildId's to highlight on line graphs * @param buildIDPatterns * @param outputDir The directory root where the files are generated * */ public ScenarioData(String baselinePrefix, List pointsOfInterest, List buildIDPatterns, File outputDir) { this.baselinePrefix = baselinePrefix; this.pointsOfInterest = pointsOfInterest; this.buildIDStreamPatterns = buildIDPatterns; this.rootDir = outputDir; } /* * Create a file handle verifying that its name does not go over * the maximum authorized length. */ private File createFile(File outputDir, String subdir, String name, String extension) { File dir = outputDir; if (subdir != null) { dir = new File(outputDir, subdir); if (!dir.exists()) { dir.mkdir(); } } return new File(dir, name + '.' + extension); } /* * Returns a LineGraph object representing measurements for a scenario over builds. */ private TimeLineGraph getLineGraph(ScenarioResults scenarioResults, ConfigResults configResults, Dim dim, List highlightedPoints, List currentBuildIdPrefixes) { Display display = Display.getDefault(); Color black = display.getSystemColor(SWT.COLOR_BLACK); Color yellow = display.getSystemColor(SWT.COLOR_DARK_YELLOW); Color magenta = display.getSystemColor(SWT.COLOR_MAGENTA); String scenarioName = scenarioResults.getName(); TimeLineGraph graph = new TimeLineGraph(scenarioName + ": " + dim.getName(), dim); String baseline = configResults.getBaselineBuildName(); String current = configResults.getCurrentBuildName(); final String defaultBaselinePrefix = DB_Results.getDbBaselinePrefix(); Iterator builds = configResults.getResults(); List lastSevenNightlyBuilds = configResults.lastNightlyBuildNames(7); buildLoop: while (builds.hasNext()) { BuildResults buildResults = (BuildResults) builds.next(); String buildID = buildResults.getName(); int underscoreIndex = buildID.indexOf('_'); String label = (underscoreIndex != -1 && buildID.equals(current)) ? buildID.substring(0, underscoreIndex) : buildID; if (buildID.startsWith(defaultBaselinePrefix)) { label = defaultBaselinePrefix+buildID.charAt(defaultBaselinePrefix.length())+buildID.substring(underscoreIndex); } double value = buildResults.getValue(dim.getId()); if (buildID.equals(current)) { Color color = black; if (buildID.startsWith("N")) color = yellow; graph.addItem("main", label, dim.getDisplayValue(value), value, color, true, Utils.getDateFromBuildID(buildID), true); continue; } if (highlightedPoints.contains(buildID)) { graph.addItem("main", label, dim.getDisplayValue(value), value, black, false, Utils.getDateFromBuildID(buildID, false), true); continue; } if (buildID.charAt(0) == 'N') { if (lastSevenNightlyBuilds.contains(buildID)) { graph.addItem("main", buildID, dim.getDisplayValue(value), value, yellow, false, Utils.getDateFromBuildID(buildID), false); } continue; } for (int i=0;i 0) { highlightedPoints.add(builds.get(builds.size()-1)); } } else { highlightedPoints.addAll(builds); } } } String scenarioFileName = scenarioResults.getFileName(); File outputFile = new File(outputDir, scenarioFileName+".html"); PrintStream stream = null; try { stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFile))); } catch (FileNotFoundException e) { System.err.println("can't create output file" + outputFile); //$NON-NLS-1$ } if (stream == null) { stream = System.out; } stream.print(Utils.HTML_OPEN); stream.print(Utils.HTML_DEFAULT_CSS); stream.print("" + scenarioResults.getName() + "(" + configBox + ")" + "\n"); //$NON-NLS-1$ stream.print("

Scenario: " + scenarioResults.getName() + " (" + configBox + ")


\n"); //$NON-NLS-1$ //$NON-NLS-2$ String failureMessage = Utils.failureMessage(configResults.getCurrentBuildDeltaInfo(), true); if (failureMessage != null){ stream.print("
"+failureMessage+"
\n"); } BuildResults currentBuildResults = configResults.getCurrentBuildResults(); String comment = currentBuildResults.getComment(); if (comment != null) { stream.print("

Note:
\n"); stream.print(comment + "

\n"); } // Print link to raw data. String rawDataFile = "raw/" + scenarioFileName+".html"; stream.print("

Raw data and Stats

\n"); stream.print("Click measurement name to view line graph of measured values over builds.

\n"); if (subMonitor.isCanceled()) throw new OperationCanceledException(); try { // Print build result table stream.print("\n"); //$NON-NLS-1$ stream.print(""); //$NON-NLS-1$ int dimLength = this.dimensions.length; for (int d=0; d" + dim.getName() + ""); } stream.print("\n"); // Write build lines printTableLine(stream, currentBuildResults); printTableLine(stream, configResults.getBaselineBuildResults()); // Write difference line printDifferenceLine(stream, configResults); // End of table stream.print("
Build Id
\n"); stream.print("*Delta values in red and green indicate degradation > 10% and improvement > 10%,respectively.

\n"); stream.print("

\n\n"); // print text legend. stream.print("Black and yellow points plot values measured in integration and last seven nightly builds.
\n" + "Magenta points plot the repeated baseline measurement over time.
\n" + "Boxed points represent previous releases, milestone builds, current reference and current build.

\n" + "Hover over any point for build id and value.\n"); // print image maps of historical for (int d=0; d\n"); stream.print("
" + dim.getName() + "
\n"); stream.print(dim.getDescription() + "

\n"); stream.print(""); stream.print(""); stream.print(lineGraph.getAreas()); stream.print("\n"); if (subMonitor.isCanceled()) throw new OperationCanceledException(); } stream.print("

\n"); stream.print(Utils.HTML_CLOSE); if (stream != System.out) stream.close(); } catch (AssertionFailedError e) { e.printStackTrace(); continue; } } } /* * Print the data for a build results. */ private void printTableLine(PrintStream stream, BuildResults buildResults) { stream.print(""); stream.print(buildResults.getName()); if (buildResults.isBaseline()) stream.print(" (reference)"); stream.print(""); int dimLength = this.dimensions.length; for (int d=0; d"); stream.print(displayValue); if (stddev < 0) { stream.print(" [n/a]\n"); } else if (stddev > 0) { stream.print(" ["); stream.print(dim.getDisplayValue(stddev)); stream.print("]"); } stream.print( ""); } stream.print("\n"); } /* * Print the line showing the difference between current and baseline builds. */ private void printDifferenceLine(PrintStream stream, ConfigResults configResults) { stream.print("*Delta"); int dimLength = this.dimensions.length; for (int d=0; d 10) { fontColor = "#006600"; // green } if (diffPercentage < -10) { fontColor = "#FF0000"; // red } // Print line String percentage = (diffPercentage == 0) ? "" : "
" + diffPercentage + " %"; if (diffPercentage > 10 || diffPercentage < -10) { stream.print("" + diffDisplayValue + percentage + ""); } else { stream.print("" + diffDisplayValue + percentage + ""); } } stream.print(""); } /* * Print details file of the scenario builds data. */ private void printDetails(String configName, String configBox, ComponentResults componentResults, File outputDir) { Iterator scenarios = componentResults.getResults(); while (scenarios.hasNext()) { ScenarioResults scenarioResults = (ScenarioResults) scenarios.next(); ConfigResults configResults = scenarioResults.getConfigResults(configName); if (configResults == null || !configResults.isValid()) continue; String scenarioName= scenarioResults.getName(); String scenarioFileName = scenarioResults.getFileName(); File outputFile = createFile(outputDir, "raw", scenarioFileName, "html"); PrintStream stream = null; try { stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFile))); } catch (FileNotFoundException e) { System.err.println("can't create output file" + outputFile); //$NON-NLS-1$ } if (stream == null) stream = System.out; RawDataTable currentResultsTable = new RawDataTable(configResults, this.buildIDStreamPatterns, stream); RawDataTable baselineResultsTable = new RawDataTable(configResults, this.baselinePrefix, stream); stream.print(Utils.HTML_OPEN); stream.print(Utils.HTML_DEFAULT_CSS); stream.print("" + scenarioName + "(" + configBox + ")" + " - Details\n"); //$NON-NLS-1$ stream.print("

Scenario: " + scenarioName + " (" + configBox + ")

\n"); //$NON-NLS-1$ stream.print("VIEW GRAPH

\n"); //$NON-NLS-1$ stream.print("\n"); stream.print("\n"); stream.print("\n"); stream.print("\n"); stream.print("\n"); stream.print("
Current Stream Test RunsBaseline Test Runs
"); currentResultsTable.print(); stream.print(""); baselineResultsTable.print(); stream.print("
\n"); stream.close(); } } /* * Prints a LineGraph object as a gif file. */ private void saveGraph(LineGraph p, File outputFile) { Image image = new Image(Display.getDefault(), GRAPH_WIDTH, GRAPH_HEIGHT); p.paint(image); /* Downscale to 8 bit depth palette to save to gif */ ImageData data = Utils.downSample(image); ImageLoader il = new ImageLoader(); il.data = new ImageData[] { data }; OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(outputFile)); il.save(out, SWT.IMAGE_GIF); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { image.dispose(); if (out != null) { try { out.close(); } catch (IOException e1) { // silently ignored } } } } }