mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-21 10:45:59 +10:00
[강운덕] [LUCYSUS-1744] classLoader별로 분리된 코드 커밋.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@1427 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
package com.profiler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.IllegalClassFormatException;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.net.URL;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
@@ -18,11 +13,9 @@ import com.profiler.logging.LoggerBinder;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
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;
|
||||
|
||||
public class TomcatProfiler implements ClassFileTransformer {
|
||||
public class TomcatProfiler {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(TomcatProfiler.class.getName());
|
||||
private boolean isFine = logger.isLoggable(Level.FINE);
|
||||
@@ -37,28 +30,16 @@ public class TomcatProfiler implements ClassFileTransformer {
|
||||
private final ProfilerConfig profilerConfig;
|
||||
private final Agent agent;
|
||||
|
||||
private AgentClassLoader agentClassLoader;
|
||||
|
||||
public static void premain(String agentArgs, Instrumentation instrumentation) {
|
||||
public void boot(Instrumentation instrumentation, String agentArgs) {
|
||||
|
||||
if (agentArgs != null) {
|
||||
logger.info("HIPPO agentArgs:" + agentArgs);
|
||||
}
|
||||
// dumpSystemProperties();
|
||||
|
||||
ClassPathResolver classPathResolver = new ClassPathResolver();
|
||||
boolean agentJarNotFound = classPathResolver.findAgentJar();
|
||||
if (!agentJarNotFound) {
|
||||
logger.severe("hippo-tomcat-profiler-x.x.x.jar not found.");
|
||||
return;
|
||||
}
|
||||
// 이게 로드할 lib List임.
|
||||
List<URL> libUrlList = resolveLib(classPathResolver);
|
||||
AgentClassLoader agentClassLoader = new AgentClassLoader(libUrlList.toArray(new URL[libUrlList.size()]));
|
||||
agentClassLoader.setBootClass("com.profiler.boot.BootClassTest");
|
||||
// agentClassLoader.test();
|
||||
try {
|
||||
agentClassLoader.boot();
|
||||
LoggerBinder loggerBinder = agentClassLoader.initializeLoggerBinder();
|
||||
|
||||
LoggerBinder loggerBinder = null;
|
||||
loggerBinder.getLogger("LoggerFactory initialize start");
|
||||
LoggerFactory.initialize(loggerBinder);
|
||||
com.profiler.logging.Logger tomcatLogger = LoggerFactory.getLogger(TomcatProfiler.class);
|
||||
@@ -68,46 +49,19 @@ public class TomcatProfiler implements ClassFileTransformer {
|
||||
}
|
||||
|
||||
try {
|
||||
ProfilerConfig profilerConfig = readConfig(classPathResolver);
|
||||
ProfilerConfig profilerConfig = null;
|
||||
if (!profilerConfig.isProfileEnable()) {
|
||||
logger.warning("Profiler Agent not started. profile.enable=" + profilerConfig.isProfileEnable());
|
||||
return;
|
||||
}
|
||||
Agent agent = new Agent(profilerConfig);
|
||||
new TomcatProfiler(agentArgs, instrumentation, agent, profilerConfig);
|
||||
Agent agent = new DefaultAgent(agentArgs, instrumentation, profilerConfig);
|
||||
// new TomcatProfiler(agentArgs, instrumentation, agent, profilerConfig);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "Profiler Agent start fail. Cause:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static ProfilerConfig readConfig(ClassPathResolver classPathResolver) throws IOException {
|
||||
|
||||
ProfilerConfig profilerConfig = new ProfilerConfig();
|
||||
String hippoConfigFormSystemProperty = findHippoConfigFormSystemProeprty();
|
||||
if (hippoConfigFormSystemProperty != null) {
|
||||
profilerConfig.readConfigFile(hippoConfigFormSystemProperty);
|
||||
} else {
|
||||
String agentConfigPath = classPathResolver.getAgentConfigPath();
|
||||
profilerConfig.readConfigFile(agentConfigPath);
|
||||
}
|
||||
return profilerConfig;
|
||||
}
|
||||
|
||||
private static List<URL> resolveLib(ClassPathResolver classPathResolver) {
|
||||
String agentJarFullPath = classPathResolver.getAgentJarFullPath();
|
||||
logger.info("agentJarPath:" + agentJarFullPath);
|
||||
|
||||
String agentLibPath = classPathResolver.getAgentLibPath();
|
||||
logger.info("agentLibPath:" + agentLibPath);
|
||||
|
||||
List<URL> urlList = classPathResolver.resolveLib();
|
||||
logger.info("agent lib list:" + urlList);
|
||||
|
||||
String agentConfigPath = classPathResolver.getAgentConfigPath();
|
||||
logger.info("agent config:" + agentConfigPath);
|
||||
|
||||
return urlList;
|
||||
}
|
||||
|
||||
private static void dumpSystemProperties() {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
@@ -119,18 +73,18 @@ public class TomcatProfiler implements ClassFileTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
public TomcatProfiler(String agentArgs, Instrumentation instrumentation, Agent agent, ProfilerConfig profilerConfig) {
|
||||
public TomcatProfiler(String agentArgs, Instrumentation instrumentation, DefaultAgent agent, ProfilerConfig profilerConfig) {
|
||||
this.agentArgString = agentArgs;
|
||||
this.profilerConfig = profilerConfig;
|
||||
this.agent = agent;
|
||||
|
||||
this.instrumentation = instrumentation;
|
||||
this.instrumentation.addTransformer(this);
|
||||
|
||||
String[] paths = getTomcatlibPath();
|
||||
this.byteCodeInstrumentor = new JavaAssistByteCodeInstrumentor(paths);
|
||||
this.byteCodeInstrumentor = new JavaAssistByteCodeInstrumentor(paths, agent);
|
||||
|
||||
this.modifierRepository = createModifierRegistry();
|
||||
this.modifierRepository = null;
|
||||
ClassFileTransformer classFileTransformerDispatcher = new ClassFileTransformerDispatcher(agent);
|
||||
this.instrumentation.addTransformer(classFileTransformerDispatcher);
|
||||
}
|
||||
|
||||
public static String findHippoConfigFormSystemProeprty() {
|
||||
@@ -161,56 +115,6 @@ public class TomcatProfiler implements ClassFileTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
private ModifierRegistry createModifierRegistry() {
|
||||
DefaultModifierRegistry modifierRepository = new DefaultModifierRegistry(byteCodeInstrumentor, agent, profilerConfig);
|
||||
|
||||
modifierRepository.addMethodModifier();
|
||||
|
||||
modifierRepository.addTomcatModifier();
|
||||
|
||||
// jdbc
|
||||
modifierRepository.addJdbcModifier();
|
||||
|
||||
// rpc
|
||||
modifierRepository.addConnectorModifier();
|
||||
|
||||
// bloc
|
||||
modifierRepository.addBLOCModifier();
|
||||
|
||||
return modifierRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws IllegalClassFormatException {
|
||||
// fast java class skip
|
||||
if (className.startsWith("java")) {
|
||||
if (className.startsWith("/", 4) || className.startsWith("x/", 4)) {
|
||||
return classFileBuffer;
|
||||
}
|
||||
}
|
||||
Modifier findModifier = this.modifierRepository.findModifier(className);
|
||||
|
||||
if (findModifier == null) {
|
||||
// TODO : 디버그 용도로 추가함
|
||||
// TODO : modifier가 중복 적용되면 어떻게 되지???
|
||||
if (profilerConfig.isProfilableClass(className)) {
|
||||
// 테스트 장비에서 callstack view가 잘 보이는지 확인하려고 추가함.
|
||||
findModifier = this.modifierRepository.findModifier("*");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (isFine) {
|
||||
logger.fine("[transform] cl" + classLoader + " className:" + className + " Modifier:" + findModifier.getClass().getName());
|
||||
}
|
||||
String javassistClassName = className.replace('/', '.');
|
||||
|
||||
try {
|
||||
return findModifier.modify(classLoader, javassistClassName, protectionDomain, classFileBuffer);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "Modifier:" + findModifier.getTargetClass() + " modify fail. Cause:" + e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user