mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-20 18:25:55 +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:
@@ -1,86 +1,101 @@
|
||||
package com.profiler.modifier;
|
||||
|
||||
import com.profiler.logging.Logger;
|
||||
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtConstructor;
|
||||
import javassist.CtMethod;
|
||||
|
||||
public abstract class AbstractModifier {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(AbstractModifier.class);
|
||||
|
||||
public static void printClassInfo(String className) {
|
||||
log("Printing Class Info of [" + className + "]");
|
||||
logger.debug("Printing Class Info of [" + className + "]");
|
||||
try {
|
||||
ClassPool pool = ClassPool.getDefault();
|
||||
log("try");
|
||||
logger.debug("try");
|
||||
String javaassistClassName = className.replace('/', '.');
|
||||
log("replace");
|
||||
logger.debug("replace");
|
||||
CtClass cc = pool.get(javaassistClassName);
|
||||
log("ClassName:" + javaassistClassName);
|
||||
logger.debug("ClassName:" + javaassistClassName);
|
||||
CtConstructor[] constructorList = cc.getConstructors();
|
||||
|
||||
for (CtConstructor cons : constructorList) {
|
||||
try {
|
||||
String signature = cons.getSignature();
|
||||
System.out.println("Constructor signature:" + signature);
|
||||
logger.info("Constructor signature:%s", signature);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
CtMethod[] methodList = cc.getDeclaredMethods();
|
||||
|
||||
for (CtMethod tempMethod : methodList) {
|
||||
try {
|
||||
String methodName = tempMethod.getLongName();
|
||||
log("MethodName:" + methodName);
|
||||
|
||||
logger.debug("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());
|
||||
logger.debug("Param" + loop + ":" + params[loop].getName());
|
||||
}
|
||||
} else {
|
||||
log(" No params");
|
||||
logger.debug(" No params");
|
||||
}
|
||||
log("ReturnType=" + tempMethod.getReturnType().getName());
|
||||
|
||||
logger.debug("ReturnType=" + tempMethod.getReturnType().getName());
|
||||
} catch (Exception methodException) {
|
||||
log("Exception : " + methodException.getMessage());
|
||||
logger.error("Exception : " + methodException.getMessage());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log(e.getMessage());
|
||||
logger.error(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--) {
|
||||
sb.append(params[loop].getName()).append(",");
|
||||
}
|
||||
// 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 !!!!!");
|
||||
logger.warn(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--) {
|
||||
@@ -88,28 +103,22 @@ public abstract class AbstractModifier {
|
||||
}
|
||||
// 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 !!!!!");
|
||||
logger.warn(constructor.getLongName() + " is empty !!!!!");
|
||||
}
|
||||
}
|
||||
return cc.toBytecode();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void log(String message) {
|
||||
System.out.println("[AbstractModifier] " + message);
|
||||
}
|
||||
|
||||
public static void printClassConvertComplete(String javassistClassName) {
|
||||
log("@@@ " + javassistClassName + " class is converted !!!");
|
||||
logger.info("%s class is converted.", javassistClassName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user