1 7 package measurements.suites; 8 9 import junit.framework.Assert; 10 import junit.framework.Test; 11 import ch.ethz.inf.util.junit.PerformanceTest; 12 import ch.ethz.inf.util.junit.PerformanceTestSuite; 13 import ch.ethz.prose.*; 14 import ch.ethz.prose.crosscut.Crosscut; 15 import ch.ethz.prose.crosscut.MethodCut; 16 import ch.ethz.prose.filter.*; 17 18 39 public class AllLocationsMeasurement extends PerformanceTest { 40 41 public void theMethodToCall() 43 { 44 int a; 45 a=1; 46 }; 47 48 public static class TrapMethodAspect1 extends DefaultAspect 49 { 50 public static class TrapMethodCrossc1 extends MethodCut 51 { 52 public void METHOD_ARGS() {} 53 54 protected PointCutter pointCutter() 55 { 56 PointCutter x = Executions.before().AND(Within.method("theMethodToCall")); 57 return x.AND(Within.type("AllLocationsMeasurement")); 58 } 59 } 60 public Crosscut c1 = new TrapMethodCrossc1(); 61 } 62 63 public static class TrapMethodAspect2 extends DefaultAspect 64 { 65 public static class TrapMethodCrossc2 extends MethodCut 66 { 67 68 public void METHOD_ARGS() {} 69 protected PointCutter pointCutter() 70 { 71 PointCutter x = Executions.before().AND(Within.method("theMethodToCall")); 72 return x.AND(Within.type("AllLocationsMeasurement")); 73 } 74 public void joinPointAction(ch.ethz.jvmai.MethodEntryJoinPoint x) {} 75 } 76 public Crosscut c2 = new TrapMethodCrossc2(); 77 } 78 79 Aspect x1; 80 Aspect x2; 81 final boolean useProse; 82 83 87 public AllLocationsMeasurement(String name) 88 { 89 super(name); 90 91 String proseParam = System.getProperty("useprose"); 92 if(proseParam==null) 93 useProse = isDebuggerEnabled(); 94 else 95 useProse = proseParam.toUpperCase().equals("TRUE"); 96 97 if (useProse) 98 RANGE = new int[]{1000000}; 99 else 100 RANGE = new int[]{1000000}; 101 102 } 103 104 107 protected void setUp() 108 { 109 if (!useProse) return; 110 111 x1 = new TrapMethodAspect1(); 112 x2 = new TrapMethodAspect2(); 113 try 114 { ProseSystem.startup(); } 115 catch (Exception e) 116 { Assert.fail("ProseSystem.startup() failed"); } 117 } 118 119 protected void tearDown() 120 { 121 if (!useProse) return; 122 123 try 124 { ProseSystem.teardown(); } 125 catch (Exception e) 126 { Assert.fail("ProseSystem.teardown() failed"); } 127 } 128 129 public void testLocalCallsNormal() 130 { 131 if (useProse) 132 ProseSystem.getAspectManager().insert(x1); 133 134 startChronometer(); 135 for (int i=0; i < RUNS; i ++) 136 this.theMethodToCall(); 137 stopChronometer(); 138 139 if (useProse) 140 ProseSystem.getAspectManager().withdraw(x1); 141 } 142 143 public void testLocalCallsFast() 144 { 145 if (useProse) 146 ProseSystem.getAspectManager().insert(x2); 147 148 startChronometer(); 149 for (int i=0; i < RUNS; i++) 150 this.theMethodToCall(); 151 stopChronometer(); 152 153 if (useProse) 154 ProseSystem.getAspectManager().withdraw(x2); 155 } 156 157 161 public static 162 Test suite() 163 { 164 return new PerformanceTestSuite(AllLocationsMeasurement.class); 165 } 166 167 } 168 169 170 | Popular Tags |