mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-17 08:46:22 +10:00
[강운덕] [LUCYSUS-1744] modifier 등록 지점 구현.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@466 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -7,7 +7,9 @@ import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
import com.profiler.modifier.DefaultModifierRegistry;
|
||||
import com.profiler.modifier.Modifier;
|
||||
import com.profiler.modifier.ModifierRegistry;
|
||||
import javassist.ClassPool;
|
||||
import javassist.NotFoundException;
|
||||
|
||||
@@ -42,19 +44,34 @@ public class TomcatProfiler implements ClassFileTransformer {
|
||||
private Instrumentation instrumentation;
|
||||
private ClassPool classPool;
|
||||
|
||||
|
||||
private final ModifierRegistry modifierRepository;
|
||||
private TomcatProfilerConfig tomcatProfilerConfig;
|
||||
|
||||
public static void premain(String agentArgs, Instrumentation inst) {
|
||||
new TomcatProfiler(agentArgs, inst);
|
||||
TomcatProfilerConfig tomcatProfilerConfig = TomcatProfilerConfig.readConfigFile();
|
||||
new TomcatProfiler(agentArgs, inst, tomcatProfilerConfig);
|
||||
}
|
||||
|
||||
public TomcatProfiler(String agentArgs, Instrumentation inst) {
|
||||
public TomcatProfiler(String agentArgs, Instrumentation inst, TomcatProfilerConfig tomcatProfilerConfig) {
|
||||
this.agentArgString = agentArgs;
|
||||
this.instrumentation = inst;
|
||||
this.instrumentation.addTransformer(this);
|
||||
this.classPool = createClassPool();
|
||||
this.modifierRepository = createModifierRegistry(tomcatProfilerConfig);
|
||||
this.tomcatProfilerConfig = tomcatProfilerConfig;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private ModifierRegistry createModifierRegistry(TomcatProfilerConfig tomcatProfilerConfig) {
|
||||
DefaultModifierRegistry modifierRepository = new DefaultModifierRegistry();
|
||||
modifierRepository.addTomcatModifier();
|
||||
if(tomcatProfilerConfig.enableJdbcProfile()) {
|
||||
modifierRepository.addJdbcModifier();
|
||||
}
|
||||
return modifierRepository;
|
||||
}
|
||||
|
||||
private ClassPool createClassPool() {
|
||||
ClassPool classPool = new ClassPool(null);
|
||||
classPool.appendSystemPath();
|
||||
@@ -76,7 +93,13 @@ public class TomcatProfiler implements ClassFileTransformer {
|
||||
|
||||
@Override
|
||||
public byte[] transform(ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws IllegalClassFormatException {
|
||||
if (className.startsWith("org/apache/catalina")) {
|
||||
Modifier findModifier = this.modifierRepository.findModifier(className);
|
||||
if(findModifier != null) {
|
||||
String javassistClassName = className.replace('/', '.');
|
||||
return findModifier.modify(classPool, classLoader, javassistClassName, classFileBuffer);
|
||||
}
|
||||
|
||||
if (className.startsWith("org/apache/catalina")) {
|
||||
String javassistClassName = className.replace('/', '.');
|
||||
if (javassistClassName.equals("org.apache.catalina.core.StandardHostValve")) {
|
||||
// Add code to monitor Request and Response
|
||||
@@ -99,7 +122,7 @@ public class TomcatProfiler implements ClassFileTransformer {
|
||||
}
|
||||
}
|
||||
// #### If JDBC_PROFILE is true, SQL data will be collected
|
||||
if (TomcatProfilerConfig.JDBC_PROFILE) {
|
||||
if (tomcatProfilerConfig.enableJdbcProfile()) {
|
||||
if (className.startsWith("com/mysql/jdbc")) {
|
||||
// MySQL !!!!!!!!!!
|
||||
String javassistClassName = className.replace('/', '.');
|
||||
@@ -256,7 +279,7 @@ public class TomcatProfiler implements ClassFileTransformer {
|
||||
try {
|
||||
classPool.appendClassPath(filePath);
|
||||
// log("Loaded "+filePath+" library.");
|
||||
} catch (Exception e) {
|
||||
} catch (NotFoundException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user