mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-23 03:36:31 +10:00
[유치수] [NOBTS] modify mysql interceptor.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@594 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
+10
-15
@@ -8,23 +8,18 @@ import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
public class CloseConnectionInterceptor implements StaticBeforeInterceptor {
|
||||
|
||||
private final Logger logger = Logger.getLogger(CloseConnectionInterceptor.class.getName());
|
||||
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("before " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
|
||||
}
|
||||
|
||||
if (target instanceof Connection) {
|
||||
ConnectionTrace connectionTrace = ConnectionTrace.getConnectionTrace();
|
||||
connectionTrace.closeConnection((Connection) target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final Logger logger = Logger.getLogger(CloseConnectionInterceptor.class.getName());
|
||||
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("before " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
|
||||
}
|
||||
|
||||
if (target instanceof Connection) {
|
||||
ConnectionTrace connectionTrace = ConnectionTrace.getConnectionTrace();
|
||||
connectionTrace.closeConnection((Connection) target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-22
@@ -1,35 +1,34 @@
|
||||
package com.profiler.modifier.db.mysql.interceptors;
|
||||
|
||||
import com.profiler.interceptor.StaticAfterInterceptor;
|
||||
import com.profiler.modifier.db.ConnectionTrace;
|
||||
import com.profiler.util.InterceptorUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.profiler.interceptor.StaticAfterInterceptor;
|
||||
import com.profiler.modifier.db.ConnectionTrace;
|
||||
import com.profiler.util.InterceptorUtils;
|
||||
|
||||
public class CreateConnectionInterceptor implements StaticAfterInterceptor {
|
||||
|
||||
private final Logger logger = Logger.getLogger(CreateConnectionInterceptor.class.getName());
|
||||
private final Logger logger = Logger.getLogger(CreateConnectionInterceptor.class.getName());
|
||||
|
||||
@Override
|
||||
public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("after " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result);
|
||||
}
|
||||
@Override
|
||||
public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("after " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result);
|
||||
}
|
||||
|
||||
if (InterceptorUtils.isThrowable(result)) {
|
||||
return;
|
||||
}
|
||||
if (InterceptorUtils.isThrowable(result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result instanceof Connection) {
|
||||
Object url = args[4];
|
||||
if (url instanceof String) {
|
||||
ConnectionTrace connectionTrace = ConnectionTrace.getConnectionTrace();
|
||||
connectionTrace.createConnection((Connection)result, (String) url);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (result instanceof Connection) {
|
||||
Object url = args[4];
|
||||
if (url instanceof String) {
|
||||
ConnectionTrace connectionTrace = ConnectionTrace.getConnectionTrace();
|
||||
connectionTrace.createConnection((Connection) result, (String) url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+36
-39
@@ -13,46 +13,43 @@ import java.util.logging.Logger;
|
||||
|
||||
public class CreateStatementInterceptor implements StaticAfterInterceptor {
|
||||
|
||||
private final Logger logger = Logger.getLogger(CreateStatementInterceptor.class.getName());
|
||||
private final Logger logger = Logger.getLogger(CreateStatementInterceptor.class.getName());
|
||||
|
||||
private Method setUrl = null;
|
||||
private Method setUrl = null;
|
||||
|
||||
@Override
|
||||
public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("after " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result);
|
||||
}
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
return;
|
||||
}
|
||||
if (target instanceof Connection) {
|
||||
ConnectionTrace connectionTrace = ConnectionTrace.getConnectionTrace();
|
||||
String connectionUrl = connectionTrace.getConnectionUrl((Connection) target);
|
||||
setUrl(result, connectionUrl);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void setUrl(Object result, String connectionUrl) {
|
||||
try {
|
||||
if (setUrl == null) {
|
||||
setUrl = result.getClass().getMethod("__setUrl", String.class);
|
||||
}
|
||||
setUrl.invoke(result, connectionUrl);
|
||||
} catch (NoSuchMethodException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("after " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result);
|
||||
}
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
return;
|
||||
}
|
||||
if (target instanceof Connection) {
|
||||
ConnectionTrace connectionTrace = ConnectionTrace.getConnectionTrace();
|
||||
String connectionUrl = connectionTrace.getConnectionUrl((Connection) target);
|
||||
setUrl(result, connectionUrl);
|
||||
}
|
||||
}
|
||||
|
||||
private void setUrl(Object result, String connectionUrl) {
|
||||
try {
|
||||
if (setUrl == null) {
|
||||
setUrl = result.getClass().getMethod("__setUrl", String.class);
|
||||
}
|
||||
setUrl.invoke(result, connectionUrl);
|
||||
} catch (NoSuchMethodException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+39
-33
@@ -18,25 +18,28 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public class ExecuteQueryMethodInterceptor implements StaticAroundInterceptor {
|
||||
|
||||
private final Logger logger = Logger.getLogger(ExecuteQueryMethodInterceptor.class.getName());
|
||||
private final Logger logger = Logger.getLogger(ExecuteQueryMethodInterceptor.class.getName());
|
||||
|
||||
private Method getUrl = null;
|
||||
private Method getUrl = null;
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("before " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
|
||||
}
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
return;
|
||||
}
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("before " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
|
||||
}
|
||||
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Trace.traceBlockBegin();
|
||||
|
||||
try {
|
||||
/**
|
||||
* If method was not called by request handler, we skip tagging.
|
||||
*/
|
||||
String url = getUrl(target);
|
||||
Trace.recordRpcName("mysql", url);
|
||||
String url = getUrl(target);
|
||||
Trace.recordRpcName("mysql", url);
|
||||
|
||||
if (args.length > 0) {
|
||||
Trace.recordAttibute("Query", args[0]);
|
||||
@@ -47,43 +50,46 @@ public class ExecuteQueryMethodInterceptor implements StaticAroundInterceptor {
|
||||
StopWatch.start("ExecuteQueryMethodInterceptor");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
Trace.traceBlockEnd();
|
||||
}
|
||||
}
|
||||
|
||||
private String getUrl(Object target) {
|
||||
try {
|
||||
// TODO classloading 시 해당 mehtod를 한번에 가져올수 없는지 검토.
|
||||
if(getUrl == null) {
|
||||
getUrl = target.getClass().getMethod("__getUrl");
|
||||
}
|
||||
return (String) getUrl.invoke(target);
|
||||
} catch (NoSuchMethodException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
private String getUrl(Object target) {
|
||||
try {
|
||||
// TODO classloading 시 해당 mehtod를 한번에 가져올수 없는지 검토.
|
||||
if (getUrl == null) {
|
||||
getUrl = target.getClass().getMethod("__getUrl");
|
||||
}
|
||||
return (String) getUrl.invoke(target);
|
||||
} catch (NoSuchMethodException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
} catch (IllegalAccessException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
} catch (InvocationTargetException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("after " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result);
|
||||
}
|
||||
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
return;
|
||||
logger.info("after " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result);
|
||||
}
|
||||
|
||||
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Trace.traceBlockBegin();
|
||||
Trace.record(Annotation.ClientRecv, StopWatch.stopAndGetElapsed("ExecuteQueryMethodInterceptor"));
|
||||
Trace.traceBlockEnd();
|
||||
}
|
||||
}
|
||||
|
||||
+14
-7
@@ -17,13 +17,16 @@ public class ExecuteUpdateMethodInterceptor implements StaticAroundInterceptor {
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
System.out.println("ExecuteUpdateMethodInterceptor.before");
|
||||
|
||||
/**
|
||||
* If method was not called by request handler, we skip tagging.
|
||||
*/
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
/**
|
||||
* If method was not called by request handler, we skip tagging.
|
||||
*/
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
return;
|
||||
}
|
||||
Trace.traceBlockBegin();
|
||||
|
||||
Trace.recordRpcName("mysql", "");
|
||||
|
||||
@@ -40,6 +43,8 @@ public class ExecuteUpdateMethodInterceptor implements StaticAroundInterceptor {
|
||||
StopWatch.start("ExecuteUpdateMethodInterceptor");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
Trace.traceBlockEnd();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +54,9 @@ public class ExecuteUpdateMethodInterceptor implements StaticAroundInterceptor {
|
||||
if (Trace.getCurrentTraceId() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Trace.traceBlockBegin();
|
||||
Trace.record(Annotation.ClientRecv, StopWatch.stopAndGetElapsed("ExecuteUpdateMethodInterceptor"));
|
||||
Trace.traceBlockEnd();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user