001: // $Id: AllLocationsMeasurement.java,v 1.2 2004/05/12 17:26:52 anicoara Exp $
002: // =====================================================================
003: //
004: // (history at end)
005: //
006:
007: package measurements.suites;
008:
009: import junit.framework.Assert;
010: import junit.framework.Test;
011: import ch.ethz.inf.util.junit.PerformanceTest;
012: import ch.ethz.inf.util.junit.PerformanceTestSuite;
013: import ch.ethz.prose.*;
014: import ch.ethz.prose.crosscut.Crosscut;
015: import ch.ethz.prose.crosscut.MethodCut;
016: import ch.ethz.prose.filter.*;
017:
018: /**
019: * JUnit performs a suite of measurements for local interceptions
020: * of a method using <em>AllLocationsCrosscut</em>.
021: *
022: * The test can be used both in native and in runes mode.
023: * In both native and runes mode, the test
024: * <code>testLocalCall</code> calls a number of <code>RUNS</code>
025: * time a void method.
026: *
027: * If RUNES in enabled, the following measurements are meaningfull
028: * <ul>
029: * <li> <code>testLocalCallsNormal</code>: measure how much it takes
030: * to call RUNS times a trapped function while extracting argument values
031: * <li> <code>testLocalCallsFast</code>: measure how much it takes
032: * to call RUNS times a trapped function without retrieving the actual
033: * arguments from the stack.
034: * </ul>
035: *
036: * @version $Revision: 1.2 $
037: * @author Andrei Popovici
038: */
039: public class AllLocationsMeasurement extends PerformanceTest {
040:
041: // fixture
042: public void theMethodToCall() {
043: int a;
044: a = 1;
045: };
046:
047: public static class TrapMethodAspect1 extends DefaultAspect {
048: public static class TrapMethodCrossc1 extends MethodCut {
049: public void METHOD_ARGS() {
050: }
051:
052: protected PointCutter pointCutter() {
053: PointCutter x = Executions.before().AND(
054: Within.method("theMethodToCall"));
055: return x.AND(Within.type("AllLocationsMeasurement"));
056: }
057: }
058:
059: public Crosscut c1 = new TrapMethodCrossc1();
060: }
061:
062: public static class TrapMethodAspect2 extends DefaultAspect {
063: public static class TrapMethodCrossc2 extends MethodCut {
064:
065: public void METHOD_ARGS() {
066: }
067:
068: protected PointCutter pointCutter() {
069: PointCutter x = Executions.before().AND(
070: Within.method("theMethodToCall"));
071: return x.AND(Within.type("AllLocationsMeasurement"));
072: }
073:
074: public void joinPointAction(
075: ch.ethz.jvmai.MethodEntryJoinPoint x) {
076: }
077: }
078:
079: public Crosscut c2 = new TrapMethodCrossc2();
080: }
081:
082: Aspect x1;
083: Aspect x2;
084: final boolean useProse;
085:
086: /**
087: * Construct test with given name.
088: * @param name test name
089: */
090: public AllLocationsMeasurement(String name) {
091: super (name);
092:
093: String proseParam = System.getProperty("useprose");
094: if (proseParam == null)
095: useProse = isDebuggerEnabled();
096: else
097: useProse = proseParam.toUpperCase().equals("TRUE");
098:
099: if (useProse)
100: RANGE = new int[] { 1000000 };
101: else
102: RANGE = new int[] { 1000000 };
103:
104: }
105:
106: /**
107: * Set up fixture.
108: */
109: protected void setUp() {
110: if (!useProse)
111: return;
112:
113: x1 = new TrapMethodAspect1();
114: x2 = new TrapMethodAspect2();
115: try {
116: ProseSystem.startup();
117: } catch (Exception e) {
118: Assert.fail("ProseSystem.startup() failed");
119: }
120: }
121:
122: protected void tearDown() {
123: if (!useProse)
124: return;
125:
126: try {
127: ProseSystem.teardown();
128: } catch (Exception e) {
129: Assert.fail("ProseSystem.teardown() failed");
130: }
131: }
132:
133: public void testLocalCallsNormal() {
134: if (useProse)
135: ProseSystem.getAspectManager().insert(x1);
136:
137: startChronometer();
138: for (int i = 0; i < RUNS; i++)
139: this .theMethodToCall();
140: stopChronometer();
141:
142: if (useProse)
143: ProseSystem.getAspectManager().withdraw(x1);
144: }
145:
146: public void testLocalCallsFast() {
147: if (useProse)
148: ProseSystem.getAspectManager().insert(x2);
149:
150: startChronometer();
151: for (int i = 0; i < RUNS; i++)
152: this .theMethodToCall();
153: stopChronometer();
154:
155: if (useProse)
156: ProseSystem.getAspectManager().withdraw(x2);
157: }
158:
159: /**
160: * Test suite.
161: * @return test instance
162: */
163: public static Test suite() {
164: return new PerformanceTestSuite(AllLocationsMeasurement.class);
165: }
166:
167: }
168:
169: //======================================================================
170: //
171: // $Log: AllLocationsMeasurement.java,v $
172: // Revision 1.2 2004/05/12 17:26:52 anicoara
173: // Adapt Junit tests to 3.8.1 version and the new package structure
174: //
175: // Revision 1.1.1.1 2003/07/02 15:30:45 apopovic
176: // Imported from ETH Zurich
177: //
178: // Revision 1.18 2003/05/05 14:03:03 popovici
179: // renaming from runes to prose
180: //
181: // Revision 1.17 2003/04/27 13:08:58 popovici
182: // Specializers renamed to PointCutter
183: //
184: // Revision 1.16 2003/04/17 15:14:53 popovici
185: // Extension->Aspect renaming
186: //
187: // Revision 1.15 2003/04/17 13:54:30 popovici
188: // Refactorization of 'ExecutionS' into 'Within' and 'Executions'.
189: // Method names refer now to 'types'
190: //
191: // Revision 1.14 2003/04/17 12:49:17 popovici
192: // Refactoring of the crosscut package
193: // ExceptionCut renamed to ThrowCut
194: // McutSignature is now SignaturePattern
195: //
196: // Revision 1.13 2003/04/17 08:46:56 popovici
197: // Important functionality additions
198: // - Cflow specializers
199: // - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
200: // - Transactional capabilities
201: // - Total refactoring of Specializer evaluation, which permits fine-grained distinction
202: // between static and dynamic specializers.
203: // - Functionality pulled up in abstract classes
204: // - Uniformization of advice methods patterns and names
205: //
206: // Revision 1.12 2003/03/04 18:35:59 popovici
207: // Organization of imprts
208: //
209: // Revision 1.11 2003/03/04 11:26:08 popovici
210: // Important refactorization step (march):
211: // - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
212: // - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
213: // structures
214: //
215: // Revision 1.10 2002/11/26 17:15:49 pschoch
216: // RootComponent now added (replaces RootComponent now added (replaces old ProseSystem)
217: // ProseSystem now owns and starts the Aspect interface.
218: // ProseSystem now containes a 'test' AspectManager
219: // AspectManager now owns the JoinPointManager.
220: // ExtensionManger can be 'connected' to the JVM, or disconnected. The
221: // JoinPointManager of a connected Ext.Mgr enables joinpoints; the
222: // JoinPointManger of a disconnected Ext.Mgr never enables join-points
223: // Documentation updated accordingly.
224: //
225: // Revision 1.9 2002/06/06 18:53:51 popovici
226: // 1. Bug fix: methodAdvice is now public; the constructor works for all subclasses.
227: // 2. Feature change/bug fix: ADVICE_NAME is now a protected method
228: //
229: // Revision 1.8 2002/06/06 14:39:50 popovici
230: // Renamings: FunctionalCrosscut->MethodCut
231: // AllFields->SetCut
232: // SetCu.fieldModiticationAdvice -> SetCut.setAdvice
233: //
234: // Revision 1.7 2002/06/04 12:36:09 popovici
235: // AllLocations occurences replaced with FunctionalCrosscut
236: //
237: // Revision 1.6 2002/05/22 11:00:33 popovici
238: // ClasseS replaced with DeclarationS
239: //
240: // Revision 1.5 2002/03/12 09:50:13 popovici
241: // Initial version of the Benchmark measurements
242: //
243: // Revision 1.4 2002/02/15 12:31:08 smarkwal
244: // minor changes like spaces/tabs, setUp
245: //
246: // Revision 1.3 2002/02/05 13:39:04 smarkwal
247: // spaces/tabs clean-up
248: //
249: // Revision 1.2 2002/02/05 11:22:30 smarkwal
250: // modifications to test JVMAI-based implementation
251: //
252: // Revision 1.1.1.1 2001/11/29 18:13:34 popovici
253: // Sources from runes
254: //
255: // Revision 1.1.2.3 2001/11/21 11:56:40 popovici
256: //
257: // -The sun.tools.agent and ch.ethz.inf.util.JVMDIUtil functionality
258: // replaced with the iks.jvmdi package. References to this old
259: // functionality replaced throughout the code.
260: // -Partial reimplementation of the ch.ethz.inf.iks.runes classes,
261: // part of their functionality moved to the ch.ethz.prose.reflect
262: // abstract classes. New classes and functionality added to the
263: // ch.ethz.prose.reflect package, partially to reflect the
264: // more stable features taken from the iks.runes packages, partially
265: // to reflect the structure of the VM (constant pool, etc). Functionality in
266: // ch.ethz.prose.crosscut and the junit classes adapted to use the
267: // new form of the ch.ethz.prose.reflect package
268: //
269: // Revision 1.1.2.2 2001/02/22 16:22:27 popovici
270: // ProseSystem.setup replaced with startup; teardown introduced
271: //
272: // Revision 1.1.2.1 2001/01/22 07:26:37 popovici
273: // Initial Revision
274: //
275: //
|