mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-21 02:35:53 +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,11 +0,0 @@
|
||||
package com.profiler;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AgentBootStrap {
|
||||
void boot() {
|
||||
System.out.println(this.getClass().getClassLoader());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.profiler;
|
||||
|
||||
import com.profiler.config.ProfilerConfig;
|
||||
import com.profiler.modifier.DefaultModifierRegistry;
|
||||
import com.profiler.modifier.Modifier;
|
||||
import com.profiler.modifier.ModifierRegistry;
|
||||
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.IllegalClassFormatException;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ClassFileTransformerDispatcher implements ClassFileTransformer {
|
||||
|
||||
private Logger logger = Logger.getLogger(this.getClass().getName());
|
||||
private boolean isFine = logger.isLoggable(Level.FINE);
|
||||
|
||||
private ModifierRegistry modifierRegistry;
|
||||
|
||||
private Agent agent;
|
||||
|
||||
private ProfilerConfig profilerConfig;
|
||||
|
||||
|
||||
public ClassFileTransformerDispatcher(Agent agent) {
|
||||
if(agent == null) {
|
||||
throw new NullPointerException("agent must not be null");
|
||||
}
|
||||
this.agent = agent;
|
||||
this.profilerConfig = agent.getProfilerConfig();
|
||||
this.modifierRegistry = createModifierRegistry();
|
||||
}
|
||||
|
||||
@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.modifierRegistry.findModifier(className);
|
||||
if (findModifier == null) {
|
||||
// TODO : 디버그 용도로 추가함
|
||||
// TODO : modifier가 중복 적용되면 어떻게 되지???
|
||||
if (this.profilerConfig.isProfilableClass(className)) {
|
||||
// 테스트 장비에서 callstack view가 잘 보이는지 확인하려고 추가함.
|
||||
findModifier = this.modifierRegistry.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 (Throwable e) {
|
||||
logger.log(Level.SEVERE, "Modifier:" + findModifier.getTargetClass() + " modify fail. Cause:" + e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ModifierRegistry createModifierRegistry() {
|
||||
DefaultModifierRegistry modifierRepository = new DefaultModifierRegistry(agent);
|
||||
|
||||
modifierRepository.addMethodModifier();
|
||||
|
||||
modifierRepository.addTomcatModifier();
|
||||
|
||||
// jdbc
|
||||
modifierRepository.addJdbcModifier();
|
||||
|
||||
// rpc
|
||||
modifierRepository.addConnectorModifier();
|
||||
|
||||
// bloc
|
||||
modifierRepository.addBLOCModifier();
|
||||
|
||||
return modifierRepository;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
package com.profiler;
|
||||
|
||||
import com.profiler.common.ServiceType;
|
||||
import com.profiler.common.dto.thrift.AgentInfo;
|
||||
import com.profiler.common.hbase.HBaseTables;
|
||||
import com.profiler.common.mapping.ApiMappingTable;
|
||||
import com.profiler.config.ProfilerConfig;
|
||||
import com.profiler.context.BypassStorageFactory;
|
||||
import com.profiler.context.DefaultTraceContext;
|
||||
import com.profiler.context.TimeBaseStorageFactory;
|
||||
import com.profiler.context.TraceContext;
|
||||
import com.profiler.interceptor.bci.ByteCodeInstrumentor;
|
||||
import com.profiler.interceptor.bci.JavaAssistByteCodeInstrumentor;
|
||||
import com.profiler.logger.Slf4jLoggerBinder;
|
||||
import com.profiler.logging.LoggerBinder;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
import com.profiler.sender.DataSender;
|
||||
import com.profiler.sender.UdpDataSender;
|
||||
import com.profiler.util.Assert;
|
||||
import com.profiler.util.NetworkUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class DefaultAgent implements Agent {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(DefaultAgent.class.getName());
|
||||
private static final Random IDENTIFIER_KEY = new Random();
|
||||
|
||||
|
||||
private final ByteCodeInstrumentor byteCodeInstrumentor;
|
||||
|
||||
private final ProfilerConfig profilerConfig;
|
||||
|
||||
private final ServerInfo serverInfo;
|
||||
private final SystemMonitor systemMonitor;
|
||||
|
||||
private DefaultTraceContext traceContext;
|
||||
|
||||
private DataSender priorityDataSender;
|
||||
private DataSender dataSender;
|
||||
|
||||
private final String machineName;
|
||||
private final String agentId;
|
||||
private final String applicationName;
|
||||
private final long startTime;
|
||||
private final short identifier;
|
||||
|
||||
// agent info는 heartbeat에서 매번 사용한다.
|
||||
private AgentInfo agentInfo;
|
||||
|
||||
// agent의 상태,
|
||||
private volatile AgentStatus agentStatus;
|
||||
private HeartBitChecker heartBitChecker;
|
||||
|
||||
|
||||
public DefaultAgent(String agentArgs, Instrumentation instrumentation, ProfilerConfig profilerConfig) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
}
|
||||
initializeLogger();
|
||||
changeStatus(AgentStatus.INITIALIZING);
|
||||
|
||||
this.profilerConfig = profilerConfig;
|
||||
this.serverInfo = new ServerInfo();
|
||||
|
||||
String[] paths = getTomcatlibPath();
|
||||
this.byteCodeInstrumentor = new JavaAssistByteCodeInstrumentor(paths, this);
|
||||
|
||||
ClassFileTransformerDispatcher classFileTransformerDispatcher = new ClassFileTransformerDispatcher(this);
|
||||
instrumentation.addTransformer(classFileTransformerDispatcher);
|
||||
|
||||
// TODO 일단 임시로 호환성을 위해 agentid에 machinename을 넣도록 하자
|
||||
// TODO 박스 하나에 서버 인스턴스를 여러개 실행할 때에 문제가 될 수 있음.
|
||||
this.machineName = NetworkUtils.getMachineName();
|
||||
this.agentId = getId("hippo.agentId", machineName, HBaseTables.AGENT_NAME_MAX_LEN);
|
||||
this.applicationName = getId("hippo.applicationName", "UnknownApplicationName", HBaseTables.APPLICATION_NAME_MAX_LEN);
|
||||
|
||||
this.priorityDataSender = createDataSender();
|
||||
this.dataSender = createDataSender();
|
||||
this.startTime = System.currentTimeMillis();
|
||||
|
||||
this.identifier = getShortIdentifier();
|
||||
|
||||
initializeTraceContext();
|
||||
|
||||
this.systemMonitor = new SystemMonitor(this.traceContext, this.profilerConfig);
|
||||
this.systemMonitor.setDataSender(dataSender);
|
||||
|
||||
// 매핑 테이블 초기화를 위해 엑세스
|
||||
ApiMappingTable.findApiId("test", null, null);
|
||||
|
||||
this.agentInfo = createAgentInfo();
|
||||
this.heartBitChecker = new HeartBitChecker(priorityDataSender, profilerConfig.getHeartbeatInterval(), agentInfo);
|
||||
|
||||
|
||||
SingletonHolder.INSTANCE = this;
|
||||
}
|
||||
|
||||
public ProfilerConfig getProfilerConfig() {
|
||||
return profilerConfig;
|
||||
}
|
||||
|
||||
public ByteCodeInstrumentor getByteCodeInstrumentor() {
|
||||
return byteCodeInstrumentor;
|
||||
}
|
||||
|
||||
private String[] getTomcatlibPath() {
|
||||
String catalinaHome = System.getProperty("catalina.home");
|
||||
|
||||
if (catalinaHome == null) {
|
||||
logger.info("CATALINA_HOME is null");
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("CATALINA_HOME=" + catalinaHome);
|
||||
}
|
||||
|
||||
if (profilerConfig.getServiceType() == ServiceType.BLOC) {
|
||||
return new String[] { catalinaHome + "/server/lib/catalina.jar", catalinaHome + "/common/lib/servlet-api.jar" };
|
||||
} else {
|
||||
return new String[] { catalinaHome + "/lib/servlet-api.jar", catalinaHome + "/lib/catalina.jar" };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private AgentInfo createAgentInfo() {
|
||||
String ip = getServerInfo().getHostip();
|
||||
String ports = "";
|
||||
for (Entry<Integer, String> entry : getServerInfo().getConnectors().entrySet()) {
|
||||
ports += " " + entry.getKey();
|
||||
}
|
||||
|
||||
AgentInfo agentInfo = new AgentInfo();
|
||||
|
||||
agentInfo.setIp(ip);
|
||||
agentInfo.setHostname(this.machineName);
|
||||
agentInfo.setPorts(ports);
|
||||
|
||||
agentInfo.setAgentId(getAgentId());
|
||||
agentInfo.setIdentifier(this.identifier);
|
||||
agentInfo.setApplicationName(getApplicationName());
|
||||
agentInfo.setServiceType(profilerConfig.getServiceType().getCode());
|
||||
|
||||
agentInfo.setIsAlive(true);
|
||||
agentInfo.setTimestamp(this.startTime);
|
||||
|
||||
return agentInfo;
|
||||
}
|
||||
|
||||
private void changeStatus(AgentStatus status) {
|
||||
this.agentStatus = status;
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("Agent status is changed. " + status);
|
||||
}
|
||||
}
|
||||
|
||||
public LoggerBinder initializeLogger() {
|
||||
Slf4jLoggerBinder binder = new Slf4jLoggerBinder();
|
||||
com.profiler.logging.Logger logger = binder.getLogger(Slf4jLoggerBinder.class.getName());
|
||||
logger.info("slf4jLoggerBinder initialized");
|
||||
LoggerFactory.initialize(binder);
|
||||
return binder;
|
||||
}
|
||||
|
||||
private short getShortIdentifier() {
|
||||
return (short) (IDENTIFIER_KEY.nextInt(65536) - 32768);
|
||||
}
|
||||
|
||||
private void initializeTraceContext() {
|
||||
this.traceContext = DefaultTraceContext.getTraceContext();
|
||||
|
||||
this.traceContext.setAgentId(this.agentId);
|
||||
this.traceContext.setApplicationId(this.applicationName);
|
||||
this.traceContext.setPriorityDataSender(this.priorityDataSender);
|
||||
|
||||
if (profilerConfig.isSamplingElapsedTimeBaseEnable()) {
|
||||
TimeBaseStorageFactory timeBaseStorageFactory = new TimeBaseStorageFactory(this.dataSender, this.profilerConfig);
|
||||
this.traceContext.setStorageFactory(timeBaseStorageFactory);
|
||||
} else {
|
||||
this.traceContext.setStorageFactory(new BypassStorageFactory(dataSender));
|
||||
}
|
||||
}
|
||||
|
||||
private UdpDataSender createDataSender() {
|
||||
return new UdpDataSender(this.profilerConfig.getCollectorServerIp(), this.profilerConfig.getCollectorServerPort());
|
||||
}
|
||||
|
||||
private String getId(String key, String defaultValue, int maxlen) {
|
||||
String value = System.getProperty(key, defaultValue);
|
||||
validateId(value, key, maxlen);
|
||||
return value;
|
||||
}
|
||||
|
||||
private void validateId(String id, String idName, int maxlen) {
|
||||
try {
|
||||
byte[] bytes = id.getBytes("UTF-8");
|
||||
if (bytes.length > maxlen) {
|
||||
logger.warning(idName + " is too long(1~24). value=" + id);
|
||||
}
|
||||
// validate = false;
|
||||
// TODO 이제 그냥 exception을 던지면 됨 agent 생성 타이밍이 최초 vm스타트와 동일하다.
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.log(Level.WARNING, "invalid agentId. Cause:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SingletonHolder {
|
||||
public static DefaultAgent INSTANCE;
|
||||
}
|
||||
|
||||
public static DefaultAgent getInstance() {
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public void addConnector(String protocol, int port){
|
||||
this.getServerInfo().addConnector(protocol, port);
|
||||
}
|
||||
|
||||
|
||||
public ServerInfo getServerInfo() {
|
||||
return this.serverInfo;
|
||||
}
|
||||
|
||||
public String getAgentId() {
|
||||
return agentId;
|
||||
}
|
||||
|
||||
public short getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public String getApplicationName() {
|
||||
return applicationName;
|
||||
}
|
||||
|
||||
public TraceContext getTraceContext() {
|
||||
return traceContext;
|
||||
}
|
||||
|
||||
|
||||
public boolean isRunning() {
|
||||
return agentStatus == AgentStatus.RUNNING;
|
||||
}
|
||||
|
||||
// TODO 필요없을것 같음 started를 start로 바꿔도 될 듯...
|
||||
@Override
|
||||
public void start() {
|
||||
logger.info("Starting HIPPO Agent.");
|
||||
}
|
||||
|
||||
/**
|
||||
* org/apache/catalina/startup/Catalina/await함수가 호출되기 전에 실행된다.
|
||||
* Tomcat이 구동되고 context가 모두 로드 된 다음 사용자의 요청을 처리할 수 있게 되었을 때 실행됨.
|
||||
*/
|
||||
public void started() {
|
||||
changeStatus(AgentStatus.RUNNING);
|
||||
this.heartBitChecker.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
logger.info("Stopping HIPPO Agent.");
|
||||
|
||||
changeStatus(AgentStatus.STOPPING);
|
||||
this.heartBitChecker.close();
|
||||
|
||||
|
||||
systemMonitor.stop();
|
||||
|
||||
agentInfo.setIsAlive(false);
|
||||
|
||||
// TODO 개선필요. 특정 collector가 죽더라도 나머지 collector가 받을수 있도록 일부러 중복해서 3번 보낸다.
|
||||
this.priorityDataSender.send(agentInfo);
|
||||
this.priorityDataSender.send(agentInfo);
|
||||
this.priorityDataSender.send(agentInfo);
|
||||
|
||||
// 종료 처리 필요.
|
||||
this.dataSender.stop();
|
||||
this.priorityDataSender.stop();
|
||||
|
||||
changeStatus(AgentStatus.STOPPED);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ public class DeadlineSpanMap {
|
||||
|
||||
private static final long FLUSH_TIMEOUT = 120000L; // 2 minutes
|
||||
|
||||
private final ConcurrentMap<TraceID.TraceKey, Span> map = new ConcurrentHashMap<TraceID.TraceKey, Span>(256);
|
||||
private final ConcurrentMap<DefaultTraceID.TraceKey, Span> map = new ConcurrentHashMap<DefaultTraceID.TraceKey, Span>(256);
|
||||
|
||||
private final Timer timer = new Timer(true);
|
||||
|
||||
public Span update(TraceID traceId, SpanUpdater spanUpdater) {
|
||||
TraceID.TraceKey traceIdKey = traceId.getTraceKey();
|
||||
public Span update(DefaultTraceID traceId, SpanUpdater spanUpdater) {
|
||||
DefaultTraceID.TraceKey traceIdKey = traceId.getTraceKey();
|
||||
Span span = map.get(traceIdKey);
|
||||
|
||||
if (span == null) {
|
||||
@@ -31,7 +31,7 @@ public class DeadlineSpanMap {
|
||||
return spanUpdater.updateSpan(span);
|
||||
}
|
||||
|
||||
public Span remove(TraceID traceId) {
|
||||
public Span remove(DefaultTraceID traceId) {
|
||||
return map.remove(traceId.getTraceKey());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
package com.profiler.context;
|
||||
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.profiler.common.AnnotationKey;
|
||||
import com.profiler.common.ServiceType;
|
||||
import com.profiler.interceptor.MethodDescriptor;
|
||||
import com.profiler.logging.LoggingUtils;
|
||||
import com.profiler.util.StringUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class DefaultAsyncTrace implements AsyncTrace {
|
||||
private static final Logger logger = Logger.getLogger(DefaultAsyncTrace.class.getName());
|
||||
private static final boolean isDebug = logger.isLoggable(Level.FINE);
|
||||
|
||||
public static final int NON_REGIST = -1;
|
||||
// private int id;
|
||||
// 비동기일 경우 traceenable의 경우 애매함. span을 보내는것으로 데이터를 생성하므로 약간 이상.
|
||||
// private boolean tracingEnabled;
|
||||
|
||||
|
||||
|
||||
private final AtomicInteger state = new AtomicInteger(STATE_INIT);
|
||||
|
||||
private int asyncId = NON_REGIST;
|
||||
private SpanEvent spanEvent;
|
||||
|
||||
private Storage storage;
|
||||
private TimerTask timeoutTask;
|
||||
|
||||
public DefaultAsyncTrace(SpanEvent spanEvent) {
|
||||
this.spanEvent = spanEvent;
|
||||
}
|
||||
|
||||
public void setStorage(Storage storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTimeoutTask(TimerTask timeoutTask) {
|
||||
this.timeoutTask = timeoutTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAsyncId(int asyncId) {
|
||||
this.asyncId = asyncId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAsyncId() {
|
||||
return asyncId;
|
||||
}
|
||||
|
||||
|
||||
private Object attachObject;
|
||||
|
||||
@Override
|
||||
public Object getAttachObject() {
|
||||
return attachObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttachObject(Object attachObject) {
|
||||
this.attachObject = attachObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceBlockBegin() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markBeforeTime() {
|
||||
spanEvent.setStartTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBeforeTime() {
|
||||
return spanEvent.getStartTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceBlockEnd() {
|
||||
logSpan(this.spanEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAfterTime() {
|
||||
spanEvent.setEndTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void recordApi(MethodDescriptor methodDescriptor) {
|
||||
if (methodDescriptor == null) {
|
||||
return;
|
||||
}
|
||||
if (methodDescriptor.getApiId() == 0) {
|
||||
recordAttribute(AnnotationKey.API, methodDescriptor.getFullName());
|
||||
} else {
|
||||
recordAttribute(AnnotationKey.API_DID, methodDescriptor.getApiId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAttribute(final AnnotationKey key, final String value) {
|
||||
recordAttribute(key, (Object) value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordException(Object result) {
|
||||
if (result instanceof Throwable) {
|
||||
Throwable th = (Throwable) result;
|
||||
String drop = StringUtils.drop(th.getMessage());
|
||||
recordAttribute(AnnotationKey.EXCEPTION, drop);
|
||||
|
||||
// TODO 비동기 api일 경우, span에 exception을 마크하기가 까다로움
|
||||
// AnnotationKey span = getCallStack().getSpan();
|
||||
// if (span.getException() == 0) {
|
||||
// span.setException(1);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void recordAttribute(final AnnotationKey key, final Object value) {
|
||||
spanEvent.addAnnotation(new TraceAnnotation(key, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordServiceType(final ServiceType serviceType) {
|
||||
this.spanEvent.setServiceType(serviceType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordRpcName(final String rpcName) {
|
||||
this.spanEvent.setRpc(rpcName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void recordDestinationId(String destinationId) {
|
||||
this.spanEvent.setDestionationId(destinationId);
|
||||
}
|
||||
|
||||
// TODO: final String... endPoint로 받으면 합치는데 비용이 들어가 그냥 한번에 받는게 나을것 같음.
|
||||
@Override
|
||||
public void recordEndPoint(final String endPoint) {
|
||||
this.spanEvent.setEndPoint(endPoint);
|
||||
}
|
||||
|
||||
private void annotate(final AnnotationKey key) {
|
||||
this.spanEvent.addAnnotation(new TraceAnnotation(key));
|
||||
|
||||
}
|
||||
|
||||
void logSpan(SpanEvent spanEvent) {
|
||||
try {
|
||||
if (isDebug) {
|
||||
Thread thread = Thread.currentThread();
|
||||
logger.info("[WRITE SpanEvent]" + spanEvent + " CurrentThreadID=" + thread.getId() + ",\n\t CurrentThreadName=" + thread.getName());
|
||||
}
|
||||
this.storage.store(spanEvent);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state.get();
|
||||
}
|
||||
|
||||
public void timeout() {
|
||||
if (state.compareAndSet(STATE_INIT, STATE_TIMEOUT)) {
|
||||
// TODO timeout spanEvent log 던지기.
|
||||
// 뭘 어떤 내용을 던져야 되는지 아직 모르겠음????
|
||||
}
|
||||
}
|
||||
|
||||
public boolean fire() {
|
||||
if (state.compareAndSet(STATE_INIT, STATE_FIRE)) {
|
||||
if (timeoutTask != null) {
|
||||
// timeout이 걸려 있는 asynctrace일 경우 호출해 준다.
|
||||
this.timeoutTask.cancel();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import com.profiler.common.AnnotationKey;
|
||||
import com.profiler.common.ServiceType;
|
||||
import com.profiler.common.util.ParsingResult;
|
||||
import com.profiler.interceptor.MethodDescriptor;
|
||||
import com.profiler.logging.LoggingUtils;
|
||||
import com.profiler.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
@@ -17,7 +16,7 @@ import java.util.logging.Logger;
|
||||
public final class DefaultTrace implements Trace {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(DefaultTrace.class.getName());
|
||||
private static final boolean isDebug = LoggingUtils.isDebug(logger);
|
||||
private static final boolean isDebug = logger.isLoggable(Level.FINE);
|
||||
|
||||
public static final int NOCHECK_STACKID = -1;
|
||||
public static final int ROOT_STACKID = 0;
|
||||
@@ -36,16 +35,16 @@ public final class DefaultTrace implements Trace {
|
||||
private int latestStackIndex = -1;
|
||||
|
||||
public DefaultTrace() {
|
||||
TraceID traceId = TraceID.newTraceId();
|
||||
DefaultTraceID traceId = DefaultTraceID.newTraceId();
|
||||
this.callStack = new CallStack(traceId);
|
||||
latestStackIndex = this.callStack.push();
|
||||
StackFrame stackFrame = createRootStackFrame(ROOT_STACKID, callStack.getSpan());
|
||||
this.callStack.setStackFrame(stackFrame);
|
||||
}
|
||||
|
||||
public DefaultTrace(TraceID continueRoot) {
|
||||
public DefaultTrace(TraceID continueTraceID) {
|
||||
// this.root = continueRoot;
|
||||
this.callStack = new CallStack(continueRoot);
|
||||
this.callStack = new CallStack(continueTraceID);
|
||||
latestStackIndex = this.callStack.push();
|
||||
StackFrame stackFrame = createRootStackFrame(ROOT_STACKID, callStack.getSpan());
|
||||
this.callStack.setStackFrame(stackFrame);
|
||||
@@ -69,7 +68,7 @@ public final class DefaultTrace implements Trace {
|
||||
// 경우에 따라 별도 timeout 처리가 있어야 될수도 있음.
|
||||
SpanEvent spanEvent = new SpanEvent(callStack.getSpan());
|
||||
spanEvent.setSequence(getSequence());
|
||||
AsyncTrace asyncTrace = new AsyncTrace(spanEvent);
|
||||
DefaultAsyncTrace asyncTrace = new DefaultAsyncTrace(spanEvent);
|
||||
// asyncTrace.setDataSender(this.getDataSender());
|
||||
asyncTrace.setStorage(this.storage);
|
||||
return asyncTrace;
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.profiler.context;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class DefaultTraceID implements TraceID {
|
||||
private UUID id;
|
||||
private int parentSpanId;
|
||||
private int spanId;
|
||||
private boolean sampled;
|
||||
private short flags;
|
||||
|
||||
public static DefaultTraceID newTraceId() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
return new DefaultTraceID(uuid, SpanID.NULL, SpanID.newSpanID(), false, (short) 0);
|
||||
}
|
||||
|
||||
public TraceID getNextTraceId() {
|
||||
return new DefaultTraceID(id, spanId, SpanID.nextSpanID(spanId, parentSpanId), sampled, flags);
|
||||
}
|
||||
|
||||
public DefaultTraceID(UUID id, int parentSpanId, int spanId, boolean sampled, short flags) {
|
||||
this.id = id;
|
||||
this.parentSpanId = parentSpanId;
|
||||
this.spanId = spanId;
|
||||
this.sampled = sampled;
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public TraceKey getTraceKey() {
|
||||
long most = id.getMostSignificantBits();
|
||||
long least = id.getLeastSignificantBits();
|
||||
return new TraceKey(most, least, spanId);
|
||||
}
|
||||
|
||||
public static final class TraceKey {
|
||||
private final long most;
|
||||
private final long least;
|
||||
private final int span;
|
||||
|
||||
public TraceKey(long most, long least, int span) {
|
||||
this.most = most;
|
||||
this.least = least;
|
||||
this.span = span;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
TraceKey traceKey = (TraceKey) o;
|
||||
|
||||
if (least != traceKey.least) return false;
|
||||
if (most != traceKey.most) return false;
|
||||
if (span != traceKey.span) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) (most ^ (most >>> 32));
|
||||
result = 31 * result + (int) (least ^ (least >>> 32));
|
||||
result = 31 * result + span;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public int getParentSpanId() {
|
||||
return parentSpanId;
|
||||
}
|
||||
|
||||
public int getSpanId() {
|
||||
return spanId;
|
||||
}
|
||||
|
||||
public boolean isSampled() {
|
||||
return sampled;
|
||||
}
|
||||
|
||||
public short getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public void setTraceId(UUID traceId) {
|
||||
this.id = traceId;
|
||||
}
|
||||
|
||||
public void setParentSpanId(int parentSpanId) {
|
||||
this.parentSpanId = parentSpanId;
|
||||
}
|
||||
|
||||
public void setSpanId(int spanId) {
|
||||
this.spanId = spanId;
|
||||
}
|
||||
|
||||
public void setSampled(boolean sampled) {
|
||||
this.sampled = sampled;
|
||||
}
|
||||
|
||||
public void setFlags(short flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public boolean isRoot() {
|
||||
return this.parentSpanId == SpanID.NULL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(128);
|
||||
|
||||
sb.append("{");
|
||||
sb.append("id=").append(id);
|
||||
sb.append(", parentSpanId=").append(parentSpanId);
|
||||
sb.append(", spanId=").append(spanId);
|
||||
sb.append(", sampled=").append(sampled);
|
||||
sb.append(", flags=").append(flags);
|
||||
sb.append("}");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class GlobalCallTrace {
|
||||
|
||||
private int put(AsyncTrace asyncTrace) {
|
||||
int id = idGenerator.getAndIncrement();
|
||||
trace.put(id, asyncTrace);
|
||||
trace.put(id, (DefaultAsyncTrace)asyncTrace);
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class GlobalCallTrace {
|
||||
public AsyncTrace removeTraceObject(int asyncId) {
|
||||
AsyncTrace asyncTrace = trace.remove(asyncId);
|
||||
if (asyncTrace != null) {
|
||||
boolean result = asyncTrace.fire();
|
||||
boolean result = ((DefaultAsyncTrace)asyncTrace).fire();
|
||||
if (!result) {
|
||||
// 이미 timeout된 asyncTrace임.
|
||||
return null;
|
||||
@@ -68,7 +68,7 @@ public class GlobalCallTrace {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
AsyncTrace asyncTrace = trace.remove(id);
|
||||
DefaultAsyncTrace asyncTrace = (DefaultAsyncTrace) trace.remove(id);
|
||||
if (asyncTrace != null) {
|
||||
asyncTrace.timeout();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.profiler.context;
|
||||
|
||||
import com.profiler.Agent;
|
||||
import com.profiler.DefaultAgent;
|
||||
import com.profiler.common.ServiceType;
|
||||
import com.profiler.common.dto.thrift.Annotation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -166,9 +167,9 @@ public class Span implements Thriftable {
|
||||
public com.profiler.common.dto.thrift.Span toThrift() {
|
||||
com.profiler.common.dto.thrift.Span span = new com.profiler.common.dto.thrift.Span();
|
||||
|
||||
span.setAgentId(Agent.getInstance().getAgentId());
|
||||
span.setApplicationId(Agent.getInstance().getApplicationName());
|
||||
span.setAgentIdentifier(Agent.getInstance().getIdentifier());
|
||||
span.setAgentId(DefaultAgent.getInstance().getAgentId());
|
||||
span.setApplicationId(DefaultAgent.getInstance().getApplicationName());
|
||||
span.setAgentIdentifier(DefaultAgent.getInstance().getIdentifier());
|
||||
|
||||
span.setStartTime(startTime);
|
||||
span.setElapsed((int) (endTime - startTime));
|
||||
@@ -197,7 +198,7 @@ public class Span implements Thriftable {
|
||||
}
|
||||
|
||||
// 여기서 데이터 인코딩을 하자.
|
||||
List<com.profiler.common.dto.thrift.Annotation> annotationList = new ArrayList<com.profiler.common.dto.thrift.Annotation>(traceAnnotationList.size());
|
||||
List<Annotation> annotationList = new ArrayList<Annotation>(traceAnnotationList.size());
|
||||
for (TraceAnnotation traceAnnotation : traceAnnotationList) {
|
||||
annotationList.add(traceAnnotation.toThrift());
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ package com.profiler.context;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.profiler.Agent;
|
||||
import com.profiler.DefaultAgent;
|
||||
import com.profiler.common.ServiceType;
|
||||
import com.profiler.common.dto.thrift.Annotation;
|
||||
|
||||
/**
|
||||
* Span represent RPC
|
||||
@@ -174,9 +175,9 @@ public class SpanEvent implements Thriftable {
|
||||
spanEvent.setSequence(sequence);
|
||||
// Span내부의 SpanEvent로 들어가지 않을 경우
|
||||
if (!child) {
|
||||
spanEvent.setAgentId(Agent.getInstance().getAgentId());
|
||||
spanEvent.setApplicationId(Agent.getInstance().getApplicationName());
|
||||
spanEvent.setAgentIdentifier(Agent.getInstance().getIdentifier());
|
||||
spanEvent.setAgentId(DefaultAgent.getInstance().getAgentId());
|
||||
spanEvent.setApplicationId(DefaultAgent.getInstance().getApplicationName());
|
||||
spanEvent.setAgentIdentifier(DefaultAgent.getInstance().getIdentifier());
|
||||
|
||||
TraceID parentSpanTraceID = parentSpan.getTraceID();
|
||||
spanEvent.setMostTraceId(parentSpanTraceID.getId().getMostSignificantBits());
|
||||
@@ -191,7 +192,7 @@ public class SpanEvent implements Thriftable {
|
||||
spanEvent.setDestinationId(this.destionationId);
|
||||
|
||||
// 여기서 데이터 인코딩을 하자.
|
||||
List<com.profiler.common.dto.thrift.Annotation> annotationList = new ArrayList<com.profiler.common.dto.thrift.Annotation>(traceAnnotationList.size());
|
||||
List<Annotation> annotationList = new ArrayList<Annotation>(traceAnnotationList.size());
|
||||
for (TraceAnnotation traceAnnotation : traceAnnotationList) {
|
||||
annotationList.add(traceAnnotation.toThrift());
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.profiler.interceptor.bci;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
import com.profiler.interceptor.Interceptor;
|
||||
import javassist.ClassPool;
|
||||
|
||||
public interface ByteCodeInstrumentor {
|
||||
|
||||
@@ -16,5 +15,7 @@ public interface ByteCodeInstrumentor {
|
||||
|
||||
Interceptor newInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, String interceptorFQCN) throws InstrumentException;
|
||||
|
||||
Interceptor newInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, String interceptorFQCN, Object[] params) throws InstrumentException;
|
||||
// Interceptor newInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, String interceptorFQCN, Object[] params) throws InstrumentException;
|
||||
|
||||
Interceptor newInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, String interceptorFQCN, Object[] params, Class[] paramClazz) throws InstrumentException;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,289 @@
|
||||
package com.profiler.logger;
|
||||
|
||||
import com.profiler.logging.Logger;
|
||||
import org.slf4j.Marker;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Slf4jLoggerAdapter implements Logger {
|
||||
private final org.slf4j.Logger logger;
|
||||
|
||||
public Slf4jLoggerAdapter(org.slf4j.Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return logger.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTraceEnabled() {
|
||||
return logger.isTraceEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String msg) {
|
||||
logger.trace(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String format, Object arg) {
|
||||
logger.trace(format, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String format, Object arg1, Object arg2) {
|
||||
logger.trace(format, arg1, arg2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String format, Object[] argArray) {
|
||||
logger.trace(format, argArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String msg, Throwable t) {
|
||||
logger.trace(msg, t);
|
||||
}
|
||||
|
||||
public boolean isTraceEnabled(Marker marker) {
|
||||
return logger.isTraceEnabled(marker);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String msg) {
|
||||
logger.trace(marker, msg);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String format, Object arg) {
|
||||
logger.trace(marker, format, arg);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String format, Object arg1, Object arg2) {
|
||||
logger.trace(marker, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String format, Object[] argArray) {
|
||||
logger.trace(marker, format, argArray);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String msg, Throwable t) {
|
||||
logger.trace(marker, msg, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return logger.isDebugEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String msg) {
|
||||
logger.debug(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format, Object arg) {
|
||||
logger.debug(format, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format, Object arg1, Object arg2) {
|
||||
logger.debug(format, arg1, arg2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format, Object[] argArray) {
|
||||
logger.debug(format, argArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String msg, Throwable t) {
|
||||
logger.debug(msg, t);
|
||||
}
|
||||
|
||||
public boolean isDebugEnabled(Marker marker) {
|
||||
return logger.isDebugEnabled(marker);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String msg) {
|
||||
logger.debug(marker, msg);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String format, Object arg) {
|
||||
logger.debug(marker, format, arg);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String format, Object arg1, Object arg2) {
|
||||
logger.debug(marker, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String format, Object[] argArray) {
|
||||
logger.debug(marker, format, argArray);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String msg, Throwable t) {
|
||||
logger.debug(marker, msg, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
return logger.isInfoEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg) {
|
||||
logger.info(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String format, Object arg) {
|
||||
logger.info(format, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String format, Object arg1, Object arg2) {
|
||||
logger.info(format, arg1, arg2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String format, Object[] argArray) {
|
||||
logger.info(format, argArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg, Throwable t) {
|
||||
logger.info(msg, t);
|
||||
}
|
||||
|
||||
public boolean isInfoEnabled(Marker marker) {
|
||||
return logger.isInfoEnabled(marker);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String msg) {
|
||||
logger.info(marker, msg);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String format, Object arg) {
|
||||
logger.info(marker, format, arg);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String format, Object arg1, Object arg2) {
|
||||
logger.info(marker, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String format, Object[] argArray) {
|
||||
logger.info(marker, format, argArray);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String msg, Throwable t) {
|
||||
logger.info(marker, msg, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnabled() {
|
||||
return logger.isWarnEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg) {
|
||||
logger.warn(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object arg) {
|
||||
logger.warn(format, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object[] argArray) {
|
||||
logger.warn(format, argArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object arg1, Object arg2) {
|
||||
logger.warn(format, arg1, arg2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg, Throwable t) {
|
||||
logger.warn(msg, t);
|
||||
}
|
||||
|
||||
public boolean isWarnEnabled(Marker marker) {
|
||||
return logger.isWarnEnabled(marker);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String msg) {
|
||||
logger.warn(marker, msg);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String format, Object arg) {
|
||||
logger.warn(marker, format, arg);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String format, Object arg1, Object arg2) {
|
||||
logger.warn(marker, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String format, Object[] argArray) {
|
||||
logger.warn(marker, format, argArray);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String msg, Throwable t) {
|
||||
logger.warn(marker, msg, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnabled() {
|
||||
return logger.isErrorEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg) {
|
||||
logger.error(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Object arg) {
|
||||
logger.error(format, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Object arg1, Object arg2) {
|
||||
logger.error(format, arg1, arg2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Object[] argArray) {
|
||||
logger.error(format, argArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg, Throwable t) {
|
||||
logger.error(msg, t);
|
||||
}
|
||||
|
||||
public boolean isErrorEnabled(Marker marker) {
|
||||
return logger.isErrorEnabled(marker);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String msg) {
|
||||
logger.error(marker, msg);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String format, Object arg) {
|
||||
logger.error(marker, format, arg);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String format, Object arg1, Object arg2) {
|
||||
logger.error(marker, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String format, Object[] argArray) {
|
||||
logger.error(marker, format, argArray);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String msg, Throwable t) {
|
||||
logger.error(marker, msg, t);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.profiler.logger;
|
||||
|
||||
import com.profiler.logging.Logger;
|
||||
import com.profiler.logging.LoggerBinder;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Slf4jLoggerBinder implements LoggerBinder {
|
||||
|
||||
private ConcurrentMap<String, Logger> loggerCache = new ConcurrentHashMap<String, Logger>();
|
||||
|
||||
@Override
|
||||
public Logger getLogger(String name) {
|
||||
|
||||
Logger hitLogger = loggerCache.get(name);
|
||||
if (hitLogger != null) {
|
||||
return hitLogger;
|
||||
}
|
||||
|
||||
org.slf4j.Logger slf4jLogger = LoggerFactory.getLogger(name);
|
||||
|
||||
Slf4jLoggerAdapter slf4jLoggerAdapter = new Slf4jLoggerAdapter(slf4jLogger);
|
||||
Logger before = loggerCache.putIfAbsent(name, slf4jLoggerAdapter);
|
||||
if (before != null) {
|
||||
return before;
|
||||
}
|
||||
return slf4jLoggerAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
// 안해도 될것도 같고. LoggerFactory의unregister만 해도 될려나?
|
||||
loggerCache = null;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,21 @@
|
||||
package com.profiler.modifier;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import com.profiler.logging.Logger;
|
||||
|
||||
import com.profiler.DefaultAgent;
|
||||
import com.profiler.common.ServiceType;
|
||||
import com.profiler.interceptor.ServiceTypeSupport;
|
||||
import javassist.ClassPool;
|
||||
|
||||
import com.profiler.Agent;
|
||||
import com.profiler.interceptor.Interceptor;
|
||||
import com.profiler.interceptor.TraceContextSupport;
|
||||
import com.profiler.interceptor.bci.ByteCodeInstrumentor;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
|
||||
public abstract class AbstractModifier implements Modifier {
|
||||
|
||||
private final Logger logger = Logger.getLogger(AbstractModifier.class.getName());
|
||||
private final Logger logger = LoggerFactory.getLogger(AbstractModifier.class.getName());
|
||||
|
||||
protected final ByteCodeInstrumentor byteCodeInstrumentor;
|
||||
protected final Agent agent;
|
||||
@@ -29,17 +30,17 @@ public abstract class AbstractModifier implements Modifier {
|
||||
}
|
||||
|
||||
public void printClassConvertComplete(String javassistClassName) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info(javassistClassName + " class is converted.");
|
||||
}
|
||||
}
|
||||
|
||||
public void setTraceContext(Interceptor interceptor) {
|
||||
// TODO TraceContext를 인터셉터에 바인하는 방안의 추가 개선 필요.
|
||||
if (interceptor instanceof TraceContextSupport) {
|
||||
((TraceContextSupport) interceptor).setTraceContext(agent.getTraceContext());
|
||||
}
|
||||
}
|
||||
// public void setTraceContext(Interceptor interceptor) {
|
||||
// // TODO TraceContext를 인터셉터에 바인하는 방안의 추가 개선 필요.
|
||||
// if (interceptor instanceof TraceContextSupport) {
|
||||
// ((TraceContextSupport) interceptor).setTraceContext(agent.getTraceContext());
|
||||
// }
|
||||
// }
|
||||
|
||||
public void setServiceType(Interceptor interceptor, ServiceType serviceType) {
|
||||
if (interceptor instanceof ServiceTypeSupport) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.profiler.Agent;
|
||||
import com.profiler.DefaultAgent;
|
||||
import com.profiler.config.ProfilerConfig;
|
||||
import com.profiler.interceptor.bci.ByteCodeInstrumentor;
|
||||
import com.profiler.modifier.arcus.ArcusClientModifier;
|
||||
@@ -27,7 +28,6 @@ import com.profiler.modifier.db.mysql.MySQLConnectionImplModifier;
|
||||
import com.profiler.modifier.db.mysql.MySQLNonRegisteringDriverModifier;
|
||||
import com.profiler.modifier.db.mysql.MySQLPreparedStatementJDBC4Modifier;
|
||||
import com.profiler.modifier.db.mysql.MySQLPreparedStatementModifier;
|
||||
import com.profiler.modifier.db.mysql.MySQLResultSetModifier;
|
||||
import com.profiler.modifier.db.mysql.MySQLStatementModifier;
|
||||
import com.profiler.modifier.db.oracle.OraclePreparedStatementModifier;
|
||||
import com.profiler.modifier.db.oracle.OracleResultSetModifier;
|
||||
@@ -50,10 +50,11 @@ public class DefaultModifierRegistry implements ModifierRegistry {
|
||||
private final ProfilerConfig profilerConfig;
|
||||
private final Agent agent;
|
||||
|
||||
public DefaultModifierRegistry(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent, ProfilerConfig profilerConfig) {
|
||||
this.byteCodeInstrumentor = byteCodeInstrumentor;
|
||||
public DefaultModifierRegistry(Agent agent) {
|
||||
this.agent = agent;
|
||||
this.profilerConfig = profilerConfig;
|
||||
// classLoader계층 구조 때문에 직접 type을 넣기가 애매하여 그냥 casting
|
||||
this.byteCodeInstrumentor = (ByteCodeInstrumentor) agent.getByteCodeInstrumentor();
|
||||
this.profilerConfig = agent.getProfilerConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -167,8 +168,8 @@ public class DefaultModifierRegistry implements ModifierRegistry {
|
||||
MySQLPreparedStatementJDBC4Modifier myqlPreparedStatementJDBC4Modifier = new MySQLPreparedStatementJDBC4Modifier(byteCodeInstrumentor, agent);
|
||||
addModifier(myqlPreparedStatementJDBC4Modifier);
|
||||
|
||||
Modifier mysqlResultSetModifier = new MySQLResultSetModifier(byteCodeInstrumentor, agent);
|
||||
addModifier(mysqlResultSetModifier);
|
||||
// Modifier mysqlResultSetModifier = new MySQLResultSetModifier(byteCodeInstrumentor, agent);
|
||||
// addModifier(mysqlResultSetModifier);
|
||||
}
|
||||
|
||||
private void addMsSqlDriver() {
|
||||
|
||||
@@ -3,4 +3,5 @@ package com.profiler.modifier;
|
||||
public interface ModifierRegistry {
|
||||
|
||||
Modifier findModifier(String className);
|
||||
|
||||
}
|
||||
|
||||
+8
-7
@@ -1,10 +1,11 @@
|
||||
package com.profiler.modifier.arcus.interceptors;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import com.profiler.logging.Logger;
|
||||
|
||||
import com.profiler.context.DefaultAsyncTrace;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
import net.spy.memcached.protocol.BaseOperationImpl;
|
||||
|
||||
import com.profiler.context.AsyncTrace;
|
||||
import com.profiler.interceptor.StaticBeforeInterceptor;
|
||||
import com.profiler.logging.LoggingUtils;
|
||||
import com.profiler.util.MetaObject;
|
||||
@@ -14,8 +15,8 @@ import com.profiler.util.MetaObject;
|
||||
*/
|
||||
public class BaseOperationCancelInterceptor implements StaticBeforeInterceptor {
|
||||
|
||||
private final Logger logger = Logger.getLogger(BaseOperationCancelInterceptor.class.getName());
|
||||
private final boolean isDebug = LoggingUtils.isDebug(logger);
|
||||
private final Logger logger = LoggerFactory.getLogger(BaseOperationCancelInterceptor.class.getName());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MetaObject getAsyncTrace = new MetaObject("__getAsyncTrace");
|
||||
|
||||
@@ -25,13 +26,13 @@ public class BaseOperationCancelInterceptor implements StaticBeforeInterceptor {
|
||||
LoggingUtils.logBefore(logger, target, className, methodName, parameterDescription, args);
|
||||
}
|
||||
|
||||
AsyncTrace asyncTrace = (AsyncTrace) getAsyncTrace.invoke(target);
|
||||
DefaultAsyncTrace asyncTrace = (DefaultAsyncTrace) getAsyncTrace.invoke(target);
|
||||
if (asyncTrace == null) {
|
||||
logger.fine("asyncTrace not found ");
|
||||
logger.debug("asyncTrace not found ");
|
||||
return;
|
||||
}
|
||||
|
||||
if (asyncTrace.getState() != AsyncTrace.STATE_INIT) {
|
||||
if (asyncTrace.getState() != DefaultAsyncTrace.STATE_INIT) {
|
||||
// 이미 동작 완료된 상태임.
|
||||
return;
|
||||
}
|
||||
|
||||
+19
-13
@@ -5,30 +5,31 @@ import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import com.profiler.logging.Logger;
|
||||
|
||||
import com.profiler.common.AnnotationKey;
|
||||
import com.profiler.context.DefaultTraceContext;
|
||||
import com.profiler.context.AsyncTrace;
|
||||
import com.profiler.context.TraceContext;
|
||||
import com.profiler.interceptor.ByteCodeMethodDescriptorSupport;
|
||||
import com.profiler.interceptor.MethodDescriptor;
|
||||
import com.profiler.interceptor.TraceContextSupport;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
import com.profiler.logging.LoggingUtils;
|
||||
import net.spy.memcached.MemcachedNode;
|
||||
import net.spy.memcached.ops.OperationState;
|
||||
import net.spy.memcached.protocol.BaseOperationImpl;
|
||||
|
||||
import com.profiler.common.ServiceType;
|
||||
import com.profiler.context.AsyncTrace;
|
||||
import com.profiler.interceptor.StaticBeforeInterceptor;
|
||||
import com.profiler.util.MetaObject;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class BaseOperationTransitionStateInterceptor implements StaticBeforeInterceptor, ByteCodeMethodDescriptorSupport {
|
||||
public class BaseOperationTransitionStateInterceptor implements StaticBeforeInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
|
||||
|
||||
private final Logger logger = Logger.getLogger(BaseOperationTransitionStateInterceptor.class.getName());
|
||||
private final boolean isDebug = LoggingUtils.isDebug(logger);
|
||||
private final Logger logger = LoggerFactory.getLogger(BaseOperationTransitionStateInterceptor.class.getName());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
|
||||
@@ -36,6 +37,7 @@ public class BaseOperationTransitionStateInterceptor implements StaticBeforeInte
|
||||
private MetaObject getServiceCode = new MetaObject("__getServiceCode");
|
||||
|
||||
private MethodDescriptor methodDescriptor;
|
||||
private TraceContext traceContext;
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
@@ -45,7 +47,7 @@ public class BaseOperationTransitionStateInterceptor implements StaticBeforeInte
|
||||
|
||||
AsyncTrace asyncTrace = (AsyncTrace) getAsyncTrace.invoke(target);
|
||||
if (asyncTrace == null) {
|
||||
logger.fine("asyncTrace not found");
|
||||
logger.debug("asyncTrace not found");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,8 +55,8 @@ public class BaseOperationTransitionStateInterceptor implements StaticBeforeInte
|
||||
|
||||
BaseOperationImpl baseOperation = (BaseOperationImpl) target;
|
||||
if (newState == OperationState.READING) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("event:" + newState + " asyncTrace:" + asyncTrace);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("event:" + newState + " asyncTrace:" + asyncTrace);
|
||||
}
|
||||
if (asyncTrace.getState() != AsyncTrace.STATE_INIT) {
|
||||
return;
|
||||
@@ -97,8 +99,8 @@ public class BaseOperationTransitionStateInterceptor implements StaticBeforeInte
|
||||
asyncTrace.markAfterTime();
|
||||
// asyncTrace.traceBlockEnd();
|
||||
} else if (newState == OperationState.COMPLETE || newState == OperationState.TIMEDOUT) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("event:" + newState + " asyncTrace:" + asyncTrace);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("event:" + newState + " asyncTrace:" + asyncTrace);
|
||||
}
|
||||
boolean fire = asyncTrace.fire();
|
||||
if (!fire) {
|
||||
@@ -136,7 +138,11 @@ public class BaseOperationTransitionStateInterceptor implements StaticBeforeInte
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.methodDescriptor = descriptor;
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
traceContext.cacheApi(descriptor);
|
||||
this.traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTraceContext(TraceContext traceContext) {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
}
|
||||
|
||||
+27
-29
@@ -3,7 +3,7 @@ package com.profiler.modifier.bloc.handler.interceptors;
|
||||
import java.util.Enumeration;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import com.profiler.logging.Logger;
|
||||
|
||||
import com.profiler.common.AnnotationKey;
|
||||
import com.profiler.common.ServiceType;
|
||||
@@ -11,19 +11,21 @@ import com.profiler.context.*;
|
||||
import com.profiler.interceptor.ByteCodeMethodDescriptorSupport;
|
||||
import com.profiler.interceptor.MethodDescriptor;
|
||||
import com.profiler.interceptor.StaticAroundInterceptor;
|
||||
import com.profiler.interceptor.TraceContextSupport;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
import com.profiler.logging.LoggingUtils;
|
||||
import com.profiler.util.NumberUtils;
|
||||
|
||||
/**
|
||||
* @author netspider
|
||||
*/
|
||||
public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport {
|
||||
public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
|
||||
|
||||
private final Logger logger = Logger.getLogger(ExecuteMethodInterceptor.class.getName());
|
||||
private final boolean isDebug = LoggingUtils.isDebug(logger);
|
||||
private final Logger logger = LoggerFactory.getLogger(ExecuteMethodInterceptor.class.getName());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MethodDescriptor descriptor;
|
||||
// private int apiId;
|
||||
private TraceContext traceContext;
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
@@ -32,33 +34,27 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
}
|
||||
|
||||
try {
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
traceContext.getActiveThreadCounter().start();
|
||||
|
||||
external.org.apache.coyote.Request request = (external.org.apache.coyote.Request) args[0];
|
||||
String requestURL = request.requestURI().toString();
|
||||
String clientIP = request.remoteAddr().toString();
|
||||
String parameters = getRequestParameter(request);
|
||||
|
||||
TraceID traceId = populateTraceIdFromRequest(request);
|
||||
DefaultTrace trace;
|
||||
DefaultTraceID traceId = populateTraceIdFromRequest(request);
|
||||
Trace trace;
|
||||
if (traceId != null) {
|
||||
// TraceID nextTraceId = traceId.getNextTraceId();
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
// logger.info("TraceID exist. continue trace. " + nextTraceId);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("TraceID exist. continue trace. " + traceId);
|
||||
logger.log(Level.FINE, "requestUrl:" + requestURL + " clientIp" + clientIP + " parameter:" + parameters);
|
||||
logger.debug("requestUrl:" + requestURL + " clientIp" + clientIP + " parameter:" + parameters);
|
||||
}
|
||||
// trace = new Trace(nextTraceId);
|
||||
trace = new DefaultTrace(traceId);
|
||||
traceContext.attachTraceObject(trace);
|
||||
|
||||
trace = traceContext.continueTraceObject(traceId);
|
||||
} else {
|
||||
trace = new DefaultTrace();
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("TraceID not exist. start new trace. " + trace.getTraceId());
|
||||
logger.log(Level.FINE, "requestUrl:" + requestURL + " clientIp" + clientIP + " parameter:" + parameters);
|
||||
logger.debug("requestUrl:" + requestURL + " clientIp" + clientIP + " parameter:" + parameters);
|
||||
}
|
||||
traceContext.attachTraceObject(trace);
|
||||
trace = traceContext.newTraceObject();
|
||||
}
|
||||
|
||||
trace.markBeforeTime();
|
||||
@@ -75,8 +71,8 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, "Tomcat StandardHostValve trace start fail. Caused:" + e.getMessage(), e);
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn( "Tomcat StandardHostValve trace start fail. Caused:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,15 +83,14 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
LoggingUtils.logAfter(logger, target, className, methodName, parameterDescription, args, result);
|
||||
}
|
||||
|
||||
DefaultTraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
traceContext.getActiveThreadCounter().end();
|
||||
// traceContext.getActiveThreadCounter().end();
|
||||
Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
traceContext.detachTraceObject();
|
||||
if (trace.getStackFrameId() != 0) {
|
||||
logger.warning("Corrupted CallStack found. StackId not Root(0)");
|
||||
logger.warn("Corrupted CallStack found. StackId not Root(0)");
|
||||
// 문제 있는 callstack을 dump하면 도움이 될듯.
|
||||
}
|
||||
|
||||
@@ -113,7 +108,7 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private TraceID populateTraceIdFromRequest(external.org.apache.coyote.Request request) {
|
||||
private DefaultTraceID populateTraceIdFromRequest(external.org.apache.coyote.Request request) {
|
||||
String strUUID = request.getHeader(Header.HTTP_TRACE_ID.toString());
|
||||
if (strUUID != null) {
|
||||
UUID uuid = UUID.fromString(strUUID);
|
||||
@@ -122,8 +117,8 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
boolean sampled = Boolean.parseBoolean(request.getHeader(Header.HTTP_SAMPLED.toString()));
|
||||
short flags = NumberUtils.parseShort(request.getHeader(Header.HTTP_FLAGS.toString()), (short) 0);
|
||||
|
||||
TraceID id = new TraceID(uuid, parentSpanID, spanID, sampled, flags);
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
DefaultTraceID id = new DefaultTraceID(uuid, parentSpanID, spanID, sampled, flags);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("TraceID exist. continue trace. " + id);
|
||||
}
|
||||
return id;
|
||||
@@ -156,9 +151,12 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setTraceContext(TraceContext traceContext) {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
}
|
||||
+13
-8
@@ -1,9 +1,11 @@
|
||||
package com.profiler.modifier.connector.httpclient4.interceptor;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.logging.Logger;
|
||||
import com.profiler.logging.Logger;
|
||||
|
||||
import com.profiler.context.*;
|
||||
import com.profiler.interceptor.TraceContextSupport;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
|
||||
@@ -24,19 +26,19 @@ import com.profiler.logging.LoggingUtils;
|
||||
* public final HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException
|
||||
* </pre>
|
||||
*/
|
||||
public class Execute2MethodInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport {
|
||||
public class Execute2MethodInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
|
||||
|
||||
private final Logger logger = Logger.getLogger(Execute2MethodInterceptor.class.getName());
|
||||
private final boolean isDebug = LoggingUtils.isDebug(logger);
|
||||
private final Logger logger = LoggerFactory.getLogger(Execute2MethodInterceptor.class.getName());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MethodDescriptor descriptor;
|
||||
private TraceContext traceContext;
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
if (isDebug) {
|
||||
LoggingUtils.logBefore(logger, target, className, methodName, parameterDescription, args);
|
||||
}
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
@@ -75,7 +77,6 @@ public class Execute2MethodInterceptor implements StaticAroundInterceptor, ByteC
|
||||
LoggingUtils.logAfter(logger, target, className, methodName, parameterDescription, args);
|
||||
}
|
||||
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
@@ -90,7 +91,6 @@ public class Execute2MethodInterceptor implements StaticAroundInterceptor, ByteC
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
@@ -147,4 +147,9 @@ public class Execute2MethodInterceptor implements StaticAroundInterceptor, ByteC
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTraceContext(TraceContext traceContext) {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
}
|
||||
+13
-9
@@ -1,9 +1,11 @@
|
||||
package com.profiler.modifier.connector.httpclient4.interceptor;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import com.profiler.logging.Logger;
|
||||
|
||||
import com.profiler.common.AnnotationKey;
|
||||
import com.profiler.context.*;
|
||||
import com.profiler.interceptor.TraceContextSupport;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
|
||||
@@ -26,20 +28,21 @@ import com.profiler.logging.LoggingUtils;
|
||||
* throws IOException, ClientProtocolException {
|
||||
* </pre>
|
||||
*/
|
||||
public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport {
|
||||
public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
|
||||
|
||||
private final Logger logger = Logger.getLogger(ExecuteMethodInterceptor.class.getName());
|
||||
private final boolean isDebug = LoggingUtils.isDebug(logger);
|
||||
private final Logger logger = LoggerFactory.getLogger(ExecuteMethodInterceptor.class.getName());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MethodDescriptor descriptor;
|
||||
// private int apiId;
|
||||
private TraceContext traceContext;
|
||||
// private int apiId;
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
if (isDebug) {
|
||||
LoggingUtils.logBefore(logger, target, className, methodName, parameterDescription, args);
|
||||
}
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
System.out.println("-------------------------");
|
||||
Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
@@ -64,7 +67,6 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
trace.recordServiceType(ServiceType.HTTP_CLIENT);
|
||||
|
||||
int port = host.getPort();
|
||||
// trace.recordEndPoint(host.getHostName() + ((port > 0) ? ":" + port : ""));
|
||||
trace.recordDestinationId(host.getHostName() + ((port > 0) ? ":" + port : ""));
|
||||
|
||||
trace.recordAttribute(AnnotationKey.HTTP_URL, request.getRequestLine().getUri());
|
||||
@@ -77,7 +79,6 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
LoggingUtils.logAfter(logger, target, className, methodName, parameterDescription, args);
|
||||
}
|
||||
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
@@ -93,8 +94,11 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTraceContext(TraceContext traceContext) {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
}
|
||||
+13
-9
@@ -1,7 +1,7 @@
|
||||
package com.profiler.modifier.connector.jdkhttpconnector.interceptor;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.logging.Logger;
|
||||
import com.profiler.logging.Logger;
|
||||
|
||||
import com.profiler.common.AnnotationKey;
|
||||
import com.profiler.common.ServiceType;
|
||||
@@ -9,25 +9,27 @@ import com.profiler.context.*;
|
||||
import com.profiler.interceptor.ByteCodeMethodDescriptorSupport;
|
||||
import com.profiler.interceptor.MethodDescriptor;
|
||||
import com.profiler.interceptor.StaticAroundInterceptor;
|
||||
import com.profiler.interceptor.TraceContextSupport;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
import com.profiler.logging.LoggingUtils;
|
||||
|
||||
/**
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public class ConnectMethodInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport {
|
||||
public class ConnectMethodInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
|
||||
|
||||
private final Logger logger = Logger.getLogger(ConnectMethodInterceptor.class.getName());
|
||||
private final boolean isDebug = LoggingUtils.isDebug(logger);
|
||||
private final Logger logger = LoggerFactory.getLogger(ConnectMethodInterceptor.class.getName());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MethodDescriptor descriptor;
|
||||
private TraceContext traceContext;
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
if (isDebug) {
|
||||
LoggingUtils.logBefore(logger, target, className, methodName, parameterDescription, args);
|
||||
}
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
@@ -55,7 +57,6 @@ public class ConnectMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
int port = request.getURL().getPort();
|
||||
|
||||
// TODO protocol은 어떻게 표기하지???
|
||||
// trace.recordEndPoint(host + ((port > 0) ? ":" + port : ""));
|
||||
trace.recordDestinationId(host + ((port > 0) ? ":" + port : ""));
|
||||
|
||||
trace.recordAttribute(AnnotationKey.HTTP_URL, request.getURL().toString());
|
||||
@@ -68,7 +69,6 @@ public class ConnectMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
LoggingUtils.logAfter(logger, target, className, methodName, parameterDescription, args);
|
||||
}
|
||||
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
@@ -83,7 +83,11 @@ public class ConnectMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTraceContext(TraceContext traceContext) {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
package com.profiler.modifier.db.interceptor;
|
||||
|
||||
import com.profiler.interceptor.StaticBeforeInterceptor;
|
||||
import com.profiler.interceptor.util.JDBCScope;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
import com.profiler.logging.LoggingUtils;
|
||||
import com.profiler.util.MetaObject;
|
||||
import com.profiler.util.StringUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Logger;
|
||||
import com.profiler.logging.Logger;
|
||||
|
||||
public class ConnectionCloseInterceptor implements StaticBeforeInterceptor {
|
||||
|
||||
private final Logger logger = Logger.getLogger(ConnectionCloseInterceptor.class.getName());
|
||||
private final boolean isDebug = LoggingUtils.isDebug(logger);
|
||||
private final Logger logger = LoggerFactory.getLogger(ConnectionCloseInterceptor.class.getName());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private static final Object[] EMPTY = new Object[]{null};
|
||||
|
||||
|
||||
+4
-5
@@ -1,21 +1,20 @@
|
||||
package com.profiler.modifier.db.interceptor;
|
||||
|
||||
import com.profiler.interceptor.StaticAroundInterceptor;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
import com.profiler.logging.LoggingUtils;
|
||||
import com.profiler.util.InterceptorUtils;
|
||||
import com.profiler.util.StringUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Logger;
|
||||
import com.profiler.logging.Logger;
|
||||
|
||||
/**
|
||||
* Datasource의 get을 추적해야 될것으로 예상됨.
|
||||
*/
|
||||
public class DataSourceGetConnectionInterceptor implements StaticAroundInterceptor {
|
||||
|
||||
private final Logger logger = Logger.getLogger(DataSourceGetConnectionInterceptor.class.getName());
|
||||
private final boolean isDebug = LoggingUtils.isDebug(logger);
|
||||
private final Logger logger = LoggerFactory.getLogger(DataSourceGetConnectionInterceptor.class.getName());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
|
||||
@@ -3,7 +3,8 @@ package com.profiler.modifier.servlet.interceptors;
|
||||
import java.util.Enumeration;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import com.profiler.logging.Logger;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -19,8 +20,8 @@ import com.profiler.util.NumberUtils;
|
||||
|
||||
public class DoXXXInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
|
||||
|
||||
private final Logger logger = Logger.getLogger(DoXXXInterceptor.class.getName());
|
||||
private final boolean isDebug = LoggingUtils.isDebug(logger);
|
||||
private final Logger logger = LoggerFactory.getLogger(DoXXXInterceptor.class.getName());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MethodDescriptor descriptor;
|
||||
private TraceContext traceContext;
|
||||
@@ -56,31 +57,26 @@ public class DoXXXInterceptor implements StaticAroundInterceptor, ByteCodeMethod
|
||||
}
|
||||
|
||||
try {
|
||||
traceContext.getActiveThreadCounter().start();
|
||||
// traceContext.getActiveThreadCounter().start();
|
||||
|
||||
HttpServletRequest request = (HttpServletRequest) args[0];
|
||||
String requestURL = request.getRequestURI();
|
||||
String clientIP = request.getRemoteAddr();
|
||||
|
||||
TraceID traceId = populateTraceIdFromRequest(request);
|
||||
DefaultTrace trace;
|
||||
Trace trace;
|
||||
if (traceId != null) {
|
||||
// TraceID nextTraceId = traceId.getNextTraceId();
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
// logger.info("TraceID exist. continue trace. " + nextTraceId);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("TraceID exist. continue trace. " + traceId);
|
||||
logger.log(Level.FINE, "requestUrl:" + requestURL + " clientIp" + clientIP);
|
||||
logger.debug("requestUrl:" + requestURL + " clientIp" + clientIP);
|
||||
}
|
||||
// trace = new Trace(nextTraceId);
|
||||
trace = new DefaultTrace(traceId);
|
||||
traceContext.attachTraceObject(trace);
|
||||
trace = traceContext.continueTraceObject(traceId);
|
||||
} else {
|
||||
trace = new DefaultTrace();
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
trace = traceContext.newTraceObject();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("TraceID not exist. start new trace. " + trace.getTraceId());
|
||||
logger.log(Level.FINE, "requestUrl:" + requestURL + " clientIp" + clientIP);
|
||||
logger.debug("requestUrl:" + requestURL + " clientIp" + clientIP);
|
||||
}
|
||||
traceContext.attachTraceObject(trace);
|
||||
}
|
||||
|
||||
trace.markBeforeTime();
|
||||
@@ -92,8 +88,8 @@ public class DoXXXInterceptor implements StaticAroundInterceptor, ByteCodeMethod
|
||||
trace.recordDestinationId(request.getServerName() + ((port > 0) ? ":" + port : ""));
|
||||
trace.recordAttribute(AnnotationKey.HTTP_URL, request.getRequestURI());
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, "Tomcat StandardHostValve trace start fail. Caused:" + e.getMessage(), e);
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Tomcat StandardHostValve trace start fail. Caused:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,7 +100,6 @@ public class DoXXXInterceptor implements StaticAroundInterceptor, ByteCodeMethod
|
||||
LoggingUtils.logAfter(logger, target, className, methodName, parameterDescription, args, result);
|
||||
}
|
||||
|
||||
traceContext.getActiveThreadCounter().end();
|
||||
Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
@@ -119,7 +114,7 @@ public class DoXXXInterceptor implements StaticAroundInterceptor, ByteCodeMethod
|
||||
|
||||
|
||||
if (trace.getStackFrameId() != 0) {
|
||||
logger.warning("Corrupted CallStack found. StackId not Root(0)");
|
||||
logger.warn("Corrupted CallStack found. StackId not Root(0)");
|
||||
// 문제 있는 callstack을 dump하면 도움이 될듯.
|
||||
}
|
||||
|
||||
@@ -147,8 +142,8 @@ public class DoXXXInterceptor implements StaticAroundInterceptor, ByteCodeMethod
|
||||
boolean sampled = Boolean.parseBoolean(request.getHeader(Header.HTTP_SAMPLED.toString()));
|
||||
short flags = NumberUtils.parseShort(request.getHeader(Header.HTTP_FLAGS.toString()), (short) 0);
|
||||
|
||||
TraceID id = new TraceID(uuid, parentSpanID, spanID, sampled, flags);
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
TraceID id = new DefaultTraceID(uuid, parentSpanID, spanID, sampled, flags);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("TraceID exist. continue trace. " + id);
|
||||
}
|
||||
return id;
|
||||
@@ -184,8 +179,7 @@ public class DoXXXInterceptor implements StaticAroundInterceptor, ByteCodeMethod
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
traceContext.cacheApi(descriptor);
|
||||
this.traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+21
-23
@@ -3,7 +3,8 @@ package com.profiler.modifier.tomcat.interceptors;
|
||||
import java.util.Enumeration;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import com.profiler.logging.Logger;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -20,8 +21,8 @@ import com.profiler.util.NumberUtils;
|
||||
|
||||
public class StandardHostValveInvokeInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
|
||||
|
||||
private final Logger logger = Logger.getLogger(StandardHostValveInvokeInterceptor.class.getName());
|
||||
private final boolean isDebug = LoggingUtils.isDebug(logger);
|
||||
private final Logger logger = LoggerFactory.getLogger(StandardHostValveInvokeInterceptor.class.getName());
|
||||
private final boolean isDebug = logger.isInfoEnabled();
|
||||
|
||||
private MethodDescriptor descriptor;
|
||||
// private int apiId;
|
||||
@@ -34,29 +35,27 @@ public class StandardHostValveInvokeInterceptor implements StaticAroundIntercept
|
||||
}
|
||||
|
||||
try {
|
||||
traceContext.getActiveThreadCounter().start();
|
||||
// traceContext.getActiveThreadCounter().start();
|
||||
|
||||
HttpServletRequest request = (HttpServletRequest) args[0];
|
||||
String requestURL = request.getRequestURI();
|
||||
String remoteAddr = request.getRemoteAddr();
|
||||
|
||||
TraceID traceId = populateTraceIdFromRequest(request);
|
||||
DefaultTrace trace;
|
||||
Trace trace;
|
||||
if (traceId != null) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("TraceID exist. continue trace. " + traceId);
|
||||
logger.log(Level.FINE, "requestUrl:" + requestURL + ", remoteAddr:" + remoteAddr);
|
||||
logger.debug("requestUrl:" + requestURL + ", remoteAddr:" + remoteAddr);
|
||||
}
|
||||
// trace = new Trace(nextTraceId);
|
||||
trace = new DefaultTrace(traceId);
|
||||
traceContext.attachTraceObject(trace);
|
||||
|
||||
trace = traceContext.continueTraceObject(traceId);
|
||||
} else {
|
||||
trace = new DefaultTrace();
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
trace = traceContext.newTraceObject();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("TraceID not exist. start new trace. " + trace.getTraceId());
|
||||
logger.log(Level.FINE, "requestUrl:" + requestURL + ", remoteAddr:" + remoteAddr);
|
||||
logger.debug("requestUrl:" + requestURL + ", remoteAddr:" + remoteAddr);
|
||||
}
|
||||
traceContext.attachTraceObject(trace);
|
||||
}
|
||||
|
||||
trace.markBeforeTime();
|
||||
@@ -80,8 +79,8 @@ public class StandardHostValveInvokeInterceptor implements StaticAroundIntercept
|
||||
// TODO 여기에서 client 정보를 수집할 수 있다.
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.log(Level.WARNING, "Tomcat StandardHostValve trace start fail. Caused:" + e.getMessage(), e);
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Tomcat StandardHostValve trace start fail. Caused:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,7 +91,7 @@ public class StandardHostValveInvokeInterceptor implements StaticAroundIntercept
|
||||
LoggingUtils.logAfter(logger, target, className, methodName, parameterDescription, args, result);
|
||||
}
|
||||
|
||||
traceContext.getActiveThreadCounter().end();
|
||||
// traceContext.getActiveThreadCounter().end();
|
||||
Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
@@ -107,7 +106,7 @@ public class StandardHostValveInvokeInterceptor implements StaticAroundIntercept
|
||||
|
||||
|
||||
if (trace.getStackFrameId() != 0) {
|
||||
logger.warning("Corrupted CallStack found. StackId not Root(0)");
|
||||
logger.warn("Corrupted CallStack found. StackId not Root(0)");
|
||||
// 문제 있는 callstack을 dump하면 도움이 될듯.
|
||||
}
|
||||
|
||||
@@ -126,7 +125,7 @@ public class StandardHostValveInvokeInterceptor implements StaticAroundIntercept
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private TraceID populateTraceIdFromRequest(HttpServletRequest request) {
|
||||
private DefaultTraceID populateTraceIdFromRequest(HttpServletRequest request) {
|
||||
String strUUID = request.getHeader(Header.HTTP_TRACE_ID.toString());
|
||||
if (strUUID != null) {
|
||||
UUID uuid = UUID.fromString(strUUID);
|
||||
@@ -135,8 +134,8 @@ public class StandardHostValveInvokeInterceptor implements StaticAroundIntercept
|
||||
boolean sampled = Boolean.parseBoolean(request.getHeader(Header.HTTP_SAMPLED.toString()));
|
||||
short flags = NumberUtils.parseShort(request.getHeader(Header.HTTP_FLAGS.toString()), (short) 0);
|
||||
|
||||
TraceID id = new TraceID(uuid, parentSpanID, spanID, sampled, flags);
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
DefaultTraceID id = new DefaultTraceID(uuid, parentSpanID, spanID, sampled, flags);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("TraceID exist. continue trace. " + id);
|
||||
}
|
||||
return id;
|
||||
@@ -184,8 +183,7 @@ public class StandardHostValveInvokeInterceptor implements StaticAroundIntercept
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
TraceContext traceContext = DefaultTraceContext.getTraceContext();
|
||||
traceContext.cacheApi(descriptor);
|
||||
this.traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,11 +4,10 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.profiler.Agent;
|
||||
import com.profiler.DefaultAgent;
|
||||
import com.profiler.common.dto.thrift.RequestDataListThriftDTO;
|
||||
import com.profiler.common.dto.thrift.RequestThriftDTO;
|
||||
import com.profiler.config.ProfilerConstant;
|
||||
import com.profiler.util.SystemUtils;
|
||||
|
||||
@Deprecated
|
||||
public class RequestTracer {
|
||||
@@ -29,7 +28,7 @@ public class RequestTracer {
|
||||
currentRequestHash.set(tempRequestHashCode);
|
||||
requestSet.add(tempRequestID);
|
||||
|
||||
RequestThriftDTO dto = new RequestThriftDTO(Agent.getInstance().getAgentId(), tempRequestHashCode, ProfilerConstant.DATA_TYPE_REQUEST, requestTime, cpuUserTime[0], cpuUserTime[1]);
|
||||
RequestThriftDTO dto = new RequestThriftDTO(DefaultAgent.getInstance().getAgentId(), tempRequestHashCode, ProfilerConstant.DATA_TYPE_REQUEST, requestTime, cpuUserTime[0], cpuUserTime[1]);
|
||||
dto.setClientIP(clientIP);
|
||||
dto.setRequestURL(requestURL);
|
||||
|
||||
@@ -48,7 +47,7 @@ public class RequestTracer {
|
||||
public static void endTransaction() {
|
||||
long cpuUserTime[] = null;
|
||||
// long cpuUserTime[] = SystemUtils.getThreadTime();
|
||||
RequestThriftDTO dto = new RequestThriftDTO(Agent.getInstance().getAgentId(), currentRequestHash.get(), ProfilerConstant.DATA_TYPE_RESPONSE, System.currentTimeMillis(), cpuUserTime[0], cpuUserTime[1]);
|
||||
RequestThriftDTO dto = new RequestThriftDTO(DefaultAgent.getInstance().getAgentId(), currentRequestHash.get(), ProfilerConstant.DATA_TYPE_RESPONSE, System.currentTimeMillis(), cpuUserTime[0], cpuUserTime[1]);
|
||||
|
||||
finishTransaction(dto);
|
||||
}
|
||||
@@ -61,7 +60,7 @@ public class RequestTracer {
|
||||
public static void exceptionTransaction(Throwable throwable) {
|
||||
// long cpuUserTime[] = SystemUtils.getThreadTime();
|
||||
long cpuUserTime[] = null;
|
||||
RequestThriftDTO dto = new RequestThriftDTO(Agent.getInstance().getAgentId(), currentRequestHash.get(), ProfilerConstant.DATA_TYPE_UNCAUGHT_EXCEPTION, System.currentTimeMillis(), cpuUserTime[0], cpuUserTime[1]);
|
||||
RequestThriftDTO dto = new RequestThriftDTO(DefaultAgent.getInstance().getAgentId(), currentRequestHash.get(), ProfilerConstant.DATA_TYPE_UNCAUGHT_EXCEPTION, System.currentTimeMillis(), cpuUserTime[0], cpuUserTime[1]);
|
||||
|
||||
dto.setExtraData1(throwable.getMessage());
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.profiler.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class ReflectionUtils {
|
||||
public static Field findField(Class targetClass, String fieldName) {
|
||||
Field[] declaredFields = targetClass.getDeclaredFields();
|
||||
for (Field f : declaredFields) {
|
||||
if (f.getName().equals(fieldName)) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user