[강운덕] [LUCYSUS-1744] span의 데이터를 api 를 기반으로 변경하기 위해 1차 적으로 정적으로 api정보를 수집받을수 있도록 수정함.

method의 parameter의 variablename을 획득할수 있도록 수정함. 단 디버그 컴파일 시만 간능함.

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@871 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Woonduk Kang
2012-11-16 13:03:57 +00:00
parent 515b0237e7
commit b8c73bfdef
14 changed files with 657 additions and 291 deletions
@@ -3,6 +3,8 @@ 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.ByteCodeMethodDescriptorSupport;
import com.profiler.interceptor.MethodDescriptor;
import com.profiler.interceptor.StaticAroundInterceptor;
import com.profiler.modifier.db.util.DatabaseInfo;
import com.profiler.util.InterceptorUtils;
@@ -16,7 +18,7 @@ import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInterceptor {
public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport {
private final Logger logger = Logger.getLogger(PreparedStatementExecuteQueryInterceptor.class.getName());
@@ -25,6 +27,7 @@ public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInt
private final MetaObject<Map> getBindValue = new MetaObject<Map>("__getBindValue");
private final MetaObject setBindValue = new MetaObject("__setBindValue", Map.class);
private MethodDescriptor descriptor;
@Override
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
@@ -37,6 +40,7 @@ public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInt
}
TraceContext traceContext = TraceContext.getTraceContext();
Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
@@ -52,6 +56,7 @@ public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInt
Map bindValue = getBindValue.invoke(target);
String bindString = toBindVariable(bindValue);
trace.recordAttribute("BindValue", bindString);
trace.recordAttribute("API", descriptor.getClassName() + "." + descriptor.getMethodName() + descriptor.getSimpleParameterDescriptor());
clean(target);
@@ -113,4 +118,8 @@ public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInt
}
}
@Override
public void setMethodDescriptor(MethodDescriptor descriptor) {
this.descriptor = descriptor;
}
}
@@ -45,9 +45,12 @@ public class MySQLPreparedStatementModifier extends AbstractModifier {
try {
InstrumentClass preparedStatement = byteCodeInstrumentor.getClass(javassistClassName);
Interceptor interceptor = new PreparedStatementExecuteQueryInterceptor();
int id = preparedStatement.addInterceptor("executeQuery", null, interceptor);
preparedStatement.reuseInterceptor("executeUpdate", null, id);
Interceptor execute = new PreparedStatementExecuteQueryInterceptor();
preparedStatement.addInterceptor("execute", null, execute);
Interceptor executeQuery = new PreparedStatementExecuteQueryInterceptor();
preparedStatement.addInterceptor("executeQuery", null, executeQuery);
Interceptor executeUpdate = new PreparedStatementExecuteQueryInterceptor();
preparedStatement.addInterceptor("executeUpdate", null, executeUpdate);
preparedStatement.addTraceVariable("__url", "__setUrl", "__getUrl", "java.lang.Object");
preparedStatement.addTraceVariable("__sql", "__setSql", "__getSql", "java.lang.String");
@@ -10,14 +10,17 @@ public class DatabaseInfo {
DBType type = DBType.UNKOWN;
String databaseId;
String url;
// 입력된 url을 보정하지 않은 값
String realUrl;
String normalizedUrl;
String host;
String port;
public DatabaseInfo(DBType type, String url, String host, String port, String databaseId) {
public DatabaseInfo(DBType type, String realUrl, String normalizedUrl, String host, String port, String databaseId) {
this.type = type;
this.url = url;
this.realUrl = realUrl;
this.normalizedUrl = normalizedUrl;
this.host = host;
this.port = port;
this.databaseId = databaseId;
@@ -39,8 +42,12 @@ public class DatabaseInfo {
return databaseId;
}
public String getRealUrl() {
return realUrl;
}
public String getUrl() {
return url;
return normalizedUrl;
}
public DBType getType() {
@@ -52,7 +59,8 @@ public class DatabaseInfo {
return "DatabaseInfo{" +
"type=" + type +
", databaseId='" + databaseId + '\'' +
", url='" + url + '\'' +
", realUrl='" + realUrl + '\'' +
", normalizedUrl='" + normalizedUrl + '\'' +
", host='" + host + '\'' +
", port='" + port + '\'' +
'}';
@@ -7,12 +7,15 @@ import java.util.regex.Matcher;
*/
public class JDBCUrlParser {
public DatabaseInfo parse(String url) {
String lowCaseURL = url.toLowerCase();
if (lowCaseURL.contains("jdbc:mysql")) {
String lowCaseURL = url.toLowerCase().trim();
if (lowCaseURL.startsWith("jdbc:mysql")) {
return parseMysql(url);
}
if (lowCaseURL.startsWith("jdbc:oracle")) {
return parseOracle(url);
}
return new DatabaseInfo(DatabaseInfo.DBType.UNKOWN, url, "error", "error", "error");
return new DatabaseInfo(DatabaseInfo.DBType.UNKOWN, url, url, "error", "error", "error");
// else if (url.indexOf("jdbc:oracle") >= 0) {
// maker.lower().after("jdbc:oracle:").after(':');
// info.type = TYPE.ORACLE;
@@ -60,6 +63,11 @@ public class JDBCUrlParser {
// return null;
}
private DatabaseInfo parseOracle(String url) {
return null;
}
private DatabaseInfo parseMysql(String url) {
// jdbc:mysql://10.98.133.22:3306/test_lucy_db
StringMaker maker = new StringMaker(url);
@@ -67,6 +75,7 @@ public class JDBCUrlParser {
String host = maker.after("//").before('/').before(':').value();
String port = maker.next().after(':').before('/').value();
String databaseId = maker.next().afterLast('/').before('?').value();
return new DatabaseInfo(DatabaseInfo.DBType.MYSQL, url, host, port, databaseId);
String normalizedUrl = maker.clear().before('?').value();
return new DatabaseInfo(DatabaseInfo.DBType.MYSQL, url, normalizedUrl, host, port, databaseId);
}
}