1 package com.tirsen.nanning.profiler; 2 3 import com.tirsen.nanning.config.*; 4 import com.tirsen.nanning.attribute.*; 5 import com.tirsen.nanning.profiler.Profiled; 6 import com.tirsen.nanning.profiler.ProfilerInterceptor; 7 import com.tirsen.nanning.profiler.ProfilerLogger; 8 9 public class ProfilerTest extends AbstractAttributesTest { 10 public void testProfiler() throws Exception { 11 Thread thread = new Thread (new Runnable () { 12 public void run() { 13 AspectSystem aspectSystem = new AspectSystem(); 14 aspectSystem.addAspect(new FindTargetMixinAspect()); 15 aspectSystem.addAspect(new InterceptorAspect(new AttributePointcut("profile"), new ProfilerInterceptor())); 16 Profiled profiled = (Profiled) aspectSystem.newInstance(Profiled.class); 17 18 profiled.someMethod(); 19 profiled.notProfiledMethod(); 20 21 } 22 }); 23 thread.start(); 24 thread.join(); 25 String log = ProfilerLogger.getProfilerLogger().lastLog; 26 assertNotNull(log); 27 assertTrue(log.matches("(.*)someMethod: (.*)ms")); 28 } 29 30 public void testMinimumProfilingDuration() throws Exception { 31 Thread thread = new Thread (new Runnable () { 32 public void run() { 33 AspectSystem aspectSystem = new AspectSystem(); 34 aspectSystem.addAspect(new FindTargetMixinAspect()); 35 aspectSystem.addAspect(new InterceptorAspect(new AttributePointcut("profile"), new ProfilerInterceptor())); 36 Profiled profiled = (Profiled) aspectSystem.newInstance(Profiled.class); 37 ProfilerInterceptor.setMinDuration(100L); 38 profiled.delayTwoHundredMillis(); 39 profiled.someMethod(); 40 41 } 42 }); 43 thread.start(); 44 thread.join(); 45 String log = ProfilerLogger.getProfilerLogger().lastLog; 46 assertNotNull(log); 47 assertTrue(log.indexOf("delayTwoHundredMillis") > 0); 48 49 } 50 } 51 | Popular Tags |