From 2489277405664123b711fbc037a01e239d25f892 Mon Sep 17 00:00:00 2001 From: Woonduk Kang Date: Wed, 14 Nov 2012 08:45:27 +0000 Subject: [PATCH] =?UTF-8?q?[=EA=B0=95=EC=9A=B4=EB=8D=95]=20[LUCYSUS-1744]?= =?UTF-8?q?=20arcus=20=ED=98=B8=EC=B6=9C=20=EB=B6=80=EB=B6=84=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= 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@866 84d0f5b1-2673-498c-a247-62c4ff18d310 --- .../java/com/profiler/context/CallStack.java | 13 +++++++++--- .../com/profiler/context/GlobalCallTrace.java | 3 ++- src/main/java/com/profiler/context/Trace.java | 1 + .../BaseOperationCancelInterceptor.java | 15 +++---------- ...seOperationTransitionStateInterceptor.java | 21 +++++-------------- .../interceptors/ConstructInterceptor.java | 6 +----- 6 files changed, 22 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/profiler/context/CallStack.java b/src/main/java/com/profiler/context/CallStack.java index d5935f6a5..6625bad5c 100644 --- a/src/main/java/com/profiler/context/CallStack.java +++ b/src/main/java/com/profiler/context/CallStack.java @@ -56,9 +56,16 @@ public class CallStack { stack[index] = null; } - public synchronized StackFrame[] copyStackFrame() { - StackFrame[] copy = new StackFrame[index]; - System.arraycopy(stack, 0, copy, 0, index); + public StackFrame[] copyStackFrame() { + int currentIndex; + StackFrame[] currentStack; + synchronized (this) { + // copy reference + currentIndex = this.index; + currentStack = this.stack; + } + StackFrame[] copy = new StackFrame[currentIndex]; + System.arraycopy(currentStack, 0, copy, 0, currentIndex); return copy; } } diff --git a/src/main/java/com/profiler/context/GlobalCallTrace.java b/src/main/java/com/profiler/context/GlobalCallTrace.java index 371d9a2bd..eff6395a3 100644 --- a/src/main/java/com/profiler/context/GlobalCallTrace.java +++ b/src/main/java/com/profiler/context/GlobalCallTrace.java @@ -9,7 +9,8 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; /** - * + * 뭔가 복잡한 비동기 call trace시 객체 등록용으로 쓰자. + * 근데 손좀봐야 될듯.뭔가 좀 구림. */ public class GlobalCallTrace { diff --git a/src/main/java/com/profiler/context/Trace.java b/src/main/java/com/profiler/context/Trace.java index 264c1706d..4c8707506 100644 --- a/src/main/java/com/profiler/context/Trace.java +++ b/src/main/java/com/profiler/context/Trace.java @@ -67,6 +67,7 @@ public final class Trace { } public AsyncTrace createAsyncTrace() { + // 경우에 따라 별도 timeout 처리가 있어야 될수도 있음. TraceID nextTraceId = getNextTraceId(); Span span = new Span(nextTraceId, null, null); AsyncTrace asyncTrace = new AsyncTrace(span); diff --git a/src/main/java/com/profiler/modifier/arcus/interceptors/BaseOperationCancelInterceptor.java b/src/main/java/com/profiler/modifier/arcus/interceptors/BaseOperationCancelInterceptor.java index f00819799..56d1260eb 100644 --- a/src/main/java/com/profiler/modifier/arcus/interceptors/BaseOperationCancelInterceptor.java +++ b/src/main/java/com/profiler/modifier/arcus/interceptors/BaseOperationCancelInterceptor.java @@ -24,21 +24,12 @@ public class BaseOperationCancelInterceptor implements StaticBeforeInterceptor { logger.info("before " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args)); } - - Object asyncId = asyncTraceId.invoke(target); - if (asyncId == null) { - logger.fine("asyncId not found id:" + asyncId); + AsyncTrace asyncTrace = (AsyncTrace) asyncTraceId.invoke(target); + if (asyncTrace == null) { + logger.fine("asyncTrace not found "); return; } -// TraceContext traceContext = TraceContext.getTraceContext(); -// GlobalCallTrace globalCallTrace = traceContext.getGlobalCallTrace(); -// AsyncTrace asyncTrace = globalCallTrace.getTraceObject((Integer) asyncId); -// if (asyncTrace == null) { -// logger.fine("asyncTrace expired"); -// return; -// } - AsyncTrace asyncTrace = (AsyncTrace) asyncId; if (asyncTrace.getState() != AsyncTrace.STATE_INIT) { // 이미 동작 완료된 상태임. return; diff --git a/src/main/java/com/profiler/modifier/arcus/interceptors/BaseOperationTransitionStateInterceptor.java b/src/main/java/com/profiler/modifier/arcus/interceptors/BaseOperationTransitionStateInterceptor.java index 9ead6054c..271039917 100644 --- a/src/main/java/com/profiler/modifier/arcus/interceptors/BaseOperationTransitionStateInterceptor.java +++ b/src/main/java/com/profiler/modifier/arcus/interceptors/BaseOperationTransitionStateInterceptor.java @@ -35,29 +35,19 @@ public class BaseOperationTransitionStateInterceptor implements StaticBeforeInte if (logger.isLoggable(Level.INFO)) { logger.info("before " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args)); } - TraceContext traceContext = TraceContext.getTraceContext(); -// GlobalCallTrace globalCallTrace = traceContext.getGlobalCallTrace(); - Object asyncId = asyncTraceId.invoke(target); - if (asyncId == null) { - logger.fine("asyncId not found"); + AsyncTrace asyncTrace = (AsyncTrace) asyncTraceId.invoke(target); + if (asyncTrace == null) { + logger.fine("asyncTrace not found"); return; } -// AsyncTrace asyncTrace = globalCallTrace.getTraceObject((Integer) asyncId); -// if (asyncTrace == null) { -// logger.fine("AsyncTrace already timeout"); -// return; -// } - System.out.println(asyncId); - AsyncTrace asyncTrace = (AsyncTrace) asyncId; - OperationState newState = (OperationState) args[0]; BaseOperationImpl baseOperation = (BaseOperationImpl) target; if (newState == OperationState.READING) { if (logger.isLoggable(Level.FINE)) { - logger.fine("event:" + newState + " asyncId:" + asyncId); + logger.fine("event:" + newState + " asyncTrace:" + asyncTrace); } if (asyncTrace.getState() != AsyncTrace.STATE_INIT) { return; @@ -79,13 +69,12 @@ public class BaseOperationTransitionStateInterceptor implements StaticBeforeInte asyncTrace.record(Annotation.ClientSend, System.currentTimeMillis() - createTime); } else if (newState == OperationState.COMPLETE || newState == OperationState.TIMEDOUT) { if (logger.isLoggable(Level.FINE)) { - logger.fine("event:" + newState + " asyncId:" + asyncId); + logger.fine("event:" + newState + " asyncTrace:" + asyncTrace); } boolean fire = asyncTrace.fire(); if (!fire) { return; } -// globalCallTrace.removeTraceObject((Integer) asyncId); Exception exception = baseOperation.getException(); if (exception != null) { asyncTrace.recordAttibute("exception", InterceptorUtils.exceptionToString(exception)); diff --git a/src/main/java/com/profiler/modifier/arcus/interceptors/ConstructInterceptor.java b/src/main/java/com/profiler/modifier/arcus/interceptors/ConstructInterceptor.java index ff4f87cb9..5e5dc7ee9 100644 --- a/src/main/java/com/profiler/modifier/arcus/interceptors/ConstructInterceptor.java +++ b/src/main/java/com/profiler/modifier/arcus/interceptors/ConstructInterceptor.java @@ -15,7 +15,6 @@ import java.util.logging.Logger; public class ConstructInterceptor implements StaticAfterInterceptor { private final Logger logger = Logger.getLogger(ConstructInterceptor.class.getName()); - // private MetaObject asyncTraceId = new MetaObject("__setAsyncTraceId", int.class); private MetaObject asyncTraceId = new MetaObject("__setAsyncTraceId", Object.class); @@ -29,13 +28,10 @@ public class ConstructInterceptor implements StaticAfterInterceptor { if (trace == null) { return; } + // 일단 이벤트가 세지 않는다는 가정하에 별도 timeout처리가 없음. AsyncTrace asyncTrace = trace.createAsyncTrace(); asyncTrace.setAttachObject(new TimeObject()); -// GlobalCallTrace globalCallTrace = traceContext.getGlobalCallTrace(); -// int asyncId = globalCallTrace.registerTraceObject(asyncTrace); -// -// asyncTraceId.invoke(target, asyncId); asyncTraceId.invoke(target, asyncTrace); } }