/******************************************************************************* * 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.internal.performance.results.db; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.test.internal.performance.results.utils.Util; /** * Class to handle performance results of an eclipse component * (for example 'org.eclipse.jdt.core'). * * It gives access to results for each scenario run for this component. * * @see ScenarioResults */ public class ComponentResults extends AbstractResults { public ComponentResults(AbstractResults parent, String name) { super(parent, name); this.printStream = parent.printStream; } Set getAllBuildNames() { Set buildNames = new HashSet(); int size = size(); for (int i=0; i *
  • {@link #BUILD_VALUE_INDEX}: the build value in milliseconds
  • *
  • {@link #BASELINE_VALUE_INDEX}: the baseline value in milliseconds
  • *
  • {@link #DELTA_VALUE_INDEX}: the difference between the build value and its more recent baseline
  • *
  • {@link #DELTA_ERROR_INDEX}: the error made while computing the difference
  • *
  • {@link #BUILD_ERROR_INDEX}: the error made while measuring the build value
  • *
  • {@link #BASELINE_ERROR_INDEX}: the error made while measuring the baseline value
  • * */ public List getConfigNumbers(String configName, boolean fingerprints, List differences) { // Initialize lists AbstractResults[] scenarios = getChildren(); int length = scenarios.length; // Print scenario names line List firstLine = new ArrayList(); for (int i=0; i 0 && lastBuildName.startsWith(DB_Results.getDbBaselinePrefix())) { lastBuildName = builds[--last]; } // appendDifferences(lastBuildName, configName, previousMilestoneName, differences, fingerprints); // appendDifferences(lastBuildName, configName, previousBuildName, differences, fingerprints); // Return the computed differences return differences; } /* double[] getConfigNumbers(BuildResults buildResults, BuildResults baselineResults) { if (baselineResults == null) { return INVALID_RESULTS; } double[] values = new double[NUMBERS_LENGTH]; for (int i=0 ;i 1 && currentCount > 1) { double baselineError = baselineResults.getError(); double currentError = buildResults.getError(); values[BASELINE_ERROR_INDEX] = baselineError; values[BUILD_ERROR_INDEX] = currentError; values[DELTA_ERROR_INDEX] = Double.isNaN(baselineError) ? currentError / baselineValue : Math.sqrt(baselineError*baselineError + currentError*currentError) / baselineValue; } return values; } */ private ScenarioResults getScenarioResults(List scenarios, int searchedId) { int size = scenarios.size(); for (int i=0; i= 0)) { scenarios.add(scenarioResults); } } } return scenarios; } private String lastBuildName(int kind) { String[] builds = getAllSortedBuildNames(); int idx = builds.length-1; String lastBuildName = builds[idx--]; switch (kind) { case 1: // no ref while (lastBuildName.startsWith(DB_Results.getDbBaselinePrefix())) { lastBuildName = builds[idx--]; } break; case 2: // only I-build or M-build char ch = lastBuildName.charAt(0); while (ch != 'I' && ch != 'M') { lastBuildName = builds[idx--]; ch = lastBuildName.charAt(0); } break; default: break; } return lastBuildName; } /* * Read local file contents and populate the results model with the collected * information. */ String readLocalFile(File dir, List scenarios) throws FileNotFoundException { // if (!dir.exists()) return null; File dataFile = new File(dir, getName()+".dat"); //$NON-NLS-1$ if (!dataFile.exists()) throw new FileNotFoundException(); DataInputStream stream = null; try { // Read local file info stream = new DataInputStream(new BufferedInputStream(new FileInputStream(dataFile))); print(" - read local files info"); //$NON-NLS-1$ String lastBuildName = stream.readUTF(); // first string is the build name // Next field is the number of scenarios for the component int size = stream.readInt(); // Then follows all the scenario information for (int i=0; i "+size+" scenarios data were read from file "+dataFile); //$NON-NLS-1$ //$NON-NLS-2$ // Return last build name stored in the local files return lastBuildName; } catch (IOException ioe) { println(" !!! "+dataFile+" should be deleted as it contained invalid data !!!"); //$NON-NLS-1$ //$NON-NLS-2$ } finally { try { stream.close(); } catch (IOException e) { // nothing else to do! } } return null; } /* * Read the database values for a build name and a list of scenarios. * The database is read only if the components does not already knows the * given build (i.e. if it has not been already read) or if the force arguments is set. */ void updateBuild(String buildName, List scenarios, boolean force, File dataDir, SubMonitor subMonitor, PerformanceResults.RemainingTimeGuess timeGuess) { // Read all variations println("Component '"+this.name+"':"); //$NON-NLS-1$ //$NON-NLS-2$ // manage monitor int size = scenarios.size(); subMonitor.setWorkRemaining(size+1); StringBuffer buffer = new StringBuffer("Component "); //$NON-NLS-1$ buffer.append(this.name); buffer.append("..."); //$NON-NLS-1$ String title = buffer.toString(); subMonitor.subTask(title+timeGuess.display()); timeGuess.count++; subMonitor.worked(1); if (subMonitor.isCanceled()) return; // Read new values for the local result boolean dirty = false; long readTime = System.currentTimeMillis(); String log = " - read scenarios from DB:"; //$NON-NLS-1$ if (size > 0) { for (int i=0; i 300000) { // save every 5mn writeData(buildName, dataDir, true, true); dirty = false; readTime = System.currentTimeMillis(); } // manage monitor subMonitor.worked(1); if (subMonitor.isCanceled()) return; } } // Write local files if (dataDir != null) { writeData(buildName, dataDir, false, dirty); } // Print global time printGlobalTime(readTime); } /* * Write the component results data to the file '.dat' in the given directory. */ void writeData(String buildName, File dir, boolean temp, boolean dirty) { // if (!dir.exists() && !dir.mkdirs()) { // System.err.println("can't create directory "+dir); //$NON-NLS-1$ // } File tmpFile = new File(dir, getName()+".tmp"); //$NON-NLS-1$ File dataFile = new File(dir, getName()+".dat"); //$NON-NLS-1$ if (!dirty) { // only possible on final write if (tmpFile.exists()) { if (dataFile.exists()) dataFile.delete(); tmpFile.renameTo(dataFile); println(" => rename temporary file to "+dataFile); //$NON-NLS-1$ } return; } if (tmpFile.exists()) { tmpFile.delete(); } File file; if (temp) { file = tmpFile; } else { if (dataFile.exists()) { dataFile.delete(); } file = dataFile; } try { DataOutputStream stream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); try { int size = this.children.size(); stream.writeUTF(lastBuildName(0)); stream.writeInt(size); for (int i=0; i extracted data "+(temp?"temporarily ":"")+"written in file "+file); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } } catch (FileNotFoundException e) { System.err.println("can't create output file"+file); //$NON-NLS-1$ } catch (IOException e) { e.printStackTrace(); } } }