1 11 12 package org.eclipse.test.internal.performance; 13 14 import java.io.PrintStream ; 15 import java.util.Arrays ; 16 import java.util.Comparator ; 17 18 import org.eclipse.test.internal.performance.data.DataPoint; 19 import org.eclipse.test.internal.performance.data.Dim; 20 import org.eclipse.test.internal.performance.data.Sample; 21 import org.eclipse.test.internal.performance.db.DB; 22 import org.eclipse.test.internal.performance.db.Variations; 23 import org.eclipse.test.internal.performance.eval.StatisticsSession; 24 import org.eclipse.test.performance.Dimension; 25 import org.eclipse.test.performance.PerformanceMeter; 26 27 28 public abstract class InternalPerformanceMeter extends PerformanceMeter { 29 30 31 private static class DimensionComparator implements Comparator { 32 33 public int compare(Object o1, Object o2) { 34 return ((Dim) o1).getId() - ((Dim) o2).getId(); 35 } 36 37 } 38 39 public static final int AVERAGE= -3; 40 public static final int BEFORE= 0; 41 public static final int AFTER= 1; 42 43 protected static final String VERBOSE_PERFORMANCE_METER_PROPERTY= "InternalPrintPerformanceResults"; 45 private String fScenarioId; 46 47 private String fShortName; 48 private Dimension[] fSummaryDimensions; 49 private boolean fSummaryIsGlobal; 50 private int fCommentType; 51 private String fComment; 52 53 54 public InternalPerformanceMeter(String scenarioId) { 55 fScenarioId= scenarioId; 56 } 57 58 public void dispose() { 59 fScenarioId= null; 60 } 61 62 public abstract Sample getSample(); 63 64 68 public String getScenarioName() { 69 return fScenarioId; 70 } 71 72 75 public void commit() { 76 Sample sample= getSample(); 77 if (sample != null) { 78 if (fSummaryDimensions != null) 79 sample.tagAsSummary(fSummaryIsGlobal, fShortName, fSummaryDimensions, fCommentType, fComment); 80 Variations variations= PerformanceTestPlugin.getVariations(); 81 if (variations != null) 82 DB.store(variations, sample); 83 if (!DB.isActive() || System.getProperty(VERBOSE_PERFORMANCE_METER_PROPERTY) != null) 84 printSample(System.out, sample); 85 } 86 } 87 88 private void printSample(PrintStream ps, Sample sample) { 89 ps.print("Scenario '" + getScenarioName() + "' "); DataPoint[] dataPoints= sample.getDataPoints(); 91 if (dataPoints.length > 0) { 92 StatisticsSession s= new StatisticsSession(dataPoints); 93 Dim[] dimensions= dataPoints[0].getDimensions(); 94 Arrays.sort(dimensions, new DimensionComparator()); 95 if (dimensions.length > 0) { 96 ps.println("(average over " + s.getCount(dimensions[0]) + " samples):"); for (int i= 0; i < dimensions.length; i++) { 98 Dim dimension= dimensions[i]; 99 ps.println(" " + dimension.getName() + ": " + dimension.getDisplayValue(s.getAverage(dimension))); } 101 } 102 } 103 ps.println(); 104 } 105 106 public void tagAsSummary(boolean global, String shortName, Dimension[] dims) { 107 fSummaryIsGlobal= global; 108 fShortName= shortName; 109 fSummaryDimensions= dims; 110 } 111 112 public void setComment(int commentType, String comment) { 113 fCommentType= commentType; 114 fComment= comment; 115 } 116 } 117 | Popular Tags |