mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-23 11:46:46 +10:00
[강운덕] [LUCYSUS-1744] udp socket data receiv
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@574 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -4,44 +4,73 @@ import java.security.ProtectionDomain;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javassist.ByteArrayClassPath;
|
||||
import com.profiler.interceptor.Interceptor;
|
||||
import com.profiler.interceptor.bci.JavaAssistClass;
|
||||
import javassist.*;
|
||||
|
||||
import com.profiler.interceptor.bci.ByteCodeInstrumentor;
|
||||
import com.profiler.interceptor.bci.InstrumentClass;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import javassist.bytecode.AccessFlag;
|
||||
|
||||
public class MySQLStatementModifier extends AbstractModifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(MySQLStatementModifier.class.getName());
|
||||
private final Logger logger = Logger.getLogger(MySQLStatementModifier.class.getName());
|
||||
|
||||
public MySQLStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
public MySQLStatementModifier(ByteCodeInstrumentor byteCodeInstrumentor) {
|
||||
super(byteCodeInstrumentor);
|
||||
}
|
||||
|
||||
public String getTargetClass() {
|
||||
return "com/mysql/jdbc/StatementImpl";
|
||||
}
|
||||
public String getTargetClass() {
|
||||
return "com/mysql/jdbc/StatementImpl";
|
||||
}
|
||||
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
public byte[] modify(ClassLoader classLoader, String javassistClassName, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("Modifing. " + javassistClassName);
|
||||
}
|
||||
|
||||
byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
classPool.insertClassPath(new ByteArrayClassPath(javassistClassName, classFileBuffer));
|
||||
byteCodeInstrumentor.checkLibrary(classLoader, javassistClassName);
|
||||
// classPool.insertClassPath(new ByteArrayClassPath(javassistClassName, classFileBuffer));
|
||||
|
||||
InstrumentClass aClass = byteCodeInstrumentor.getClass(javassistClassName);
|
||||
InstrumentClass aClass = byteCodeInstrumentor.getClass(javassistClassName);
|
||||
Interceptor interceptor = newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.mysql.interceptors.ExecuteQueryMethodInterceptor");
|
||||
boolean executeQuery = aClass.addInterceptor("executeQuery", new String[]{"java.lang.String"}, interceptor);
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("executeQuery =" + executeQuery);
|
||||
}
|
||||
|
||||
boolean instrumented = aClass.addInterceptor("executeQuery", new String[] { "java.lang.String" }, newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.mysql.interceptors.ExecuteQueryMethodInterceptor"));
|
||||
Interceptor interceptor1 = newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.mysql.interceptors.ExecuteUpdateMethodInterceptor");
|
||||
boolean executeUpdate = aClass.addInterceptor("executeUpdate", new String[]{"java.lang.String", "boolean", "boolean"}, interceptor1);
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("executeUpdate =" + executeUpdate);
|
||||
}
|
||||
addTraceData((JavaAssistClass) aClass);
|
||||
|
||||
instrumented &= aClass.addInterceptor("executeUpdate", new String[] { "java.lang.String", "boolean", "boolean" }, newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.db.mysql.interceptors.ExecuteUpdateMethodInterceptor"));
|
||||
|
||||
System.out.println("instrumented=" + instrumented);
|
||||
|
||||
if (!instrumented) {
|
||||
return null;
|
||||
}
|
||||
if (executeQuery && executeQuery) {
|
||||
return aClass.toBytecode();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return aClass.toBytecode();
|
||||
}
|
||||
private void addTraceData(JavaAssistClass aClass) {
|
||||
try {
|
||||
ClassPool classPool1 = byteCodeInstrumentor.getClassPool();
|
||||
JavaAssistClass jc = (JavaAssistClass) aClass;
|
||||
CtClass ctClass = jc.getCtClass();
|
||||
CtClass string = classPool1.get("java.lang.String");
|
||||
CtField traceUrl = new CtField(string, "__url", ctClass);
|
||||
traceUrl.setModifiers(AccessFlag.PUBLIC);
|
||||
ctClass.addField(traceUrl);
|
||||
CtMethod setUrl = CtNewMethod.setter("__setUrl", traceUrl);
|
||||
ctClass.addMethod(setUrl);
|
||||
CtMethod getUrl = CtNewMethod.getter("__getUrl", traceUrl);
|
||||
ctClass.addMethod(getUrl);
|
||||
} catch (NotFoundException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
} catch (CannotCompileException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user