From 0fc2b4d383b0b44607eb89d4ff3963fbaeac3262 Mon Sep 17 00:00:00 2001 From: Woonduk Kang Date: Mon, 30 Jun 2014 08:33:45 +0000 Subject: [PATCH] =?UTF-8?q?[=EA=B0=95=EC=9A=B4=EB=8D=95]=20[PROFILER-31]?= =?UTF-8?q?=20traceContext=20=EC=A1=B4=EC=9E=AC=20=EB=B0=8F=20=ED=95=B8?= =?UTF-8?q?=EB=93=A4=EB=A7=81=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20SpanSimpleAr?= =?UTF-8?q?oundInterceptor=EB=A1=9C=20=EC=9C=84=EC=9E=84=ED=95=A8.=20bloc?= =?UTF-8?q?=EB=8F=84=20=EA=B0=99=EC=9D=B4=20=EC=88=98=EC=A0=95=ED=95=A8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@4106 84d0f5b1-2673-498c-a247-62c4ff18d310 --- .../interceptor/ExecuteMethodInterceptor.java | 117 ++++++------------ .../StandardHostValveInvokeInterceptor.java | 2 +- 2 files changed, 42 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/nhn/pinpoint/profiler/modifier/bloc/handler/interceptor/ExecuteMethodInterceptor.java b/src/main/java/com/nhn/pinpoint/profiler/modifier/bloc/handler/interceptor/ExecuteMethodInterceptor.java index 8a63b2ca0..ba70bcbcc 100644 --- a/src/main/java/com/nhn/pinpoint/profiler/modifier/bloc/handler/interceptor/ExecuteMethodInterceptor.java +++ b/src/main/java/com/nhn/pinpoint/profiler/modifier/bloc/handler/interceptor/ExecuteMethodInterceptor.java @@ -22,53 +22,43 @@ import external.org.apache.coyote.Request; * @author netspider * @author emeroad */ -public class ExecuteMethodInterceptor implements SimpleAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport, TargetClassLoader { +public class ExecuteMethodInterceptor extends SpanSimpleAroundInterceptor implements ByteCodeMethodDescriptorSupport, TraceContextSupport, TargetClassLoader { - private final PLogger logger = PLoggerFactory.getLogger(this.getClass()); - private final boolean isDebug = logger.isDebugEnabled(); - private final boolean isInfo = logger.isInfoEnabled(); - private MethodDescriptor descriptor; - private TraceContext traceContext; - @Override - public void before(Object target, Object[] args) { - if (isDebug) { - logger.beforeInterceptor(target, args); - } - - try { - final external.org.apache.coyote.Request request = (external.org.apache.coyote.Request) args[0]; - final Trace trace = createTrace(request); - - trace.markBeforeTime(); - if (trace.canSampled()) { - trace.recordServiceType(ServiceType.BLOC); - - final String requestURL = request.requestURI().toString(); - trace.recordRpcName(requestURL); - - // TODO tomcat과 로직이 미묘하게 다름 차이점 알아내서 고칠것. - // String remoteAddr = request.remoteAddr().toString(); - - trace.recordEndPoint(request.protocol().toString() + ":" + request.serverName().toString() + ":" + request.getServerPort()); - trace.recordDestinationId(request.serverName().toString() + ":" + request.getServerPort()); - trace.recordAttribute(AnnotationKey.HTTP_URL, request.requestURI().toString()); - } -// 부모 정보를 샘플링여부를 따지면 안됨. -// TODO 부모정보 레코딩로직이 없음. -// if (!trace.isRoot()) { -// recordParentInfo(trace, request); -// } - - } catch (Throwable e) { - if (logger.isWarnEnabled()) { - logger.warn( "Tomcat StandardHostValve trace start fail. Caused:{}", e.getMessage(), e); - } - } + public ExecuteMethodInterceptor() { + super(PLoggerFactory.getLogger(ExecuteMethodInterceptor.class)); } - private Trace createTrace(Request request) { + @Override + public void doInBeforeTrace(Trace trace, Object[] args) { + + final external.org.apache.coyote.Request request = (external.org.apache.coyote.Request) args[0]; + trace.markBeforeTime(); + if (trace.canSampled()) { + trace.recordServiceType(ServiceType.BLOC); + + final String requestURL = request.requestURI().toString(); + trace.recordRpcName(requestURL); + + // TODO tomcat과 로직이 미묘하게 다름 차이점 알아내서 고칠것. + // String remoteAddr = request.remoteAddr().toString(); + + trace.recordEndPoint(request.protocol().toString() + ":" + request.serverName().toString() + ":" + request.getServerPort()); + trace.recordDestinationId(request.serverName().toString() + ":" + request.getServerPort()); + trace.recordAttribute(AnnotationKey.HTTP_URL, request.requestURI().toString()); + } +// 부모 정보를 샘플링여부를 따지면 안됨. +// TODO 부모정보 레코딩로직이 없음. +// if (!trace.isRoot()) { +// recordParentInfo(trace, request); +// } + + } + + @Override + protected Trace createTrace(Object[] args) { + final external.org.apache.coyote.Request request = (external.org.apache.coyote.Request) args[0]; final boolean sampling = samplingEnable(request); if (!sampling) { // 샘플링 대상이 아닐 경우도 TraceObject를 생성하여, sampling 대상이 아니라는것을 명시해야 한다. @@ -113,33 +103,19 @@ public class ExecuteMethodInterceptor implements SimpleAroundInterceptor, ByteCo @Override - public void after(Object target, Object[] args, Object result) { - if (isDebug) { - logger.afterInterceptor(target, args, result); - } + public void doInAfterTrace(Trace trace, Object target, Object[] args, Object result) { - final Trace trace = traceContext.currentRawTraceObject(); - if (trace == null) { - return; - } - traceContext.detachTraceObject(); - - try { - if (trace.canSampled()) { - external.org.apache.coyote.Request request = (external.org.apache.coyote.Request) args[0]; - String parameters = getRequestParameter(request, 64, 512); - if (parameters != null && parameters.length() > 0) { - trace.recordAttribute(AnnotationKey.HTTP_PARAM, parameters); - } - - trace.recordApi(descriptor); + if (trace.canSampled()) { + external.org.apache.coyote.Request request = (external.org.apache.coyote.Request) args[0]; + String parameters = getRequestParameter(request, 64, 512); + if (parameters != null && parameters.length() > 0) { + trace.recordAttribute(AnnotationKey.HTTP_PARAM, parameters); } - trace.recordException(result); - trace.markAfterTime(); - } finally { - trace.traceRootBlockEnd(); + trace.recordApi(descriptor); } + trace.recordException(result); + trace.markAfterTime(); } private boolean samplingEnable(external.org.apache.coyote.Request request) { @@ -196,15 +172,4 @@ public class ExecuteMethodInterceptor implements SimpleAroundInterceptor, ByteCo return params.toString(); } - @Override - public void setMethodDescriptor(MethodDescriptor descriptor) { - this.descriptor = descriptor; - traceContext.cacheApi(descriptor); - } - - - @Override - public void setTraceContext(TraceContext traceContext) { - this.traceContext = traceContext; - } } \ No newline at end of file diff --git a/src/main/java/com/nhn/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java b/src/main/java/com/nhn/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java index 0cf7f61bb..b5f6c8c90 100644 --- a/src/main/java/com/nhn/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java +++ b/src/main/java/com/nhn/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java @@ -109,7 +109,7 @@ public class StandardHostValveInvokeInterceptor extends SpanSimpleAroundIntercep } @Override - protected void doInAfterTrace(Trace trace, Object[] args, Object result) { + protected void doInAfterTrace(Trace trace, Object target, Object[] args, Object result) { if (trace.canSampled()) { final HttpServletRequest request = (HttpServletRequest) args[0]; final String parameters = getRequestParameter(request, 64, 512);