mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-16 16:28:48 +10:00
[유치수] [NOBTS] call stack을 위한 수정, depth, nextid 추가. traceid를 rpc call하기 전에 next id를 발급하도록 변경.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@1113 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -81,7 +81,9 @@ public class TomcatProfiler implements ClassFileTransformer {
|
||||
|
||||
private ModifierRegistry createModifierRegistry() {
|
||||
DefaultModifierRegistry modifierRepository = new DefaultModifierRegistry(byteCodeInstrumentor, agent, profilerConfig);
|
||||
|
||||
|
||||
modifierRepository.addDummyModifier();
|
||||
|
||||
modifierRepository.addTomcatModifier();
|
||||
|
||||
// jdbc
|
||||
|
||||
@@ -38,18 +38,18 @@ public class CallStack {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public synchronized void setStackFrame(StackFrame stackFrame) {
|
||||
stack[index] = stackFrame;
|
||||
}
|
||||
|
||||
public synchronized void push() {
|
||||
public synchronized int push() {
|
||||
index++;
|
||||
if (index > stack.length - 1) {
|
||||
StackFrame[] old = stack;
|
||||
stack = new RootStackFrame[index + 4];
|
||||
stack = new StackFrame[index + 4];
|
||||
System.arraycopy(old, 0, stack, 0, old.length);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
public synchronized int getStackFrameIndex() {
|
||||
@@ -86,4 +86,8 @@ public class CallStack {
|
||||
System.arraycopy(currentStack, 0, copy, 0, currentIndex);
|
||||
return copy;
|
||||
}
|
||||
|
||||
public synchronized int index() {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ public class Span implements Thriftable {
|
||||
private final List<HippoAnnotation> annotations = new ArrayList<HippoAnnotation>(5);
|
||||
|
||||
private List<SubSpan> subSpanList;
|
||||
|
||||
|
||||
public Span(TraceID traceId) {
|
||||
this.traceID = traceId;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.profiler.context;
|
||||
|
||||
import com.profiler.Agent;
|
||||
import com.profiler.common.ServiceType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.profiler.Agent;
|
||||
import com.profiler.common.ServiceType;
|
||||
|
||||
/**
|
||||
* Span represent RPC
|
||||
*
|
||||
@@ -27,6 +27,9 @@ public class SubSpan implements Thriftable {
|
||||
|
||||
private final List<HippoAnnotation> annotations = new ArrayList<HippoAnnotation>(5);
|
||||
|
||||
private Long nextSpanId = null;
|
||||
private Integer depth = null;
|
||||
|
||||
public SubSpan(Span parentSpan) {
|
||||
this.parentSpan = parentSpan;
|
||||
}
|
||||
@@ -110,13 +113,31 @@ public class SubSpan implements Thriftable {
|
||||
public void setException(boolean exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
public void setDepth(int depth) {
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
public long getNextSpanId() {
|
||||
return nextSpanId;
|
||||
}
|
||||
|
||||
public void setNextSpanId(long nextSpanId) {
|
||||
this.nextSpanId = nextSpanId;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("{");
|
||||
sb.append("\n\t Depth = ").append(depth);
|
||||
sb.append("\n\t NextSpanid=").append(nextSpanId);
|
||||
sb.append("\n\t ParentTraceID=").append(parentSpan.getTraceID());
|
||||
sb.append("\n\t sequence=").append(sequence);
|
||||
sb.append("\n\t Sequence=").append(sequence);
|
||||
sb.append(",\n\t StartTime=").append(startTime);
|
||||
sb.append(", EndTime=").append(endTime);
|
||||
sb.append(",\n\t Name=").append(rpc);
|
||||
@@ -174,6 +195,14 @@ public class SubSpan implements Thriftable {
|
||||
}
|
||||
subSpan.setAnnotations(annotationList);
|
||||
|
||||
if (depth != null) {
|
||||
subSpan.setDepth(depth);
|
||||
}
|
||||
|
||||
if (nextSpanId != null) {
|
||||
subSpan.setNextSpanId(nextSpanId);
|
||||
}
|
||||
|
||||
return subSpan;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.profiler.interceptor.MethodDescriptor;
|
||||
import com.profiler.metadata.SqlCacheTable;
|
||||
import com.profiler.sender.DataSender;
|
||||
import com.profiler.sender.LoggingDataSender;
|
||||
import com.profiler.util.Assert;
|
||||
|
||||
/**
|
||||
* @author netspider
|
||||
@@ -24,7 +23,6 @@ public final class Trace {
|
||||
|
||||
private static final DataSender DEFULT_DATA_SENDER = new LoggingDataSender();
|
||||
|
||||
public static final int HANDLER_STACKID = -2;
|
||||
public static final int NOCHECK_STACKID = -1;
|
||||
public static final int ROOT_STACKID = 0;
|
||||
|
||||
@@ -40,22 +38,25 @@ public final class Trace {
|
||||
private SqlCacheTable sqlCacheTable;
|
||||
private SqlParser sqlParser;
|
||||
|
||||
// use for calculating depth of each Span.
|
||||
private Integer latestStackIndex = null;
|
||||
|
||||
public Trace() {
|
||||
// traceObject에서 spanid의 유효성을 히스토리를 관리한다면 같은 thread에서는 span랜덤생성아이디의 충돌을 방지할수 있기는 함.
|
||||
TraceID traceId = TraceID.newTraceId();
|
||||
this.callStack = new CallStack(traceId);
|
||||
this.callStack.push();
|
||||
latestStackIndex = this.callStack.push();
|
||||
StackFrame stackFrame = createRootStackFrame(ROOT_STACKID, callStack.getSpan());
|
||||
this.callStack.setStackFrame(stackFrame);
|
||||
}
|
||||
|
||||
public Trace(TraceID continueRoot) {
|
||||
// this.root = continueRoot;
|
||||
this.callStack = new CallStack(continueRoot);
|
||||
this.callStack.push();
|
||||
// StackFrame stackFrame = createStackFrame(ROOT_STACKID);
|
||||
StackFrame stackFrame = createRootStackFrame(ROOT_STACKID, callStack.getSpan());
|
||||
this.callStack.setStackFrame(stackFrame);
|
||||
// this.root = continueRoot;
|
||||
this.callStack = new CallStack(continueRoot);
|
||||
latestStackIndex = this.callStack.push();
|
||||
// StackFrame stackFrame = createStackFrame(ROOT_STACKID);
|
||||
StackFrame stackFrame = createRootStackFrame(ROOT_STACKID, callStack.getSpan());
|
||||
this.callStack.setStackFrame(stackFrame);
|
||||
}
|
||||
|
||||
public CallStack getCallStack() {
|
||||
@@ -80,13 +81,13 @@ public final class Trace {
|
||||
}
|
||||
|
||||
public AsyncTrace createAsyncTrace() {
|
||||
// 경우에 따라 별도 timeout 처리가 있어야 될수도 있음.
|
||||
SubSpan subSpan = new SubSpan(callStack.getSpan());
|
||||
subSpan.setSequence(getSequence());
|
||||
AsyncTrace asyncTrace = new AsyncTrace(subSpan);
|
||||
// asyncTrace.setDataSender(this.getDataSender());
|
||||
asyncTrace.setStorage(this.storage);
|
||||
return asyncTrace;
|
||||
// 경우에 따라 별도 timeout 처리가 있어야 될수도 있음.
|
||||
SubSpan subSpan = new SubSpan(callStack.getSpan());
|
||||
subSpan.setSequence(getSequence());
|
||||
AsyncTrace asyncTrace = new AsyncTrace(subSpan);
|
||||
// asyncTrace.setDataSender(this.getDataSender());
|
||||
asyncTrace.setStorage(this.storage);
|
||||
return asyncTrace;
|
||||
}
|
||||
|
||||
private StackFrame createSubStackFrame(int stackId) {
|
||||
@@ -103,19 +104,18 @@ public final class Trace {
|
||||
stackFrame.setSpan(span);
|
||||
stackFrame.setStackFrameId(ROOT_STACKID);
|
||||
return stackFrame;
|
||||
}
|
||||
}
|
||||
|
||||
public void traceBlockBegin() {
|
||||
traceBlockBegin(NOCHECK_STACKID);
|
||||
}
|
||||
public void traceBlockBegin() {
|
||||
traceBlockBegin(NOCHECK_STACKID);
|
||||
}
|
||||
|
||||
public void markBeforeTime() {
|
||||
StackFrame stackFrame = getCurrentStackFrame();
|
||||
stackFrame.markBeforeTime();
|
||||
}
|
||||
|
||||
public void markBeforeTime() {
|
||||
StackFrame stackFrame = getCurrentStackFrame();
|
||||
stackFrame.markBeforeTime();
|
||||
}
|
||||
|
||||
public long getBeforeTime() {
|
||||
public long getBeforeTime() {
|
||||
StackFrame stackFrame = getCurrentStackFrame();
|
||||
return stackFrame.getBeforeTime();
|
||||
}
|
||||
@@ -135,13 +135,18 @@ public final class Trace {
|
||||
// stackFrame.attachObject(object);
|
||||
// }
|
||||
|
||||
public void traceBlockBegin(int stackId) {
|
||||
int currentStackIndex = callStack.push();
|
||||
StackFrame stackFrame = createSubStackFrame(stackId);
|
||||
|
||||
if (latestStackIndex != currentStackIndex) {
|
||||
latestStackIndex = currentStackIndex;
|
||||
SubSpan span = ((SubStackFrame) stackFrame).getSubSpan();
|
||||
span.setDepth(latestStackIndex);
|
||||
}
|
||||
|
||||
public void traceBlockBegin(int stackId) {
|
||||
// TraceID nextId = getNextTraceId();
|
||||
callStack.push();
|
||||
StackFrame stackFrame = createSubStackFrame(stackId);
|
||||
callStack.setStackFrame(stackFrame);
|
||||
}
|
||||
callStack.setStackFrame(stackFrame);
|
||||
}
|
||||
|
||||
public void traceBlockEnd() {
|
||||
traceBlockEnd(NOCHECK_STACKID);
|
||||
@@ -170,7 +175,6 @@ public final class Trace {
|
||||
callStack.pop();
|
||||
}
|
||||
|
||||
|
||||
public StackFrame getCurrentStackFrame() {
|
||||
return callStack.getCurrentStackFrame();
|
||||
}
|
||||
@@ -214,10 +218,10 @@ public final class Trace {
|
||||
logger.info("[WRITE SPAN]" + span + " CurrentThreadID=" + Thread.currentThread().getId() + ",\n\t CurrentThreadName=" + Thread.currentThread().getName() + "\n\n");
|
||||
}
|
||||
|
||||
// dataSender.send(span);
|
||||
this.storage.store(span);
|
||||
// subSpan.cancelTimer();
|
||||
} catch (Exception e) {
|
||||
// dataSender.send(span);
|
||||
this.storage.store(span);
|
||||
// subSpan.cancelTimer();
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
@@ -230,80 +234,78 @@ public final class Trace {
|
||||
annotate(annotation.getCode());
|
||||
}
|
||||
|
||||
public void recordException(Object result) {
|
||||
if (result instanceof Throwable) {
|
||||
Throwable th = (Throwable) result;
|
||||
recordAttribute(AnnotationNames.EXCEPTION, th.getMessage());
|
||||
public void recordException(Object result) {
|
||||
if (result instanceof Throwable) {
|
||||
Throwable th = (Throwable) result;
|
||||
recordAttribute(AnnotationNames.EXCEPTION, th.getMessage());
|
||||
|
||||
try {
|
||||
StackFrame currentStackFrame = getCurrentStackFrame();
|
||||
if (currentStackFrame instanceof RootStackFrame) {
|
||||
((RootStackFrame) currentStackFrame).getSpan().setException(true);
|
||||
} else {
|
||||
((SubStackFrame) currentStackFrame).getSubSpan().setException(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
StackFrame currentStackFrame = getCurrentStackFrame();
|
||||
if (currentStackFrame instanceof RootStackFrame) {
|
||||
((RootStackFrame) currentStackFrame).getSpan().setException(true);
|
||||
} else {
|
||||
((SubStackFrame) currentStackFrame).getSubSpan().setException(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void recordApi(MethodDescriptor methodDescriptor) {
|
||||
if (methodDescriptor == null) {
|
||||
return;
|
||||
}
|
||||
String method = methodDescriptor.getClassName() + "." + methodDescriptor.getMethodName() + methodDescriptor.getParameterDescriptor() + ":" + methodDescriptor.getLineNumber();
|
||||
recordAttribute(AnnotationNames.API, method);
|
||||
}
|
||||
public void recordApi(MethodDescriptor methodDescriptor) {
|
||||
if (methodDescriptor == null) {
|
||||
return;
|
||||
}
|
||||
String method = methodDescriptor.getClassName() + "." + methodDescriptor.getMethodName() + methodDescriptor.getParameterDescriptor() + ":" + methodDescriptor.getLineNumber();
|
||||
recordAttribute(AnnotationNames.API, method);
|
||||
}
|
||||
|
||||
public void recordApi(MethodDescriptor methodDescriptor, Object[] args) {
|
||||
// API 저장 방법의 개선 필요.
|
||||
String method = methodDescriptor.getClassName() + "." + methodDescriptor.getMethodName() + methodDescriptor.getParameterDescriptor() + ":" + methodDescriptor.getLineNumber();
|
||||
recordAttribute(AnnotationNames.API, method);
|
||||
recocordArgs(args);
|
||||
}
|
||||
public void recordApi(MethodDescriptor methodDescriptor, Object[] args) {
|
||||
// API 저장 방법의 개선 필요.
|
||||
String method = methodDescriptor.getClassName() + "." + methodDescriptor.getMethodName() + methodDescriptor.getParameterDescriptor() + ":" + methodDescriptor.getLineNumber();
|
||||
recordAttribute(AnnotationNames.API, method);
|
||||
recocordArgs(args);
|
||||
}
|
||||
|
||||
public void recordApi(int apiId) {
|
||||
recordAttribute(AnnotationNames.API_ID, apiId);
|
||||
}
|
||||
public void recordApi(int apiId) {
|
||||
recordAttribute(AnnotationNames.API_ID, apiId);
|
||||
}
|
||||
|
||||
public void recordApi(int apiId, Object[] args) {
|
||||
recordAttribute(AnnotationNames.API_ID, apiId);
|
||||
recocordArgs(args);
|
||||
}
|
||||
public void recordApi(int apiId, Object[] args) {
|
||||
recordAttribute(AnnotationNames.API_ID, apiId);
|
||||
recocordArgs(args);
|
||||
}
|
||||
|
||||
private void recocordArgs(Object[] args) {
|
||||
if (args != null) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
recordAttribute("args[" + i + "]", args[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void recocordArgs(Object[] args) {
|
||||
if (args != null) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
recordAttribute("args[" + i + "]", args[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void recordAttribute(final String key, final String value) {
|
||||
recordAttribute(key, (Object) value);
|
||||
}
|
||||
public void recordAttribute(final String key, final String value) {
|
||||
recordAttribute(key, (Object) value);
|
||||
}
|
||||
|
||||
public ParsingResult recordSqlInfo(String sql) {
|
||||
if (sql == null) {
|
||||
return null;
|
||||
}
|
||||
ParsingResult parsingResult = parseSql(sql);
|
||||
recordSqlParsingResult(parsingResult);
|
||||
return parsingResult;
|
||||
}
|
||||
public ParsingResult recordSqlInfo(String sql) {
|
||||
if (sql == null) {
|
||||
return null;
|
||||
}
|
||||
ParsingResult parsingResult = parseSql(sql);
|
||||
recordSqlParsingResult(parsingResult);
|
||||
return parsingResult;
|
||||
}
|
||||
|
||||
public void recordSqlParsingResult(ParsingResult parsingResult) {
|
||||
recordAttribute(AnnotationNames.SQL_ID, parsingResult.getSql().hashCode());
|
||||
String output = parsingResult.getOutput();
|
||||
if (output != null && output.length() != 0) {
|
||||
recordAttribute(AnnotationNames.SQL_PARAM, output);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ParsingResult parseSql(String sql) {
|
||||
public void recordSqlParsingResult(ParsingResult parsingResult) {
|
||||
recordAttribute(AnnotationNames.SQL_ID, parsingResult.getSql().hashCode());
|
||||
String output = parsingResult.getOutput();
|
||||
if (output != null && output.length() != 0) {
|
||||
recordAttribute(AnnotationNames.SQL_PARAM, output);
|
||||
}
|
||||
}
|
||||
|
||||
public ParsingResult parseSql(String sql) {
|
||||
// 해당 api의 구현을 그냥 tarceContext api에 만들어야 될듯 하다.
|
||||
ParsingResult parsingResult = this.sqlParser.normalizedSql(sql);
|
||||
String normalizedSql = parsingResult.getSql();
|
||||
@@ -330,56 +332,55 @@ public final class Trace {
|
||||
return parsingResult;
|
||||
}
|
||||
|
||||
public void recordAttribute(final String key, final Object value) {
|
||||
if (!tracingEnabled)
|
||||
return;
|
||||
public void recordAttribute(final String key, final Object value) {
|
||||
if (!tracingEnabled)
|
||||
return;
|
||||
|
||||
try {
|
||||
// TODO API 단일화 필요.
|
||||
StackFrame currentStackFrame = getCurrentStackFrame();
|
||||
if (currentStackFrame instanceof RootStackFrame) {
|
||||
Span span = ((RootStackFrame) currentStackFrame).getSpan();
|
||||
span.addAnnotation(new HippoAnnotation(key, value));
|
||||
} else {
|
||||
SubSpan span = ((SubStackFrame) currentStackFrame).getSubSpan();
|
||||
span.addAnnotation(new HippoAnnotation(key, value));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
// TODO API 단일화 필요.
|
||||
StackFrame currentStackFrame = getCurrentStackFrame();
|
||||
if (currentStackFrame instanceof RootStackFrame) {
|
||||
Span span = ((RootStackFrame) currentStackFrame).getSpan();
|
||||
span.addAnnotation(new HippoAnnotation(key, value));
|
||||
} else {
|
||||
SubSpan span = ((SubStackFrame) currentStackFrame).getSubSpan();
|
||||
span.addAnnotation(new HippoAnnotation(key, value));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void recordMessage(String message) {
|
||||
if (!tracingEnabled)
|
||||
return;
|
||||
public void recordMessage(String message) {
|
||||
if (!tracingEnabled)
|
||||
return;
|
||||
|
||||
annotate(message);
|
||||
}
|
||||
annotate(message);
|
||||
}
|
||||
|
||||
public void recordRpcName(final ServiceType serviceType, final String serviceName, final String rpc) {
|
||||
if (!tracingEnabled)
|
||||
return;
|
||||
public void recordRpcName(final ServiceType serviceType, final String serviceName, final String rpc) {
|
||||
if (!tracingEnabled)
|
||||
return;
|
||||
|
||||
try {
|
||||
// TODO API 단일화 필요.
|
||||
StackFrame currentStackFrame = getCurrentStackFrame();
|
||||
if (currentStackFrame instanceof RootStackFrame) {
|
||||
Span span = ((RootStackFrame) currentStackFrame).getSpan();
|
||||
span.setServiceType(serviceType);
|
||||
span.setServiceName(serviceName);
|
||||
span.setRpc(rpc);
|
||||
} else {
|
||||
SubSpan span = ((SubStackFrame) currentStackFrame).getSubSpan();
|
||||
span.setServiceType(serviceType);
|
||||
span.setServiceName(serviceName);
|
||||
span.setRpc(rpc);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
// TODO API 단일화 필요.
|
||||
StackFrame currentStackFrame = getCurrentStackFrame();
|
||||
if (currentStackFrame instanceof RootStackFrame) {
|
||||
Span span = ((RootStackFrame) currentStackFrame).getSpan();
|
||||
span.setServiceType(serviceType);
|
||||
span.setServiceName(serviceName);
|
||||
span.setRpc(rpc);
|
||||
} else {
|
||||
SubSpan span = ((SubStackFrame) currentStackFrame).getSubSpan();
|
||||
span.setServiceType(serviceType);
|
||||
span.setServiceName(serviceName);
|
||||
span.setRpc(rpc);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: final String... endPoint로 받으면 합치는데 비용이 들어가 그냥 한번에 받는게 나을것 같음.
|
||||
public void recordEndPoint(final String endPoint) {
|
||||
if (!tracingEnabled)
|
||||
return;
|
||||
@@ -396,35 +397,48 @@ public final class Trace {
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void annotate(final String key) {
|
||||
if (!tracingEnabled)
|
||||
return;
|
||||
public void recordNextSpanId(long spanId) {
|
||||
if (!tracingEnabled)
|
||||
return;
|
||||
|
||||
try {
|
||||
StackFrame currentStackFrame = getCurrentStackFrame();
|
||||
if (currentStackFrame instanceof RootStackFrame) {
|
||||
Span span = ((RootStackFrame) currentStackFrame).getSpan();
|
||||
span.addAnnotation(new HippoAnnotation(key));
|
||||
} else {
|
||||
SubSpan span = ((SubStackFrame) currentStackFrame).getSubSpan();
|
||||
span.addAnnotation(new HippoAnnotation(key));
|
||||
}
|
||||
try {
|
||||
StackFrame currentStackFrame = getCurrentStackFrame();
|
||||
if (currentStackFrame instanceof RootStackFrame) {
|
||||
logger.log(Level.WARNING, "OMG. Something's going wrong. Current stackframe is root Span. nextSpanId={}", spanId);
|
||||
} else {
|
||||
SubSpan span = ((SubStackFrame) currentStackFrame).getSubSpan();
|
||||
span.setNextSpanId(spanId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
private void annotate(final String key) {
|
||||
if (!tracingEnabled)
|
||||
return;
|
||||
|
||||
try {
|
||||
StackFrame currentStackFrame = getCurrentStackFrame();
|
||||
if (currentStackFrame instanceof RootStackFrame) {
|
||||
Span span = ((RootStackFrame) currentStackFrame).getSpan();
|
||||
span.addAnnotation(new HippoAnnotation(key));
|
||||
} else {
|
||||
SubSpan span = ((SubStackFrame) currentStackFrame).getSubSpan();
|
||||
span.addAnnotation(new HippoAnnotation(key));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSqlCacheTable(SqlCacheTable sqlCacheTable) {
|
||||
this.sqlCacheTable = sqlCacheTable;
|
||||
}
|
||||
|
||||
public void setSqlParser(SqlParser sqlParser) {
|
||||
this.sqlParser = sqlParser;
|
||||
}
|
||||
|
||||
public void setSqlCacheTable(SqlCacheTable sqlCacheTable) {
|
||||
this.sqlCacheTable = sqlCacheTable;
|
||||
}
|
||||
|
||||
public void setSqlParser(SqlParser sqlParser) {
|
||||
this.sqlParser = sqlParser;
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import com.profiler.modifier.db.mysql.MySQLStatementModifier;
|
||||
import com.profiler.modifier.db.oracle.OraclePreparedStatementModifier;
|
||||
import com.profiler.modifier.db.oracle.OracleResultSetModifier;
|
||||
import com.profiler.modifier.db.oracle.OracleStatementModifier;
|
||||
import com.profiler.modifier.dummy.DummyModifier;
|
||||
import com.profiler.modifier.servlet.FilterModifier;
|
||||
import com.profiler.modifier.servlet.HttpServletModifier;
|
||||
import com.profiler.modifier.servlet.SpringFrameworkServletModifier;
|
||||
@@ -65,6 +66,11 @@ public class DefaultModifierRegistry implements ModifierRegistry {
|
||||
throw new IllegalStateException("Modifier already exist new:" + modifier.getClass() + " old:" + old.getTargetClass());
|
||||
}
|
||||
}
|
||||
|
||||
public void addDummyModifier() {
|
||||
DummyModifier modifier = new DummyModifier(byteCodeInstrumentor, agent);
|
||||
addModifier(modifier);
|
||||
}
|
||||
|
||||
public void addConnectorModifier() {
|
||||
FilterModifier filterModifier = new FilterModifier(byteCodeInstrumentor, agent);
|
||||
|
||||
+5
-3
@@ -47,12 +47,14 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
TraceID traceId = populateTraceIdFromRequest(request);
|
||||
Trace trace;
|
||||
if (traceId != null) {
|
||||
TraceID nextTraceId = traceId.getNextTraceId();
|
||||
// TraceID nextTraceId = traceId.getNextTraceId();
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("TraceID exist. continue trace. " + nextTraceId);
|
||||
// logger.info("TraceID exist. continue trace. " + nextTraceId);
|
||||
logger.info("TraceID exist. continue trace. " + traceId);
|
||||
logger.log(Level.FINE, "requestUrl:" + requestURL + " clientIp" + clientIP + " parameter:" + parameters);
|
||||
}
|
||||
trace = new Trace(nextTraceId);
|
||||
// trace = new Trace(nextTraceId);
|
||||
trace = new Trace(traceId);
|
||||
traceContext.attachTraceObject(trace);
|
||||
} else {
|
||||
trace = new Trace();
|
||||
|
||||
+3
-2
@@ -47,7 +47,8 @@ public class Execute2MethodInterceptor implements StaticAroundInterceptor, ByteC
|
||||
trace.traceBlockBegin();
|
||||
trace.markBeforeTime();
|
||||
|
||||
TraceID nextId = trace.getTraceId();
|
||||
TraceID nextId = trace.getTraceId().getNextTraceId();
|
||||
trace.recordNextSpanId(nextId.getSpanId());
|
||||
|
||||
final HttpUriRequest request = (HttpUriRequest) args[0];
|
||||
|
||||
@@ -63,7 +64,7 @@ public class Execute2MethodInterceptor implements StaticAroundInterceptor, ByteC
|
||||
trace.recordRpcName(ServiceType.HTTP_CLIENT, request.getProtocolVersion().toString(), "CLIENT");
|
||||
|
||||
int port = host.getPort();
|
||||
trace.recordEndPoint(host.getHostName() + ((port > 0) ? ":" + port : ""));
|
||||
trace.recordEndPoint(request.getProtocolVersion() + ":" + host.getHostName() + ((port > 0) ? ":" + port : ""));
|
||||
trace.recordAttribute(AnnotationNames.HTTP_URL, request.getRequestLine().getUri());
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -51,8 +51,9 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
trace.traceBlockBegin();
|
||||
trace.markBeforeTime();
|
||||
|
||||
TraceID nextId = trace.getTraceId();
|
||||
nextId.getNextTraceId();
|
||||
TraceID nextId = trace.getTraceId().getNextTraceId();
|
||||
trace.recordNextSpanId(nextId.getSpanId());
|
||||
|
||||
final HttpHost host = (HttpHost) args[0];
|
||||
final HttpRequest request = (HttpRequest) args[1];
|
||||
// UUID format을 그대로.
|
||||
@@ -65,7 +66,7 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
trace.recordRpcName(ServiceType.HTTP_CLIENT, request.getProtocolVersion().toString(), "CLIENT");
|
||||
|
||||
int port = host.getPort();
|
||||
trace.recordEndPoint(host.getHostName() + ((port > 0) ? ":" + port : ""));
|
||||
trace.recordEndPoint(request.getProtocolVersion() + ":" + host.getHostName() + ((port > 0) ? ":" + port : ""));
|
||||
trace.recordAttribute(AnnotationNames.HTTP_URL, request.getRequestLine().getUri());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.profiler.modifier.dummy;
|
||||
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.profiler.Agent;
|
||||
import com.profiler.interceptor.Interceptor;
|
||||
import com.profiler.interceptor.bci.ByteCodeInstrumentor;
|
||||
import com.profiler.interceptor.bci.InstrumentClass;
|
||||
import com.profiler.interceptor.bci.InstrumentException;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
|
||||
/**
|
||||
* @author netspider
|
||||
*/
|
||||
public class DummyModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(DummyModifier.class.getName());
|
||||
|
||||
public DummyModifier(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent) {
|
||||
super(byteCodeInstrumentor, agent);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "com/nhn/hippo/testweb/service/DummyService";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
|
||||
byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
try {
|
||||
Interceptor doSomethingInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.method.interceptors.MethodInterceptor");
|
||||
Interceptor aInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.method.interceptors.MethodInterceptor");
|
||||
Interceptor bInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.method.interceptors.MethodInterceptor");
|
||||
Interceptor baInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.method.interceptors.MethodInterceptor");
|
||||
Interceptor bbInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.method.interceptors.MethodInterceptor");
|
||||
Interceptor baaInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.method.interceptors.MethodInterceptor");
|
||||
Interceptor cInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.method.interceptors.MethodInterceptor");
|
||||
Interceptor caInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.method.interceptors.MethodInterceptor");
|
||||
|
||||
setTraceContext(doSomethingInterceptor);
|
||||
setTraceContext(aInterceptor);
|
||||
setTraceContext(bInterceptor);
|
||||
setTraceContext(baInterceptor);
|
||||
setTraceContext(bbInterceptor);
|
||||
setTraceContext(baaInterceptor);
|
||||
setTraceContext(cInterceptor);
|
||||
setTraceContext(caInterceptor);
|
||||
|
||||
InstrumentClass dummyService = byteCodeInstrumentor.getClass(javassistClassName);
|
||||
|
||||
dummyService.addInterceptor("doSomething", null, doSomethingInterceptor);
|
||||
dummyService.addInterceptor("a", null, aInterceptor);
|
||||
dummyService.addInterceptor("b", null, bInterceptor);
|
||||
dummyService.addInterceptor("ba", null, baInterceptor);
|
||||
dummyService.addInterceptor("bb", null, bbInterceptor);
|
||||
dummyService.addInterceptor("baa", null, baaInterceptor);
|
||||
dummyService.addInterceptor("c", null, cInterceptor);
|
||||
dummyService.addInterceptor("ca", null, caInterceptor);
|
||||
|
||||
return dummyService.toBytecode();
|
||||
} catch (InstrumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,13 @@ public class MethodInterceptor implements StaticAroundInterceptor, ByteCodeMetho
|
||||
return;
|
||||
}
|
||||
|
||||
trace.traceBlockBegin();
|
||||
try {
|
||||
trace.traceBlockBegin();
|
||||
} catch (Exception e) {
|
||||
System.out.println("@@@@@@@@@@@@" + e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
trace.recordRpcName(ServiceType.INTERNAL_METHOD, null, null);
|
||||
trace.markBeforeTime();
|
||||
}
|
||||
@@ -52,11 +58,9 @@ public class MethodInterceptor implements StaticAroundInterceptor, ByteCodeMetho
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
trace.recordApi(descriptor);
|
||||
// trace.recordApi(this.apiId);
|
||||
trace.recordException(result);
|
||||
|
||||
trace.markAfterTime();
|
||||
trace.traceBlockEnd();
|
||||
}
|
||||
|
||||
@@ -70,12 +70,14 @@ public class DoXXXInterceptor implements StaticAroundInterceptor, ByteCodeMethod
|
||||
TraceID traceId = populateTraceIdFromRequest(request);
|
||||
Trace trace;
|
||||
if (traceId != null) {
|
||||
TraceID nextTraceId = traceId.getNextTraceId();
|
||||
// TraceID nextTraceId = traceId.getNextTraceId();
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("TraceID exist. continue trace. " + nextTraceId);
|
||||
// logger.info("TraceID exist. continue trace. " + nextTraceId);
|
||||
logger.info("TraceID exist. continue trace. " + traceId);
|
||||
logger.log(Level.FINE, "requestUrl:" + requestURL + " clientIp" + clientIP);
|
||||
}
|
||||
trace = new Trace(nextTraceId);
|
||||
// trace = new Trace(nextTraceId);
|
||||
trace = new Trace(traceId);
|
||||
traceContext.attachTraceObject(trace);
|
||||
} else {
|
||||
trace = new Trace();
|
||||
|
||||
+5
-3
@@ -46,12 +46,14 @@ public class StandardHostValveInvokeInterceptor implements StaticAroundIntercept
|
||||
TraceID traceId = populateTraceIdFromRequest(request);
|
||||
Trace trace;
|
||||
if (traceId != null) {
|
||||
TraceID nextTraceId = traceId.getNextTraceId();
|
||||
// TraceID nextTraceId = traceId.getNextTraceId();
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("TraceID exist. continue trace. " + nextTraceId);
|
||||
// logger.info("TraceID exist. continue trace. " + nextTraceId);
|
||||
logger.info("TraceID exist. continue trace. " + traceId);
|
||||
logger.log(Level.FINE, "requestUrl:" + requestURL + " clientIp" + clientIP);
|
||||
}
|
||||
trace = new Trace(nextTraceId);
|
||||
// trace = new Trace(nextTraceId);
|
||||
trace = new Trace(traceId);
|
||||
traceContext.attachTraceObject(trace);
|
||||
} else {
|
||||
trace = new Trace();
|
||||
|
||||
Reference in New Issue
Block a user