[유치수] [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
+36 -41
View File
@@ -12,56 +12,51 @@ import com.profiler.modifier.DefaultModifierRegistry;
import com.profiler.modifier.Modifier;
import com.profiler.modifier.ModifierRegistry;
import com.profiler.config.TomcatProfilerConfig;
public class TomcatProfiler implements ClassFileTransformer {
private static final Logger logger = Logger.getLogger(TomcatProfiler.class.getName());
private static final Logger logger = Logger.getLogger(TomcatProfiler.class.getName());
private String agentArgString = "";
private Instrumentation instrumentation;
private ByteCodeInstrumentor byteCodeInstrumentor;
private String agentArgString = "";
private Instrumentation instrumentation;
private ByteCodeInstrumentor byteCodeInstrumentor;
private final ModifierRegistry modifierRepository;
private TomcatProfilerConfig tomcatProfilerConfig;
private final ModifierRegistry modifierRepository;
private TomcatProfilerConfig tomcatProfilerConfig;
public static void premain(String agentArgs, Instrumentation inst) {
TomcatProfilerConfig tomcatProfilerConfig = TomcatProfilerConfig.readConfigFile();
new TomcatProfiler(agentArgs, inst, tomcatProfilerConfig);
}
public static void premain(String agentArgs, Instrumentation inst) {
TomcatProfilerConfig tomcatProfilerConfig = TomcatProfilerConfig.readConfigFile();
new TomcatProfiler(agentArgs, inst, tomcatProfilerConfig);
}
public TomcatProfiler(String agentArgs, Instrumentation inst, TomcatProfilerConfig tomcatProfilerConfig) {
this.agentArgString = agentArgs;
this.instrumentation = inst;
this.instrumentation.addTransformer(this);
this.byteCodeInstrumentor = new JavaAssistByteCodeInstrumentor();
// this.classPool = createClassPool();
this.modifierRepository = createModifierRegistry(byteCodeInstrumentor, tomcatProfilerConfig);
this.tomcatProfilerConfig = tomcatProfilerConfig;
}
public TomcatProfiler(String agentArgs, Instrumentation inst, TomcatProfilerConfig tomcatProfilerConfig) {
this.agentArgString = agentArgs;
this.instrumentation = inst;
this.instrumentation.addTransformer(this);
this.byteCodeInstrumentor = new JavaAssistByteCodeInstrumentor();
// this.classPool = createClassPool();
this.modifierRepository = createModifierRegistry(byteCodeInstrumentor, tomcatProfilerConfig);
this.tomcatProfilerConfig = tomcatProfilerConfig;
}
private ModifierRegistry createModifierRegistry(ByteCodeInstrumentor byteCodeInstrumentor, TomcatProfilerConfig tomcatProfilerConfig) {
DefaultModifierRegistry modifierRepository = new DefaultModifierRegistry(byteCodeInstrumentor);
modifierRepository.addTomcatModifier();
if (tomcatProfilerConfig.enableJdbcProfile()) {
modifierRepository.addJdbcModifier();
}
return modifierRepository;
}
private ModifierRegistry createModifierRegistry(ByteCodeInstrumentor byteCodeInstrumentor, TomcatProfilerConfig tomcatProfilerConfig) {
DefaultModifierRegistry modifierRepository = new DefaultModifierRegistry(byteCodeInstrumentor);
modifierRepository.addTomcatModifier();
if (tomcatProfilerConfig.enableJdbcProfile()) {
modifierRepository.addJdbcModifier();
}
return modifierRepository;
}
@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('/', '.');
@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);
}
return findModifier.modify(classLoader, javassistClassName, classFileBuffer);
}
}