mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-17 00:36:02 +10:00
[강운덕] [LUCYSUS-1744] 바이트 코드 조작 클래스 별도 분리.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@530 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -4,14 +4,14 @@ import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.IllegalClassFormatException;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.profiler.interceptor.bci.ByteCodeInstrumentor;
|
||||
import com.profiler.interceptor.bci.JavaAssistByteCodeInstrumentor;
|
||||
import com.profiler.modifier.DefaultModifierRegistry;
|
||||
import com.profiler.modifier.Modifier;
|
||||
import com.profiler.modifier.ModifierRegistry;
|
||||
import javassist.ClassPool;
|
||||
import javassist.NotFoundException;
|
||||
|
||||
|
||||
import com.profiler.config.TomcatProfilerConfig;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class TomcatProfiler implements ClassFileTransformer {
|
||||
|
||||
private String agentArgString = "";
|
||||
private Instrumentation instrumentation;
|
||||
private ClassPool classPool;
|
||||
private ByteCodeInstrumentor byteCodeInstrumentor;
|
||||
|
||||
private final ModifierRegistry modifierRepository;
|
||||
private TomcatProfilerConfig tomcatProfilerConfig;
|
||||
@@ -35,13 +35,14 @@ public class TomcatProfiler implements ClassFileTransformer {
|
||||
this.agentArgString = agentArgs;
|
||||
this.instrumentation = inst;
|
||||
this.instrumentation.addTransformer(this);
|
||||
this.classPool = createClassPool();
|
||||
this.modifierRepository = createModifierRegistry(this.classPool, tomcatProfilerConfig);
|
||||
this.byteCodeInstrumentor = new JavaAssistByteCodeInstrumentor();
|
||||
// this.classPool = createClassPool();
|
||||
this.modifierRepository = createModifierRegistry(byteCodeInstrumentor, tomcatProfilerConfig);
|
||||
this.tomcatProfilerConfig = tomcatProfilerConfig;
|
||||
}
|
||||
|
||||
private ModifierRegistry createModifierRegistry(ClassPool classPool, TomcatProfilerConfig tomcatProfilerConfig) {
|
||||
DefaultModifierRegistry modifierRepository = new DefaultModifierRegistry(classPool);
|
||||
private ModifierRegistry createModifierRegistry(ByteCodeInstrumentor byteCodeInstrumentor, TomcatProfilerConfig tomcatProfilerConfig) {
|
||||
DefaultModifierRegistry modifierRepository = new DefaultModifierRegistry(byteCodeInstrumentor);
|
||||
modifierRepository.addTomcatModifier();
|
||||
if (tomcatProfilerConfig.enableJdbcProfile()) {
|
||||
modifierRepository.addJdbcModifier();
|
||||
@@ -49,41 +50,18 @@ public class TomcatProfiler implements ClassFileTransformer {
|
||||
return modifierRepository;
|
||||
}
|
||||
|
||||
private ClassPool createClassPool() {
|
||||
ClassPool classPool = new ClassPool(null);
|
||||
classPool.appendSystemPath();
|
||||
|
||||
String catalinaHome = System.getProperty("catalina.home");
|
||||
if (catalinaHome != null) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("CATALINA_HOME=" + catalinaHome);
|
||||
}
|
||||
|
||||
appendClassPath(classPool, catalinaHome + "/lib/servlet-api.jar");
|
||||
appendClassPath(classPool, catalinaHome + "/lib/catalina.jar");
|
||||
}
|
||||
return classPool;
|
||||
}
|
||||
|
||||
private void appendClassPath(ClassPool classPool, String pathName) {
|
||||
try {
|
||||
classPool.appendClassPath(pathName);
|
||||
} catch (NotFoundException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.warning("lib not found. " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws IllegalClassFormatException {
|
||||
Modifier findModifier = this.modifierRepository.findModifier(className);
|
||||
if (findModifier == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
String javassistClassName = className.replace('/', '.');
|
||||
|
||||
|
||||
return findModifier.modify(classLoader, javassistClassName, classFileBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user