[유치수] [NOBTS] add interceptor debugging code.

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@532 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Chisu Yu
2012-08-22 10:32:28 +00:00
parent e13abc08b5
commit 01c0bc2e62
10 changed files with 258 additions and 208 deletions
@@ -1,40 +1,66 @@
package com.profiler.interceptor.bci;
import com.profiler.interceptor.Interceptor;
import javassist.CannotCompileException;
import javassist.CtClass;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import javassist.CannotCompileException;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.NotFoundException;
import com.profiler.interceptor.Interceptor;
import com.profiler.interceptor.InterceptorRegistry;
import com.profiler.interceptor.StaticAroundInterceptor;
public class JavaAssistClass implements InstrumentClass {
private final Logger logger = Logger.getLogger(this.getClass().getName());
private final Logger logger = Logger.getLogger(this.getClass().getName());
private JavaAssistByteCodeInstrumentor instrumentor;
private CtClass ctClass;
private JavaAssistByteCodeInstrumentor instrumentor;
private CtClass ctClass;
public JavaAssistClass(JavaAssistByteCodeInstrumentor instrumentor, CtClass ctClass) {
this.instrumentor = instrumentor;
this.ctClass = ctClass;
}
private final AtomicInteger interceptorNo = new AtomicInteger(1);
@Override
public void addInterceptor(String methodName, String[] args, Interceptor interceptor) {
public JavaAssistClass(JavaAssistByteCodeInstrumentor instrumentor, CtClass ctClass) {
this.instrumentor = instrumentor;
this.ctClass = ctClass;
}
@Override
public void addInterceptor(String methodName, String[] args, Interceptor interceptor) {
int num = interceptorNo.getAndIncrement();
InterceptorRegistry.addInterceptor(num, interceptor);
}
try {
CtClass[] params = new CtClass[args.length];
@Override
public byte[] toBytecode() {
try {
return ctClass.toBytecode();
} catch (IOException e) {
logger.log(Level.INFO, "IoException class:" + ctClass.getName() + " " + e.getMessage(), e);
} catch (CannotCompileException e) {
logger.log(Level.INFO, "CannotCompileException class:" + ctClass.getName() + " " + e.getMessage(), e);
}
return null;
}
for (int i = 0; i < args.length; i++) {
params[i] = instrumentor.getClassPool().getCtClass(args[i]);
}
CtMethod method = ctClass.getDeclaredMethod(methodName, params);
// if (interceptor instanceof StaticAroundInterceptor) {
method.insertBefore("System.out.println(\"request=\" + this.getClass().getClassLoader()); ((com.profiler.interceptor.StaticAroundInterceptor) com.profiler.interceptor.InterceptorRegistry.getInterceptor(" + num + ")).before(this, \"" + ctClass.getName() + "\", \"" + methodName + "\", $args);");
// }
} catch (NotFoundException e) {
e.printStackTrace();
} catch (CannotCompileException e) {
e.printStackTrace();
}
}
@Override
public byte[] toBytecode() {
try {
return ctClass.toBytecode();
} catch (IOException e) {
logger.log(Level.INFO, "IoException class:" + ctClass.getName() + " " + e.getMessage(), e);
} catch (CannotCompileException e) {
logger.log(Level.INFO, "CannotCompileException class:" + ctClass.getName() + " " + e.getMessage(), e);
}
return null;
}
}