mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-21 02:35:53 +10:00
[유치수] [NOBTS] refactoring
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@453 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -7,100 +7,109 @@ import javassist.CtMethod;
|
||||
|
||||
public abstract class AbstractModifier {
|
||||
public static void printClassInfo(String className) {
|
||||
log("Printing Class Info of ["+className+"]");
|
||||
log("Printing Class Info of [" + className + "]");
|
||||
try {
|
||||
ClassPool pool=ClassPool.getDefault();
|
||||
// pool.insertClassPath(new ClassClassPath(currentClass));
|
||||
ClassPool pool = ClassPool.getDefault();
|
||||
log("try");
|
||||
String javaassistClassName = className.replace('/', '.');
|
||||
log("replace");
|
||||
CtClass cc=pool.get(javaassistClassName);
|
||||
log("ClassName:"+javaassistClassName);
|
||||
CtConstructor[] constructorList=cc.getConstructors();
|
||||
for(CtConstructor cons:constructorList) {
|
||||
CtClass cc = pool.get(javaassistClassName);
|
||||
log("ClassName:" + javaassistClassName);
|
||||
CtConstructor[] constructorList = cc.getConstructors();
|
||||
for (CtConstructor cons : constructorList) {
|
||||
try {
|
||||
String signature=cons.getSignature();
|
||||
System.out.println("Constructor signature:"+signature);
|
||||
} catch(Exception e) {
|
||||
String signature = cons.getSignature();
|
||||
System.out.println("Constructor signature:" + signature);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
CtMethod[] methodList=cc.getDeclaredMethods();
|
||||
for(CtMethod tempMethod:methodList) {
|
||||
CtMethod[] methodList = cc.getDeclaredMethods();
|
||||
for (CtMethod tempMethod : methodList) {
|
||||
try {
|
||||
String methodName=tempMethod.getLongName();
|
||||
log("MethodName:"+methodName);
|
||||
CtClass[] params=tempMethod.getParameterTypes();
|
||||
if(params.length!=0) {
|
||||
int paramsLength=params.length;
|
||||
for(int loop=paramsLength-1;loop>0;loop--) {
|
||||
log("Param"+loop+":"+params[loop].getName());
|
||||
String methodName = tempMethod.getLongName();
|
||||
log("MethodName:" + methodName);
|
||||
CtClass[] params = tempMethod.getParameterTypes();
|
||||
if (params.length != 0) {
|
||||
int paramsLength = params.length;
|
||||
for (int loop = paramsLength - 1; loop > 0; loop--) {
|
||||
log("Param" + loop + ":" + params[loop].getName());
|
||||
}
|
||||
} else {
|
||||
log(" No params");
|
||||
}
|
||||
log("ReturnType="+tempMethod.getReturnType().getName());
|
||||
} catch(Exception methodException) {
|
||||
log("Exception : "+methodException.getMessage());
|
||||
log("ReturnType=" + tempMethod.getReturnType().getName());
|
||||
} catch (Exception methodException) {
|
||||
log("Exception : " + methodException.getMessage());
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
log(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] addBeforeAfterLogics(ClassPool classPool,String javassistClassName) {
|
||||
public static byte[] addBeforeAfterLogics(ClassPool classPool,
|
||||
String javassistClassName) {
|
||||
try {
|
||||
CtClass cc = classPool.get(javassistClassName);
|
||||
CtMethod[] methods=cc.getDeclaredMethods();
|
||||
for(CtMethod method:methods) {
|
||||
if(!method.isEmpty() ) {
|
||||
String methodName=method.getName();
|
||||
CtClass[] params=method.getParameterTypes();
|
||||
StringBuilder sb=new StringBuilder();
|
||||
if(params.length!=0) {
|
||||
int paramsLength=params.length;
|
||||
for(int loop=paramsLength-1;loop>0;loop--) {
|
||||
CtMethod[] methods = cc.getDeclaredMethods();
|
||||
for (CtMethod method : methods) {
|
||||
if (!method.isEmpty()) {
|
||||
String methodName = method.getName();
|
||||
CtClass[] params = method.getParameterTypes();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (params.length != 0) {
|
||||
int paramsLength = params.length;
|
||||
for (int loop = paramsLength - 1; loop > 0; loop--) {
|
||||
sb.append(params[loop].getName()).append(",");
|
||||
}
|
||||
// sb.substring(0, sb.length()-2);
|
||||
// sb.substring(0, sb.length()-2);
|
||||
}
|
||||
method.insertBefore("{System.out.println(\"*****"+javassistClassName+"."+methodName+"("+sb+") is started.\");}");
|
||||
method.insertAfter("{System.out.println(\"*****"+javassistClassName+"."+methodName+"("+sb+") is finished.\");}");
|
||||
method.insertBefore("{System.out.println(\"*****"
|
||||
+ javassistClassName + "." + methodName + "(" + sb
|
||||
+ ") is started.\");}");
|
||||
method.insertAfter("{System.out.println(\"*****"
|
||||
+ javassistClassName + "." + methodName + "(" + sb
|
||||
+ ") is finished.\");}");
|
||||
} else {
|
||||
log(method.getLongName()+" is empty !!!!!");
|
||||
log(method.getLongName() + " is empty !!!!!");
|
||||
}
|
||||
}
|
||||
CtConstructor[] constructors=cc.getConstructors();
|
||||
for(CtConstructor constructor:constructors) {
|
||||
if(!constructor.isEmpty()) {
|
||||
CtClass[] params=constructor.getParameterTypes();
|
||||
StringBuilder sb=new StringBuilder();
|
||||
if(params.length!=0) {
|
||||
int paramsLength=params.length;
|
||||
for(int loop=paramsLength-1;loop>0;loop--) {
|
||||
CtConstructor[] constructors = cc.getConstructors();
|
||||
for (CtConstructor constructor : constructors) {
|
||||
if (!constructor.isEmpty()) {
|
||||
CtClass[] params = constructor.getParameterTypes();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (params.length != 0) {
|
||||
int paramsLength = params.length;
|
||||
for (int loop = paramsLength - 1; loop > 0; loop--) {
|
||||
sb.append(params[loop].getName()).append(",");
|
||||
}
|
||||
// sb.substring(0, sb.length()-2);
|
||||
// sb.substring(0, sb.length()-2);
|
||||
}
|
||||
constructor.insertBefore("{System.out.println(\"*****"+javassistClassName+" Constructor:Param=("+sb+") is started.\");}");
|
||||
constructor.insertAfter("{System.out.println(\"*****"+javassistClassName+" Constructor:Param=("+sb+") is finished.\");}");
|
||||
constructor.insertBefore("{System.out.println(\"*****"
|
||||
+ javassistClassName + " Constructor:Param=(" + sb
|
||||
+ ") is started.\");}");
|
||||
constructor.insertAfter("{System.out.println(\"*****"
|
||||
+ javassistClassName + " Constructor:Param=(" + sb
|
||||
+ ") is finished.\");}");
|
||||
} else {
|
||||
log(constructor.getLongName()+" is empty !!!!!");
|
||||
log(constructor.getLongName() + " is empty !!!!!");
|
||||
}
|
||||
}
|
||||
return cc.toBytecode();
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void log(String message) {
|
||||
System.out.println("[AbstractModifier] "+message);
|
||||
System.out.println("[AbstractModifier] " + message);
|
||||
}
|
||||
|
||||
public static void printClassConvertComplete(String javassistClassName) {
|
||||
log("@@@ "+javassistClassName+" class is converted !!!");
|
||||
|
||||
log("@@@ " + javassistClassName + " class is converted !!!");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user