mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-20 18:25:55 +10:00
[강운덕] [LUCYSUS-1744] api 를 상수로 매핑하는 코드 개발.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@927 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.profiler.common.dto.thrift.AgentInfo;
|
||||
import com.profiler.common.mapping.ApiMappingTable;
|
||||
import com.profiler.common.util.SpanUtils;
|
||||
import com.profiler.context.TraceContext;
|
||||
import com.profiler.sender.DataSender;
|
||||
@@ -46,6 +47,11 @@ public class Agent {
|
||||
TraceContext traceContext = TraceContext.getTraceContext();
|
||||
traceContext.setDataSender(this.dataSender);
|
||||
systemMonitor.setDataSender(dataSender);
|
||||
|
||||
// 매핑 테이블 초기화를 위해 엑세스
|
||||
|
||||
ApiMappingTable.findApiId("test", null, null);
|
||||
|
||||
}
|
||||
|
||||
private String getId(String key, String defaultValue) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.profiler.context;
|
||||
|
||||
@Deprecated
|
||||
public interface SpanUpdater {
|
||||
Span updateSpan(Span span);
|
||||
Span updateSpan(Span span);
|
||||
}
|
||||
|
||||
@@ -227,17 +227,27 @@ public final class Trace {
|
||||
if (methodDescriptor == null) {
|
||||
return;
|
||||
}
|
||||
String method = methodDescriptor.getClassName() + "." + methodDescriptor.getMethodName() + methodDescriptor.getSimpleParameterDescriptor() + ":" + methodDescriptor.getLineNumber();
|
||||
String method = methodDescriptor.getClassName() + "." + methodDescriptor.getMethodName() + methodDescriptor.getParameterDescriptor() + ":" + methodDescriptor.getLineNumber();
|
||||
recordAttribute("API", method);
|
||||
}
|
||||
|
||||
public void recordApi(MethodDescriptor methodDescriptor, Object[] args) {
|
||||
// API 저장 방법의 개선 필요.
|
||||
String method = methodDescriptor.getClassName() + "." + methodDescriptor.getMethodName() + methodDescriptor.getSimpleParameterDescriptor() + ":" + methodDescriptor.getLineNumber();
|
||||
String method = methodDescriptor.getClassName() + "." + methodDescriptor.getMethodName() + methodDescriptor.getParameterDescriptor() + ":" + methodDescriptor.getLineNumber();
|
||||
recordAttribute("API", method);
|
||||
recocordArgs(args);
|
||||
}
|
||||
|
||||
public void recordApi(int apiId) {
|
||||
recordAttribute("API-ID", apiId);
|
||||
}
|
||||
|
||||
public void recordApi(int apiId, Object[] args) {
|
||||
recordAttribute("API-ID", apiId);
|
||||
recocordArgs(args);
|
||||
}
|
||||
|
||||
|
||||
private void recocordArgs(Object[] args) {
|
||||
if (args != null) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
@@ -310,4 +320,7 @@ public final class Trace {
|
||||
}
|
||||
|
||||
|
||||
public void setTransactionId(int transactionId) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import com.profiler.sender.DataSender;
|
||||
import com.profiler.sender.LoggingDataSender;
|
||||
import com.profiler.util.NamedThreadLocal;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class TraceContext {
|
||||
|
||||
private static TraceContext CONTEXT = new TraceContext();
|
||||
@@ -19,9 +21,13 @@ public class TraceContext {
|
||||
return CONTEXT;
|
||||
}
|
||||
|
||||
private ThreadLocal<Trace> threadLocal = new NamedThreadLocal<Trace>("TraceContext");
|
||||
private ThreadLocal<Trace> threadLocal = new NamedThreadLocal<Trace>("Trace");
|
||||
|
||||
private final ActiveThreadCounter activeThreadCounter = new ActiveThreadCounter();
|
||||
|
||||
// internal stacktrace 추적때 필요한 unique 아이디, activethreadcount의 slow 타임 계산의 위해서도 필요할듯 함.
|
||||
private final AtomicInteger transactionId = new AtomicInteger(0);
|
||||
|
||||
private static final DataSender DEFAULT_DATA_SENDER = new LoggingDataSender();
|
||||
|
||||
private DataSender dataSender = DEFAULT_DATA_SENDER;
|
||||
@@ -43,6 +49,8 @@ public class TraceContext {
|
||||
}
|
||||
// datasender연결 부분 수정 필요.
|
||||
trace.setDataSender(this.dataSender);
|
||||
//
|
||||
// trace.setTransactionId(transactionId.getAndIncrement());
|
||||
threadLocal.set(trace);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.profiler.interceptor;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface ApiIdSupport {
|
||||
void setApiId(int apiId);
|
||||
}
|
||||
@@ -5,12 +5,10 @@ package com.profiler.interceptor;
|
||||
*/
|
||||
public class DefaultMethodDescriptor implements MethodDescriptor {
|
||||
private String className;
|
||||
private String simpleClassName;
|
||||
|
||||
private String methodName;
|
||||
|
||||
private String[] parameterTypes;
|
||||
private String[] simpleParameterTypes;
|
||||
|
||||
private String[] parameterVariableName;
|
||||
|
||||
@@ -18,14 +16,19 @@ public class DefaultMethodDescriptor implements MethodDescriptor {
|
||||
private String parameterDescriptor;
|
||||
|
||||
|
||||
private String simpleParameterDescriptor;
|
||||
|
||||
private int lineNumber;
|
||||
|
||||
|
||||
public DefaultMethodDescriptor() {
|
||||
}
|
||||
|
||||
public DefaultMethodDescriptor(String className, String methodName, String[] parameterTypes, String[] parameterVariableName) {
|
||||
this.className = className;
|
||||
this.methodName = methodName;
|
||||
this.parameterTypes = parameterTypes;
|
||||
this.parameterVariableName = parameterVariableName;
|
||||
}
|
||||
|
||||
public String getParameterDescriptor() {
|
||||
return parameterDescriptor;
|
||||
}
|
||||
@@ -34,14 +37,6 @@ public class DefaultMethodDescriptor implements MethodDescriptor {
|
||||
this.parameterDescriptor = parameterDescriptor;
|
||||
}
|
||||
|
||||
public String getSimpleParameterDescriptor() {
|
||||
return simpleParameterDescriptor;
|
||||
}
|
||||
|
||||
public void setSimpleParameterDescriptor(String simpleParameterDescriptor) {
|
||||
this.simpleParameterDescriptor = simpleParameterDescriptor;
|
||||
}
|
||||
|
||||
|
||||
public void setMethodName(String methodName) {
|
||||
this.methodName = methodName;
|
||||
@@ -69,14 +64,6 @@ public class DefaultMethodDescriptor implements MethodDescriptor {
|
||||
return className;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSimpleClassName() {
|
||||
return simpleClassName;
|
||||
}
|
||||
|
||||
public void setSimpleClassName(String simpleClassName) {
|
||||
this.simpleClassName = simpleClassName;
|
||||
}
|
||||
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
@@ -92,13 +79,6 @@ public class DefaultMethodDescriptor implements MethodDescriptor {
|
||||
return parameterVariableName;
|
||||
}
|
||||
|
||||
public String[] getSimpleParameterTypes() {
|
||||
return simpleParameterTypes;
|
||||
}
|
||||
|
||||
public void setSimpleParameterTypes(String[] simpleParameterTypes) {
|
||||
this.simpleParameterTypes = simpleParameterTypes;
|
||||
}
|
||||
|
||||
public int getLineNumber() {
|
||||
return lineNumber;
|
||||
|
||||
@@ -10,18 +10,14 @@ public interface MethodDescriptor {
|
||||
|
||||
String getClassName();
|
||||
|
||||
String getSimpleClassName();
|
||||
|
||||
String[] getParameterTypes();
|
||||
|
||||
String[] getSimpleParameterTypes();
|
||||
|
||||
String[] getParameterVariableName();
|
||||
|
||||
|
||||
String getParameterDescriptor();
|
||||
|
||||
String getSimpleParameterDescriptor();
|
||||
|
||||
int getLineNumber();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.profiler.common.mapping.ApiMappingTable;
|
||||
import com.profiler.common.mapping.ApiUtils;
|
||||
import com.profiler.interceptor.*;
|
||||
import com.profiler.util.JavaAssistUtils;
|
||||
import javassist.*;
|
||||
@@ -166,6 +168,9 @@ public class JavaAssistClass implements InstrumentClass {
|
||||
if (interceptor instanceof ByteCodeMethodDescriptorSupport) {
|
||||
setMethodDescriptor(behavior, (ByteCodeMethodDescriptorSupport) interceptor);
|
||||
}
|
||||
if (interceptor instanceof ApiIdSupport) {
|
||||
setApiId(behavior, (ApiIdSupport) interceptor);
|
||||
}
|
||||
} else {
|
||||
interceptor = InterceptorRegistry.getInterceptor(interceptorId);
|
||||
}
|
||||
@@ -197,6 +202,13 @@ public class JavaAssistClass implements InstrumentClass {
|
||||
}
|
||||
}
|
||||
|
||||
private void setApiId(CtBehavior behavior, ApiIdSupport interceptor) throws NotFoundException {
|
||||
CtClass[] parameterTypes = behavior.getParameterTypes();
|
||||
String[] parameterType = JavaAssistUtils.getParameterType(parameterTypes);
|
||||
int apiId = ApiMappingTable.findApiId(ctClass.getName(), behavior.getName(), parameterType);
|
||||
interceptor.setApiId(apiId);
|
||||
}
|
||||
|
||||
private void setMethodDescriptor(CtBehavior behavior, ByteCodeMethodDescriptorSupport interceptor) throws NotFoundException {
|
||||
DefaultMethodDescriptor methodDescriptor = new DefaultMethodDescriptor();
|
||||
|
||||
@@ -204,26 +216,20 @@ public class JavaAssistClass implements InstrumentClass {
|
||||
methodDescriptor.setMethodName(methodName);
|
||||
|
||||
methodDescriptor.setClassName(ctClass.getName());
|
||||
methodDescriptor.setSimpleClassName(ctClass.getSimpleName());
|
||||
|
||||
CtClass[] parameterTypes = behavior.getParameterTypes();
|
||||
String[] parameterType = JavaAssistUtils.getParameterType(parameterTypes);
|
||||
methodDescriptor.setParameterTypes(parameterType);
|
||||
|
||||
String[] parameterSimpleType = JavaAssistUtils.getParameterSimpleType(parameterTypes);
|
||||
methodDescriptor.setSimpleParameterTypes(parameterSimpleType);
|
||||
|
||||
String[] parameterVariableName = JavaAssistUtils.getParameterVariableName(behavior);
|
||||
methodDescriptor.setParameterVariableName(parameterVariableName);
|
||||
|
||||
int lineNumber = JavaAssistUtils.getLineNumber(behavior);
|
||||
methodDescriptor.setLineNumber(lineNumber);
|
||||
|
||||
String parameterDescription = JavaAssistUtils.mergeParameterVariableNameDescription(parameterType, parameterVariableName);
|
||||
String parameterDescription = ApiUtils.mergeParameterVariableNameDescription(parameterType, parameterVariableName);
|
||||
methodDescriptor.setParameterDescriptor(parameterDescription);
|
||||
|
||||
String simpleParameterDescription = JavaAssistUtils.mergeParameterVariableNameDescription(parameterType, parameterVariableName);
|
||||
methodDescriptor.setSimpleParameterDescriptor(simpleParameterDescription);
|
||||
|
||||
interceptor.setMethodDescriptor(methodDescriptor);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.profiler.modifier.db.interceptor;
|
||||
import com.profiler.context.Annotation;
|
||||
import com.profiler.context.Trace;
|
||||
import com.profiler.context.TraceContext;
|
||||
import com.profiler.interceptor.ApiIdSupport;
|
||||
import com.profiler.interceptor.ByteCodeMethodDescriptorSupport;
|
||||
import com.profiler.interceptor.MethodDescriptor;
|
||||
import com.profiler.interceptor.StaticAroundInterceptor;
|
||||
@@ -19,13 +20,15 @@ import java.util.logging.Logger;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class DriverConnectInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport {
|
||||
public class DriverConnectInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport, ApiIdSupport {
|
||||
|
||||
private final Logger logger = Logger.getLogger(DriverConnectInterceptor.class.getName());
|
||||
private final MetaObject setUrl = new MetaObject("__setUrl", Object.class);
|
||||
|
||||
private JDBCUrlParser urlParser = new JDBCUrlParser();
|
||||
|
||||
private MethodDescriptor descriptor;
|
||||
private int apiId;
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
@@ -74,7 +77,8 @@ public class DriverConnectInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
|
||||
trace.recordApi(descriptor, new Object[]{args[0]});
|
||||
// trace.recordApi(descriptor, new Object[]{args[0]});
|
||||
trace.recordApi(apiId, new Object[]{args[0]});
|
||||
trace.recordException(result);
|
||||
|
||||
trace.markAfterTime();
|
||||
@@ -94,4 +98,9 @@ public class DriverConnectInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApiId(int apiId) {
|
||||
this.apiId = apiId;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-6
@@ -2,10 +2,7 @@ package com.profiler.modifier.db.interceptor;
|
||||
|
||||
import com.profiler.context.Trace;
|
||||
import com.profiler.context.TraceContext;
|
||||
import com.profiler.interceptor.ByteCodeMethodDescriptorSupport;
|
||||
import com.profiler.interceptor.MethodDescriptor;
|
||||
import com.profiler.interceptor.StaticAfterInterceptor;
|
||||
import com.profiler.interceptor.StaticAroundInterceptor;
|
||||
import com.profiler.interceptor.*;
|
||||
import com.profiler.modifier.db.util.DatabaseInfo;
|
||||
import com.profiler.util.InterceptorUtils;
|
||||
import com.profiler.util.MetaObject;
|
||||
@@ -16,7 +13,7 @@ import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class PreparedStatementCreateInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport {
|
||||
public class PreparedStatementCreateInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport, ApiIdSupport {
|
||||
private final Logger logger = Logger.getLogger(PreparedStatementCreateInterceptor.class.getName());
|
||||
|
||||
private MethodDescriptor descriptor;
|
||||
@@ -26,6 +23,7 @@ public class PreparedStatementCreateInterceptor implements StaticAroundIntercept
|
||||
private final MetaObject setUrl = new MetaObject("__setUrl", Object.class);
|
||||
|
||||
private final MetaObject setSql = new MetaObject("__setSql", String.class);
|
||||
private int apiId;
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
@@ -77,7 +75,8 @@ public class PreparedStatementCreateInterceptor implements StaticAroundIntercept
|
||||
// trace.recordAttribute("PreparedStatement", sql);
|
||||
}
|
||||
|
||||
trace.recordApi(descriptor, args);
|
||||
// trace.recordApi(descriptor, args);
|
||||
trace.recordApi(apiId, args);
|
||||
|
||||
trace.markAfterTime();
|
||||
trace.traceBlockEnd();
|
||||
@@ -88,4 +87,9 @@ public class PreparedStatementCreateInterceptor implements StaticAroundIntercept
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApiId(int apiId) {
|
||||
this.apiId = apiId;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-2
@@ -3,6 +3,7 @@ package com.profiler.modifier.db.interceptor;
|
||||
import com.profiler.context.Annotation;
|
||||
import com.profiler.context.Trace;
|
||||
import com.profiler.context.TraceContext;
|
||||
import com.profiler.interceptor.ApiIdSupport;
|
||||
import com.profiler.interceptor.ByteCodeMethodDescriptorSupport;
|
||||
import com.profiler.interceptor.MethodDescriptor;
|
||||
import com.profiler.interceptor.StaticAroundInterceptor;
|
||||
@@ -18,7 +19,7 @@ import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport {
|
||||
public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport, ApiIdSupport {
|
||||
|
||||
private final Logger logger = Logger.getLogger(PreparedStatementExecuteQueryInterceptor.class.getName());
|
||||
|
||||
@@ -28,6 +29,7 @@ public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInt
|
||||
private final MetaObject setBindValue = new MetaObject("__setBindValue", Map.class);
|
||||
|
||||
private MethodDescriptor descriptor;
|
||||
private int apiId;
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
@@ -57,7 +59,8 @@ public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInt
|
||||
String bindString = toBindVariable(bindValue);
|
||||
trace.recordAttribute("BindValue", bindString);
|
||||
|
||||
trace.recordApi(descriptor, args);
|
||||
// trace.recordApi(descriptor, args);
|
||||
trace.recordApi(apiId);
|
||||
|
||||
clean(target);
|
||||
|
||||
@@ -118,4 +121,9 @@ public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInt
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApiId(int apiId) {
|
||||
this.apiId = apiId;
|
||||
}
|
||||
}
|
||||
|
||||
+14
-12
@@ -3,6 +3,7 @@ package com.profiler.modifier.db.interceptor;
|
||||
import com.profiler.context.Annotation;
|
||||
import com.profiler.context.Trace;
|
||||
import com.profiler.context.TraceContext;
|
||||
import com.profiler.interceptor.ApiIdSupport;
|
||||
import com.profiler.interceptor.StaticAroundInterceptor;
|
||||
import com.profiler.modifier.db.util.DatabaseInfo;
|
||||
import com.profiler.util.MetaObject;
|
||||
@@ -17,11 +18,12 @@ import java.util.logging.Logger;
|
||||
*
|
||||
* @author netspider
|
||||
*/
|
||||
public class StatementExecuteUpdateInterceptor implements StaticAroundInterceptor {
|
||||
public class StatementExecuteUpdateInterceptor implements StaticAroundInterceptor, ApiIdSupport {
|
||||
|
||||
private final Logger logger = Logger.getLogger(StatementExecuteUpdateInterceptor.class.getName());
|
||||
|
||||
private final MetaObject<Object> getUrl = new MetaObject<Object>("__getUrl");
|
||||
private int apiId;
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
@@ -42,17 +44,10 @@ public class StatementExecuteUpdateInterceptor implements StaticAroundIntercepto
|
||||
trace.markBeforeTime();
|
||||
|
||||
try {
|
||||
if (args.length > 0) {
|
||||
DatabaseInfo databaseInfo = (DatabaseInfo) this.getUrl.invoke(target);
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
trace.recordAttribute("Query", args[0]);
|
||||
} else {
|
||||
DatabaseInfo databaseInfo = (DatabaseInfo) this.getUrl.invoke(target);
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
trace.recordAttribute("Query", "args size is 0");
|
||||
}
|
||||
DatabaseInfo databaseInfo = (DatabaseInfo) this.getUrl.invoke(target);
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
trace.recordApi(apiId, args);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -76,8 +71,15 @@ public class StatementExecuteUpdateInterceptor implements StaticAroundIntercepto
|
||||
return;
|
||||
}
|
||||
|
||||
trace.recordException(result);
|
||||
|
||||
// TODO 결과, 수행시간을.알수 있어야 될듯.
|
||||
trace.markAfterTime();
|
||||
trace.traceBlockEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApiId(int apiId) {
|
||||
this.apiId = apiId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import com.profiler.context.Trace;
|
||||
import com.profiler.context.TraceContext;
|
||||
import com.profiler.interceptor.ApiIdSupport;
|
||||
import com.profiler.interceptor.ByteCodeMethodDescriptorSupport;
|
||||
import com.profiler.interceptor.MethodDescriptor;
|
||||
import com.profiler.interceptor.StaticAroundInterceptor;
|
||||
@@ -14,12 +15,13 @@ import com.profiler.modifier.db.util.DatabaseInfo;
|
||||
import com.profiler.util.MetaObject;
|
||||
import com.profiler.util.StringUtils;
|
||||
|
||||
public class TransactionInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport {
|
||||
public class TransactionInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport, ApiIdSupport {
|
||||
|
||||
private final Logger logger = Logger.getLogger(TransactionInterceptor.class.getName());
|
||||
|
||||
private final MetaObject<Object> getUrl = new MetaObject<Object>("__getUrl");
|
||||
private MethodDescriptor descriptor;
|
||||
private int apiId;
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
@@ -83,7 +85,8 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
|
||||
|
||||
private void afterStartTransaction(Trace trace, Connection target, Object[] arg, Object result) {
|
||||
try {
|
||||
trace.recordApi(descriptor, arg);
|
||||
// trace.recordApi(descriptor, arg);
|
||||
trace.recordApi(apiId, arg);
|
||||
trace.recordException(result);
|
||||
// Boolean autocommit = (Boolean) arg;
|
||||
// boolean success = InterceptorUtils.isSuccess(result);
|
||||
@@ -135,7 +138,8 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
|
||||
trace.recordApi(descriptor);
|
||||
// trace.recordApi(descriptor);
|
||||
trace.recordApi(apiId);
|
||||
trace.recordException(result);
|
||||
|
||||
// boolean success = InterceptorUtils.isSuccess(result);
|
||||
@@ -174,7 +178,8 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
|
||||
trace.recordApi(descriptor);
|
||||
// trace.recordApi(descriptor);
|
||||
trace.recordApi(apiId);
|
||||
trace.recordException(result);
|
||||
// boolean success = InterceptorUtils.isSuccess(result);
|
||||
// if (success) {
|
||||
@@ -197,4 +202,9 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApiId(int apiId) {
|
||||
this.apiId = apiId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,15 @@ public class MySQLStatementModifier extends AbstractModifier {
|
||||
statementClass.addInterceptor("executeQuery", new String[]{"java.lang.String"}, interceptor);
|
||||
|
||||
// TODO 이거 고쳐야 됨.
|
||||
Interceptor executeUpdate = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.interceptor.StatementExecuteUpdateInterceptor");
|
||||
statementClass.addInterceptor("executeUpdate", new String[]{"java.lang.String", "boolean", "boolean"}, executeUpdate);
|
||||
Interceptor executeUpdate1 = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.interceptor.StatementExecuteUpdateInterceptor");
|
||||
statementClass.addInterceptor("executeUpdate", new String[]{"java.lang.String"}, executeUpdate1);
|
||||
Interceptor executeUpdate2 = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.interceptor.StatementExecuteUpdateInterceptor");
|
||||
statementClass.addInterceptor("executeUpdate", new String[]{"java.lang.String", "boolean"}, executeUpdate2);
|
||||
|
||||
Interceptor executeUpdate3 = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.interceptor.StatementExecuteUpdateInterceptor");
|
||||
statementClass.addInterceptor("execute", new String[]{"java.lang.String"}, executeUpdate3);
|
||||
Interceptor executeUpdate4 = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.interceptor.StatementExecuteUpdateInterceptor");
|
||||
statementClass.addInterceptor("execute", new String[]{"java.lang.String", "boolean"}, executeUpdate4);
|
||||
|
||||
statementClass.addTraceVariable("__url", "__setUrl", "__getUrl", "java.lang.Object");
|
||||
return statementClass.toBytecode();
|
||||
|
||||
@@ -85,29 +85,6 @@ public class JavaAssistUtils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String mergeParameterVariableNameDescription(String[] paramterType, String[] variableName) {
|
||||
if (paramterType.length != variableName.length) {
|
||||
throw new IllegalArgumentException("args size not equal");
|
||||
}
|
||||
if (paramterType.length == 0) {
|
||||
return EMTPY_ARRAY;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder(64);
|
||||
sb.append('(');
|
||||
int end = paramterType.length - 1;
|
||||
for (int i = 0; i < paramterType.length; i++) {
|
||||
sb.append(paramterType[i]);
|
||||
sb.append(' ');
|
||||
sb.append(variableName[i]);
|
||||
if (i < end) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
sb.append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String getParameterDescription(String[] params) {
|
||||
if (params == null) {
|
||||
|
||||
Reference in New Issue
Block a user