KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > test > internal > performance > eval > Evaluator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.test.internal.performance.eval;
12
13 import java.util.HashSet JavaDoc;
14 import junit.framework.Assert;
15
16 import org.eclipse.test.internal.performance.InternalPerformanceMeter;
17 import org.eclipse.test.internal.performance.PerformanceTestPlugin;
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.performance.PerformanceMeter;
24
25 /**
26  * The default implementation of an evaluator backed by a database.
27  * @since 3.1
28  */

29 public class Evaluator extends EmptyEvaluator {
30     
31     private AssertChecker[] fCheckers;
32
33
34     public void setAssertCheckers(AssertChecker[] asserts) {
35         fCheckers= asserts;
36     }
37
38     /*
39      * @see org.eclipse.test.internal.performance.eval.IEvaluator#evaluate(org.eclipse.jdt.ui.tests.performance.PerformanceMeter)
40      */

41     public void evaluate(PerformanceMeter performanceMeter) throws RuntimeException JavaDoc {
42         
43         if (fCheckers == null)
44             return; // nothing to do
45

46         // get reference build tag
47
Variations refKeys= PerformanceTestPlugin.getAssertAgainst();
48         if (refKeys == null)
49             return; // nothing to do
50

51         if (!(performanceMeter instanceof InternalPerformanceMeter))
52             return; // we cannot handle this.
53

54         InternalPerformanceMeter ipm= (InternalPerformanceMeter) performanceMeter;
55         Sample session= ipm.getSample();
56         Assert.assertTrue("metering session is null", session != null); //$NON-NLS-1$
57
String JavaDoc scenarioName= session.getScenarioID();
58         
59         // determine all dimensions we need
60
HashSet JavaDoc allDimensions= new HashSet JavaDoc();
61         for (int i= 0; i < fCheckers.length; i++) {
62             AssertChecker chk= fCheckers[i];
63             Dim[] dims= chk.getDimensions();
64             for (int j= 0; j < dims.length; j++)
65                 allDimensions.add(dims[j]);
66         }
67         
68         // get data for this session
69
DataPoint[] sessionDatapoints;
70         Variations config= PerformanceTestPlugin.getVariations();
71         if (config != null)
72             sessionDatapoints= DB.queryDataPoints(config, scenarioName, allDimensions);
73         else
74             sessionDatapoints= session.getDataPoints();
75         if (sessionDatapoints == null || sessionDatapoints.length == 0) {
76             PerformanceTestPlugin.logWarning("no session data named '" + config + "' found"); //$NON-NLS-1$ //$NON-NLS-2$
77
return;
78         }
79
80         // get reference data
81
DataPoint[] datapoints= DB.queryDataPoints(refKeys, scenarioName, allDimensions);
82         if (datapoints == null || datapoints.length == 0) {
83             PerformanceTestPlugin.logWarning("no reference data named '" + refKeys + "' found"); //$NON-NLS-1$ //$NON-NLS-2$
84
return;
85         }
86         
87         // calculate the average
88
StatisticsSession referenceStats= new StatisticsSession(datapoints);
89         StatisticsSession measuredStats= new StatisticsSession(sessionDatapoints);
90
91         StringBuffer JavaDoc failMesg= new StringBuffer JavaDoc("Performance criteria not met when compared to '" + refKeys + "':"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
92
boolean pass= true;
93         for (int i= 0; i < fCheckers.length; i++) {
94             AssertChecker chk= fCheckers[i];
95             pass &= chk.test(referenceStats, measuredStats, failMesg);
96         }
97         
98         if (!pass) {
99             if (config != null)
100                     DB.markAsFailed(config, session, failMesg.toString());
101 // else
102
// Assert.assertTrue(failMesg.toString(), false);
103
}
104     }
105 }
106
Popular Tags