diff options
Diffstat (limited to 'bundles/org.eclipse.test.performance/src/org/eclipse/test/performance')
7 files changed, 0 insertions, 1053 deletions
diff --git a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/AbstractPerformanceTestCase.java b/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/AbstractPerformanceTestCase.java deleted file mode 100644 index 8ed034f2..00000000 --- a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/AbstractPerformanceTestCase.java +++ /dev/null @@ -1,155 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2020 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Copied and modified from PerformanceTestCase.java - *******************************************************************************/ - -package org.eclipse.test.performance; - -/** - * Common parts of Junit4 and Junit5 - * - * @since 3.16 - */ -public class AbstractPerformanceTestCase { - - protected PerformanceMeter fPerformanceMeter; - - /** - * Mark the scenario of this test case to be included into the global and the component performance summary. The summary shows - * the given dimension of the scenario and labels the scenario with the short name. - * - * @param shortName - * a short (shorter than 40 characters) descritive name of the scenario - * @param dimension - * the dimension to show in the summary - */ - public void tagAsGlobalSummary(String shortName, Dimension dimension) { - Performance performance = Performance.getDefault(); - performance.tagAsGlobalSummary(fPerformanceMeter, shortName, new Dimension[] { dimension }); - } - - /** - * Mark the scenario represented by the given PerformanceMeter to be included into the global and the component performance - * summary. The summary shows the given dimensions of the scenario and labels the scenario with the short name. - * - * @param shortName - * a short (shorter than 40 characters) descritive name of the scenario - * @param dimensions - * an array of dimensions to show in the summary - */ - public void tagAsGlobalSummary(String shortName, Dimension[] dimensions) { - Performance performance = Performance.getDefault(); - performance.tagAsGlobalSummary(fPerformanceMeter, shortName, dimensions); - } - - /** - * Mark the scenario of this test case to be included into the component performance summary. The summary shows the given - * dimension of the scenario and labels the scenario with the short name. - * - * @param shortName - * a short (shorter than 40 characters) descritive name of the scenario - * @param dimension - * the dimension to show in the summary - */ - public void tagAsSummary(String shortName, Dimension dimension) { - Performance performance = Performance.getDefault(); - performance.tagAsSummary(fPerformanceMeter, shortName, new Dimension[] { dimension }); - } - - /** - * Mark the scenario represented by the given PerformanceMeter to be included into the component performance summary. The - * summary shows the given dimensions of the scenario and labels the scenario with the short name. - * - * @param shortName - * a short (shorter than 40 characters) descritive name of the scenario - * @param dimensions - * an array of dimensions to show in the summary - */ - public void tagAsSummary(String shortName, Dimension[] dimensions) { - Performance performance = Performance.getDefault(); - performance.tagAsSummary(fPerformanceMeter, shortName, dimensions); - } - - /** - * Set a comment for the scenario represented by this TestCase. Currently only comments with a commentKind of - * EXPLAINS_DEGRADATION_COMMENT are used. Their commentText is shown in a hover of the performance summaries graph if a - * performance degradation exists. - * - * @param commentKind - * kind of comment. Must be EXPLAINS_DEGRADATION_COMMENT to have an effect. - * @param commentText - * the comment (shorter than 400 characters) - */ - public void setComment(int commentKind, String commentText) { - Performance performance = Performance.getDefault(); - performance.setComment(fPerformanceMeter, commentKind, commentText); - } - - /** - * Called from within a test case immediately before the code to measure is run. It starts capturing of performance data. Must - * be followed by a call to {@link AbstractPerformanceTestCase#stopMeasuring()} before subsequent calls to this method or - * {@link AbstractPerformanceTestCase#commitMeasurements()}. - * - * @see PerformanceMeter#start() - */ - protected void startMeasuring() { - fPerformanceMeter.start(); - } - - /** - * Called from within a test case immediately after the operation to measure. Must be preceded by a call to - * {@link AbstractPerformanceTestCase#startMeasuring()}, that follows any previous call to this method. - * - * @see PerformanceMeter#stop() - */ - protected void stopMeasuring() { - fPerformanceMeter.stop(); - } - - /** - * Called exactly once after repeated measurements are done and before their analysis. Afterwards - * {@link AbstractPerformanceTestCase#startMeasuring()} and {@link AbstractPerformanceTestCase#stopMeasuring()} must not be called. - * - * @see PerformanceMeter#commit() - */ - protected void commitMeasurements() { - fPerformanceMeter.commit(); - } - - /** - * Asserts default properties of the measurements captured for this test case. - * - * @throws RuntimeException - * if the properties do not hold - */ - protected void assertPerformance() { - Performance.getDefault().assertPerformance(fPerformanceMeter); - } - - /** - * Asserts that the measurement specified by the given dimension is within a certain range with respect to some reference value. - * If the specified dimension isn't available, the call has no effect. - * - * @param dim - * the Dimension to check - * @param lowerPercentage - * a negative number indicating the percentage the measured value is allowed to be smaller than some reference value - * @param upperPercentage - * a positive number indicating the percentage the measured value is allowed to be greater than some reference value - * @throws RuntimeException - * if the properties do not hold - */ - protected void assertPerformanceInRelativeBand(Dimension dim, int lowerPercentage, int upperPercentage) { - Performance.getDefault().assertPerformanceInRelativeBand(fPerformanceMeter, dim, lowerPercentage, upperPercentage); - } -} diff --git a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/Dimension.java b/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/Dimension.java deleted file mode 100644 index eca8db99..00000000 --- a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/Dimension.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.test.performance; - -import java.io.Serializable; - -import org.eclipse.test.internal.performance.InternalDimensions; - -/** - * Some predefined dimensions most likely supported on all platforms. - * - * This interface is not intended to be implemented by clients. - * - * @since 3.1 - */ -public interface Dimension extends Serializable { - - // Dimensions available on all platforms: - - /** - * The amount of time that the process has executed in kernel mode. It is calculated by taking the sum of the time that each of - * the threads of the process has executed in kernel mode. - */ - public Dimension KERNEL_TIME = InternalDimensions.KERNEL_TIME; - - /** - * The amount of CPU time used so far by this process. It is calculated by adding the KERNEL_TIME and the amount of time that - * the process has executed in user mode. The user time is calculated by taking the sum of the time that each of the threads of - * the process has executed in user mode. It does not include any time where the process is waiting for OS resources. It is the - * best approximation for ELAPSED_PROCESS (which is not available on all platforms). - */ - public Dimension CPU_TIME = InternalDimensions.CPU_TIME; - - /** - * WORKING_SET is the amount of memory in the working set of this process. The working set is the set of memory pages touched - * recently by the threads in the process. If free memory in the computer is above a threshold, pages are left in the working - * set of a process even if they are not in use. When free memory falls below a threshold, pages are removed from working sets. - */ - public Dimension WORKING_SET = InternalDimensions.WORKING_SET; - - /** - * The total elapsed time this process has been running. Since it starts at 0 on process start it can be used to measure startup - * time. On Windows it is calculated by subtracting the creation time of the process from the current system time. On Linux it - * is calculated by subtracting the value of the system property "eclipse.startTime" from System.currentTimeMillis() Please note - * that in contrast to the CPU_TIME the elapsed time of a process is influenced by other processes running in parallel. - */ - public Dimension ELAPSED_PROCESS = InternalDimensions.ELAPSED_PROCESS; - - /** - * The amount of memory used in the JVM. It is calculated by subtracting <code>Runtime.freeMemory()</code> from - * <code>Runtime.totalMemory()</code>. - */ - public Dimension USED_JAVA_HEAP = InternalDimensions.USED_JAVA_HEAP; - - // the following Dimensions not available on all platforms! - - /** - * WORKING_SET_PEAK is the maximum amount of memory in the working set of this process at any point in time. The working set is - * the set of memory pages touched recently by the threads in the process. If free memory in the computer is above a threshold, - * pages are left in the working set of a process even if they are not in use. When free memory falls below a threshold, pages - * are removed from working sets. Currently this dimension is only available on Windows. - */ - public Dimension WORKING_SET_PEAK = InternalDimensions.WORKING_SET_PEAK; - - /** - * The total amount of committed memory (for the entire machine). Committed memory is the size of virtual memory that has been - * committed (as opposed to simply reserved). Committed memory must have backing (i.e., disk) storage available, or must be - * assured never to need disk storage (because main memory is large enough to hold it.) Notice that this is an instantaneous - * count, not an average over the time interval. Currently this dimension is only available on Windows. - */ - public Dimension COMITTED = InternalDimensions.COMITTED; -} diff --git a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/Performance.java b/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/Performance.java deleted file mode 100644 index 2a964c9f..00000000 --- a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/Performance.java +++ /dev/null @@ -1,370 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.test.performance; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.test.internal.performance.InternalDimensions; -import org.eclipse.test.internal.performance.InternalPerformanceMeter; -import org.eclipse.test.internal.performance.NullPerformanceMeter; -import org.eclipse.test.internal.performance.OSPerformanceMeterFactory; -import org.eclipse.test.internal.performance.PerformanceMeterFactory; -import org.eclipse.test.internal.performance.PerformanceTestPlugin; -import org.eclipse.test.internal.performance.data.Dim; -import org.eclipse.test.internal.performance.eval.AbsoluteBandChecker; -import org.eclipse.test.internal.performance.eval.AssertChecker; -import org.eclipse.test.internal.performance.eval.Evaluator; -import org.eclipse.test.internal.performance.eval.IEvaluator; -import org.eclipse.test.internal.performance.eval.RelativeBandChecker; -import org.osgi.framework.Bundle; - -import junit.framework.TestCase; - -/** - * Helper for performance measurements. Currently provides performance meter creation and checking of measurements. - * - * This class is not intended to be subclassed by clients. - * - * @since 3.1 - */ -public class Performance { - - /** - * A comment kind of a comment that explains a performance degradation. - */ - public static final int EXPLAINS_DEGRADATION_COMMENT = 1; - - private static final String PERFORMANCE_METER_FACTORY = "/option/performanceMeterFactory"; //$NON-NLS-1$ - private static final String PERFORMANCE_METER_FACTORY_PROPERTY = "PerformanceMeterFactory"; //$NON-NLS-1$ - - private static Performance fgDefault; - - private PerformanceMeterFactory fPerformanceMeterFactory; - private IEvaluator fDefaultEvaluator; - - /** Null performance meter singleton */ - private NullPerformanceMeter fNullPeformanceMeter; - - /** - * Private constructor to block instance creation. - */ - private Performance() { - // empty - } - - /** - * Returns the singleton of <code>Performance</code> - * - * @return the singleton of <code>Performance</code> - */ - public static Performance getDefault() { - if (fgDefault == null) - fgDefault = new Performance(); - return fgDefault; - } - - /** - * Asserts default properties of the measurements captured by the given performance meter. - * - * @param performanceMeter - * the performance meter - * @throws RuntimeException - * if the properties do not hold - */ - public void assertPerformance(PerformanceMeter performanceMeter) { - if (fDefaultEvaluator == null) { - fDefaultEvaluator = new Evaluator(); - fDefaultEvaluator.setAssertCheckers(new AssertChecker[] { new RelativeBandChecker(InternalDimensions.ELAPSED_PROCESS, - 0.0f, 1.10f), - // new RelativeBandChecker(InternalDimensions.CPU_TIME, 0.0f, 1.10f), - // new RelativeBandChecker(InternalDimensions.WORKING_SET, 0.0f, 3.00f), - // new RelativeBandChecker(InternalDimensions.USED_JAVA_HEAP, 0.0f, 2.00f), - // new RelativeBandChecker(InternalDimensions.SYSTEM_TIME, 0.0f, 1.10f) - }); - } - fDefaultEvaluator.evaluate(performanceMeter); - } - - /** - * Asserts that the measurement specified by the dimension captured in the given performance meter is within a certain range - * with respect to some reference value. If the performance meter doesn't provide the specified dimension, the call has no - * effect. - * - * @param performanceMeter - * the performance meter - * @param dim - * the Dimension to check - * @param lowerPercentage - * a negative number indicating the percentage the measured value is allowed to be smaller than some reference value - * @param upperPercentage - * a positive number indicating the percentage the measured value is allowed to be greater than some reference value - * @throws RuntimeException - * if the properties do not hold - */ - public void assertPerformanceInRelativeBand(PerformanceMeter performanceMeter, Dimension dim, int lowerPercentage, - int upperPercentage) { - Evaluator e = new Evaluator(); - e.setAssertCheckers(new AssertChecker[] { new RelativeBandChecker((Dim) dim, 1.0 + (lowerPercentage / 100.0), - 1.0 + (upperPercentage / 100.0)), }); - e.evaluate(performanceMeter); - } - - /** - * Asserts that the measurement specified by the dimension captured in the given performance meter is within a certain range - * with respect to some reference value. If the performance meter doesn't provide the specified dimension, the call has no - * effect. - * - * @param performanceMeter - * the performance meter - * @param dim - * the Dimension to check - * @param lowerBand - * a negative number indicating the absolute amount the measured value is allowed to be smaller than some reference - * value - * @param upperBand - * a positive number indicating the absolute amount the measured value is allowed to be greater than some reference - * value - * @throws RuntimeException - * if the properties do not hold - */ - public void assertPerformanceInAbsoluteBand(PerformanceMeter performanceMeter, Dimension dim, int lowerBand, int upperBand) { - Evaluator e = new Evaluator(); - e.setAssertCheckers(new AssertChecker[] { new AbsoluteBandChecker((Dim) dim, lowerBand, upperBand), }); - e.evaluate(performanceMeter); - } - - /** - * Creates a performance meter for the given scenario id. - * - * @param scenarioId - * the scenario id - * @return a performance meter for the given scenario id - * @throws IllegalArgumentException - * if a performance meter for the given scenario id has already been created - */ - public PerformanceMeter createPerformanceMeter(String scenarioId) { - return getPeformanceMeterFactory().createPerformanceMeter(scenarioId); - } - - /** - * Returns the null performance meter singleton. - * - * @return the null performance meter singleton - */ - public PerformanceMeter getNullPerformanceMeter() { - if (fNullPeformanceMeter == null) - fNullPeformanceMeter = new NullPerformanceMeter(); - return fNullPeformanceMeter; - } - - /** - * Returns a default scenario id for the given test. The test's name must have been set, such that <code>test.getName()</code> - * is not <code>null</code>. - * - * @param test - * the test - * @return the default scenario id for the test - */ - public String getDefaultScenarioId(TestCase test) { - return test.getClass().getName() + '#' + test.getName() + "()"; //$NON-NLS-1$ - } - - /** - * Returns a default scenario id for the given test class. - * - * @param test - * the test class - * @return the default scenario id for the test - * @since 3.15 - */ - public String getDefaultScenarioId(Class<?> test) { - return test.getName() + '#' + test.getName() + "()"; //$NON-NLS-1$ - } - - /** - * Returns a default scenario id for the given test class. - * - * @param test - * the test class - * @param methodName - * the methodname of the test method - * @return the default scenario id for the test - * @since 3.16 - */ - public String getDefaultScenarioId(Class<?> test, String methodName) { - return test.getName() + '#' + methodName + "()"; //$NON-NLS-1$ - } - - /** - * Returns a default scenario id for the given test and id. The test's name must have been set, such that - * <code>test.getName()</code> is not <code>null</code>. The id distinguishes multiple scenarios in the same test. - * - * @param test - * the test - * @param id - * the id - * @return the default scenario id for the test and the id - */ - public String getDefaultScenarioId(TestCase test, String id) { - return getDefaultScenarioId(test) + '-' + id; - } - - private PerformanceMeterFactory getPeformanceMeterFactory() { - if (fPerformanceMeterFactory == null) - fPerformanceMeterFactory = createPerformanceMeterFactory(); - return fPerformanceMeterFactory; - } - - private PerformanceMeterFactory createPerformanceMeterFactory() { - PerformanceMeterFactory factory; - factory = tryInstantiate(System.getProperty(PERFORMANCE_METER_FACTORY_PROPERTY)); - if (factory != null) - return factory; - - factory = tryInstantiate(Platform.getDebugOption(PerformanceTestPlugin.PLUGIN_ID + PERFORMANCE_METER_FACTORY)); - if (factory != null) - return factory; - - return createDefaultPerformanceMeterFactory(); - } - - private PerformanceMeterFactory tryInstantiate(String className) { - PerformanceMeterFactory instance = null; - if (className != null && className.length() > 0) { - try { - Class<?> c = null; - if (Platform.isRunning()) { - int separator = className.indexOf(':'); - Bundle bundle = null; - if (separator == -1) { - bundle = PerformanceTestPlugin.getDefault().getBundle(); - } else { - String bundleName = className.substring(0, separator); - className = className.substring(separator + 1); - bundle = Platform.getBundle(bundleName); - } - c = bundle.loadClass(className); - } else { - c = Class.forName(className); - } - instance = (PerformanceMeterFactory) c.getDeclaredConstructor().newInstance(); - } catch ( - ClassNotFoundException | - InstantiationException | - IllegalAccessException | - ClassCastException | - IllegalArgumentException | - InvocationTargetException | - NoSuchMethodException | - SecurityException e) { - PerformanceTestPlugin.log(e); - } - } - return instance; - } - - private PerformanceMeterFactory createDefaultPerformanceMeterFactory() { - return new OSPerformanceMeterFactory(); - } - - /** - * Mark the scenario represented by the given PerformanceMeter to be included into the global and the component performance - * summary. The summary shows the given dimension of the scenario and labels the scenario with the short name. - * - * @param pm - * the PerformanceMeter - * @param shortName - * a short (shorter than 40 characters) descriptive name of the scenario - * @param dimension - * the dimension to show in the summary - */ - public void tagAsGlobalSummary(PerformanceMeter pm, String shortName, Dimension dimension) { - tagAsGlobalSummary(pm, shortName, new Dimension[] { dimension }); - } - - /** - * Mark the scenario represented by the given PerformanceMeter to be included into the global and the component performance - * summary. The summary shows the given dimensions of the scenario and labels the scenario with the short name. - * - * @param pm - * the PerformanceMeter - * @param shortName - * a short (shorter than 40 characters) descriptive name of the scenario - * @param dimensions - * an array of dimensions to show in the summary - */ - public void tagAsGlobalSummary(PerformanceMeter pm, String shortName, Dimension[] dimensions) { - if (pm instanceof InternalPerformanceMeter) { - InternalPerformanceMeter ipm = (InternalPerformanceMeter) pm; - ipm.tagAsSummary(true, shortName, dimensions); - } - } - - /** - * Mark the scenario represented by the given PerformanceMeter to be included into the component performance summary. The - * summary shows the given dimension of the scenario and labels the scenario with the short name. - * - * @param pm - * the PerformanceMeter - * @param shortName - * a short (shorter than 40 characters) descriptive name of the scenario - * @param dimension - * the dimension to show in the summary - */ - public void tagAsSummary(PerformanceMeter pm, String shortName, Dimension dimension) { - tagAsSummary(pm, shortName, new Dimension[] { dimension }); - } - - /** - * Mark the scenario represented by the given PerformanceMeter to be included into the component performance summary. The - * summary shows the given dimensions of the scenario and labels the scenario with the short name. - * - * @param pm - * the PerformanceMeter - * @param shortName - * a short (shorter than 40 characters) descriptive name of the scenario - * @param dimensions - * an array of dimensions to show in the summary - */ - public void tagAsSummary(PerformanceMeter pm, String shortName, Dimension[] dimensions) { - if (pm instanceof InternalPerformanceMeter) { - InternalPerformanceMeter ipm = (InternalPerformanceMeter) pm; - ipm.tagAsSummary(false, shortName, dimensions); - } - } - - /** - * Set a comment for the scenario represented by the given PerformanceMeter. Currently only comments with a commentKind of - * EXPLAINS_DEGRADATION_COMMENT are used. Their commentText is shown in a hover of the performance summaries graph if a - * performance degradation exists. - * - * @param pm - * the PerformanceMeter - * @param commentKind - * kind of comment. Must be EXPLAINS_DEGRADATION_COMMENT to have an effect. - * @param commentText - * the comment (shorter than 400 characters) - */ - public void setComment(PerformanceMeter pm, int commentKind, String commentText) { - if (commentKind == EXPLAINS_DEGRADATION_COMMENT) { - if (pm instanceof InternalPerformanceMeter) { - InternalPerformanceMeter ipm = (InternalPerformanceMeter) pm; - ipm.setComment(commentKind, commentText); - } - } - } - -} diff --git a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/PerformanceMeter.java b/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/PerformanceMeter.java deleted file mode 100644 index ac6e49aa..00000000 --- a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/PerformanceMeter.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.test.performance; - -/** - * A <code>PerformanceMeter</code> is used for doing repeated measurements of an arbitrary operation. - * - * The kind of measurement and the retrieval of the results remain internal to the implementation. Measurements can include time, - * CPU cycle and memory consumption. - * - * A <code>PerformanceMeter</code> is created using the method {@link Performance#createPerformanceMeter(String)}. An operation is - * measured by calling {@link PerformanceMeter#start()} before and {@link PerformanceMeter#stop()} after that operation. The - * measurement can be repeated, for example, to let the VM warm up and to allow for statistical analysis afterwards. - * - * After measurements are done and before an analysis of the results can be made {@link PerformanceMeter#commit()} has to be called. - * This allows for example to prepare the measurements for analysis or persist them. - * {@link Performance#assertPerformance(PerformanceMeter)} provides a default analysis of the measurements. After the - * <code>PerformanceMeter</code> is no longer used {@link PerformanceMeter#dispose()} must be called. - * - * Example usage in a test case: - * - * <pre> - * - * public void testOpenEditor() { - * Performance perf = Performance.getDefault(); - * PerformanceMeter performanceMeter = perf.createPerformanceMeter(perf.getDefaultScenarioId(this)); - * try { - * for (int i = 0; i < 10; i++) { - * performanceMeter.start(); - * openEditor(); - * performanceMeter.stop(); - * closeEditor(); - * } - * performanceMeter.commit(); - * perf.assertPerformance(performanceMeter); - * } - * finally { - * performanceMeter.dispose(); - * } - * } - * </pre> - * - * This class is not intended to be subclassed by clients. - */ -public abstract class PerformanceMeter { - - /** - * Called immediately before the operation to measure. Must be followed by a call to {@link PerformanceMeter#stop()} before - * subsequent calls to this method or {@link PerformanceMeter#commit()}. - */ - public abstract void start(); - - /** - * Called immediately after the operation to measure. Must be preceded by a call to {@link PerformanceMeter#start()}, that - * follows any previous call to this method. - */ - public abstract void stop(); - - /** - * Called exactly once after repeated measurements are done and before their analysis. Afterwards - * {@link PerformanceMeter#start()} and {@link PerformanceMeter#stop()} must not be called. - */ - public abstract void commit(); - - /** - * Dispose associated resources. Clients must call this method exactly once. Afterwards no methods must be called on the - * performance meter. - */ - public abstract void dispose(); -} diff --git a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/PerformanceTestCase.java b/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/PerformanceTestCase.java deleted file mode 100644 index 84afb267..00000000 --- a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/PerformanceTestCase.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.test.performance; - -import junit.framework.TestCase; - -/** - * A PerformanceTestCase is a convenience class that takes care of managing a <code>PerformanceMeter</code>. - * <p> - * Here is an example: - * - * <pre> - * public class MyPerformanceTestCase extends PeformanceTestCase { - * - * public void testMyOperation() { - * for (int i= 0; i < 10; i++) { - * // preparation - * startMeasuring(); - * // my operation - * stopMeasuring(); - * // clean up - * } - * commitMeasurements(); - * assertPerformance(); - * } - * } - */ -public class PerformanceTestCase extends TestCase { - - protected PerformanceMeter fPerformanceMeter; - - /** - * Constructs a performance test case. - */ - public PerformanceTestCase() { - super(); - } - - /** - * Constructs a performance test case with the given name. - * - * @param name - * the name of the performance test case - */ - public PerformanceTestCase(String name) { - super(name); - } - - /** - * Overridden to create a default performance meter for this test case. - * - * @throws Exception - */ - @Override - protected void setUp() throws Exception { - Performance performance = Performance.getDefault(); - fPerformanceMeter = performance.createPerformanceMeter(performance.getDefaultScenarioId(this)); - } - - /** - * Overridden to dispose of the performance meter. - * - * @throws Exception - */ - @Override - protected void tearDown() throws Exception { - fPerformanceMeter.dispose(); - } - - /** - * Mark the scenario of this test case to be included into the global and the component performance summary. The summary shows - * the given dimension of the scenario and labels the scenario with the short name. - * - * @param shortName - * a short (shorter than 40 characters) descritive name of the scenario - * @param dimension - * the dimension to show in the summary - */ - public void tagAsGlobalSummary(String shortName, Dimension dimension) { - Performance performance = Performance.getDefault(); - performance.tagAsGlobalSummary(fPerformanceMeter, shortName, new Dimension[] { dimension }); - } - - /** - * Mark the scenario represented by the given PerformanceMeter to be included into the global and the component performance - * summary. The summary shows the given dimensions of the scenario and labels the scenario with the short name. - * - * @param shortName - * a short (shorter than 40 characters) descritive name of the scenario - * @param dimensions - * an array of dimensions to show in the summary - */ - public void tagAsGlobalSummary(String shortName, Dimension[] dimensions) { - Performance performance = Performance.getDefault(); - performance.tagAsGlobalSummary(fPerformanceMeter, shortName, dimensions); - } - - /** - * Mark the scenario of this test case to be included into the component performance summary. The summary shows the given - * dimension of the scenario and labels the scenario with the short name. - * - * @param shortName - * a short (shorter than 40 characters) descritive name of the scenario - * @param dimension - * the dimension to show in the summary - */ - public void tagAsSummary(String shortName, Dimension dimension) { - Performance performance = Performance.getDefault(); - performance.tagAsSummary(fPerformanceMeter, shortName, new Dimension[] { dimension }); - } - - /** - * Mark the scenario represented by the given PerformanceMeter to be included into the component performance summary. The - * summary shows the given dimensions of the scenario and labels the scenario with the short name. - * - * @param shortName - * a short (shorter than 40 characters) descritive name of the scenario - * @param dimensions - * an array of dimensions to show in the summary - */ - public void tagAsSummary(String shortName, Dimension[] dimensions) { - Performance performance = Performance.getDefault(); - performance.tagAsSummary(fPerformanceMeter, shortName, dimensions); - } - - /** - * Set a comment for the scenario represented by this TestCase. Currently only comments with a commentKind of - * EXPLAINS_DEGRADATION_COMMENT are used. Their commentText is shown in a hover of the performance summaries graph if a - * performance degradation exists. - * - * @param commentKind - * kind of comment. Must be EXPLAINS_DEGRADATION_COMMENT to have an effect. - * @param commentText - * the comment (shorter than 400 characters) - */ - public void setComment(int commentKind, String commentText) { - Performance performance = Performance.getDefault(); - performance.setComment(fPerformanceMeter, commentKind, commentText); - } - - /** - * Called from within a test case immediately before the code to measure is run. It starts capturing of performance data. Must - * be followed by a call to {@link PerformanceTestCase#stopMeasuring()} before subsequent calls to this method or - * {@link PerformanceTestCase#commitMeasurements()}. - * - * @see PerformanceMeter#start() - */ - protected void startMeasuring() { - fPerformanceMeter.start(); - } - - /** - * Called from within a test case immediately after the operation to measure. Must be preceded by a call to - * {@link PerformanceTestCase#startMeasuring()}, that follows any previous call to this method. - * - * @see PerformanceMeter#stop() - */ - protected void stopMeasuring() { - fPerformanceMeter.stop(); - } - - /** - * Called exactly once after repeated measurements are done and before their analysis. Afterwards - * {@link PerformanceTestCase#startMeasuring()} and {@link PerformanceTestCase#stopMeasuring()} must not be called. - * - * @see PerformanceMeter#commit() - */ - protected void commitMeasurements() { - fPerformanceMeter.commit(); - } - - /** - * Asserts default properties of the measurements captured for this test case. - * - * @throws RuntimeException - * if the properties do not hold - */ - protected void assertPerformance() { - Performance.getDefault().assertPerformance(fPerformanceMeter); - } - - /** - * Asserts that the measurement specified by the given dimension is within a certain range with respect to some reference value. - * If the specified dimension isn't available, the call has no effect. - * - * @param dim - * the Dimension to check - * @param lowerPercentage - * a negative number indicating the percentage the measured value is allowed to be smaller than some reference value - * @param upperPercentage - * a positive number indicating the percentage the measured value is allowed to be greater than some reference value - * @throws RuntimeException - * if the properties do not hold - */ - protected void assertPerformanceInRelativeBand(Dimension dim, int lowerPercentage, int upperPercentage) { - Performance.getDefault().assertPerformanceInRelativeBand(fPerformanceMeter, dim, lowerPercentage, upperPercentage); - } -} diff --git a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/PerformanceTestCaseJunit4.java b/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/PerformanceTestCaseJunit4.java deleted file mode 100644 index 6605ce15..00000000 --- a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/PerformanceTestCaseJunit4.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Copied and modified for Junit4 from PerformanceTestCase.java - *******************************************************************************/ - -package org.eclipse.test.performance; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.TestName; - -/** - * A PerformanceTestCaseJunit4 is a convenience class that takes care of managing a <code>PerformanceMeter</code>. - * <p> - * Here is an example: - * - * <blockquote> - * - * <pre> - * public class MyPerformanceTestCase extends PerformanceTestCaseJunit4 { - * - * @Test - * public void testMyOperation() { - * for (int i = 0; i < 10; i++) { - * // preparation - * startMeasuring(); - * // my operation - * stopMeasuring(); - * // clean up - * } - * commitMeasurements(); - * assertPerformance(); - * } - * } - * </pre> - * - * </blockquote> - * - * @since 3.16 - */ -public class PerformanceTestCaseJunit4 extends AbstractPerformanceTestCase { - - @Rule - public TestName tn = new TestName(); - - /** - * Create a default performance meter for this test case. - * - * @throws Exception - */ - @Before - public void setUp() throws Exception { - Performance performance = Performance.getDefault(); - fPerformanceMeter = performance.createPerformanceMeter(performance.getDefaultScenarioId(this.getClass(), tn.getMethodName())); - } - - /** - * Dispose of the performance meter. - * - * @throws Exception - */ - @After - public void tearDown() throws Exception { - fPerformanceMeter.dispose(); - } -} diff --git a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/PerformanceTestCaseJunit5.java b/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/PerformanceTestCaseJunit5.java deleted file mode 100644 index 9d39cfa4..00000000 --- a/bundles/org.eclipse.test.performance/src/org/eclipse/test/performance/PerformanceTestCaseJunit5.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Copied and modified for Junit4 from PerformanceTestCase.java - *******************************************************************************/ - -package org.eclipse.test.performance; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.TestInfo; - -/** - * A PerformanceTestCaseJunit5 is a convenience class that takes care of managing a <code>PerformanceMeter</code>. - * <p> - * Here is an example: - * - * <blockquote> - * - * <pre> - * public class MyPerformanceTestCase extends PerformanceTestCaseJunit% { - * - * @Test - * public void testMyOperation() { - * for (int i = 0; i < 10; i++) { - * // preparation - * startMeasuring(); - * // my operation - * stopMeasuring(); - * // clean up - * } - * commitMeasurements(); - * assertPerformance(); - * } - * } - * </pre> - * - * </blockquote> - * - * @since 3.16 - */ -public class PerformanceTestCaseJunit5 extends AbstractPerformanceTestCase { - - /** - * Create a default performance meter for this test case. - * - * @param testInfo - * - * @throws Exception - */ - @BeforeEach - public void setUp(TestInfo testInfo) throws Exception { - Performance performance = Performance.getDefault(); - fPerformanceMeter = performance.createPerformanceMeter(performance.getDefaultScenarioId(this.getClass(), testInfo.getDisplayName())); - } - - /** - * Dispose of the performance meter. - * - * @throws Exception - */ - @AfterEach - public void tearDown() throws Exception { - fPerformanceMeter.dispose(); - } -} |