mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-24 12:16:33 +10:00
[유치수] [NOBTS] refactoring
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@461 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -5,70 +5,64 @@ import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.logging.Logger;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
|
||||
public class DBCPPoolModifier extends AbstractModifier{
|
||||
public static byte[] modify(ClassPool classPool,ClassLoader classLoader,String javassistClassName,byte[] classFileBuffer) {
|
||||
log("DBCPPoolModifier(PoolingDataSource$PoolGuardConnectionWrapper) modifing");
|
||||
// printClassInfo(javassistClassName);
|
||||
return changeMethod(classPool,classLoader,javassistClassName,classFileBuffer);
|
||||
public class DBCPPoolModifier extends AbstractModifier {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(DBCPPoolModifier.class);
|
||||
|
||||
public static byte[] modify(ClassPool classPool, ClassLoader classLoader, String javassistClassName, byte[] classFileBuffer) {
|
||||
logger.info("DBCPPoolModifier(PoolingDataSource$PoolGuardConnectionWrapper) modifing. %s", javassistClassName);
|
||||
return changeMethod(classPool, classLoader, javassistClassName, classFileBuffer);
|
||||
}
|
||||
private static byte[] changeMethod(ClassPool classPool,ClassLoader classLoader,String javassistClassName,byte[] classfileBuffer) {
|
||||
|
||||
private static byte[] changeMethod(ClassPool classPool, ClassLoader classLoader, String javassistClassName, byte[] classfileBuffer) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
// updateGetConnectionMethod(classPool,cc);
|
||||
updateCloseMethod(classPool,cc);
|
||||
/*
|
||||
CtMethod[] methods=cc.getDeclaredMethods();
|
||||
for(CtMethod method:methods) {
|
||||
// System.out.println(method.getLongName());
|
||||
if(!method.isEmpty() ) {
|
||||
String methodName=method.getName();
|
||||
if(methodName.equals("getConnection")) {
|
||||
// && !methodName.startsWith("version")) {
|
||||
method.insertBefore("{System.out.println(\"-----DBCP "+method.getLongName()+" is started.\");}");
|
||||
method.insertAfter("{System.out.println(\"-----DBCP "+method.getLongName()+" is finished.\");}");
|
||||
System.out.println(method.getLongName());
|
||||
}
|
||||
} else {
|
||||
log(method.getLongName()+" is empty !!!!!");
|
||||
}
|
||||
}
|
||||
*/
|
||||
byte[] newClassfileBuffer=null;
|
||||
newClassfileBuffer= cc.toBytecode();
|
||||
// cc.writeFile();
|
||||
updateCloseMethod(classPool, cc);
|
||||
|
||||
byte[] newClassfileBuffer = null;
|
||||
newClassfileBuffer = cc.toBytecode();
|
||||
// cc.writeFile();
|
||||
printClassConvertComplete(javassistClassName);
|
||||
return newClassfileBuffer;
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void updateCloseMethod(ClassPool classPool,CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod=cc.getDeclaredMethod("close", null);
|
||||
log("*** Changing close method ");
|
||||
// serviceMethod.insertBefore(getCloseMethodBeforeInsertCode());
|
||||
|
||||
private static void updateCloseMethod(ClassPool classPool, CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod = cc.getDeclaredMethod("close", null);
|
||||
logger.info("Changing close method ");
|
||||
// serviceMethod.insertBefore(getCloseMethodBeforeInsertCode());
|
||||
serviceMethod.insertAfter(getCloseMethodAfterInsertCode());
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static String getCloseMethodBeforeInsertCode() {
|
||||
StringBuilder sb=new StringBuilder();
|
||||
// sb.append("{");
|
||||
// sb.append("System.out.println(\"-----PoolingDataSource$PoolGuardConnectionWrapper.close() method is called\");");
|
||||
// sb.append("}");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
sb.append("{");
|
||||
sb.append("System.out.println(\"-----PoolingDataSource$PoolGuardConnectionWrapper.close() method is called\");");
|
||||
sb.append("}");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
private static String getCloseMethodAfterInsertCode() {
|
||||
StringBuilder sb=new StringBuilder();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
// sb.append("System.out.println(\"-----PoolingDataSource$PoolGuardConnectionWrapper.close() method is ended\");");
|
||||
sb.append(TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER+".put("+TomcatProfilerConstant.REQ_DATA_TYPE_DB_CLOSE_CONNECTION+");");
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
sb.append("System.out.println(\"-----PoolingDataSource$PoolGuardConnectionWrapper.close() method is ended\");");
|
||||
}
|
||||
|
||||
sb.append(TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_CLOSE_CONNECTION + ");");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user