1 17 package org.alfresco.util.perf; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 22 import com.vladium.utils.timing.ITimer; 23 import com.vladium.utils.timing.TimerFactory; 24 25 50 public class PerformanceMonitor extends AbstractPerformanceMonitor 51 { 52 private String methodName; 53 private ThreadLocal <ITimer> threadLocalTimer; 54 private boolean log; 55 56 61 public PerformanceMonitor(String entityName, String methodName) 62 { 63 super(entityName); 64 this.methodName = methodName; 65 this.threadLocalTimer = new ThreadLocal <ITimer>(); 66 67 Log methodLogger = LogFactory.getLog("performance." + entityName + "." + methodName); 69 this.log = AbstractPerformanceMonitor.isDebugEnabled() && methodLogger.isDebugEnabled(); 70 } 71 72 79 public void start() 80 { 81 if (!log) 82 { 83 return; 85 } 86 ITimer timer = TimerFactory.newTimer(); 88 threadLocalTimer.set(timer); 89 timer.start(); 91 } 92 93 98 public void stop() 99 { 100 if (!log) 101 { 102 return; 104 } 105 ITimer timer = threadLocalTimer.get(); 107 if (timer == null) 108 { 109 return; 111 } 112 timer.stop(); 114 recordStats(methodName, timer.getDuration()); 115 116 threadLocalTimer.set(null); 118 } 119 } 120 | Popular Tags |