KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > test > performance > PerformanceMeter


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
12 package org.eclipse.test.performance;
13
14 /**
15  * A <code>PerformanceMeter</code> is used for doing repeated measurements of
16  * an arbitrary operation.
17  *
18  * The kind of measurement and the retrieval of the results remain internal to
19  * the implementation. Measurements can include time, CPU cycle and memory
20  * consumption.
21  *
22  * A <code>PerformanceMeter</code> is created using the method
23  * {@link Performance#createPerformanceMeter(String)}. An operation is measured
24  * by calling {@link PerformanceMeter#start()} before and
25  * {@link PerformanceMeter#stop()} after that operation. The measurement can be
26  * repeated, for example, to let the VM warm up and to allow for statistical
27  * analysis afterwards.
28  *
29  * After measurements are done and before an analysis of the results can be made
30  * {@link PerformanceMeter#commit()} has to be called. This allows for example
31  * to prepare the measurements for analysis or persist them.
32  * {@link Performance#assertPerformance(PerformanceMeter)} provides a default
33  * analysis of the measurements. After the <code>PerformanceMeter</code> is no
34  * longer used {@link PerformanceMeter#dispose()} must be called.
35  *
36  * Example usage in a test case:
37  * <pre>
38  * public void testOpenEditor() {
39  * Performance perf= Performance.getDefault();
40  * PerformanceMeter performanceMeter= perf.createPerformanceMeter(perf.getDefaultScenarioId(this));
41  * try {
42  * for (int i= 0; i &lt; 10; i++) {
43  * performanceMeter.start();
44  * openEditor();
45  * performanceMeter.stop();
46  * closeEditor();
47  * }
48  * performanceMeter.commit();
49  * perf.assertPerformance(performanceMeter);
50  * } finally {
51  * performanceMeter.dispose();
52  * }
53  * }
54  * </pre>
55  *
56  * This class is not intended to be subclassed by clients.
57  */

58 public abstract class PerformanceMeter {
59
60     /**
61      * Called immediately before the operation to measure. Must be followed
62      * by a call to {@link PerformanceMeter#stop()} before subsequent calls
63      * to this method or {@link PerformanceMeter#commit()}.
64      */

65     public abstract void start();
66
67     /**
68      * Called immediately after the operation to measure. Must be preceded
69      * by a call to {@link PerformanceMeter#start()}, that follows any
70      * previous call to this method.
71      */

72     public abstract void stop();
73
74     /**
75      * Called exactly once after repeated measurements are done and before
76      * their analysis. Afterwards {@link PerformanceMeter#start()} and
77      * {@link PerformanceMeter#stop()} must not be called.
78      */

79     public abstract void commit();
80
81     /**
82      * Dispose associated resources. Clients must call this method exactly
83      * once. Afterwards no methods must be called on the performance meter.
84      */

85     public abstract void dispose();
86 }
87
Popular Tags