By Sonia Dimitrov, Christof Marti, Andre Weinand
2005/02/24
The Eclipse performance test plugin (org.eclipse.test.performance) provides infrastructure for instrumenting programs to collect performance data and to assert that performance doesn't drop below a baseline. The infrastructure is supported on Windows, Linux, and MacOS X.
The first part of this document describes how performance tests are written and executed, the second part explains how performance data is collected in a database and how this database is installed and configured.
public void testMyOperation() { Performance perf= Performance.getDefault(); PerformanceMeter performanceMeter= perf.createPerformanceMeter(perf.getDefaultScenarioId(this)); try { for (int i= 0; i < 10; i++) { performanceMeter.start(); toMeasure(); performanceMeter.stop(); } performanceMeter.commit(); perf.assertPerformance(performanceMeter); } finally { performanceMeter.dispose(); } }
PerformanceTestCase
which is a convenience class that makes the
use of PerformanceMeter
transparent:
public class MyPerformanceTestCase extends PeformanceTestCase { public void testMyOperation() { for (int i= 0; i < 10; i++) { startMeasuring(); toMeasure(); stopMeasuring(); } commitMeasurements(); assertPerformance(); } }
createPerformanceMeter(...)
must be unique in a single test run
and must be the same for each build. This enables comparisons between builds.
The Peformance#getDefaultScenarioId(...)
methods are provided for convenience.
PerformanceMeter
supports repeated measurements by multiple invocations
of the start()
, stop()
sequence. The call
to commit()
is required before evaluation with assertPerformance()
and dispose()
is required before releasing the meter.
for
-loop will generally take more time because the
code is not optimized by the JIT compiler yet. This can introduce some variance to the
measurements, especially if other tests run before and change in some way that affects
the JIT's optimization of the measured code. A simple way to stabilize the measurements
is to run the code a few times before the measurements start. Caches also need special
caution as they can affect the measurements.
A summary bar chart shows the performance development of about 20 tests relative to a reference build in an easy to grasp red/green presentation.
So dependent on the total number of components every Eclipse component can tag one or two tests for inclusion in a global and up to 20 for a local performance summary. Tests marked for the global summary are automatically included for a local summary.
Marking a test for inclusion is done by passing a performance meter into the method Performance.tagAsGlobalSummary(...) or Performance.tagAsSummary(...). Both methods should be called outside of start/stop calls but it must be called before the the call to commit().
// .... Performance perf= Performance.getDefault(); PerformanceMeter pm= perf.createPerformanceMeter(perf.getDefaultScenarioId(this)); perf.tagAsGlobalSummary(pm, "A Short Name", Dimension.CPU_TIME); try { // ...
In order to keep the overview graph small, only a single dimension (CPU_TIME, USED_JAVA_HEAP etc.) of
the test's data is shown and only a short name is used to label the
data (instead of the rather long scenario ID). Both the short label as
well as the dimension must be supplied in the calls to tagAsGlobalSummary and tagAsSummary.
The available dimensions can be found in org.eclipse.test.performance.Dimension
.
The PerformanceTestCase provides similar methods that must be called before startMeasuring():
public class MyPerformanceTestCase extends PerformanceTestCase { public void testMyOperation() { tagAsSummary("A Short Name", Dimension.CPU_TIME); for (int i= 0; i < 10; i++) { startMeasuring(); toMeasure(); stopMeasuring(); } commitMeasurements(); assertPerformance(); } }
commit()
. This is
surpressed if performance tests are configured to store data in the
database (see below).
@echo off REM Installation paths SET ECLIPSEPATH=c:\eclipse SET JVMPATH=c:\jdk\jdk1.4.2_05 REM Paths, relative to ECLIPSEPATH SET BUILD=I200411050810 SET WORKSPACE=workspace\performance REM Test SET TESTPLUGIN=org.eclipse.jdt.text.tests SET TESTCLASS=org.eclipse.jdt.text.tests.performance.OpenQuickOutlineTest REM For headless tests use: org.eclipse.test.coretestapplication SET APPLICATION=org.eclipse.test.uitestapplication REM Add -clean when the installation changes SET OPTIONS=-console -consolelog -showlocation SET JVMOPTIONS=-Xms256M -Xmx256M ECHO Build: %ECLIPSEPATH%\%BUILD% ECHO Workspace: %ECLIPSEPATH%\%WORKSPACE% ECHO Test: %TESTPLUGIN%\%TESTCLASS% %JVMPATH%\bin\java %JVMOPTIONS% -cp %ECLIPSEPATH%\%BUILD%\startup.jar org.eclipse.core.launcher.Main %OPTIONS% -application %APPLICATION% -data %ECLIPSEPATH%\%WORKSPACE% -testPluginName %TESTPLUGIN% -className %TESTCLASS% pause
test.xml
of your test plug-in already exists
and looks similar to the jdt.text.tests
' one, add targets
similar to those shown below. The performance
target is
the entry point for performance testing like the run
target
is for correctness testing.
<!-- This target defines the performance tests that need to be run. --> <target name="performance-suite"> <property name="your-performance-folder" value="${eclipse-home}/your_performance_folder"/> <delete dir="${your-performance-folder}" quiet="true"/> <ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}"> <property name="data-dir" value="${your-performance-folder}"/> <property name="plugin-name" value="${plugin-name}"/> <property name="classname" value="<your fully qualified test case class name>"/> </ant> </target> <!-- This target runs the performance test suite. Any actions that need to happen --> <!-- after all the tests have been run should go here. --> <target name="performance" depends="init,performance-suite,cleanup"> <ant target="collect" antfile="${library-file}" dir="${eclipse-home}"> <property name="includes" value="org*.xml"/> <property name="output-file" value="${plugin-name}.xml"/> </ant> </target>Notes:
test.xml
as described above
java -jar <an eclipse install>/startup.jar -application org.eclipse.ant.core.antRunner -file <target eclipse install/plugins/your test plug-in id_version>/test.xml performance -Dos=<os> -Dws=<ws> -Darch=<arch> -Declipse_home=<target eclipse install> "-Dvmargs=-Xms256M -Xmx256M" -logger org.apache.tools.ant.DefaultLogger
Derby is a database engine written in Java that can be accessed via JDBC. Derby is easily embeddable in Java programs or can run as a network server.
This section describes how to install Derby and how to configure the performance test plugin to use Derby.
The performance plugin has an optional prereq for a "org.apche.derby"
library project. Since it is optional, you won't see any compile time
errors when loading the performance plugin from the Eclipse repository
and the Derby project is not available in your workspace. However
you'll see runtime errors when running the tests and trying to access
the database.
If you have access to the following repository you can get the org.apache.derby library project from there:
:pserver:anonymous@ottcvs1.ott.oti.com:/home/cvs/zrheclipseOtherwise get Derby from here. Unpack the archive to any directory.
<?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.0"?> <plugin id="org.apache.derby" name="Derby" version="1.0.0"> <runtime> <library name="db2jcc.jar"> <export name="*"/> </library> <library name="db2jcc_license_c.jar"> <export name="*"/> </library> <library name="derby.jar"> <export name="*"/> </library> <library name="derbynet.jar"> <export name="*"/> </library> <library name="derbytools.jar"> <export name="*"/> </library> </runtime> </plugin>In addition you'll need to load the performance plugin (org.eclipse.test.performance) and if you are running on Windows the associated fragment (org.eclipse.test.performance.win32).
The eclipse.perf.dbloc specifies where the Derby DB is located. If no value is given
-Declipse.perf.dbloc=Derby runs in embedded mode (not as a separate server) and the DB will live in your home directory.
If an absolute or relative path is given, Derby uses or creates the DB in that location. E.g. with (Linux and MacOS X)
-Declipse.perf.dbloc=/tmp/derbyDerby runs in embedded mode and creates the database under /tmp/derby.
To connect to a Derby server running locally (or remotely) use the following:
-Declipse.perf.dbloc=net://tcp-ip addressWith the properties eclipse.perf.config and eclipse.perf.assertAgainst you specify the name under which performance data is stored in the database and the name of the reference data to compare against. This "name" is not a single string but a set of key/value pairs separated by semicolons:
-Declipse.perf.config=key1=value1;key2=value2;...;keyn=valuen -Declipse.perf.assertAgainst=key1=value1;key2=value2;...;keyn=valuenThe key/value pairs can be used to associate the collected performance data with information about the configuration that was used to generate the data. Typically this includes the name of the build, the system on which the test were run, or the used Java VM. So in this example:
-Declipse.perf.config=build=N20040914;host=relengwin;jvm=j9performance data for the nightly build N20040914 is stored in the database under a "name" that consist of three key/value pairs.
To assert that performance data collected for another build does not degrade with respect to some reference data the assertAgainst property is used similarly:
-Declipse.perf.assertAgainst=build=R3.0;host=relengwin;jvm=j9This property enables any "assertPerformance" calls in your performance tests and compares the newly measured data against the data specified by the three key/value pairs. Please note that the order of the pairs does not matter when looking up the data in the database. However, the number of key/value pairs must be identical.
Because in most cases you want to store newly collected data as well as assert against other reference data at the same time you'll need to specify both properties. In this case only those key/value pairs must be listed in the assertAgainst property, that differ from the config property:
-Declipse.perf.config=build=N20040914;host=relengwin -Declipse.perf.assertAgainst=build=R3.0So in the example from above the new performance data is stored in the database under the build name "N20040914" and the host "relengwin" and the "assertPerformance" compares this data against data tagged with a build name of "R3.0" and an implicitely specified host "relengwin".
If you want to assert the average of multiple runs (instead of the data of a single run) against the reference data, do the following:
// Run program 4 times to collect data under build name "I20040914" ... -Declipse.perf.config=build=I20040914 ... -Declipse.perf.config=build=I20040914 ... -Declipse.perf.config=build=I20040914 ... -Declipse.perf.config=build=I20040914 // Run program a 5th time and collect more data under I20040914 // and assert the average of 5 runs of I20040914 against some baseline data ... -Declipse.perf.config=build=I20040914 -Declipse.perf.assertAgainst=build=R3.0
org.eclipse.test.internal.performance.db.View
that can be run as a standalone program for viewing the data contained in the database in a tabular format.
You need to specify the database location via the eclipse.perf.dbloc
property (most easily done via a launch configuration).
Select the data to view by either specifying a variation via the eclipse.perf.config
property or
by directly setting the key/value pairs of the variation at the beginning of the program's main
method.
If you only want to view specific scenarios, use an appropriate pattern for the local variable scenarioPattern
.
The local variable seriesKey
specifies what variation is shown on the x-axis of the table.
So the following setup:
public class View { public static void main(String[] args) { Variations variations= PerformanceTestPlugin.getVariations(); variations.put("host", "relengwin"); variations.put("build", "I%"); String scenarioPattern= "%RevertJavaEditorTest%"; String seriesKey= "build"; // ...creates a table showing all dimensions of the (single) scenario selected by the pattern "
%testRevertJavaEditor%
" for all integration builds (that is builds starting with a capital 'I').
Scenario: org.eclipse.jdt.text.tests.performance.RevertJavaEditorTest#testRevertJavaEditor() Builds: I200409240800 I200409281200 I200410050800 I200410190941 I200410260800 CPU Time: 1.02 s [284 ms] 1.05 s [327 ms] 971 ms 1 s 481 ms Committed: 69K [246K] 119K [389K] 103K 111K -97484 Elapsed Process: 1.02 s [286 ms] 1.07 s [345 ms] 981 ms 1.01 s 481 ms Kernel time: 41 ms [27 ms] 48 ms [40 ms] 46 ms 28 ms 22 ms Page Faults: 145 [125] 148 [125] 176 191 143 System Time: 1.02 s [285 ms] 1.06 s [345 ms] 981 ms 1.01 s 477 msIf you are interested in creating performance charts and tables similar to those available on the eclipse platform download pages, you could try the stand-alone java program org.eclipse.test.performance.ui.Main stored in the org.eclipse.releng.basebuilder project. Refer to the readme.html in org.eclipse.releng.basebuilder/plugins/org.eclipse.test.performance.ui for more details.
org.eclipse.test.performance
and install it on the server
(rename it to "derby" and make it executable; if you've checked out the
file on Windows and copied it to Linux,
it might be necessary to convert line delimiters with the dos2unix
tool).
The script simplifies the usage of the Derby tools - especially
starting and stopping the server - because
it sets the correct classpath and some important properties.
CSLIB
, DBROOT
,
and JAVA
to your installation. CSLIB
should point to the directory
containing the Derby jars.
If you've used the Derby installer, then this is the lib directory
inside the Cloudscape 10.0 directory.
If you are using the org.apache.derby project from the repository, then this
is just the project folder.
derby start &to launch the server in background. The server will send this to stdout:
Server is ready to accept connections on port 1527.to the console.
derby stop