001: /*******************************************************************************
002: * Copyright (c) 2004, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.tests.performance;
011:
012: import junit.framework.TestCase;
013:
014: import org.eclipse.test.performance.Dimension;
015: import org.eclipse.test.performance.Performance;
016: import org.eclipse.test.performance.PerformanceMeter;
017:
018: /**
019: * @since 3.1
020: */
021: final class PerformanceTester {
022:
023: protected PerformanceMeter fPerformanceMeter;
024:
025: /**
026: * @param testCase
027: */
028: public PerformanceTester(TestCase testCase) {
029: Performance performance = Performance.getDefault();
030: fPerformanceMeter = performance
031: .createPerformanceMeter(performance
032: .getDefaultScenarioId(testCase));
033: }
034:
035: /**
036: * Asserts default properties of the measurements captured for this test
037: * case.
038: *
039: * @throws RuntimeException if the properties do not hold
040: */
041: public void assertPerformance() {
042: Performance.getDefault().assertPerformance(fPerformanceMeter);
043: }
044:
045: /**
046: * Asserts that the measurement specified by the given dimension is within a
047: * certain range with respect to some reference value. If the specified
048: * dimension isn't available, the call has no effect.
049: *
050: * @param dim
051: * the Dimension to check
052: * @param lowerPercentage
053: * a negative number indicating the percentage the measured value
054: * is allowed to be smaller than some reference value
055: * @param upperPercentage
056: * a positive number indicating the percentage the measured value
057: * is allowed to be greater than some reference value
058: * @throws RuntimeException
059: * if the properties do not hold
060: */
061: public void assertPerformanceInRelativeBand(Dimension dim,
062: int lowerPercentage, int upperPercentage) {
063: Performance.getDefault().assertPerformanceInRelativeBand(
064: fPerformanceMeter, dim, lowerPercentage,
065: upperPercentage);
066: }
067:
068: public void commitMeasurements() {
069: fPerformanceMeter.commit();
070: }
071:
072: public void dispose() {
073: fPerformanceMeter.dispose();
074: }
075:
076: /**
077: * Called from within a test case immediately before the code to measure is
078: * run. It starts capturing of performance data. Must be followed by a call
079: * to {@link PerformanceTestCase#stopMeasuring()}before subsequent calls to
080: * this method or {@link PerformanceTestCase#commitMeasurements()}.
081: */
082: public void startMeasuring() {
083: fPerformanceMeter.start();
084: }
085:
086: public void stopMeasuring() {
087: fPerformanceMeter.stop();
088: }
089:
090: /**
091: * Mark the scenario of this test case to be included both into the global
092: * and the local (component) performance summary. The summary shows the given dimension of the
093: * scenario and labels the scenario with the short name.
094: *
095: * @param shortName
096: * a short (shorter than 40 characters) descritive name of the scenario
097: * @param dimension
098: * the dimension to show in the summary
099: */
100: public void tagAsGlobalSummary(String shortName, Dimension dimension) {
101: Performance.getDefault().tagAsGlobalSummary(fPerformanceMeter,
102: shortName, new Dimension[] { dimension });
103: }
104:
105: /**
106: * Mark the scenario represented by the given PerformanceMeter to be
107: * included into the global and the local (component) performance summary. The summary shows the given
108: * dimensions of the scenario and labels the scenario with the short name.
109: *
110: * @param shortName
111: * a short (shorter than 40 characters) descritive name of the scenario
112: * @param dimensions
113: * an array of dimensions to show in the summary
114: */
115: public void tagAsGlobalSummary(String shortName,
116: Dimension[] dimensions) {
117: Performance.getDefault().tagAsGlobalSummary(fPerformanceMeter,
118: shortName, dimensions);
119: }
120:
121: /**
122: * Mark the scenario of this test case to be included into the local (component)
123: * performance summary. The summary shows the given dimension of the
124: * scenario and labels the scenario with the short name.
125: *
126: * @param shortName
127: * a short (shorter than 40 characters) descriptive name of the scenario
128: * @param dimension
129: * the dimension to show in the summary
130: */
131: public void tagAsSummary(String shortName, Dimension dimension) {
132: Performance.getDefault().tagAsSummary(fPerformanceMeter,
133: shortName, new Dimension[] { dimension });
134: }
135:
136: /**
137: * Mark the scenario represented by the given PerformanceMeter to be
138: * included into the local (component) performance summary. The summary shows the given
139: * dimensions of the scenario and labels the scenario with the short name.
140: *
141: * @param shortName
142: * a short (shorter than 40 characters) descriptive name of the scenario
143: * @param dimensions
144: * an array of dimensions to show in the summary
145: */
146: public void tagAsSummary(String shortName, Dimension[] dimensions) {
147: Performance.getDefault().tagAsSummary(fPerformanceMeter,
148: shortName, dimensions);
149: }
150:
151: /**
152: * Set a degradation comment for the current meter.
153: * @param string
154: */
155: public void setDegradationComment(String string) {
156: Performance.getDefault().setComment(fPerformanceMeter,
157: Performance.EXPLAINS_DEGRADATION_COMMENT, string);
158:
159: }
160: }
|