Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 package com.tirsen.nanning.profiler; 2 3 import com.tirsen.nanning.Invocation; 4 import com.tirsen.nanning.MethodInterceptor; 5 6 import java.lang.reflect.Method ; 7 import java.util.HashMap ; 8 import java.util.Map ; 9 10 11 public class ProfilerInterceptor implements MethodInterceptor { 12 static ThreadLocal threadLocal = new ThreadLocal (); 13 14 private static long minDuration = 0; 15 16 public Object invoke(Invocation invocation) throws Throwable { 17 18 Map methodsStartingTime = (Map ) threadLocal.get(); 19 if (methodsStartingTime == null) { 20 methodsStartingTime = new HashMap (); 21 threadLocal.set(methodsStartingTime); 22 } 23 Method method = invocation.getMethod(); 24 methodsStartingTime.put(method, new Long (System.currentTimeMillis())); 25 Object result = invocation.invokeNext(); 26 long duration = System.currentTimeMillis() - ((Long ) methodsStartingTime.get(method)).longValue(); 27 if (duration >= minDuration) ProfilerLogger.getProfilerLogger().log(invocation, duration); 28 return result; 29 } 30 31 public static long getMinDuration() { 32 return minDuration; 33 } 34 35 public static void setMinDuration(long l) { 36 minDuration = l; 37 } 38 39 } 40
| Popular Tags
|