[정현길] [PROFILER-16] iBatis SqlMapClient 지원

SqlMap 관련 작업 인터셉팅하는 코드 refactoring

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@3854 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Hyun Jeong
2014-05-15 05:03:23 +00:00
parent 922a3491fe
commit fc38afca99
3 changed files with 46 additions and 18 deletions
@@ -1,4 +1,4 @@
package com.nhn.pinpoint.profiler.modifier.orm.ibatis.interceptor;
package com.nhn.pinpoint.profiler.modifier.orm;
import com.nhn.pinpoint.bootstrap.context.Trace;
import com.nhn.pinpoint.bootstrap.context.TraceContext;
@@ -7,24 +7,28 @@ import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
import com.nhn.pinpoint.bootstrap.interceptor.TraceContextSupport;
import com.nhn.pinpoint.bootstrap.logging.PLogger;
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
import com.nhn.pinpoint.common.ServiceType;
/**
* @author Hyun Jeong
*/
public class IbatisApiInterceptor implements SimpleAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
public abstract class SqlMapOperationInterceptor implements SimpleAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
private final boolean isDebug = logger.isDebugEnabled();
private final ServiceType serviceType;
private MethodDescriptor descriptor;
private TraceContext traceContext;
public SqlMapOperationInterceptor(ServiceType serviceType) {
this.serviceType = serviceType;
}
protected abstract PLogger getLogger();
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
public final void before(Object target, Object[] args) {
if (getLogger().isDebugEnabled()) {
getLogger().beforeInterceptor(target, args);
}
Trace trace = traceContext.currentTraceObject();
@@ -36,9 +40,9 @@ public class IbatisApiInterceptor implements SimpleAroundInterceptor, ByteCodeMe
}
@Override
public void after(Object target, Object[] args, Object result) {
if (isDebug) {
logger.afterInterceptor(target, args, result);
public final void after(Object target, Object[] args, Object result) {
if (getLogger().isDebugEnabled()) {
getLogger().afterInterceptor(target, args, result);
}
Trace trace = traceContext.currentTraceObject();
@@ -46,14 +50,13 @@ public class IbatisApiInterceptor implements SimpleAroundInterceptor, ByteCodeMe
return;
}
try {
trace.recordServiceType(ServiceType.IBATIS);
trace.recordServiceType(this.serviceType);
trace.recordException(result);
if (args != null && args.length > 0) {
trace.recordApi(descriptor, args[0], 0);
} else {
trace.recordApi(descriptor);
}
trace.recordException(result);
trace.markAfterTime();
} finally {
trace.traceBlockEnd();
@@ -61,14 +64,13 @@ public class IbatisApiInterceptor implements SimpleAroundInterceptor, ByteCodeMe
}
@Override
public void setTraceContext(TraceContext traceContext) {
public final void setTraceContext(TraceContext traceContext) {
this.traceContext = traceContext;
}
@Override
public void setMethodDescriptor(MethodDescriptor descriptor) {
public final void setMethodDescriptor(MethodDescriptor descriptor) {
this.descriptor = descriptor;
traceContext.cacheApi(descriptor);
}
}
@@ -7,12 +7,13 @@ import org.slf4j.Logger;
import com.nhn.pinpoint.bootstrap.Agent;
import com.nhn.pinpoint.bootstrap.interceptor.Interceptor;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor;
import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentClass;
import com.nhn.pinpoint.profiler.interceptor.bci.Method;
import com.nhn.pinpoint.profiler.interceptor.bci.MethodFilter;
import com.nhn.pinpoint.profiler.modifier.AbstractModifier;
import com.nhn.pinpoint.profiler.modifier.orm.ibatis.interceptor.IbatisApiInterceptor;
import com.nhn.pinpoint.profiler.modifier.orm.ibatis.interceptor.IbatisSqlMapOperationInterceptor;
import com.nhn.pinpoint.profiler.modifier.orm.ibatis.interceptor.IbatisScope;
import com.nhn.pinpoint.profiler.util.DepthScope;
@@ -23,6 +24,7 @@ import com.nhn.pinpoint.profiler.util.DepthScope;
*/
public abstract class IbatisClientModifier extends AbstractModifier {
private static final ServiceType serviceType = ServiceType.IBATIS;
private static final DepthScope scope = IbatisScope.SCOPE;
protected abstract Logger getLogger();
@@ -44,7 +46,7 @@ public abstract class IbatisClientModifier extends AbstractModifier {
List<Method> declaredMethods = ibatisClientImpl.getDeclaredMethods(getIbatisApiMethodFilter());
for (Method method : declaredMethods) {
Interceptor ibatisApiInterceptor = new IbatisApiInterceptor();
Interceptor ibatisApiInterceptor = new IbatisSqlMapOperationInterceptor(serviceType);
ibatisClientImpl.addScopeInterceptor(method.getMethodName(), method.getMethodParams(), ibatisApiInterceptor, scope);
}
@@ -0,0 +1,24 @@
package com.nhn.pinpoint.profiler.modifier.orm.ibatis.interceptor;
import com.nhn.pinpoint.bootstrap.logging.PLogger;
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.profiler.modifier.orm.SqlMapOperationInterceptor;
/**
* @author Hyun Jeong
*/
public class IbatisSqlMapOperationInterceptor extends SqlMapOperationInterceptor {
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
public IbatisSqlMapOperationInterceptor(ServiceType serviceType) {
super(serviceType);
}
@Override
protected PLogger getLogger() {
return this.logger;
}
}