mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-09 04:46:06 +10:00
#2524 Apply dependency injection framework to agent.
- apply google guice & refactoring
This commit is contained in:
+3
-2
@@ -25,6 +25,7 @@ import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanChunk;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanChunkFactory;
|
||||
@@ -141,7 +142,7 @@ public class SpanStreamUDPSenderTest {
|
||||
}
|
||||
|
||||
private Span createSpan(int spanEventSize) throws InterruptedException {
|
||||
AgentInformation agentInformation = new AgentInformation("agentId", "applicationName", 0, 0, "machineName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
AgentInformation agentInformation = new DefaultAgentInformation("agentId", "applicationName", 0, 0, "machineName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION), Version.VERSION);
|
||||
SpanChunkFactory spanChunkFactory = new SpanChunkFactory(agentInformation);
|
||||
|
||||
@@ -157,7 +158,7 @@ public class SpanStreamUDPSenderTest {
|
||||
}
|
||||
|
||||
private SpanChunk createSpanChunk(int spanEventSize) throws InterruptedException {
|
||||
AgentInformation agentInformation = new AgentInformation("agentId", "applicationName", 0, 0, "machineName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
AgentInformation agentInformation = new DefaultAgentInformation("agentId", "applicationName", 0, 0, "machineName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION), Version.VERSION);
|
||||
SpanChunkFactory spanChunkFactory = new SpanChunkFactory(agentInformation);
|
||||
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.test;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor;
|
||||
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class MockApiMetaDataService implements ApiMetaDataService {
|
||||
private static final Comparator<Map.Entry<Integer, MethodInfo>> COMPARATOR = new Comparator<Map.Entry<Integer, MethodInfo>>() {
|
||||
|
||||
@Override
|
||||
public int compare(Map.Entry<Integer, MethodInfo> o1, Map.Entry<Integer, MethodInfo> o2) {
|
||||
return o1.getKey() > o2.getKey() ? 1 : (o1.getKey() < o2.getKey() ? -1 : 0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private final BiMap<Integer, MethodInfo> apiIdMap = HashBiMap.create();
|
||||
|
||||
private static final int INITIAL_ID = 1;
|
||||
private int nextId = INITIAL_ID;
|
||||
|
||||
|
||||
public MockApiMetaDataService() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int cacheApi(MethodDescriptor methodDescriptor) {
|
||||
int apiId1 = methodDescriptor.getApiId();
|
||||
|
||||
final String apiDescriptor = MethodDescriptionUtils.toJavaMethodDescriptor(methodDescriptor.getApiDescriptor());
|
||||
MethodInfo methodInfo = new MethodInfo(apiDescriptor, methodDescriptor);
|
||||
synchronized (this.apiIdMap) {
|
||||
final MethodInfo exist = this.apiIdMap.get(methodInfo);
|
||||
if (exist != null) {
|
||||
return exist.getMethodDescriptor().getApiId();
|
||||
}
|
||||
|
||||
final int apiId = nextId();
|
||||
this.apiIdMap.put(apiId, methodInfo);
|
||||
return apiId;
|
||||
}
|
||||
}
|
||||
|
||||
private class MethodInfo {
|
||||
private final String apiDescriptor;
|
||||
private final MethodDescriptor methodDescriptor;
|
||||
|
||||
public MethodInfo(String apiDescriptor, MethodDescriptor methodDescriptor) {
|
||||
if (apiDescriptor == null) {
|
||||
throw new NullPointerException("apiDescriptor must not be null");
|
||||
}
|
||||
this.apiDescriptor = apiDescriptor;
|
||||
this.methodDescriptor = methodDescriptor;
|
||||
}
|
||||
|
||||
public String getApiDescriptor() {
|
||||
return apiDescriptor;
|
||||
}
|
||||
|
||||
public MethodDescriptor getMethodDescriptor() {
|
||||
return methodDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
MethodInfo that = (MethodInfo) o;
|
||||
|
||||
return apiDescriptor != null ? apiDescriptor.equals(that.apiDescriptor) : that.apiDescriptor == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return apiDescriptor != null ? apiDescriptor.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MethodInfo{" +
|
||||
"apiDescriptor='" + apiDescriptor + '\'' +
|
||||
", methodDescriptor=" + methodDescriptor +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
private int nextId() {
|
||||
synchronized (apiIdMap) {
|
||||
return nextId++;
|
||||
}
|
||||
}
|
||||
|
||||
public int getApiId(String methodDescriptor) {
|
||||
|
||||
MethodInfo key = new MethodInfo(methodDescriptor, null);
|
||||
synchronized (this.apiIdMap) {
|
||||
BiMap<MethodInfo, Integer> apiIdMap = this.apiIdMap.inverse();
|
||||
final Integer id = apiIdMap.get(key);
|
||||
if (id == null) {
|
||||
throw new NullPointerException("apiMetaDataNotFound " + key);
|
||||
}
|
||||
System.out.println("getApiId " + methodDescriptor + " id:" + id);
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
synchronized (apiIdMap) {
|
||||
this.apiIdMap.clear();
|
||||
nextId = INITIAL_ID;
|
||||
}
|
||||
}
|
||||
|
||||
public void print(PrintStream out) {
|
||||
out.println("API(" + apiIdMap.size() + "):");
|
||||
printApis(out);
|
||||
|
||||
}
|
||||
|
||||
public void printApis(PrintStream out) {
|
||||
synchronized (this.apiIdMap) {
|
||||
List<Map.Entry<Integer, MethodInfo>> apis = new ArrayList<Map.Entry<Integer, MethodInfo>>(apiIdMap.entrySet());
|
||||
printEntries(out, apis);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void printEntries(PrintStream out, List<Map.Entry<Integer, MethodInfo>> entries) {
|
||||
Collections.sort(entries, COMPARATOR);
|
||||
|
||||
for (Map.Entry<Integer, MethodInfo> e : entries) {
|
||||
MethodInfo methodInfo = e.getValue();
|
||||
out.println(e.getKey() + ": " + methodInfo.getApiDescriptor());
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-95
@@ -19,42 +19,24 @@ package com.navercorp.pinpoint.test;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.util.Modules;
|
||||
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplate;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplateAware;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.Provider;
|
||||
import com.navercorp.pinpoint.profiler.plugin.GuardProfilerPluginContext;
|
||||
import com.navercorp.pinpoint.profiler.receiver.CommandDispatcher;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClient;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClientFactory;
|
||||
import org.apache.thrift.TBase;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.AgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.DefaultAgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation;
|
||||
import com.navercorp.pinpoint.common.plugin.PluginLoader;
|
||||
import com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService;
|
||||
import com.navercorp.pinpoint.common.service.DefaultServiceTypeRegistryService;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanEvent;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.instrument.ClassInjector;
|
||||
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultProfilerPluginContext;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
|
||||
import com.navercorp.pinpoint.thrift.dto.TAnnotation;
|
||||
|
||||
/**
|
||||
@@ -68,7 +50,7 @@ public class MockApplicationContext extends DefaultApplicationContext {
|
||||
public static MockApplicationContext of(String configPath) {
|
||||
ProfilerConfig profilerConfig = null;
|
||||
try {
|
||||
URL resource = MockApplicationContext.class.getClassLoader().getResource(configPath);
|
||||
final URL resource = MockApplicationContext.class.getClassLoader().getResource(configPath);
|
||||
if (resource == null) {
|
||||
throw new FileNotFoundException("pinpoint.config not found. configPath:" + configPath);
|
||||
}
|
||||
@@ -83,85 +65,28 @@ public class MockApplicationContext extends DefaultApplicationContext {
|
||||
public static MockApplicationContext of(ProfilerConfig config) {
|
||||
AgentOption agentOption = new DefaultAgentOption(new DummyInstrumentation(), "mockAgent", "mockApplicationName", config, new URL[0], null, new DefaultServiceTypeRegistryService(), new DefaultAnnotationKeyRegistryService());
|
||||
InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder();
|
||||
binder.bind();
|
||||
|
||||
|
||||
return new MockApplicationContext(agentOption, binder);
|
||||
}
|
||||
|
||||
|
||||
public MockApplicationContext(AgentOption agentOption, InterceptorRegistryBinder binder) {
|
||||
super(agentOption, binder);
|
||||
this.interceptorRegistryBinder = binder;
|
||||
binder.bind();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Provider<DataSender> newUdpStatDataSenderProvider() {
|
||||
protected Module newApplicationContextModule(AgentOption agentOption, InterceptorRegistryBinder interceptorRegistryBinder) {
|
||||
Module applicationContextModule = super.newApplicationContextModule(agentOption, interceptorRegistryBinder);
|
||||
MockApplicationContextModule mockApplicationContextModule = new MockApplicationContextModule();
|
||||
|
||||
DataSender dataSender = new ListenableDataSender<TBase<?, ?>>("StatDataSender");
|
||||
return new DelegateProvider<DataSender>(dataSender);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Provider<DataSender> newUdpSpanDataSenderProvider() {
|
||||
DataSender dataSender = new ListenableDataSender<TBase<?, ?>>("SpanDataSender");
|
||||
return new DelegateProvider<DataSender>(dataSender);
|
||||
return Modules.override(applicationContextModule).with(mockApplicationContextModule);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Provider<StorageFactory> newStorageFactoryProvider(ProfilerConfig profilerConfig, DataSender spanDataSender, AgentInformation agentInformation) {
|
||||
StorageFactory storageFactory = new SimpleSpanStorageFactory(spanDataSender);
|
||||
return new DelegateProvider<StorageFactory>(storageFactory);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Provider<PinpointClientFactory> newPinpointClientFactoryProvider(ProfilerConfig profilerConfig, AgentInformation agentInformation, CommandDispatcher commandDispatcher) {
|
||||
return new NullProvider<PinpointClientFactory>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Provider<PinpointClient> newPinpointClientProvider(ProfilerConfig profilerConfig, PinpointClientFactory clientFactory) {
|
||||
return new NullProvider<PinpointClient>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Provider<EnhancedDataSender> newTcpDataSenderProvider(PinpointClient client) {
|
||||
EnhancedDataSender enhancedDataSender = new TestTcpDataSender();
|
||||
return new DelegateProvider<EnhancedDataSender>(enhancedDataSender);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Provider<ServerMetaDataHolder> newServerMetaDataHolderProvider() {
|
||||
List<String> vmArgs = RuntimeMXBeanUtils.getVmArgs();
|
||||
ServerMetaDataHolder serverMetaDataHolder = new ResettableServerMetaDataHolder(vmArgs);
|
||||
return new DelegateProvider<ServerMetaDataHolder>(serverMetaDataHolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DefaultProfilerPluginContext> loadPlugins(AgentOption agentOption) {
|
||||
List<DefaultProfilerPluginContext> pluginContexts = new ArrayList<DefaultProfilerPluginContext>();
|
||||
ClassInjector classInjector = new TestProfilerPluginClassLoader();
|
||||
|
||||
List<ProfilerPlugin> plugins = PluginLoader.load(ProfilerPlugin.class, ClassLoader.getSystemClassLoader());
|
||||
|
||||
for (ProfilerPlugin plugin : plugins) {
|
||||
final DefaultProfilerPluginContext context = new DefaultProfilerPluginContext(this, classInjector);
|
||||
final GuardProfilerPluginContext guard = new GuardProfilerPluginContext(context);
|
||||
try {
|
||||
preparePlugin(plugin, context);
|
||||
plugin.setup(guard);
|
||||
} finally {
|
||||
guard.close();
|
||||
}
|
||||
pluginContexts.add(context);
|
||||
}
|
||||
|
||||
|
||||
return pluginContexts;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
@@ -171,18 +96,7 @@ public class MockApplicationContext extends DefaultApplicationContext {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicated code : com/navercorp/pinpoint/profiler/plugin/ProfilerPluginLoader.java
|
||||
* @param plugin
|
||||
* @param context
|
||||
*/
|
||||
private void preparePlugin(ProfilerPlugin plugin, InstrumentContext context) {
|
||||
|
||||
if (plugin instanceof TransformTemplateAware) {
|
||||
final TransformTemplate transformTemplate = new TransformTemplate(context);
|
||||
((TransformTemplateAware) plugin).setTransformTemplate(transformTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String toString(Span span) {
|
||||
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.test;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Scopes;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.profiler.context.module.SpanDataSender;
|
||||
import com.navercorp.pinpoint.profiler.context.module.StatDataSender;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginContextLoadResult;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginSetup;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClient;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClientFactory;
|
||||
import com.navercorp.pinpoint.test.provder.NullPinpointClientFactoryProvider;
|
||||
import com.navercorp.pinpoint.test.provder.NullPinpointClientProvider;
|
||||
import org.apache.thrift.TBase;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class MockApplicationContextModule extends AbstractModule {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public MockApplicationContextModule() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
||||
final DataSender spanDataSender = newUdpSpanDataSender();
|
||||
logger.debug("spanDataSender:{}", spanDataSender);
|
||||
bind(DataSender.class).annotatedWith(SpanDataSender.class).toInstance(spanDataSender);
|
||||
|
||||
final DataSender statDataSender = newUdpStatDataSender();
|
||||
logger.debug("statDataSender:{}", statDataSender);
|
||||
bind(DataSender.class).annotatedWith(StatDataSender.class).toInstance(statDataSender);
|
||||
|
||||
StorageFactory storageFactory = newStorageFactory(spanDataSender);
|
||||
logger.debug("spanFactory:{}", spanDataSender);
|
||||
bind(StorageFactory.class).toInstance(storageFactory);
|
||||
|
||||
bind(PinpointClientFactory.class).toProvider(NullPinpointClientFactoryProvider.class);
|
||||
bind(PinpointClient.class).toProvider(NullPinpointClientProvider.class);
|
||||
|
||||
EnhancedDataSender enhancedDataSender = newTcpDataSender();
|
||||
logger.debug("enhancedDataSender:{}", enhancedDataSender);
|
||||
bind(EnhancedDataSender.class).toInstance(enhancedDataSender);
|
||||
|
||||
ServerMetaDataHolder serverMetaDataHolder = newServerMetaDataHolder();
|
||||
logger.debug("serverMetaDataHolder:{}", serverMetaDataHolder);
|
||||
bind(ServerMetaDataHolder.class).toInstance(serverMetaDataHolder);
|
||||
|
||||
|
||||
bind(PluginSetup.class).to(MockPluginSetup.class).in(Scopes.SINGLETON);
|
||||
bind(PluginContextLoadResult.class).toProvider(MockPluginContextLoadResult.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
|
||||
protected DataSender newUdpStatDataSender() {
|
||||
DataSender dataSender = new ListenableDataSender<TBase<?, ?>>("StatDataSender");
|
||||
return dataSender;
|
||||
}
|
||||
|
||||
|
||||
protected DataSender newUdpSpanDataSender() {
|
||||
DataSender dataSender = new ListenableDataSender<TBase<?, ?>>("SpanDataSender");
|
||||
return dataSender;
|
||||
}
|
||||
|
||||
protected EnhancedDataSender newTcpDataSender() {
|
||||
return new TestTcpDataSender();
|
||||
}
|
||||
|
||||
protected StorageFactory newStorageFactory(DataSender spanDataSender) {
|
||||
logger.debug("newStorageFactory dataSender:{}", spanDataSender);
|
||||
StorageFactory storageFactory = new SimpleSpanStorageFactory(spanDataSender);
|
||||
return storageFactory;
|
||||
}
|
||||
|
||||
protected ServerMetaDataHolder newServerMetaDataHolder() {
|
||||
List<String> vmArgs = RuntimeMXBeanUtils.getVmArgs();
|
||||
ServerMetaDataHolder serverMetaDataHolder = new ResettableServerMetaDataHolder(vmArgs);
|
||||
return serverMetaDataHolder;
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.test;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
|
||||
import com.navercorp.pinpoint.common.plugin.PluginLoader;
|
||||
import com.navercorp.pinpoint.profiler.instrument.ClassInjector;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultPluginContextLoadResult;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultProfilerPluginContext;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginContextLoadResult;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginSetup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class MockPluginContextLoadResult implements Provider<PluginContextLoadResult> {
|
||||
|
||||
|
||||
private PluginSetup pluginSetup;
|
||||
|
||||
@Inject
|
||||
public MockPluginContextLoadResult(PluginSetup pluginSetup) {
|
||||
|
||||
this.pluginSetup = pluginSetup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginContextLoadResult get() {
|
||||
List<DefaultProfilerPluginContext> pluginContexts = new ArrayList<DefaultProfilerPluginContext>();
|
||||
ClassInjector classInjector = new TestProfilerPluginClassLoader();
|
||||
|
||||
List<ProfilerPlugin> plugins = PluginLoader.load(ProfilerPlugin.class, ClassLoader.getSystemClassLoader());
|
||||
|
||||
for (ProfilerPlugin plugin : plugins) {
|
||||
DefaultProfilerPluginContext context = pluginSetup.setupPlugin(plugin, classInjector);
|
||||
pluginContexts.add(context);
|
||||
}
|
||||
|
||||
|
||||
return new DefaultPluginContextLoadResult(pluginContexts);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.test;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplate;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplateAware;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.instrument.ClassInjector;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultProfilerPluginContext;
|
||||
import com.navercorp.pinpoint.profiler.plugin.GuardProfilerPluginContext;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginSetup;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class MockPluginSetup implements PluginSetup {
|
||||
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
@Inject
|
||||
public MockPluginSetup(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultProfilerPluginContext setupPlugin(ProfilerPlugin plugin, ClassInjector classInjector) {
|
||||
final DefaultProfilerPluginContext context = new DefaultProfilerPluginContext(applicationContext, classInjector);
|
||||
|
||||
final GuardProfilerPluginContext guard = new GuardProfilerPluginContext(context);
|
||||
try {
|
||||
preparePlugin(plugin, context);
|
||||
plugin.setup(guard);
|
||||
} finally {
|
||||
guard.close();
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicated code : com/navercorp/pinpoint/profiler/plugin/ProfilerPluginLoader.java
|
||||
* @param plugin
|
||||
* @param context
|
||||
*/
|
||||
private void preparePlugin(ProfilerPlugin plugin, InstrumentContext context) {
|
||||
|
||||
if (plugin instanceof TransformTemplateAware) {
|
||||
final TransformTemplate transformTemplate = new TransformTemplate(context);
|
||||
((TransformTemplateAware) plugin).setTransformTemplate(transformTemplate);
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-5
@@ -21,19 +21,23 @@ import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.bootstrap.sampler.Sampler;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.AtomicIdGenerator;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultTraceContext;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultTraceFactoryBuilder;
|
||||
import com.navercorp.pinpoint.profiler.context.IdGenerator;
|
||||
import com.navercorp.pinpoint.profiler.context.PluginMonitorContextBuilder;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.DefaultPluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.context.TraceFactoryBuilder;
|
||||
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.PluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.LogStorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataCacheService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.SqlMetaDataCacheService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.SqlMetaDataService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.StringMetaDataCacheService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.StringMetaDataService;
|
||||
import com.navercorp.pinpoint.profiler.sampler.SamplerFactory;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.profiler.sender.LoggingDataSender;
|
||||
@@ -52,7 +56,7 @@ public class MockTraceContextFactory {
|
||||
|
||||
private final StorageFactory storageFactory;
|
||||
|
||||
private final IdGenerator idGenerator;
|
||||
private final AtomicIdGenerator idGenerator;
|
||||
private final Sampler sampler;
|
||||
private final ActiveTraceRepository activeTraceRepository;
|
||||
|
||||
@@ -89,12 +93,11 @@ public class MockTraceContextFactory {
|
||||
final SamplerFactory samplerFactory = new SamplerFactory();
|
||||
this.sampler = createSampler(profilerConfig, samplerFactory);
|
||||
|
||||
this.idGenerator = new IdGenerator();
|
||||
this.idGenerator = new AtomicIdGenerator();
|
||||
this.activeTraceRepository = newActiveTraceRepository();
|
||||
|
||||
final TraceFactoryBuilder traceFactoryBuilder = new DefaultTraceFactoryBuilder(storageFactory, sampler, idGenerator, activeTraceRepository);
|
||||
final PluginMonitorContextBuilder pluginMonitorContextBuilder = new PluginMonitorContextBuilder(TRACE_DATASOURCE);
|
||||
this.pluginMonitorContext = pluginMonitorContextBuilder.build();
|
||||
this.pluginMonitorContext = new DefaultPluginMonitorContext();
|
||||
|
||||
this.serverMetaDataHolder = new DefaultServerMetaDataHolder(RuntimeMXBeanUtils.getVmArgs());
|
||||
|
||||
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.test;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.profiler.context.module.SpanDataSender;
|
||||
import com.navercorp.pinpoint.profiler.context.module.StatDataSender;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClient;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClientFactory;
|
||||
import com.navercorp.pinpoint.test.provder.NullPinpointClientFactoryProvider;
|
||||
import com.navercorp.pinpoint.test.provder.NullPinpointClientProvider;
|
||||
import org.apache.thrift.TBase;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class PluginApplicationContextModule extends AbstractModule {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private TestableServerMetaDataListener serverMetaDataListener;
|
||||
private TestTcpDataSender tcpDataSender;
|
||||
private OrderedSpanRecorder orderedSpanRecorder;
|
||||
private ServerMetaDataHolder serverMetaDataHolder;
|
||||
|
||||
public PluginApplicationContextModule() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
||||
final DataSender spanDataSender = newUdpSpanDataSender();
|
||||
logger.debug("spanDataSender:{}", spanDataSender);
|
||||
bind(DataSender.class).annotatedWith(SpanDataSender.class).toInstance(spanDataSender);
|
||||
|
||||
final DataSender statDataSender = newUdpStatDataSender();
|
||||
logger.debug("statDataSender:{}", statDataSender);
|
||||
bind(DataSender.class).annotatedWith(StatDataSender.class).toInstance(statDataSender);
|
||||
|
||||
StorageFactory storageFactory = newStorageFactory(spanDataSender);
|
||||
logger.debug("spanFactory:{}", spanDataSender);
|
||||
bind(StorageFactory.class).toInstance(storageFactory);
|
||||
|
||||
bind(PinpointClientFactory.class).toProvider(NullPinpointClientFactoryProvider.class);
|
||||
bind(PinpointClient.class).toProvider(NullPinpointClientProvider.class);
|
||||
|
||||
EnhancedDataSender enhancedDataSender = newTcpDataSender();
|
||||
logger.debug("enhancedDataSender:{}", enhancedDataSender);
|
||||
bind(EnhancedDataSender.class).toInstance(enhancedDataSender);
|
||||
|
||||
ServerMetaDataHolder serverMetaDataHolder = newServerMetaDataHolder();
|
||||
logger.debug("serverMetaDataHolder:{}", serverMetaDataHolder);
|
||||
bind(ServerMetaDataHolder.class).toInstance(serverMetaDataHolder);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private DataSender newUdpStatDataSender() {
|
||||
return new ListenableDataSender<TBase<?, ?>>("StatDataSender");
|
||||
}
|
||||
|
||||
private DataSender newUdpSpanDataSender() {
|
||||
|
||||
ListenableDataSender<TBase<?, ?>> sender = new ListenableDataSender<TBase<?, ?>>("SpanDataSender");
|
||||
OrderedSpanRecorder orderedSpanRecorder = new OrderedSpanRecorder();
|
||||
sender.setListener(orderedSpanRecorder);
|
||||
this.orderedSpanRecorder = orderedSpanRecorder;
|
||||
return sender;
|
||||
}
|
||||
|
||||
protected EnhancedDataSender newTcpDataSender() {
|
||||
TestTcpDataSender tcpDataSender = new TestTcpDataSender();
|
||||
this.tcpDataSender = tcpDataSender;
|
||||
return tcpDataSender;
|
||||
}
|
||||
|
||||
|
||||
private ServerMetaDataHolder newServerMetaDataHolder() {
|
||||
List<String> vmArgs = RuntimeMXBeanUtils.getVmArgs();
|
||||
ServerMetaDataHolder serverMetaDataHolder = new ResettableServerMetaDataHolder(vmArgs);
|
||||
this.serverMetaDataListener = new TestableServerMetaDataListener();
|
||||
this.serverMetaDataHolder = serverMetaDataHolder;
|
||||
serverMetaDataHolder.addListener(this.serverMetaDataListener);
|
||||
return serverMetaDataHolder;
|
||||
}
|
||||
|
||||
protected StorageFactory newStorageFactory(DataSender spanDataSender) {
|
||||
logger.debug("newStorageFactory dataSender:{}", spanDataSender);
|
||||
StorageFactory storageFactory = new SimpleSpanStorageFactory(spanDataSender);
|
||||
return storageFactory;
|
||||
}
|
||||
|
||||
public TestableServerMetaDataListener getServerMetaDataListener() {
|
||||
return serverMetaDataListener;
|
||||
}
|
||||
|
||||
public TestTcpDataSender getTcpDataSender() {
|
||||
return tcpDataSender;
|
||||
}
|
||||
|
||||
public OrderedSpanRecorder getOrderedSpanRecorder() {
|
||||
return orderedSpanRecorder;
|
||||
}
|
||||
}
|
||||
@@ -27,21 +27,16 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.util.Modules;
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.common.util.AnnotationKeyUtils;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.Provider;
|
||||
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClient;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClientFactory;
|
||||
import org.apache.thrift.TBase;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.navercorp.pinpoint.bootstrap.AgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServiceInfo;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.test.Expectations;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation;
|
||||
@@ -57,12 +52,8 @@ import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgent;
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanEvent;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.interceptor.registry.DefaultInterceptorRegistryBinder;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.profiler.util.JavaAssistUtils;
|
||||
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
|
||||
import com.navercorp.pinpoint.thrift.dto.TAnnotation;
|
||||
import com.navercorp.pinpoint.thrift.dto.TIntStringStringValue;
|
||||
import com.navercorp.pinpoint.thrift.dto.TSpan;
|
||||
@@ -76,13 +67,12 @@ import com.navercorp.pinpoint.thrift.dto.TSpanEvent;
|
||||
*/
|
||||
public class PluginTestAgent extends DefaultAgent implements PluginTestVerifier {
|
||||
|
||||
private TestableServerMetaDataListener serverMetaDataListener;
|
||||
|
||||
private AnnotationKeyRegistryService annotationKeyRegistryService;
|
||||
|
||||
private final List<Short> ignoredServiceTypes = new ArrayList<Short>();
|
||||
|
||||
private TestTcpDataSender tcpDataSender;
|
||||
private OrderedSpanRecorder orderedSpanRecorder;
|
||||
private PluginApplicationContextModule pluginApplicationContextModule;
|
||||
|
||||
|
||||
public PluginTestAgent(AgentOption agentOption) {
|
||||
@@ -93,50 +83,17 @@ public class PluginTestAgent extends DefaultAgent implements PluginTestVerifier
|
||||
|
||||
@Override
|
||||
protected ApplicationContext newApplicationContext(AgentOption agentOption, InterceptorRegistryBinder interceptorRegistryBinder) {
|
||||
final DataSender spanDataSender = createUdpSpanDataSender();
|
||||
|
||||
final DataSender statDataSender = createUdpStatDataSender();
|
||||
final ServerMetaDataHolder serverMetaDataHolder = createServerMetaDataHolder();
|
||||
final EnhancedDataSender tcpDataSender = createTcpDataSender();
|
||||
this.pluginApplicationContextModule = new PluginApplicationContextModule();
|
||||
|
||||
ApplicationContext applicationContext = new DefaultApplicationContext(agentOption, interceptorRegistryBinder) {
|
||||
@Override
|
||||
protected Provider<DataSender> newUdpSpanDataSenderProvider() {
|
||||
return new DelegateProvider<DataSender>(spanDataSender);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Provider<DataSender> newUdpStatDataSenderProvider() {
|
||||
return new DelegateProvider<DataSender>(statDataSender);
|
||||
}
|
||||
protected Module newApplicationContextModule(AgentOption agentOption, InterceptorRegistryBinder interceptorRegistryBinder) {
|
||||
Module applicationContextModule = super.newApplicationContextModule(agentOption, interceptorRegistryBinder);
|
||||
|
||||
@Override
|
||||
protected Provider<StorageFactory> newStorageFactoryProvider(ProfilerConfig profilerConfig, DataSender spanDataSender, AgentInformation agentInformation) {
|
||||
System.out.println("spanDataSender:" + spanDataSender);
|
||||
StorageFactory storageFactory = new SimpleSpanStorageFactory(spanDataSender);
|
||||
return new DelegateProvider<StorageFactory>(storageFactory);
|
||||
return Modules.override(applicationContextModule).with(pluginApplicationContextModule);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Provider<ServerMetaDataHolder> newServerMetaDataHolderProvider() {
|
||||
return new DelegateProvider<ServerMetaDataHolder>(serverMetaDataHolder);
|
||||
}
|
||||
|
||||
// skip tcp connection
|
||||
public Provider<PinpointClientFactory> newPinpointClientFactoryProvider() {
|
||||
return new NullProvider<PinpointClientFactory>();
|
||||
}
|
||||
|
||||
// skip tcp connection
|
||||
public Provider<PinpointClient> newPinpointClientProvider(ProfilerConfig profilerConfig, PinpointClientFactory clientFactory) {
|
||||
return new NullProvider<PinpointClient>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Provider<EnhancedDataSender> newTcpDataSenderProvider(PinpointClient client) {
|
||||
return new DelegateProvider<EnhancedDataSender>(tcpDataSender);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -144,38 +101,6 @@ public class PluginTestAgent extends DefaultAgent implements PluginTestVerifier
|
||||
|
||||
}
|
||||
|
||||
private DataSender createUdpStatDataSender() {
|
||||
return new ListenableDataSender<TBase<?, ?>>("StatDataSender");
|
||||
}
|
||||
|
||||
private DataSender createUdpSpanDataSender() {
|
||||
|
||||
ListenableDataSender<TBase<?, ?>> sender = new ListenableDataSender<TBase<?, ?>>("SpanDataSender");
|
||||
OrderedSpanRecorder orderedSpanRecorder = new OrderedSpanRecorder();
|
||||
sender.setListener(orderedSpanRecorder);
|
||||
this.orderedSpanRecorder = orderedSpanRecorder;
|
||||
return sender;
|
||||
}
|
||||
|
||||
private StorageFactory createStorageFactory(DataSender dataSender) {
|
||||
return new SimpleSpanStorageFactory(dataSender);
|
||||
}
|
||||
|
||||
protected EnhancedDataSender createTcpDataSender() {
|
||||
TestTcpDataSender tcpDataSender = new TestTcpDataSender();
|
||||
this.tcpDataSender = tcpDataSender;
|
||||
return tcpDataSender;
|
||||
}
|
||||
|
||||
|
||||
private ServerMetaDataHolder createServerMetaDataHolder() {
|
||||
List<String> vmArgs = RuntimeMXBeanUtils.getVmArgs();
|
||||
ServerMetaDataHolder serverMetaDataHolder = new ResettableServerMetaDataHolder(vmArgs);
|
||||
this.serverMetaDataListener = new TestableServerMetaDataListener();
|
||||
serverMetaDataHolder.addListener(this.serverMetaDataListener);
|
||||
return serverMetaDataHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void verifyServerType(String serviceTypeName) {
|
||||
final ApplicationContext applicationContext = getApplicationContext();
|
||||
@@ -190,7 +115,7 @@ public class PluginTestAgent extends DefaultAgent implements PluginTestVerifier
|
||||
|
||||
@Override
|
||||
public void verifyServerInfo(String expected) {
|
||||
String actualName = this.serverMetaDataListener.getServerMetaData().getServerInfo();
|
||||
String actualName = this.pluginApplicationContextModule.getServerMetaDataListener().getServerMetaData().getServerInfo();
|
||||
|
||||
if (!actualName.equals(expected)) {
|
||||
throw new AssertionError("ResolvedExpectedTrace server name [" + expected + "] but was [" + actualName + "]");
|
||||
@@ -199,7 +124,7 @@ public class PluginTestAgent extends DefaultAgent implements PluginTestVerifier
|
||||
|
||||
@Override
|
||||
public void verifyConnector(String protocol, int port) {
|
||||
Map<Integer, String> connectorMap = this.serverMetaDataListener.getServerMetaData().getConnectors();
|
||||
Map<Integer, String> connectorMap = this.pluginApplicationContextModule.getServerMetaDataListener().getServerMetaData().getConnectors();
|
||||
String actualProtocol = connectorMap.get(port);
|
||||
|
||||
if (actualProtocol == null || !actualProtocol.equals(protocol)) {
|
||||
@@ -209,7 +134,7 @@ public class PluginTestAgent extends DefaultAgent implements PluginTestVerifier
|
||||
|
||||
@Override
|
||||
public void verifyService(String name, List<String> libs) {
|
||||
List<ServiceInfo> serviceInfos = this.serverMetaDataListener.getServerMetaData().getServiceInfos();
|
||||
List<ServiceInfo> serviceInfos = this.pluginApplicationContextModule.getServerMetaDataListener().getServerMetaData().getServiceInfos();
|
||||
|
||||
for (ServiceInfo serviceInfo : serviceInfos) {
|
||||
if (serviceInfo.getServiceName().equals(name)) {
|
||||
@@ -785,11 +710,11 @@ public class PluginTestAgent extends DefaultAgent implements PluginTestVerifier
|
||||
}
|
||||
|
||||
private TestTcpDataSender getTestTcpDataSender() {
|
||||
return tcpDataSender;
|
||||
return this.pluginApplicationContextModule.getTcpDataSender();
|
||||
}
|
||||
|
||||
private OrderedSpanRecorder getRecorder() {
|
||||
return this.orderedSpanRecorder;
|
||||
return this.pluginApplicationContextModule.getOrderedSpanRecorder();
|
||||
}
|
||||
|
||||
private Object popSpan() {
|
||||
|
||||
@@ -20,12 +20,12 @@ import com.navercorp.pinpoint.common.Version;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgentInformation;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
*/
|
||||
public class TestAgentInformation extends AgentInformation {
|
||||
public class TestAgentInformation extends DefaultAgentInformation {
|
||||
|
||||
private static final String AGENT_ID = "test-agent";
|
||||
private static final String APPLICATION_NAME = "TEST_APPLICATION";
|
||||
|
||||
+1
@@ -21,6 +21,7 @@ import com.navercorp.pinpoint.bootstrap.instrument.matcher.ClassNameMatcher;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.matcher.Matcher;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.matcher.MultiClassNameMatcher;
|
||||
import com.navercorp.pinpoint.profiler.ClassFileTransformerDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.DefaultClassFileTransformerDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.plugin.xml.transformer.MatchableClassFileTransformer;
|
||||
import com.navercorp.pinpoint.profiler.util.JavaAssistUtils;
|
||||
import com.navercorp.pinpoint.test.util.BytecodeUtils;
|
||||
|
||||
+2
-1
@@ -24,6 +24,8 @@ import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.ClassFileTransformerDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.DefaultClassFileTransformerDispatcher;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
|
||||
@@ -33,7 +35,6 @@ import org.slf4j.LoggerFactory;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.matcher.ClassNameMatcher;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.matcher.Matcher;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.matcher.MultiClassNameMatcher;
|
||||
import com.navercorp.pinpoint.profiler.ClassFileTransformerDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.plugin.xml.transformer.MatchableClassFileTransformer;
|
||||
import com.navercorp.pinpoint.profiler.util.JavaAssistUtils;
|
||||
|
||||
|
||||
+4
-2
@@ -27,6 +27,7 @@ import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.instrument.ASMClassPool;
|
||||
import com.navercorp.pinpoint.profiler.instrument.JavassistClassPool;
|
||||
import com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformerGuardDelegate;
|
||||
import com.navercorp.pinpoint.test.MockApplicationContext;
|
||||
import javassist.ClassPool;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
@@ -45,15 +46,16 @@ public class TestClassLoader extends TransformClassLoader {
|
||||
|
||||
private final Logger logger = Logger.getLogger(TestClassLoader.class.getName());
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
private final MockApplicationContext applicationContext;
|
||||
private Translator instrumentTranslator;
|
||||
private final DefaultProfilerPluginContext context;
|
||||
private final List<String> delegateClass;
|
||||
|
||||
public TestClassLoader(ApplicationContext applicationContext) {
|
||||
public TestClassLoader(MockApplicationContext applicationContext) {
|
||||
Asserts.notNull(applicationContext, "applicationContext");
|
||||
|
||||
this.applicationContext = applicationContext;
|
||||
|
||||
this.context = new DefaultProfilerPluginContext(applicationContext, new LegacyProfilerPluginClassInjector(getClass().getClassLoader()));
|
||||
|
||||
this.delegateClass = new ArrayList<String>();
|
||||
|
||||
+2
-1
@@ -18,6 +18,7 @@
|
||||
package com.navercorp.pinpoint.test.classloader;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import com.navercorp.pinpoint.test.MockApplicationContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -36,7 +37,7 @@ public class TestClassLoaderFactory {
|
||||
|
||||
private static final String ATLASSIAN_CLOVER = "com_atlassian_clover.Clover";
|
||||
|
||||
public static TestClassLoader createTestClassLoader(ApplicationContext applicationContext) {
|
||||
public static TestClassLoader createTestClassLoader(MockApplicationContext applicationContext) {
|
||||
final TestClassLoader testClassLoader = new TestClassLoader(applicationContext);
|
||||
addCloverPackage(testClassLoader, CENQUA_CLOVER);
|
||||
addCloverPackage(testClassLoader, ATLASSIAN_CLOVER);
|
||||
|
||||
+5
-5
@@ -14,18 +14,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.test;
|
||||
package com.navercorp.pinpoint.test.provder;
|
||||
|
||||
|
||||
import com.navercorp.pinpoint.profiler.context.provider.Provider;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClientFactory;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class NullProvider<T> implements Provider<T> {
|
||||
public class NullPinpointClientFactoryProvider implements Provider<PinpointClientFactory> {
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
public PinpointClientFactory get() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.test.provder;
|
||||
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClient;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClientFactory;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class NullPinpointClientProvider implements Provider<PinpointClient> {
|
||||
|
||||
@Override
|
||||
public PinpointClient get() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.test;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.util.Modules;
|
||||
import com.navercorp.pinpoint.bootstrap.AgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.DefaultAgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService;
|
||||
import com.navercorp.pinpoint.common.service.DefaultServiceTypeRegistryService;
|
||||
import com.navercorp.pinpoint.profiler.AgentInfoSender;
|
||||
import com.navercorp.pinpoint.profiler.ClassFileTransformerDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class MockApplicationContextModuleTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ProfilerConfig profilerConfig = new DefaultProfilerConfig();
|
||||
InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder();
|
||||
AgentOption agentOption = new DefaultAgentOption(new DummyInstrumentation(),
|
||||
"mockAgent", "mockApplicationName", profilerConfig, new URL[0],
|
||||
null, new DefaultServiceTypeRegistryService(), new DefaultAnnotationKeyRegistryService());
|
||||
|
||||
final PluginApplicationContextModule pluginApplicationContextModule = new PluginApplicationContextModule();
|
||||
PluginTestAgent pluginTestAgent = new PluginTestAgent(agentOption) {
|
||||
@Override
|
||||
protected ApplicationContext newApplicationContext(AgentOption agentOption, InterceptorRegistryBinder interceptorRegistryBinder) {
|
||||
|
||||
|
||||
ApplicationContext applicationContext = new DefaultApplicationContext(agentOption, interceptorRegistryBinder) {
|
||||
|
||||
@Override
|
||||
protected Module newApplicationContextModule(AgentOption agentOption, InterceptorRegistryBinder interceptorRegistryBinder) {
|
||||
Module applicationContextModule = super.newApplicationContextModule(agentOption, interceptorRegistryBinder);
|
||||
// PluginApplicationContextModule pluginApplicationContextModule = new PluginApplicationContextModule();
|
||||
return Modules.override(applicationContextModule).with(pluginApplicationContextModule);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return applicationContext;
|
||||
}
|
||||
};
|
||||
// pluginTestAgent.start();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMockApplicationContext() {
|
||||
ProfilerConfig profilerConfig = new DefaultProfilerConfig();
|
||||
InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder();
|
||||
AgentOption agentOption = new DefaultAgentOption(new DummyInstrumentation(),
|
||||
"mockAgent", "mockApplicationName", profilerConfig, new URL[0],
|
||||
null, new DefaultServiceTypeRegistryService(), new DefaultAnnotationKeyRegistryService());
|
||||
DefaultApplicationContext applicationContext = new DefaultApplicationContext(agentOption, binder) {
|
||||
@Override
|
||||
protected Module newApplicationContextModule(AgentOption agentOption, InterceptorRegistryBinder interceptorRegistryBinder) {
|
||||
Module module = super.newApplicationContextModule(agentOption, interceptorRegistryBinder);
|
||||
PluginApplicationContextModule pluginApplicationContextModule = new PluginApplicationContextModule();
|
||||
|
||||
return Modules.override(module).with(pluginApplicationContextModule);
|
||||
}
|
||||
};
|
||||
|
||||
Injector injector = applicationContext.getInjector();
|
||||
AgentInfoSender instance1 = injector.getInstance(AgentInfoSender.class);
|
||||
AgentInfoSender instance2 = injector.getInstance(AgentInfoSender.class);
|
||||
Assert.assertSame(instance1, instance2);
|
||||
|
||||
ClassFileTransformerDispatcher instance4 = injector.getInstance(ClassFileTransformerDispatcher.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -190,7 +190,7 @@ public class JavassistClassTest {
|
||||
|
||||
DefaultProfilerConfig profilerConfig = new DefaultProfilerConfig();
|
||||
profilerConfig.setApplicationServerType(ServiceType.TEST_STAND_ALONE.getName());
|
||||
ApplicationContext applicationContext = MockApplicationContext.of(profilerConfig);
|
||||
MockApplicationContext applicationContext = MockApplicationContext.of(profilerConfig);
|
||||
|
||||
TestClassLoader testClassLoader = new TestClassLoader(applicationContext);
|
||||
testClassLoader.initialize();
|
||||
|
||||
+1
-2
@@ -26,7 +26,6 @@ import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback
|
||||
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.logging.Slf4jLoggerBinder;
|
||||
import com.navercorp.pinpoint.test.MockApplicationContext;
|
||||
import com.navercorp.pinpoint.test.classloader.TestClassLoader;
|
||||
@@ -52,7 +51,7 @@ public class AccessorInjectionTest {
|
||||
|
||||
DefaultProfilerConfig profilerConfig = new DefaultProfilerConfig();
|
||||
profilerConfig.setApplicationServerType(ServiceType.TEST_STAND_ALONE.getName());
|
||||
ApplicationContext applicationContext = MockApplicationContext.of(profilerConfig);
|
||||
MockApplicationContext applicationContext = MockApplicationContext.of(profilerConfig);
|
||||
|
||||
TestClassLoader testClassLoader = new TestClassLoader(applicationContext);
|
||||
testClassLoader.initialize();
|
||||
|
||||
+6
-4
@@ -19,14 +19,16 @@ package com.navercorp.pinpoint.test.monitor;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.context.AtomicIdGenerator;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultTransactionCounter;
|
||||
import com.navercorp.pinpoint.profiler.context.IdGenerator;
|
||||
import com.navercorp.pinpoint.profiler.context.TransactionCounter;
|
||||
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.DefaultPluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.PluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor;
|
||||
import com.navercorp.pinpoint.profiler.monitor.DefaultAgentStatMonitor;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.AgentStatCollectorFactory;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.DefaultAgentStatCollectorFactory;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.test.ListenableDataSender;
|
||||
import com.navercorp.pinpoint.test.TBaseRecorder;
|
||||
@@ -72,7 +74,7 @@ public class AgentStatMonitorTest {
|
||||
// When
|
||||
AgentStatCollectorFactory agentStatCollectorFactory = newAgentStatCollectorFactory();
|
||||
|
||||
AgentStatMonitor monitor = new AgentStatMonitor(this.dataSender, "agentId", System.currentTimeMillis(),
|
||||
AgentStatMonitor monitor = new DefaultAgentStatMonitor(this.dataSender, "agentId", System.currentTimeMillis(),
|
||||
agentStatCollectorFactory, collectionIntervalMs, numCollectionsPerBatch);
|
||||
monitor.start();
|
||||
Thread.sleep(totalTestDurationMs);
|
||||
@@ -88,10 +90,10 @@ public class AgentStatMonitorTest {
|
||||
private AgentStatCollectorFactory newAgentStatCollectorFactory() {
|
||||
ProfilerConfig profilerConfig = new DefaultProfilerConfig();
|
||||
ActiveTraceRepository activeTraceRepository = new ActiveTraceRepository();
|
||||
IdGenerator idGenerator = new IdGenerator();
|
||||
AtomicIdGenerator idGenerator = new AtomicIdGenerator();
|
||||
TransactionCounter transactionCounter = new DefaultTransactionCounter(idGenerator);
|
||||
PluginMonitorContext pluginMonitorContext = new DefaultPluginMonitorContext();
|
||||
return new AgentStatCollectorFactory(profilerConfig, activeTraceRepository, transactionCounter, pluginMonitorContext);
|
||||
return new DefaultAgentStatCollectorFactory(profilerConfig, activeTraceRepository, transactionCounter, pluginMonitorContext);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-1
@@ -22,7 +22,6 @@ import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod;
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.instrument.JavassistClassPool;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultProfilerPluginContext;
|
||||
import com.navercorp.pinpoint.profiler.util.TypeUtils;
|
||||
|
||||
+6
-1
@@ -60,7 +60,12 @@
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-google-guava</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.inject</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
<version>4.1.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.context.provider.JvmInformationProvider;
|
||||
import com.navercorp.pinpoint.thrift.dto.TJvmGcType;
|
||||
import com.navercorp.pinpoint.thrift.dto.TJvmInfo;
|
||||
import org.slf4j.Logger;
|
||||
@@ -215,7 +216,7 @@ public class AgentInfoSender implements ServerMetaDataListener {
|
||||
private int maxTryPerAttempt = DEFAULT_MAX_TRY_COUNT_PER_ATTEMPT;
|
||||
|
||||
Builder(EnhancedDataSender dataSender, AgentInformation agentInformation) {
|
||||
this(dataSender, agentInformation, new JvmInformationFactory().createJvmInformation());
|
||||
this(dataSender, agentInformation, new JvmInformationProvider().get());
|
||||
}
|
||||
|
||||
public Builder(EnhancedDataSender dataSender, AgentInformation agentInformation, JvmInformation jvmInformation) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -17,110 +17,26 @@
|
||||
package com.navercorp.pinpoint.profiler;
|
||||
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.rpc.packet.HandshakePropertyType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author koo.taejin
|
||||
* @author hyungil.jeong
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class AgentInformation {
|
||||
private final String agentId;
|
||||
private final String applicationName;
|
||||
private final long startTime;
|
||||
private final int pid;
|
||||
private final String machineName;
|
||||
private final String hostIp;
|
||||
private final ServiceType serverType;
|
||||
private final String jvmVersion;
|
||||
private final String agentVersion;
|
||||
public interface AgentInformation {
|
||||
String getAgentId();
|
||||
|
||||
public AgentInformation(
|
||||
String agentId,
|
||||
String applicationName,
|
||||
long startTime,
|
||||
int pid,
|
||||
String machineName,
|
||||
String hostIp,
|
||||
ServiceType serverType,
|
||||
String jvmVersion,
|
||||
String agentVersion) {
|
||||
if (agentId == null) {
|
||||
throw new NullPointerException("agentId must not be null");
|
||||
}
|
||||
if (applicationName == null) {
|
||||
throw new NullPointerException("applicationName must not be null");
|
||||
}
|
||||
if (machineName == null) {
|
||||
throw new NullPointerException("machineName must not be null");
|
||||
}
|
||||
if (agentVersion == null) {
|
||||
throw new NullPointerException("version must not be null");
|
||||
}
|
||||
this.agentId = agentId;
|
||||
this.applicationName = applicationName;
|
||||
this.startTime = startTime;
|
||||
this.pid = pid;
|
||||
this.machineName = machineName;
|
||||
this.hostIp = hostIp;
|
||||
this.serverType = serverType;
|
||||
this.jvmVersion = jvmVersion;
|
||||
this.agentVersion = agentVersion;
|
||||
}
|
||||
String getApplicationName();
|
||||
|
||||
public String getAgentId() {
|
||||
return agentId;
|
||||
}
|
||||
long getStartTime();
|
||||
|
||||
public String getApplicationName() {
|
||||
return applicationName;
|
||||
}
|
||||
int getPid();
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
String getMachineName();
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
String getHostIp();
|
||||
|
||||
public String getMachineName() {
|
||||
return machineName;
|
||||
}
|
||||
ServiceType getServerType();
|
||||
|
||||
public String getHostIp() {
|
||||
return hostIp;
|
||||
}
|
||||
String getJvmVersion();
|
||||
|
||||
public ServiceType getServerType() {
|
||||
return serverType;
|
||||
}
|
||||
|
||||
public String getJvmVersion() {
|
||||
return this.jvmVersion;
|
||||
}
|
||||
|
||||
public String getAgentVersion() {
|
||||
return agentVersion;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("AgentInformation{");
|
||||
sb.append("agentId='").append(agentId).append('\'');
|
||||
sb.append(", applicationName='").append(applicationName).append('\'');
|
||||
sb.append(", startTime=").append(startTime);
|
||||
sb.append(", pid=").append(pid);
|
||||
sb.append(", machineName='").append(machineName).append('\'');
|
||||
sb.append(", hostIp='").append(hostIp).append('\'');
|
||||
sb.append(", serverType=").append(serverType);
|
||||
sb.append(", jvmVersion='").append(jvmVersion).append('\'');
|
||||
sb.append(", agentVersion='").append(agentVersion).append('\'');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
String getAgentVersion();
|
||||
}
|
||||
|
||||
+5
-49
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,53 +16,9 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.util.IdValidateUtils;
|
||||
import com.navercorp.pinpoint.bootstrap.util.NetworkUtils;
|
||||
import com.navercorp.pinpoint.common.Version;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
|
||||
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class AgentInformationFactory {
|
||||
|
||||
private final String agentId;
|
||||
private final String applicationName;
|
||||
|
||||
public AgentInformationFactory(String agentId, String applicationName) {
|
||||
if (agentId == null) {
|
||||
throw new NullPointerException("agentId must not be null");
|
||||
}
|
||||
if (applicationName == null) {
|
||||
throw new NullPointerException("applicationName must not be null");
|
||||
}
|
||||
|
||||
this.agentId = checkId(agentId);
|
||||
this.applicationName = checkId(applicationName);
|
||||
}
|
||||
|
||||
public AgentInformation createAgentInformation(ServiceType serverType) {
|
||||
if (serverType == null) {
|
||||
throw new NullPointerException("serverType must not be null");
|
||||
}
|
||||
final String machineName = NetworkUtils.getHostName();
|
||||
final String hostIp = NetworkUtils.getRepresentationHostIp();
|
||||
final long startTime = RuntimeMXBeanUtils.getVmStartTime();
|
||||
final int pid = RuntimeMXBeanUtils.getPid();
|
||||
final String jvmVersion = JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION);
|
||||
return new AgentInformation(agentId, applicationName, startTime, pid, machineName, hostIp, serverType, jvmVersion, Version.VERSION);
|
||||
}
|
||||
|
||||
private String checkId(String id) {
|
||||
if (!IdValidateUtils.validateId(id)) {
|
||||
throw new IllegalStateException("invalid Id=" + id);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public interface AgentInformationFactory {
|
||||
AgentInformation createAgentInformation();
|
||||
}
|
||||
|
||||
+10
-163
@@ -1,175 +1,22 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.navercorp.pinpoint.profiler;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.DynamicTransformRequestListener;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.RequestHandle;
|
||||
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.IllegalClassFormatException;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.List;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.RequestHandle;
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.Filter;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.DynamicTransformRequestListener;
|
||||
import com.navercorp.pinpoint.profiler.instrument.LegacyProfilerPluginClassInjector;
|
||||
import com.navercorp.pinpoint.profiler.instrument.transformer.DebugTransformer;
|
||||
import com.navercorp.pinpoint.profiler.instrument.transformer.DefaultTransformerRegistry;
|
||||
import com.navercorp.pinpoint.profiler.instrument.transformer.TransformerRegistry;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultProfilerPluginContext;
|
||||
import com.navercorp.pinpoint.profiler.plugin.xml.transformer.MatchableClassFileTransformer;
|
||||
import com.navercorp.pinpoint.profiler.util.JavaAssistUtils;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author netspider
|
||||
* @author jaehong.kim
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class ClassFileTransformerDispatcher implements ClassFileTransformer, DynamicTransformRequestListener {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private final ClassLoader agentClassLoader = this.getClass().getClassLoader();
|
||||
|
||||
private final TransformerRegistry transformerRegistry;
|
||||
private final DynamicTransformerRegistry dynamicTransformerRegistry;
|
||||
|
||||
private final DefaultProfilerPluginContext globalContext;
|
||||
private final Filter<String> debugTargetFilter;
|
||||
private final DebugTransformer debugTransformer;
|
||||
|
||||
private final ClassFileFilter pinpointClassFilter;
|
||||
private final ClassFileFilter unmodifiableFilter;
|
||||
|
||||
public ClassFileTransformerDispatcher(ApplicationContext applicationContext, List<DefaultProfilerPluginContext> pluginContexts) {
|
||||
if (applicationContext == null) {
|
||||
throw new NullPointerException("applicationContext must not be null");
|
||||
}
|
||||
|
||||
this.globalContext = new DefaultProfilerPluginContext(applicationContext, new LegacyProfilerPluginClassInjector(getClass().getClassLoader()));
|
||||
ProfilerConfig profilerConfig = applicationContext.getProfilerConfig();
|
||||
this.debugTargetFilter = profilerConfig.getProfilableClassFilter();
|
||||
this.debugTransformer = new DebugTransformer(globalContext);
|
||||
|
||||
this.pinpointClassFilter = new PinpointClassFilter(agentClassLoader);
|
||||
this.unmodifiableFilter = new UnmodifiableClassFilter();
|
||||
|
||||
this.transformerRegistry = createTransformerRegistry(pluginContexts);
|
||||
this.dynamicTransformerRegistry = new DefaultDynamicTransformerRegistry();
|
||||
}
|
||||
public interface ClassFileTransformerDispatcher extends ClassFileTransformer, DynamicTransformRequestListener {
|
||||
@Override
|
||||
byte[] transform(ClassLoader classLoader, String classInternalName, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws IllegalClassFormatException;
|
||||
|
||||
@Override
|
||||
public byte[] transform(ClassLoader classLoader, String classInternalName, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws IllegalClassFormatException {
|
||||
if (!pinpointClassFilter.accept(classLoader, classInternalName, classBeingRedefined, protectionDomain, classFileBuffer)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ClassFileTransformer dynamicTransformer = dynamicTransformerRegistry.getTransformer(classLoader, classInternalName);
|
||||
if (dynamicTransformer != null) {
|
||||
return transform0(classLoader, classInternalName, classBeingRedefined, protectionDomain, classFileBuffer, dynamicTransformer);
|
||||
}
|
||||
|
||||
if (!unmodifiableFilter.accept(classLoader, classInternalName, classBeingRedefined, protectionDomain, classFileBuffer)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ClassFileTransformer transformer = this.transformerRegistry.findTransformer(classInternalName);
|
||||
if (transformer == null) {
|
||||
// For debug
|
||||
// TODO What if a modifier is duplicated?
|
||||
if (this.debugTargetFilter.filter(classInternalName)) {
|
||||
// Added to see if call stack view is OK on a test machine.
|
||||
transformer = debugTransformer;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return transform0(classLoader, classInternalName, classBeingRedefined, protectionDomain, classFileBuffer, transformer);
|
||||
}
|
||||
|
||||
private byte[] transform0(ClassLoader classLoader, String classInternalName, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer, ClassFileTransformer transformer) {
|
||||
final String className = JavaAssistUtils.jvmNameToJavaName(classInternalName);
|
||||
|
||||
if (isDebug) {
|
||||
if (classBeingRedefined == null) {
|
||||
logger.debug("[transform] classLoader:{} className:{} transformer:{}", classLoader, className, transformer.getClass().getName());
|
||||
} else {
|
||||
logger.debug("[retransform] classLoader:{} className:{} transformer:{}", classLoader, className, transformer.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
final Thread thread = Thread.currentThread();
|
||||
final ClassLoader before = getContextClassLoader(thread);
|
||||
thread.setContextClassLoader(this.agentClassLoader);
|
||||
try {
|
||||
return transformer.transform(classLoader, className, classBeingRedefined, protectionDomain, classFileBuffer);
|
||||
} finally {
|
||||
// The context class loader have to be recovered even if it was null.
|
||||
thread.setContextClassLoader(before);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error("Transformer:{} threw an exception. cl:{} ctxCl:{} agentCl:{} Cause:{}",
|
||||
transformer.getClass().getName(), classLoader, Thread.currentThread().getContextClassLoader(), agentClassLoader, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
RequestHandle onRetransformRequest(Class<?> target, ClassFileTransformer transformer);
|
||||
|
||||
@Override
|
||||
public RequestHandle onRetransformRequest(Class<?> target, final ClassFileTransformer transformer) {
|
||||
return this.dynamicTransformerRegistry.onRetransformRequest(target, transformer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransformRequest(ClassLoader classLoader, String targetClassName, ClassFileTransformer transformer) {
|
||||
this.dynamicTransformerRegistry.onTransformRequest(classLoader, targetClassName, transformer);
|
||||
}
|
||||
|
||||
private ClassLoader getContextClassLoader(Thread thread) throws Throwable {
|
||||
try {
|
||||
return thread.getContextClassLoader();
|
||||
} catch (SecurityException se) {
|
||||
throw se;
|
||||
} catch (Throwable th) {
|
||||
if (isDebug) {
|
||||
logger.debug("getContextClassLoader(). Caused:{}", th.getMessage(), th);
|
||||
}
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
|
||||
private TransformerRegistry createTransformerRegistry(List<DefaultProfilerPluginContext> pluginContexts) {
|
||||
DefaultTransformerRegistry registry = new DefaultTransformerRegistry();
|
||||
|
||||
for (DefaultProfilerPluginContext pluginContext : pluginContexts) {
|
||||
for (ClassFileTransformer transformer : pluginContext.getClassEditors()) {
|
||||
if (transformer instanceof MatchableClassFileTransformer) {
|
||||
MatchableClassFileTransformer t = (MatchableClassFileTransformer) transformer;
|
||||
logger.info("Registering class file transformer {} for {} ", t, t.getMatcher());
|
||||
registry.addTransformer(t.getMatcher(), t);
|
||||
} else {
|
||||
logger.warn("Ignore class file transformer {}", transformer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return registry;
|
||||
}
|
||||
}
|
||||
void onTransformRequest(ClassLoader classLoader, String targetClassName, ClassFileTransformer transformer);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.navercorp.pinpoint.ProductInfo;
|
||||
import com.navercorp.pinpoint.bootstrap.Agent;
|
||||
import com.navercorp.pinpoint.bootstrap.AgentOption;
|
||||
@@ -141,10 +142,6 @@ public class DefaultAgent implements Agent {
|
||||
}
|
||||
}
|
||||
|
||||
public ProfilerConfig getProfilerConfig() {
|
||||
return profilerConfig;
|
||||
}
|
||||
|
||||
private void changeStatus(AgentStatus status) {
|
||||
this.agentStatus = status;
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler;
|
||||
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author koo.taejin
|
||||
* @author hyungil.jeong
|
||||
*/
|
||||
public class DefaultAgentInformation implements AgentInformation {
|
||||
private final String agentId;
|
||||
private final String applicationName;
|
||||
private final long startTime;
|
||||
private final int pid;
|
||||
private final String machineName;
|
||||
private final String hostIp;
|
||||
private final ServiceType serverType;
|
||||
private final String jvmVersion;
|
||||
private final String agentVersion;
|
||||
|
||||
public DefaultAgentInformation(
|
||||
String agentId,
|
||||
String applicationName,
|
||||
long startTime,
|
||||
int pid,
|
||||
String machineName,
|
||||
String hostIp,
|
||||
ServiceType serverType,
|
||||
String jvmVersion,
|
||||
String agentVersion) {
|
||||
if (agentId == null) {
|
||||
throw new NullPointerException("agentId must not be null");
|
||||
}
|
||||
if (applicationName == null) {
|
||||
throw new NullPointerException("applicationName must not be null");
|
||||
}
|
||||
if (machineName == null) {
|
||||
throw new NullPointerException("machineName must not be null");
|
||||
}
|
||||
if (agentVersion == null) {
|
||||
throw new NullPointerException("version must not be null");
|
||||
}
|
||||
this.agentId = agentId;
|
||||
this.applicationName = applicationName;
|
||||
this.startTime = startTime;
|
||||
this.pid = pid;
|
||||
this.machineName = machineName;
|
||||
this.hostIp = hostIp;
|
||||
this.serverType = serverType;
|
||||
this.jvmVersion = jvmVersion;
|
||||
this.agentVersion = agentVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAgentId() {
|
||||
return agentId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getApplicationName() {
|
||||
return applicationName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMachineName() {
|
||||
return machineName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHostIp() {
|
||||
return hostIp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceType getServerType() {
|
||||
return serverType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJvmVersion() {
|
||||
return this.jvmVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAgentVersion() {
|
||||
return agentVersion;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("AgentInformation{");
|
||||
sb.append("agentId='").append(agentId).append('\'');
|
||||
sb.append(", applicationName='").append(applicationName).append('\'');
|
||||
sb.append(", startTime=").append(startTime);
|
||||
sb.append(", pid=").append(pid);
|
||||
sb.append(", machineName='").append(machineName).append('\'');
|
||||
sb.append(", hostIp='").append(hostIp).append('\'');
|
||||
sb.append(", serverType=").append(serverType);
|
||||
sb.append(", jvmVersion='").append(jvmVersion).append('\'');
|
||||
sb.append(", agentVersion='").append(agentVersion).append('\'');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.navercorp.pinpoint.bootstrap.util.IdValidateUtils;
|
||||
import com.navercorp.pinpoint.bootstrap.util.NetworkUtils;
|
||||
import com.navercorp.pinpoint.common.Version;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentId;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentServiceType;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentStartTime;
|
||||
import com.navercorp.pinpoint.profiler.context.module.ApplicationName;
|
||||
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
|
||||
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class DefaultAgentInformationFactory implements AgentInformationFactory {
|
||||
|
||||
private final String agentId;
|
||||
private final String applicationName;
|
||||
private final long agentStartTime;
|
||||
private final ServiceType serverType;
|
||||
|
||||
@Inject
|
||||
public DefaultAgentInformationFactory(@AgentId String agentId, @ApplicationName String applicationName, @AgentStartTime long agentStartTime, @AgentServiceType ServiceType serverType) {
|
||||
if (agentId == null) {
|
||||
throw new NullPointerException("agentId must not be null");
|
||||
}
|
||||
if (applicationName == null) {
|
||||
throw new NullPointerException("applicationName must not be null");
|
||||
}
|
||||
if (serverType == null) {
|
||||
throw new NullPointerException("serverType must not be null");
|
||||
}
|
||||
|
||||
this.agentId = checkId(agentId);
|
||||
this.applicationName = checkId(applicationName);
|
||||
this.serverType = serverType;
|
||||
this.agentStartTime = agentStartTime;
|
||||
}
|
||||
|
||||
public AgentInformation createAgentInformation() {
|
||||
|
||||
final String machineName = NetworkUtils.getHostName();
|
||||
final String hostIp = NetworkUtils.getRepresentationHostIp();
|
||||
|
||||
final int pid = RuntimeMXBeanUtils.getPid();
|
||||
final String jvmVersion = JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION);
|
||||
return new DefaultAgentInformation(agentId, applicationName, agentStartTime, pid, machineName, hostIp, serverType, jvmVersion, Version.VERSION);
|
||||
}
|
||||
|
||||
private String checkId(String id) {
|
||||
if (!IdValidateUtils.validateId(id)) {
|
||||
throw new IllegalStateException("invalid Id=" + id);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.navercorp.pinpoint.profiler;
|
||||
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.IllegalClassFormatException;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.DynamicTransformTrigger;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClassPool;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.RequestHandle;
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.instrument.ClassInjector;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginContextLoadResult;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.Filter;
|
||||
import com.navercorp.pinpoint.profiler.instrument.LegacyProfilerPluginClassInjector;
|
||||
import com.navercorp.pinpoint.profiler.instrument.transformer.DebugTransformer;
|
||||
import com.navercorp.pinpoint.profiler.instrument.transformer.DefaultTransformerRegistry;
|
||||
import com.navercorp.pinpoint.profiler.instrument.transformer.TransformerRegistry;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultProfilerPluginContext;
|
||||
import com.navercorp.pinpoint.profiler.plugin.xml.transformer.MatchableClassFileTransformer;
|
||||
import com.navercorp.pinpoint.profiler.util.JavaAssistUtils;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author netspider
|
||||
* @author jaehong.kim
|
||||
*/
|
||||
public class DefaultClassFileTransformerDispatcher implements ClassFileTransformerDispatcher {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private final ClassLoader agentClassLoader = this.getClass().getClassLoader();
|
||||
|
||||
private final TransformerRegistry transformerRegistry;
|
||||
private final DynamicTransformerRegistry dynamicTransformerRegistry;
|
||||
|
||||
private final DefaultProfilerPluginContext globalContext;
|
||||
private final Filter<String> debugTargetFilter;
|
||||
private final DebugTransformer debugTransformer;
|
||||
|
||||
private final ClassFileFilter pinpointClassFilter;
|
||||
private final ClassFileFilter unmodifiableFilter;
|
||||
|
||||
@Inject
|
||||
public DefaultClassFileTransformerDispatcher(ApplicationContext applicationContext, PluginContextLoadResult pluginContexts) {
|
||||
|
||||
|
||||
this.globalContext = new DefaultProfilerPluginContext(applicationContext, new LegacyProfilerPluginClassInjector(getClass().getClassLoader()));
|
||||
this.debugTargetFilter = applicationContext.getProfilerConfig().getProfilableClassFilter();
|
||||
this.debugTransformer = new DebugTransformer(globalContext);
|
||||
|
||||
this.pinpointClassFilter = new PinpointClassFilter(agentClassLoader);
|
||||
this.unmodifiableFilter = new UnmodifiableClassFilter();
|
||||
|
||||
this.transformerRegistry = createTransformerRegistry(pluginContexts);
|
||||
this.dynamicTransformerRegistry = new DefaultDynamicTransformerRegistry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(ClassLoader classLoader, String classInternalName, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws IllegalClassFormatException {
|
||||
if (!pinpointClassFilter.accept(classLoader, classInternalName, classBeingRedefined, protectionDomain, classFileBuffer)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ClassFileTransformer dynamicTransformer = dynamicTransformerRegistry.getTransformer(classLoader, classInternalName);
|
||||
if (dynamicTransformer != null) {
|
||||
return transform0(classLoader, classInternalName, classBeingRedefined, protectionDomain, classFileBuffer, dynamicTransformer);
|
||||
}
|
||||
|
||||
if (!unmodifiableFilter.accept(classLoader, classInternalName, classBeingRedefined, protectionDomain, classFileBuffer)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ClassFileTransformer transformer = this.transformerRegistry.findTransformer(classInternalName);
|
||||
if (transformer == null) {
|
||||
// For debug
|
||||
// TODO What if a modifier is duplicated?
|
||||
if (this.debugTargetFilter.filter(classInternalName)) {
|
||||
// Added to see if call stack view is OK on a test machine.
|
||||
transformer = debugTransformer;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return transform0(classLoader, classInternalName, classBeingRedefined, protectionDomain, classFileBuffer, transformer);
|
||||
}
|
||||
|
||||
private byte[] transform0(ClassLoader classLoader, String classInternalName, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer, ClassFileTransformer transformer) {
|
||||
final String className = JavaAssistUtils.jvmNameToJavaName(classInternalName);
|
||||
|
||||
if (isDebug) {
|
||||
if (classBeingRedefined == null) {
|
||||
logger.debug("[transform] classLoader:{} className:{} transformer:{}", classLoader, className, transformer.getClass().getName());
|
||||
} else {
|
||||
logger.debug("[retransform] classLoader:{} className:{} transformer:{}", classLoader, className, transformer.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
final Thread thread = Thread.currentThread();
|
||||
final ClassLoader before = getContextClassLoader(thread);
|
||||
thread.setContextClassLoader(this.agentClassLoader);
|
||||
try {
|
||||
return transformer.transform(classLoader, className, classBeingRedefined, protectionDomain, classFileBuffer);
|
||||
} finally {
|
||||
// The context class loader have to be recovered even if it was null.
|
||||
thread.setContextClassLoader(before);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error("Transformer:{} threw an exception. cl:{} ctxCl:{} agentCl:{} Cause:{}",
|
||||
transformer.getClass().getName(), classLoader, Thread.currentThread().getContextClassLoader(), agentClassLoader, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestHandle onRetransformRequest(Class<?> target, final ClassFileTransformer transformer) {
|
||||
return this.dynamicTransformerRegistry.onRetransformRequest(target, transformer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransformRequest(ClassLoader classLoader, String targetClassName, ClassFileTransformer transformer) {
|
||||
this.dynamicTransformerRegistry.onTransformRequest(classLoader, targetClassName, transformer);
|
||||
}
|
||||
|
||||
private ClassLoader getContextClassLoader(Thread thread) throws Throwable {
|
||||
try {
|
||||
return thread.getContextClassLoader();
|
||||
} catch (SecurityException se) {
|
||||
throw se;
|
||||
} catch (Throwable th) {
|
||||
if (isDebug) {
|
||||
logger.debug("getContextClassLoader(). Caused:{}", th.getMessage(), th);
|
||||
}
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
|
||||
private TransformerRegistry createTransformerRegistry(PluginContextLoadResult pluginContexts) {
|
||||
DefaultTransformerRegistry registry = new DefaultTransformerRegistry();
|
||||
|
||||
List<DefaultProfilerPluginContext> profilerPluginContextList = pluginContexts.getProfilerPluginContextList();
|
||||
for (DefaultProfilerPluginContext pluginContext : profilerPluginContextList) {
|
||||
for (ClassFileTransformer transformer : pluginContext.getClassEditors()) {
|
||||
if (transformer instanceof MatchableClassFileTransformer) {
|
||||
MatchableClassFileTransformer t = (MatchableClassFileTransformer) transformer;
|
||||
logger.info("Registering class file transformer {} for {} ", t, t.getMatcher());
|
||||
registry.addTransformer(t.getMatcher(), t);
|
||||
} else {
|
||||
logger.warn("Ignore class file transformer {}", transformer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return registry;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.instrument.UnmodifiableClassException;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.RequestHandle;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -39,6 +40,11 @@ public class DynamicTransformService implements DynamicTransformTrigger {
|
||||
|
||||
private DynamicTransformRequestListener dynamicTransformRequestListener;
|
||||
|
||||
@Inject
|
||||
public DynamicTransformService(Instrumentation instrumentation, ClassFileTransformerDispatcher listener) {
|
||||
this(instrumentation, (DynamicTransformRequestListener)listener);
|
||||
}
|
||||
|
||||
public DynamicTransformService(Instrumentation instrumentation, DynamicTransformRequestListener listener) {
|
||||
Asserts.notNull(instrumentation, "instrumentation");
|
||||
Asserts.notNull(listener, "listener");
|
||||
|
||||
@@ -24,7 +24,7 @@ public class JvmInformation {
|
||||
private final String jvmVersion;
|
||||
private final int gcTypeCode;
|
||||
|
||||
JvmInformation(String jvmVersion, int gcTypeCode) {
|
||||
public JvmInformation(String jvmVersion, int gcTypeCode) {
|
||||
this.jvmVersion = jvmVersion;
|
||||
this.gcTypeCode = gcTypeCode;
|
||||
}
|
||||
|
||||
+2
-2
@@ -18,10 +18,10 @@ package com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.DynamicTransformTrigger;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClassPool;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.ClassFileTransformerDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.DynamicTransformService;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.util.List;
|
||||
@@ -39,7 +39,7 @@ public interface ApplicationContext {
|
||||
|
||||
List<String> getBootstrapJarPaths();
|
||||
|
||||
DynamicTransformService getDynamicTransformService();
|
||||
DynamicTransformTrigger getDynamicTransformTrigger();
|
||||
|
||||
Instrumentation getInstrumentation();
|
||||
|
||||
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.navercorp.pinpoint.bootstrap.AgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.DynamicTransformTrigger;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClassPool;
|
||||
import com.navercorp.pinpoint.bootstrap.sampler.Sampler;
|
||||
import com.navercorp.pinpoint.common.service.ServiceTypeRegistryService;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.profiler.AgentInfoSender;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.ClassFileTransformerDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.DefaultClassFileTransformerDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.DynamicTransformService;
|
||||
import com.navercorp.pinpoint.profiler.JvmInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentId;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentServiceType;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentStartTime;
|
||||
import com.navercorp.pinpoint.profiler.context.module.ApplicationName;
|
||||
import com.navercorp.pinpoint.profiler.context.module.BootstrapJarPaths;
|
||||
import com.navercorp.pinpoint.profiler.context.module.PluginJars;
|
||||
import com.navercorp.pinpoint.profiler.context.module.SpanDataSender;
|
||||
import com.navercorp.pinpoint.profiler.context.module.StatDataSender;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.PluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.AgentInfoSenderProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.AgentInformationProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.AgentServiceTypeProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.AgentStartTimeProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.ApplicationServerTypeResolverProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.ClassFileTransformerDispatcherProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.ClassFileTransformerWrapProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.CommandDispatcherProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.DynamicTransformTriggerProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.InstrumentEngineProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.JvmInformationProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.PinpointClientFactoryProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.PinpointClientProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.PluginContextLoadResultProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.PluginMonitorContextProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.PluginSetupProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.SamplerProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.ServerMetaDataHolderProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.StorageFactoryProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.TcpDataSenderProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.UdpSpanDataSenderProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.UdpStatDataSenderProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
|
||||
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataCacheService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.SqlMetaDataCacheService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.SqlMetaDataService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.StringMetaDataCacheService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.StringMetaDataService;
|
||||
import com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor;
|
||||
import com.navercorp.pinpoint.profiler.monitor.DefaultAgentStatMonitor;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.AgentStatCollectorFactory;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.DefaultAgentStatCollectorFactory;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginContextLoadResult;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginSetup;
|
||||
import com.navercorp.pinpoint.profiler.receiver.CommandDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.profiler.util.ApplicationServerTypeResolver;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClient;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClientFactory;
|
||||
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class ApplicationContextModule extends AbstractModule {
|
||||
private final ProfilerConfig profilerConfig;
|
||||
private final ApplicationContext applicationContext;
|
||||
private final ServiceTypeRegistryService serviceTypeRegistryService;
|
||||
private final AgentOption agentOption;
|
||||
private final InterceptorRegistryBinder interceptorRegistryBinder;
|
||||
|
||||
public ApplicationContextModule(ApplicationContext applicationContext, AgentOption agentOption, ProfilerConfig profilerConfig,
|
||||
ServiceTypeRegistryService serviceTypeRegistryService, InterceptorRegistryBinder interceptorRegistryBinder) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
}
|
||||
this.agentOption = agentOption;
|
||||
this.applicationContext = applicationContext;
|
||||
this.profilerConfig = profilerConfig;
|
||||
this.serviceTypeRegistryService = serviceTypeRegistryService;
|
||||
this.interceptorRegistryBinder = interceptorRegistryBinder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(ApplicationContext.class).toInstance(applicationContext);
|
||||
bind(ProfilerConfig.class).toInstance(profilerConfig);
|
||||
bind(ServiceTypeRegistryService.class).toInstance(serviceTypeRegistryService);
|
||||
bind(AgentOption.class).toInstance(agentOption);
|
||||
bind(Instrumentation.class).toInstance(agentOption.getInstrumentation());
|
||||
bind(InterceptorRegistryBinder.class).toInstance(interceptorRegistryBinder);
|
||||
|
||||
bind(URL[].class).annotatedWith(PluginJars.class).toInstance(agentOption.getPluginJars());
|
||||
|
||||
TypeLiteral<List<String>> listString = new TypeLiteral<List<String>>() {};
|
||||
bind(listString).annotatedWith(BootstrapJarPaths.class).toInstance(agentOption.getBootstrapJarPaths());
|
||||
|
||||
bindAgentInformation(agentOption.getAgentId(), agentOption.getApplicationName());
|
||||
|
||||
bindDataTransferComponent();
|
||||
|
||||
bind(ServerMetaDataHolder.class).toProvider(ServerMetaDataHolderProvider.class).in(Scopes.SINGLETON);
|
||||
bind(StorageFactory.class).toProvider(StorageFactoryProvider.class).in(Scopes.SINGLETON);
|
||||
|
||||
|
||||
bindServiceComponent();
|
||||
|
||||
bind(PluginMonitorContext.class).toProvider(PluginMonitorContextProvider.class).in(Scopes.SINGLETON);
|
||||
|
||||
bind(IdGenerator.class).to(AtomicIdGenerator.class);
|
||||
bind(TransactionCounter.class).to(DefaultTransactionCounter.class).in(Scopes.SINGLETON);
|
||||
|
||||
bind(Sampler.class).toProvider(SamplerProvider.class).in(Scopes.SINGLETON);
|
||||
bind(TraceFactoryBuilder.class).to(DefaultTraceFactoryBuilder.class).in(Scopes.SINGLETON);
|
||||
bind(TraceContext.class).to(DefaultTraceContext.class).in(Scopes.SINGLETON);
|
||||
bind(AgentStatCollectorFactory.class).to(DefaultAgentStatCollectorFactory.class).in(Scopes.SINGLETON);
|
||||
bind(AgentStatMonitor.class).to(DefaultAgentStatMonitor.class).in(Scopes.SINGLETON);
|
||||
|
||||
bind(PluginSetup.class).toProvider(PluginSetupProvider.class).in(Scopes.SINGLETON);
|
||||
bind(PluginContextLoadResult.class).toProvider(PluginContextLoadResultProvider.class).in(Scopes.SINGLETON);
|
||||
bind(ApplicationServerTypeResolver.class).toProvider(ApplicationServerTypeResolverProvider.class).in(Scopes.SINGLETON);
|
||||
bind(AgentInformation.class).toProvider(AgentInformationProvider.class).in(Scopes.SINGLETON);
|
||||
// bind(DefaultClassFileTransformerDispatcher.class).to(DefaultClassFileTransformerDispatcher.class).in(Scopes.SINGLETON);
|
||||
bind(JvmInformation.class).toProvider(JvmInformationProvider.class).in(Scopes.SINGLETON);
|
||||
bind(AgentInfoSender.class).toProvider(AgentInfoSenderProvider.class).in(Scopes.SINGLETON);
|
||||
|
||||
|
||||
bind(InstrumentClassPool.class).toProvider(InstrumentEngineProvider.class).in(Scopes.SINGLETON);
|
||||
bind(ClassFileTransformerDispatcher.class).toProvider(ClassFileTransformerDispatcherProvider.class).in(Scopes.SINGLETON);
|
||||
bind(DynamicTransformTrigger.class).toProvider(DynamicTransformTriggerProvider.class).in(Scopes.SINGLETON);
|
||||
bind(ClassFileTransformer.class).toProvider(ClassFileTransformerWrapProvider.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
private void bindDataTransferComponent() {
|
||||
// create tcp channel
|
||||
|
||||
bind(PinpointClientFactory.class).toProvider(PinpointClientFactoryProvider.class).in(Scopes.SINGLETON);
|
||||
bind(EnhancedDataSender.class).toProvider(TcpDataSenderProvider.class).in(Scopes.SINGLETON);
|
||||
bind(PinpointClient.class).toProvider(PinpointClientProvider.class).in(Scopes.SINGLETON);
|
||||
|
||||
bind(CommandDispatcher.class).toProvider(CommandDispatcherProvider.class).in(Scopes.SINGLETON);
|
||||
|
||||
bind(DataSender.class).annotatedWith(SpanDataSender.class)
|
||||
.toProvider(UdpSpanDataSenderProvider.class).in(Scopes.SINGLETON);
|
||||
bind(DataSender.class).annotatedWith(StatDataSender.class)
|
||||
.toProvider(UdpStatDataSenderProvider.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
private void bindServiceComponent() {
|
||||
|
||||
bind(StringMetaDataService.class).to(StringMetaDataCacheService.class).in(Scopes.SINGLETON);
|
||||
bind(ApiMetaDataService.class).to(ApiMetaDataCacheService.class).in(Scopes.SINGLETON);
|
||||
bind(SqlMetaDataService.class).to(SqlMetaDataCacheService.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
private void bindAgentInformation(String agentId, String applicationName) {
|
||||
|
||||
bind(String.class).annotatedWith(AgentId.class).toInstance(agentId);
|
||||
bind(String.class).annotatedWith(ApplicationName.class).toInstance(applicationName);
|
||||
bind(Long.class).annotatedWith(AgentStartTime.class).toProvider(AgentStartTimeProvider.class);
|
||||
bind(ServiceType.class).annotatedWith(AgentServiceType.class).toProvider(AgentServiceTypeProvider.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.util.jdk.LongAdder;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author HyunGil Jeong
|
||||
*/
|
||||
public class AtomicIdGenerator implements IdGenerator {
|
||||
// TODO might be a good idea to refactor these into SamplingType
|
||||
|
||||
// Reserved negative space (0 ~ -1000)
|
||||
public static final long UNTRACKED_ID = 0L;
|
||||
public static final long RESERVED_MAX = 0L;
|
||||
public static final long RESERVED_MIN = -1000;
|
||||
|
||||
// Positive value for sampled new traces
|
||||
public static final long INITIAL_TRANSACTION_ID = 1L;
|
||||
// Negative value for sampled continuations, and unsampled new traces/continuations
|
||||
public static final long INITIAL_CONTINUED_TRANSACTION_ID = RESERVED_MIN - 1; // -1001
|
||||
public static final long INITIAL_DISABLED_ID = RESERVED_MIN - 2; // -1002
|
||||
public static final long INITIAL_CONTINUED_DISABLED_ID = RESERVED_MIN - 3; // -1003
|
||||
|
||||
public static final int DECREMENT_CYCLE = 3;
|
||||
public static final int NEGATIVE_DECREMENT_CYCLE = DECREMENT_CYCLE * -1;
|
||||
|
||||
// Unique id for tracing a internal stacktrace and calculating a slow time of activethreadcount
|
||||
// moved here in order to make codes simpler for now
|
||||
// id generator for sampled new traces
|
||||
private final AtomicLong transactionId = new AtomicLong(INITIAL_TRANSACTION_ID);
|
||||
// id generator for sampled continued traces
|
||||
private final AtomicLong continuedTransactionId = new AtomicLong(INITIAL_CONTINUED_TRANSACTION_ID);
|
||||
// id generator for unsampled new traces
|
||||
private final AtomicLong disabledId = new AtomicLong(INITIAL_DISABLED_ID);
|
||||
// id generator for unsampled continued traces
|
||||
private final AtomicLong continuedDisabledId = new AtomicLong(INITIAL_CONTINUED_DISABLED_ID);
|
||||
|
||||
@Override
|
||||
public long nextTransactionId() {
|
||||
return this.transactionId.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextContinuedTransactionId() {
|
||||
return this.continuedTransactionId.getAndAdd(NEGATIVE_DECREMENT_CYCLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextDisabledId() {
|
||||
return this.disabledId.getAndAdd(NEGATIVE_DECREMENT_CYCLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextContinuedDisabledId() {
|
||||
return this.continuedDisabledId.getAndAdd(NEGATIVE_DECREMENT_CYCLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long currentTransactionId() {
|
||||
return this.transactionId.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long currentContinuedTransactionId() {
|
||||
return this.continuedTransactionId.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long currentDisabledId() {
|
||||
return this.disabledId.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long currentContinuedDisabledId() {
|
||||
return this.continuedDisabledId.get();
|
||||
}
|
||||
}
|
||||
+46
-228
@@ -16,56 +16,26 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Stage;
|
||||
import com.navercorp.pinpoint.bootstrap.AgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.DynamicTransformTrigger;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClassPool;
|
||||
import com.navercorp.pinpoint.bootstrap.sampler.Sampler;
|
||||
import com.navercorp.pinpoint.common.service.ServiceTypeRegistryService;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.profiler.AgentInfoSender;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformationFactory;
|
||||
import com.navercorp.pinpoint.profiler.ClassFileTransformerDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.DynamicTransformService;
|
||||
import com.navercorp.pinpoint.profiler.JvmInformationFactory;
|
||||
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.PluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.PinpointClientFactoryProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.PinpointClientProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.Provider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.ServerMetaDataHolderProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.StorageFactoryProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.TcpDataSenderProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.UdpSpanDataSenderProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.UdpStatDataSenderProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.instrument.ASMBytecodeDumpService;
|
||||
import com.navercorp.pinpoint.profiler.instrument.ASMClassPool;
|
||||
import com.navercorp.pinpoint.profiler.instrument.BytecodeDumpTransformer;
|
||||
import com.navercorp.pinpoint.profiler.instrument.JavassistClassPool;
|
||||
import com.navercorp.pinpoint.profiler.context.module.SpanDataSender;
|
||||
import com.navercorp.pinpoint.profiler.context.module.StatDataSender;
|
||||
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
|
||||
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataCacheService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.SqlMetaDataCacheService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.SqlMetaDataService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.StringMetaDataCacheService;
|
||||
import com.navercorp.pinpoint.profiler.metadata.StringMetaDataService;
|
||||
import com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.AgentStatCollectorFactory;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultProfilerPluginContext;
|
||||
import com.navercorp.pinpoint.profiler.plugin.ProfilerPluginLoader;
|
||||
import com.navercorp.pinpoint.profiler.receiver.CommandDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandLocatorBuilder;
|
||||
import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandServiceLocator;
|
||||
import com.navercorp.pinpoint.profiler.receiver.service.ActiveThreadService;
|
||||
import com.navercorp.pinpoint.profiler.receiver.service.EchoService;
|
||||
import com.navercorp.pinpoint.profiler.sampler.SamplerFactory;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.profiler.util.ApplicationServerTypeResolver;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClient;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClientFactory;
|
||||
import org.slf4j.Logger;
|
||||
@@ -97,16 +67,18 @@ public class DefaultApplicationContext implements ApplicationContext {
|
||||
private final DataSender spanDataSender;
|
||||
|
||||
private final AgentInformation agentInformation;
|
||||
private final ServerMetaDataHolder serverMetaDataHolder;
|
||||
private final AgentOption agentOption;
|
||||
|
||||
private final ServiceTypeRegistryService serviceTypeRegistryService;
|
||||
|
||||
private final ClassFileTransformerDispatcher classFileTransformer;
|
||||
private final ClassFileTransformerDispatcher classFileDispatcher;
|
||||
|
||||
private final Instrumentation instrumentation;
|
||||
private final InstrumentClassPool classPool;
|
||||
private final DynamicTransformService dynamicTransformService;
|
||||
private final DynamicTransformTrigger dynamicTransformTrigger;
|
||||
|
||||
private final Injector injector;
|
||||
|
||||
|
||||
public DefaultApplicationContext(AgentOption agentOption, final InterceptorRegistryBinder interceptorRegistryBinder) {
|
||||
if (agentOption == null) {
|
||||
@@ -121,78 +93,57 @@ public class DefaultApplicationContext implements ApplicationContext {
|
||||
this.instrumentation = agentOption.getInstrumentation();
|
||||
this.serviceTypeRegistryService = agentOption.getServiceTypeRegistryService();
|
||||
|
||||
this.classPool = createInstrumentEngine(this.profilerConfig, agentOption, interceptorRegistryBinder);
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("DefaultAgent classLoader:{}", this.getClass().getClassLoader());
|
||||
}
|
||||
|
||||
List<DefaultProfilerPluginContext> pluginContexts = loadPlugins(agentOption);
|
||||
final Module applicationContextModule = newApplicationContextModule(agentOption, interceptorRegistryBinder);
|
||||
this.injector = Guice.createInjector(Stage.PRODUCTION, applicationContextModule);
|
||||
|
||||
this.classFileTransformer = new ClassFileTransformerDispatcher(this, pluginContexts);
|
||||
this.dynamicTransformService = new DynamicTransformService(instrumentation, classFileTransformer);
|
||||
this.classPool = injector.getInstance(InstrumentClassPool.class);
|
||||
|
||||
ClassFileTransformer wrappedTransformer = wrapClassFileTransformer(this.profilerConfig, classFileTransformer);
|
||||
instrumentation.addTransformer(wrappedTransformer, true);
|
||||
this.classFileDispatcher = injector.getInstance(ClassFileTransformerDispatcher.class);
|
||||
this.dynamicTransformTrigger = injector.getInstance(DynamicTransformTrigger.class);
|
||||
ClassFileTransformer classFileTransformer = injector.getInstance(ClassFileTransformer.class);
|
||||
instrumentation.addTransformer(classFileTransformer, true);
|
||||
|
||||
String applicationServerTypeString = profilerConfig.getApplicationServerType();
|
||||
ServiceType applicationServerType = this.serviceTypeRegistryService.findServiceTypeByName(applicationServerTypeString);
|
||||
|
||||
final ApplicationServerTypeResolver typeResolver = new ApplicationServerTypeResolver(pluginContexts, applicationServerType, profilerConfig.getApplicationTypeDetectOrder());
|
||||
|
||||
final AgentInformationFactory agentInformationFactory = new AgentInformationFactory(agentOption.getAgentId(), agentOption.getApplicationName());
|
||||
this.agentInformation = agentInformationFactory.createAgentInformation(typeResolver.resolve());
|
||||
logger.info("agentInformation:{}", agentInformation);
|
||||
|
||||
final Provider<ServerMetaDataHolder> serverMetaDataHolderProvider = newServerMetaDataHolderProvider();
|
||||
this.serverMetaDataHolder = serverMetaDataHolderProvider.get();
|
||||
|
||||
Provider<DataSender> udpSpanDataSenderProvider = newUdpSpanDataSenderProvider();
|
||||
this.spanDataSender = udpSpanDataSenderProvider.get();
|
||||
this.spanDataSender = newUdpSpanDataSender();
|
||||
logger.info("spanDataSender:{}", spanDataSender);
|
||||
|
||||
Provider<DataSender> udpStatDataSenderProvider = newUdpStatDataSenderProvider();
|
||||
this.statDataSender = udpStatDataSenderProvider.get();
|
||||
this.statDataSender = newUdpStatDataSender();
|
||||
logger.info("statDataSender:{}", statDataSender);
|
||||
|
||||
final ActiveTraceRepository activeTraceRepository = createActiveTraceRepository(profilerConfig);
|
||||
final CommandDispatcher commandService = createCommandService(profilerConfig, activeTraceRepository);
|
||||
|
||||
Provider<PinpointClientFactory> pinpointClientFactoryProvider = newPinpointClientFactoryProvider(profilerConfig, this.agentInformation, commandService);
|
||||
this.clientFactory = pinpointClientFactoryProvider.get();
|
||||
this.clientFactory = injector.getInstance(PinpointClientFactory.class);
|
||||
logger.info("clientFactory:{}", clientFactory);
|
||||
|
||||
Provider<PinpointClient> pinpointClientProvider = newPinpointClientProvider(profilerConfig, clientFactory);
|
||||
this.client = pinpointClientProvider.get();
|
||||
this.client = injector.getInstance(PinpointClient.class);
|
||||
logger.info("client:{}", client);
|
||||
|
||||
Provider<EnhancedDataSender> tcpDataSenderProvider = newTcpDataSenderProvider(client);
|
||||
this.tcpDataSender = tcpDataSenderProvider.get();
|
||||
this.tcpDataSender = injector.getInstance(EnhancedDataSender.class);
|
||||
logger.info("tcpDataSender:{}", tcpDataSender);
|
||||
|
||||
final IdGenerator idGenerator = new IdGenerator();
|
||||
final TransactionCounter transactionCounter = new DefaultTransactionCounter(idGenerator);
|
||||
this.traceContext = injector.getInstance(TraceContext.class);
|
||||
|
||||
final PluginMonitorContext pluginMonitorContext = createPluginMonitorContext(this.profilerConfig);
|
||||
this.agentInformation = injector.getInstance(AgentInformation.class);
|
||||
logger.info("agentInformation:{}", agentInformation);
|
||||
|
||||
Provider<StorageFactory> storageFactoryProvider = newStorageFactoryProvider(profilerConfig, spanDataSender, agentInformation);
|
||||
final StorageFactory storageFactory = storageFactoryProvider.get();
|
||||
this.traceContext = newTraceContext(this.profilerConfig, storageFactory, this.serverMetaDataHolder, this.tcpDataSender, idGenerator, activeTraceRepository, pluginMonitorContext);
|
||||
final AgentStatCollectorFactory agentStatCollectorFactory = new AgentStatCollectorFactory(profilerConfig, activeTraceRepository, transactionCounter, pluginMonitorContext);
|
||||
|
||||
final JvmInformationFactory jvmInformationFactory = new JvmInformationFactory(agentStatCollectorFactory.getGarbageCollector());
|
||||
|
||||
this.agentInfoSender = new AgentInfoSender.Builder(this.tcpDataSender, this.agentInformation, jvmInformationFactory.createJvmInformation()).sendInterval(profilerConfig.getAgentInfoSendRetryInterval()).build();
|
||||
this.serverMetaDataHolder.addListener(this.agentInfoSender);
|
||||
this.agentStatMonitor = new AgentStatMonitor(this.statDataSender, this.agentInformation.getAgentId(), this.agentInformation.getStartTime(), agentStatCollectorFactory);
|
||||
this.agentInfoSender = injector.getInstance(AgentInfoSender.class);
|
||||
this.agentStatMonitor = injector.getInstance(AgentStatMonitor.class);
|
||||
}
|
||||
|
||||
protected Provider<DataSender> newUdpStatDataSenderProvider() {
|
||||
return new UdpStatDataSenderProvider(profilerConfig);
|
||||
protected Module newApplicationContextModule(AgentOption agentOption, InterceptorRegistryBinder interceptorRegistryBinder) {
|
||||
return new ApplicationContextModule(this, agentOption, profilerConfig, serviceTypeRegistryService, interceptorRegistryBinder);
|
||||
}
|
||||
|
||||
protected Provider<DataSender> newUdpSpanDataSenderProvider() {
|
||||
return new UdpSpanDataSenderProvider(profilerConfig);
|
||||
protected DataSender newUdpStatDataSender() {
|
||||
|
||||
Key<DataSender> statDataSenderKey = Key.get(DataSender.class, StatDataSender.class);
|
||||
return injector.getInstance(statDataSenderKey);
|
||||
}
|
||||
|
||||
protected DataSender newUdpSpanDataSender() {
|
||||
Key<DataSender> spanDataSenderKey = Key.get(DataSender.class, SpanDataSender.class);
|
||||
return injector.getInstance(spanDataSenderKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -200,8 +151,8 @@ public class DefaultApplicationContext implements ApplicationContext {
|
||||
return profilerConfig;
|
||||
}
|
||||
|
||||
protected Provider<ServerMetaDataHolder> newServerMetaDataHolderProvider() {
|
||||
return new ServerMetaDataHolderProvider();
|
||||
public Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -219,68 +170,14 @@ public class DefaultApplicationContext implements ApplicationContext {
|
||||
}
|
||||
|
||||
|
||||
private ActiveTraceRepository createActiveTraceRepository(ProfilerConfig profilerConfig) {
|
||||
if (profilerConfig.isTraceAgentActiveThread()) {
|
||||
return new ActiveTraceRepository();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private InstrumentClassPool createInstrumentEngine(ProfilerConfig profilerConfig, AgentOption agentOption, InterceptorRegistryBinder interceptorRegistryBinder) {
|
||||
|
||||
final String instrumentEngine = profilerConfig.getProfileInstrumentEngine().toUpperCase();
|
||||
|
||||
if (DefaultProfilerConfig.INSTRUMENT_ENGINE_ASM.equals(instrumentEngine)) {
|
||||
logger.info("ASM InstrumentEngine.");
|
||||
|
||||
return new ASMClassPool(interceptorRegistryBinder, agentOption.getBootstrapJarPaths());
|
||||
|
||||
} else if (DefaultProfilerConfig.INSTRUMENT_ENGINE_JAVASSIST.equals(instrumentEngine)) {
|
||||
logger.info("JAVASSIST InstrumentEngine.");
|
||||
|
||||
return new JavassistClassPool(interceptorRegistryBinder, agentOption.getBootstrapJarPaths());
|
||||
} else {
|
||||
logger.warn("Unknown InstrumentEngine:{}", instrumentEngine);
|
||||
|
||||
throw new IllegalArgumentException("Unknown InstrumentEngine:" + instrumentEngine);
|
||||
}
|
||||
}
|
||||
|
||||
private ClassFileTransformer wrapClassFileTransformer(ProfilerConfig profilerConfig, ClassFileTransformer classFileTransformerDispatcher) {
|
||||
final boolean enableBytecodeDump = profilerConfig.readBoolean(ASMBytecodeDumpService.ENABLE_BYTECODE_DUMP, ASMBytecodeDumpService.ENABLE_BYTECODE_DUMP_DEFAULT_VALUE);
|
||||
if (enableBytecodeDump) {
|
||||
logger.info("wrapBytecodeDumpTransformer");
|
||||
return BytecodeDumpTransformer.wrap(classFileTransformerDispatcher, profilerConfig);
|
||||
}
|
||||
return classFileTransformerDispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getBootstrapJarPaths() {
|
||||
return agentOption.getBootstrapJarPaths();
|
||||
}
|
||||
|
||||
protected List<DefaultProfilerPluginContext> loadPlugins(AgentOption agentOption) {
|
||||
final ProfilerPluginLoader loader = new ProfilerPluginLoader(this);
|
||||
return loader.load(agentOption.getPluginJars());
|
||||
}
|
||||
|
||||
private CommandDispatcher createCommandService(ProfilerConfig profilerConfig, ActiveTraceRepository activeTraceRepository) {
|
||||
ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder();
|
||||
builder.addService(new EchoService());
|
||||
if (activeTraceRepository != null) {
|
||||
ActiveThreadService activeThreadService = new ActiveThreadService(profilerConfig, activeTraceRepository);
|
||||
builder.addService(activeThreadService);
|
||||
}
|
||||
|
||||
ProfilerCommandServiceLocator commandServiceLocator = builder.build();
|
||||
CommandDispatcher commandDispatcher = new CommandDispatcher(commandServiceLocator);
|
||||
return commandDispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DynamicTransformService getDynamicTransformService() {
|
||||
return dynamicTransformService;
|
||||
public DynamicTransformTrigger getDynamicTransformTrigger() {
|
||||
return dynamicTransformTrigger;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -290,7 +187,7 @@ public class DefaultApplicationContext implements ApplicationContext {
|
||||
|
||||
@Override
|
||||
public ClassFileTransformerDispatcher getClassFileTransformerDispatcher() {
|
||||
return classFileTransformer;
|
||||
return classFileDispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -300,85 +197,6 @@ public class DefaultApplicationContext implements ApplicationContext {
|
||||
|
||||
|
||||
|
||||
private TraceContext newTraceContext(ProfilerConfig profilerConfig, StorageFactory storageFactory, ServerMetaDataHolder serverMetaDataHolder, EnhancedDataSender enhancedDataSender, IdGenerator idGenerator, ActiveTraceRepository activeTraceRepository, PluginMonitorContext pluginMonitorContext) {
|
||||
|
||||
|
||||
logger.info("StorageFactoryType:{}", storageFactory);
|
||||
|
||||
final Sampler sampler = createSampler(profilerConfig);
|
||||
logger.info("SamplerType:{}", sampler);
|
||||
|
||||
final TraceFactoryBuilder traceFactoryBuilder = createTraceFactory(storageFactory, sampler, idGenerator, activeTraceRepository);
|
||||
|
||||
final String agentId = this.agentInformation.getAgentId();
|
||||
final long agentStartTime = this.agentInformation.getStartTime();
|
||||
|
||||
final ApiMetaDataService apiMetaDataService = newApiMetaDataCacheService(profilerConfig, agentId, agentStartTime, enhancedDataSender);
|
||||
final StringMetaDataService stringMetaDataService = newStringMetaDataCacheService(profilerConfig, agentId, agentStartTime, enhancedDataSender);
|
||||
final SqlMetaDataService sqlMetaDataService = newSqlMetaDataService(profilerConfig, agentId, agentStartTime, enhancedDataSender);
|
||||
|
||||
final TraceContext traceContext = new DefaultTraceContext(profilerConfig, this.agentInformation,
|
||||
traceFactoryBuilder, pluginMonitorContext, serverMetaDataHolder,
|
||||
apiMetaDataService, stringMetaDataService, sqlMetaDataService
|
||||
);
|
||||
|
||||
return traceContext;
|
||||
}
|
||||
|
||||
private SqlMetaDataService newSqlMetaDataService(ProfilerConfig profilerConfig, String agentId, long agentStartTime, EnhancedDataSender enhancedDataSender) {
|
||||
int jdbcSqlCacheSize = profilerConfig.getJdbcSqlCacheSize();
|
||||
return new SqlMetaDataCacheService(agentId, agentStartTime, enhancedDataSender, jdbcSqlCacheSize);
|
||||
}
|
||||
|
||||
private StringMetaDataCacheService newStringMetaDataCacheService(ProfilerConfig profilerConfig, String agentId, long agentStartTime, EnhancedDataSender enhancedDataSender) {
|
||||
return new StringMetaDataCacheService(agentId, agentStartTime, enhancedDataSender);
|
||||
}
|
||||
|
||||
protected ApiMetaDataService newApiMetaDataCacheService(ProfilerConfig profilerConfig, String agentId, long agentStartTime, EnhancedDataSender enhancedDataSender) {
|
||||
return new ApiMetaDataCacheService(agentId, agentStartTime, enhancedDataSender);
|
||||
}
|
||||
|
||||
|
||||
private PluginMonitorContext createPluginMonitorContext(ProfilerConfig profilerConfig) {
|
||||
final boolean traceDataSource = profilerConfig.isTraceAgentDataSource();
|
||||
final PluginMonitorContextBuilder monitorContextBuilder = new PluginMonitorContextBuilder(traceDataSource);
|
||||
return monitorContextBuilder.build();
|
||||
}
|
||||
|
||||
private TraceFactoryBuilder createTraceFactory(StorageFactory storageFactory, Sampler sampler, IdGenerator idGenerator, ActiveTraceRepository activeTraceRepository) {
|
||||
|
||||
final TraceFactoryBuilder builder = new DefaultTraceFactoryBuilder(storageFactory, sampler, idGenerator, activeTraceRepository);
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
protected Provider<StorageFactory> newStorageFactoryProvider(ProfilerConfig profilerConfig, DataSender spanDataSender, AgentInformation agentInformation) {
|
||||
return new StorageFactoryProvider(profilerConfig, spanDataSender, agentInformation);
|
||||
}
|
||||
|
||||
private Sampler createSampler(ProfilerConfig profilerConfig) {
|
||||
boolean samplingEnable = profilerConfig.isSamplingEnable();
|
||||
int samplingRate = profilerConfig.getSamplingRate();
|
||||
|
||||
SamplerFactory samplerFactory = new SamplerFactory();
|
||||
return samplerFactory.createSampler(samplingEnable, samplingRate);
|
||||
}
|
||||
|
||||
protected Provider<PinpointClientFactory> newPinpointClientFactoryProvider(ProfilerConfig profilerConfig, AgentInformation agentInformation, CommandDispatcher commandDispatcher) {
|
||||
Provider<PinpointClientFactory> pinpointClientFactoryProvider = new PinpointClientFactoryProvider(profilerConfig, agentInformation, commandDispatcher);
|
||||
return pinpointClientFactoryProvider;
|
||||
}
|
||||
|
||||
protected Provider<PinpointClient> newPinpointClientProvider(ProfilerConfig profilerConfig, PinpointClientFactory clientFactory) {
|
||||
return new PinpointClientProvider(profilerConfig, clientFactory);
|
||||
}
|
||||
|
||||
protected Provider<EnhancedDataSender> newTcpDataSenderProvider(PinpointClient client) {
|
||||
return new TcpDataSenderProvider(client);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
this.agentInfoSender.start();
|
||||
|
||||
+3
-3
@@ -39,9 +39,9 @@ public class DefaultBaseTraceFactory implements BaseTraceFactory {
|
||||
private final StorageFactory storageFactory;
|
||||
private final Sampler sampler;
|
||||
|
||||
private final IdGenerator idGenerator;
|
||||
private final AtomicIdGenerator idGenerator;
|
||||
|
||||
public DefaultBaseTraceFactory(TraceContext traceContext, StorageFactory storageFactory, Sampler sampler, IdGenerator idGenerator) {
|
||||
public DefaultBaseTraceFactory(TraceContext traceContext, StorageFactory storageFactory, Sampler sampler, AtomicIdGenerator idGenerator) {
|
||||
if (traceContext == null) {
|
||||
throw new NullPointerException("traceContext must not be null");
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class DefaultBaseTraceFactory implements BaseTraceFactory {
|
||||
final boolean sampling = true;
|
||||
final Storage storage = storageFactory.createStorage();
|
||||
final Storage asyncStorage = new AsyncStorage(storage);
|
||||
final Trace trace = new DefaultTrace(traceContext, asyncStorage, parentTraceId, IdGenerator.UNTRACKED_ID, sampling);
|
||||
final Trace trace = new DefaultTrace(traceContext, asyncStorage, parentTraceId, AtomicIdGenerator.UNTRACKED_ID, sampling);
|
||||
|
||||
final AsyncTrace asyncTrace = new AsyncTrace(trace, asyncId, traceId.nextAsyncSequence(), startTime);
|
||||
|
||||
|
||||
+2
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.context.AsyncTraceId;
|
||||
import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor;
|
||||
@@ -58,6 +59,7 @@ public class DefaultTraceContext implements TraceContext {
|
||||
|
||||
private final AsyncIdGenerator asyncIdGenerator = new AsyncIdGenerator();
|
||||
|
||||
@Inject
|
||||
public DefaultTraceContext(ProfilerConfig profilerConfig, final AgentInformation agentInformation,
|
||||
TraceFactoryBuilder traceFactoryBuilder,
|
||||
PluginMonitorContext pluginMonitorContext,
|
||||
|
||||
+4
-2
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.bootstrap.sampler.Sampler;
|
||||
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceFactory;
|
||||
@@ -33,10 +34,11 @@ public class DefaultTraceFactoryBuilder implements TraceFactoryBuilder {
|
||||
|
||||
private final StorageFactory storageFactory;
|
||||
private final Sampler sampler;
|
||||
private final IdGenerator idGenerator;
|
||||
private final AtomicIdGenerator idGenerator;
|
||||
private final ActiveTraceRepository activeTraceRepository;
|
||||
|
||||
public DefaultTraceFactoryBuilder(StorageFactory storageFactory, Sampler sampler, IdGenerator idGenerator, ActiveTraceRepository activeTraceRepository) {
|
||||
@Inject
|
||||
public DefaultTraceFactoryBuilder(StorageFactory storageFactory, Sampler sampler, AtomicIdGenerator idGenerator, ActiveTraceRepository activeTraceRepository) {
|
||||
if (storageFactory == null) {
|
||||
throw new NullPointerException("storageFactory must not be null");
|
||||
}
|
||||
|
||||
+7
-4
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
*/
|
||||
@@ -23,6 +25,7 @@ public class DefaultTransactionCounter implements TransactionCounter {
|
||||
|
||||
private final IdGenerator idGenerator;
|
||||
|
||||
@Inject
|
||||
public DefaultTransactionCounter(IdGenerator idGenerator) {
|
||||
if (idGenerator == null) {
|
||||
throw new NullPointerException("idGenerator cannot be null");
|
||||
@@ -35,13 +38,13 @@ public class DefaultTransactionCounter implements TransactionCounter {
|
||||
// overflow improbable
|
||||
switch (samplingType) {
|
||||
case SAMPLED_NEW:
|
||||
return idGenerator.currentTransactionId() - IdGenerator.INITIAL_TRANSACTION_ID;
|
||||
return idGenerator.currentTransactionId() - AtomicIdGenerator.INITIAL_TRANSACTION_ID;
|
||||
case SAMPLED_CONTINUATION:
|
||||
return Math.abs(idGenerator.currentContinuedTransactionId() - IdGenerator.INITIAL_CONTINUED_TRANSACTION_ID) / IdGenerator.DECREMENT_CYCLE;
|
||||
return Math.abs(idGenerator.currentContinuedTransactionId() - AtomicIdGenerator.INITIAL_CONTINUED_TRANSACTION_ID) / AtomicIdGenerator.DECREMENT_CYCLE;
|
||||
case UNSAMPLED_NEW:
|
||||
return Math.abs(idGenerator.currentDisabledId() - IdGenerator.INITIAL_DISABLED_ID) / IdGenerator.DECREMENT_CYCLE;
|
||||
return Math.abs(idGenerator.currentDisabledId() - AtomicIdGenerator.INITIAL_DISABLED_ID) / AtomicIdGenerator.DECREMENT_CYCLE;
|
||||
case UNSAMPLED_CONTINUATION:
|
||||
return Math.abs(idGenerator.currentContinuedDisabledId() - IdGenerator.INITIAL_CONTINUED_DISABLED_ID) / IdGenerator.DECREMENT_CYCLE;
|
||||
return Math.abs(idGenerator.currentContinuedDisabledId() - AtomicIdGenerator.INITIAL_CONTINUED_DISABLED_ID) / AtomicIdGenerator.DECREMENT_CYCLE;
|
||||
default:
|
||||
return 0L;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,71 +16,25 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author HyunGil Jeong
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class IdGenerator {
|
||||
public interface IdGenerator {
|
||||
|
||||
// TODO might be a good idea to refactor these into SamplingType
|
||||
|
||||
// Reserved negative space (0 ~ -1000)
|
||||
public static final long UNTRACKED_ID = 0L;
|
||||
public static final long RESERVED_MAX = 0L;
|
||||
public static final long RESERVED_MIN = -1000;
|
||||
long nextTransactionId();
|
||||
|
||||
// Positive value for sampled new traces
|
||||
public static final long INITIAL_TRANSACTION_ID = 1L;
|
||||
// Negative value for sampled continuations, and unsampled new traces/continuations
|
||||
public static final long INITIAL_CONTINUED_TRANSACTION_ID = RESERVED_MIN - 1; // -1001
|
||||
public static final long INITIAL_DISABLED_ID = RESERVED_MIN - 2; // -1002
|
||||
public static final long INITIAL_CONTINUED_DISABLED_ID = RESERVED_MIN - 3; // -1003
|
||||
long nextContinuedTransactionId();
|
||||
|
||||
public static final int DECREMENT_CYCLE = 3;
|
||||
public static final int NEGATIVE_DECREMENT_CYCLE = DECREMENT_CYCLE * -1;
|
||||
long nextDisabledId();
|
||||
|
||||
// Unique id for tracing a internal stacktrace and calculating a slow time of activethreadcount
|
||||
// moved here in order to make codes simpler for now
|
||||
// id generator for sampled new traces
|
||||
private final AtomicLong transactionId = new AtomicLong(INITIAL_TRANSACTION_ID);
|
||||
// id generator for sampled continued traces
|
||||
private final AtomicLong continuedTransactionId = new AtomicLong(INITIAL_CONTINUED_TRANSACTION_ID);
|
||||
// id generator for unsampled new traces
|
||||
private final AtomicLong disabledId = new AtomicLong(INITIAL_DISABLED_ID);
|
||||
// id generator for unsampled continued traces
|
||||
private final AtomicLong continuedDisabledId = new AtomicLong(INITIAL_CONTINUED_DISABLED_ID);
|
||||
long nextContinuedDisabledId();
|
||||
|
||||
public long nextTransactionId() {
|
||||
return this.transactionId.getAndIncrement();
|
||||
}
|
||||
long currentTransactionId();
|
||||
|
||||
public long nextContinuedTransactionId() {
|
||||
return this.continuedTransactionId.getAndAdd(NEGATIVE_DECREMENT_CYCLE);
|
||||
}
|
||||
long currentContinuedTransactionId();
|
||||
|
||||
public long nextDisabledId() {
|
||||
return this.disabledId.getAndAdd(NEGATIVE_DECREMENT_CYCLE);
|
||||
}
|
||||
long currentDisabledId();
|
||||
|
||||
public long nextContinuedDisabledId() {
|
||||
return this.continuedDisabledId.getAndAdd(NEGATIVE_DECREMENT_CYCLE);
|
||||
}
|
||||
|
||||
public long currentTransactionId() {
|
||||
return this.transactionId.get();
|
||||
}
|
||||
|
||||
public long currentContinuedTransactionId() {
|
||||
return this.continuedTransactionId.get();
|
||||
}
|
||||
|
||||
public long currentDisabledId() {
|
||||
return this.disabledId.get();
|
||||
}
|
||||
|
||||
public long currentContinuedDisabledId() {
|
||||
return this.continuedDisabledId.get();
|
||||
}
|
||||
long currentContinuedDisabledId();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.module;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
@BindingAnnotation
|
||||
@Target(PARAMETER)
|
||||
@Retention(RUNTIME)
|
||||
public @interface AgentId {
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.module;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
@BindingAnnotation
|
||||
@Target(PARAMETER)
|
||||
@Retention(RUNTIME)
|
||||
public @interface AgentServiceType {
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.module;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
@BindingAnnotation
|
||||
@Target(PARAMETER)
|
||||
@Retention(RUNTIME)
|
||||
public @interface AgentStartTime {
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.module;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
@BindingAnnotation
|
||||
@Target(PARAMETER)
|
||||
@Retention(RUNTIME)
|
||||
public @interface ApplicationName {
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.module;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
@BindingAnnotation
|
||||
@Target(PARAMETER)
|
||||
@Retention(RUNTIME)
|
||||
public @interface BootstrapJarPaths {
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.module;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
@BindingAnnotation
|
||||
@Target(PARAMETER)
|
||||
@Retention(RUNTIME)
|
||||
public @interface PluginJars {
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.module;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
@BindingAnnotation
|
||||
@Target(PARAMETER)
|
||||
@Retention(RUNTIME)
|
||||
public @interface SpanDataSender {
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.module;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
@BindingAnnotation
|
||||
@Target(PARAMETER)
|
||||
@Retention(RUNTIME)
|
||||
public @interface StatDataSender {
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class ActiveTraceRepositoryProvider implements Provider<ActiveTraceRepository> {
|
||||
|
||||
private final ProfilerConfig profilerConfig;
|
||||
|
||||
@Inject
|
||||
private ActiveTraceRepositoryProvider(ProfilerConfig profilerConfig) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
}
|
||||
this.profilerConfig = profilerConfig;
|
||||
}
|
||||
|
||||
public ActiveTraceRepository get() {
|
||||
if (profilerConfig.isTraceAgentActiveThread()) {
|
||||
return new ActiveTraceRepository();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.AgentInfoSender;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.JvmInformation;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class AgentInfoSenderProvider implements Provider<AgentInfoSender> {
|
||||
|
||||
private final ProfilerConfig profilerConfig;
|
||||
private final EnhancedDataSender enhancedDataSender;
|
||||
private final AgentInformation agentInformation;
|
||||
private final JvmInformation jvmInformation;
|
||||
|
||||
@Inject
|
||||
public AgentInfoSenderProvider(ProfilerConfig profilerConfig, EnhancedDataSender enhancedDataSender, AgentInformation agentInformation, JvmInformation jvmInformation) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
}
|
||||
if (enhancedDataSender == null) {
|
||||
throw new NullPointerException("enhancedDataSender must not be null");
|
||||
}
|
||||
if (agentInformation == null) {
|
||||
throw new NullPointerException("agentInformation must not be null");
|
||||
}
|
||||
if (jvmInformation == null) {
|
||||
throw new NullPointerException("jvmInformation must not be null");
|
||||
}
|
||||
|
||||
this.profilerConfig = profilerConfig;
|
||||
this.enhancedDataSender = enhancedDataSender;
|
||||
this.agentInformation = agentInformation;
|
||||
this.jvmInformation = jvmInformation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentInfoSender get() {
|
||||
final AgentInfoSender.Builder builder = new AgentInfoSender.Builder(this.enhancedDataSender, this.agentInformation, jvmInformation);
|
||||
builder.sendInterval(profilerConfig.getAgentInfoSendRetryInterval());
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformationFactory;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgentInformationFactory;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentId;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentServiceType;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentStartTime;
|
||||
import com.navercorp.pinpoint.profiler.context.module.ApplicationName;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class AgentInformationProvider implements Provider<AgentInformation> {
|
||||
|
||||
private final String agentId;
|
||||
private final String applicationName;
|
||||
private final long agentStartTime;
|
||||
private final ServiceType serverType;
|
||||
|
||||
@Inject
|
||||
public AgentInformationProvider(@AgentId String agentId, @ApplicationName String applicationName, @AgentStartTime long agentStartTime, @AgentServiceType ServiceType serverType) {
|
||||
if (agentId == null) {
|
||||
throw new NullPointerException("agentId must not be null");
|
||||
}
|
||||
if (applicationName == null) {
|
||||
throw new NullPointerException("applicationName must not be null");
|
||||
}
|
||||
if (serverType == null) {
|
||||
throw new NullPointerException("serverType must not be null");
|
||||
}
|
||||
|
||||
this.agentId = agentId;
|
||||
this.applicationName = applicationName;
|
||||
this.agentStartTime = agentStartTime;
|
||||
this.serverType = serverType;
|
||||
|
||||
}
|
||||
|
||||
public AgentInformation get() {
|
||||
AgentInformationFactory agentInformationFactory = new DefaultAgentInformationFactory(agentId, applicationName, agentStartTime, serverType);
|
||||
return agentInformationFactory.createAgentInformation();
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.common.service.ServiceTypeRegistryService;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class AgentServiceTypeProvider implements Provider<ServiceType> {
|
||||
|
||||
private final ProfilerConfig profilerConfig;
|
||||
private final ServiceTypeRegistryService serviceTypeRegistryService;
|
||||
|
||||
@Inject
|
||||
public AgentServiceTypeProvider(ProfilerConfig profilerConfig, ServiceTypeRegistryService serviceTypeRegistryService) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
}
|
||||
if (serviceTypeRegistryService == null) {
|
||||
throw new NullPointerException("serviceTypeRegistryService must not be null");
|
||||
}
|
||||
this.profilerConfig = profilerConfig;
|
||||
this.serviceTypeRegistryService = serviceTypeRegistryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceType get() {
|
||||
String applicationServerTypeString = profilerConfig.getApplicationServerType();
|
||||
return this.serviceTypeRegistryService.findServiceTypeByName(applicationServerTypeString);
|
||||
}
|
||||
}
|
||||
+10
-12
@@ -14,26 +14,24 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.test;
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.context.provider.Provider;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class DelegateProvider<T> implements Provider<T> {
|
||||
private final T delegate;
|
||||
public class AgentStartTimeProvider implements Provider<Long> {
|
||||
|
||||
public DelegateProvider(T delegate) {
|
||||
if (delegate == null) {
|
||||
throw new NullPointerException("delegate must not be null");
|
||||
}
|
||||
|
||||
this.delegate = delegate;
|
||||
@Inject
|
||||
public AgentStartTimeProvider() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
return delegate;
|
||||
public Long get() {
|
||||
return RuntimeMXBeanUtils.getVmStartTime();
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentServiceType;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginContextLoadResult;
|
||||
import com.navercorp.pinpoint.profiler.util.ApplicationServerTypeResolver;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class ApplicationServerTypeResolverProvider implements Provider<ApplicationServerTypeResolver> {
|
||||
|
||||
private final PluginContextLoadResult pluginContextLoadResult;
|
||||
private final ServiceType serviceType;
|
||||
private final ProfilerConfig profilerConfig;
|
||||
|
||||
@Inject
|
||||
public ApplicationServerTypeResolverProvider(PluginContextLoadResult pluginContextLoadResult, @AgentServiceType ServiceType serviceType, ProfilerConfig profilerConfig) {
|
||||
if (pluginContextLoadResult == null) {
|
||||
throw new NullPointerException("pluginContextLoadResult must not be null");
|
||||
}
|
||||
if (serviceType == null) {
|
||||
throw new NullPointerException("serviceType must not be null");
|
||||
}
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
}
|
||||
this.pluginContextLoadResult = pluginContextLoadResult;
|
||||
this.serviceType = serviceType;
|
||||
this.profilerConfig = profilerConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationServerTypeResolver get() {
|
||||
return new ApplicationServerTypeResolver(pluginContextLoadResult, serviceType, profilerConfig.getApplicationTypeDetectOrder());
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.navercorp.pinpoint.profiler.ClassFileTransformerDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.DefaultClassFileTransformerDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginContextLoadResult;
|
||||
|
||||
import javax.inject.Provider;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class ClassFileTransformerDispatcherProvider implements Provider<ClassFileTransformerDispatcher> {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
private final PluginContextLoadResult pluginContextLoadResult;
|
||||
|
||||
@Inject
|
||||
public ClassFileTransformerDispatcherProvider(ApplicationContext applicationContext, PluginContextLoadResult pluginContextLoadResult) {
|
||||
if (applicationContext == null) {
|
||||
throw new NullPointerException("applicationContext must not be null");
|
||||
}
|
||||
if (pluginContextLoadResult == null) {
|
||||
throw new NullPointerException("pluginContextLoadResult must not be null");
|
||||
}
|
||||
this.applicationContext = applicationContext;
|
||||
this.pluginContextLoadResult = pluginContextLoadResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassFileTransformerDispatcher get() {
|
||||
return new DefaultClassFileTransformerDispatcher(applicationContext, pluginContextLoadResult);
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.ClassFileTransformerDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.instrument.ASMBytecodeDumpService;
|
||||
import com.navercorp.pinpoint.profiler.instrument.BytecodeDumpTransformer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class ClassFileTransformerWrapProvider implements Provider<ClassFileTransformer> {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final ProfilerConfig profilerConfig;
|
||||
private final ClassFileTransformerDispatcher classFileTransformerDispatcher;
|
||||
|
||||
@Inject
|
||||
public ClassFileTransformerWrapProvider(ProfilerConfig profilerConfig, ClassFileTransformerDispatcher classFileTransformerDispatcher) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
}
|
||||
if (classFileTransformerDispatcher == null) {
|
||||
throw new NullPointerException("classFileTransformerDispatcher must not be null");
|
||||
}
|
||||
|
||||
this.profilerConfig = profilerConfig;
|
||||
this.classFileTransformerDispatcher = classFileTransformerDispatcher;
|
||||
}
|
||||
|
||||
|
||||
public ClassFileTransformer get() {
|
||||
final boolean enableBytecodeDump = profilerConfig.readBoolean(ASMBytecodeDumpService.ENABLE_BYTECODE_DUMP, ASMBytecodeDumpService.ENABLE_BYTECODE_DUMP_DEFAULT_VALUE);
|
||||
if (enableBytecodeDump) {
|
||||
logger.info("wrapBytecodeDumpTransformer");
|
||||
return BytecodeDumpTransformer.wrap(classFileTransformerDispatcher, profilerConfig);
|
||||
}
|
||||
return classFileTransformerDispatcher;
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository;
|
||||
import com.navercorp.pinpoint.profiler.receiver.CommandDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandLocatorBuilder;
|
||||
import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandServiceLocator;
|
||||
import com.navercorp.pinpoint.profiler.receiver.service.ActiveThreadService;
|
||||
import com.navercorp.pinpoint.profiler.receiver.service.EchoService;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class CommandDispatcherProvider implements Provider<CommandDispatcher> {
|
||||
|
||||
private final ProfilerConfig profilerConfig;
|
||||
private final ActiveTraceRepository activeTraceRepository;
|
||||
|
||||
@Inject
|
||||
public CommandDispatcherProvider(ProfilerConfig profilerConfig, ActiveTraceRepository activeTraceRepository) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
}
|
||||
if (activeTraceRepository == null) {
|
||||
throw new NullPointerException("activeTraceRepository must not be null");
|
||||
}
|
||||
this.profilerConfig = profilerConfig;
|
||||
this.activeTraceRepository = activeTraceRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandDispatcher get() {
|
||||
ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder();
|
||||
builder.addService(new EchoService());
|
||||
if (activeTraceRepository != null) {
|
||||
ActiveThreadService activeThreadService = new ActiveThreadService(profilerConfig, activeTraceRepository);
|
||||
builder.addService(activeThreadService);
|
||||
}
|
||||
|
||||
ProfilerCommandServiceLocator commandServiceLocator = builder.build();
|
||||
CommandDispatcher commandDispatcher = new CommandDispatcher(commandServiceLocator);
|
||||
return commandDispatcher;
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.DynamicTransformTrigger;
|
||||
import com.navercorp.pinpoint.profiler.ClassFileTransformerDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.DynamicTransformService;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class DynamicTransformTriggerProvider implements Provider<DynamicTransformTrigger> {
|
||||
|
||||
private final Instrumentation instrumentation;
|
||||
private final ClassFileTransformerDispatcher listener;
|
||||
|
||||
@Inject
|
||||
public DynamicTransformTriggerProvider(Instrumentation instrumentation, ClassFileTransformerDispatcher listener) {
|
||||
if (instrumentation == null) {
|
||||
throw new NullPointerException("instrumentation must not be null");
|
||||
}
|
||||
if (listener == null) {
|
||||
throw new NullPointerException("listener must not be null");
|
||||
}
|
||||
|
||||
this.instrumentation = instrumentation;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DynamicTransformTrigger get() {
|
||||
|
||||
return new DynamicTransformService(instrumentation, listener);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.AgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClassPool;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.instrument.ASMClassPool;
|
||||
import com.navercorp.pinpoint.profiler.instrument.JavassistClassPool;
|
||||
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class InstrumentEngineProvider implements Provider<InstrumentClassPool> {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final ProfilerConfig profilerConfig;
|
||||
private final AgentOption agentOption;
|
||||
private final InterceptorRegistryBinder interceptorRegistryBinder;
|
||||
|
||||
@Inject
|
||||
public InstrumentEngineProvider(ProfilerConfig profilerConfig, AgentOption agentOption, InterceptorRegistryBinder interceptorRegistryBinder) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
}
|
||||
if (agentOption == null) {
|
||||
throw new NullPointerException("agentOption must not be null");
|
||||
}
|
||||
if (interceptorRegistryBinder == null) {
|
||||
throw new NullPointerException("interceptorRegistryBinder must not be null");
|
||||
}
|
||||
|
||||
this.profilerConfig = profilerConfig;
|
||||
this.agentOption = agentOption;
|
||||
this.interceptorRegistryBinder = interceptorRegistryBinder;
|
||||
}
|
||||
|
||||
public InstrumentClassPool get() {
|
||||
final String instrumentEngine = profilerConfig.getProfileInstrumentEngine().toUpperCase();
|
||||
|
||||
if (DefaultProfilerConfig.INSTRUMENT_ENGINE_ASM.equals(instrumentEngine)) {
|
||||
logger.info("ASM InstrumentEngine.");
|
||||
|
||||
return new ASMClassPool(interceptorRegistryBinder, agentOption.getBootstrapJarPaths());
|
||||
|
||||
} else if (DefaultProfilerConfig.INSTRUMENT_ENGINE_JAVASSIST.equals(instrumentEngine)) {
|
||||
logger.info("JAVASSIST InstrumentEngine.");
|
||||
|
||||
return new JavassistClassPool(interceptorRegistryBinder, agentOption.getBootstrapJarPaths());
|
||||
} else {
|
||||
logger.warn("Unknown InstrumentEngine:{}", instrumentEngine);
|
||||
|
||||
throw new IllegalArgumentException("Unknown InstrumentEngine:" + instrumentEngine);
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-8
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -14,26 +14,36 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler;
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.JvmInformation;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.AgentStatCollectorFactory;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.GarbageCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.UnknownGarbageCollector;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
*/
|
||||
public class JvmInformationFactory {
|
||||
public class JvmInformationProvider implements Provider<JvmInformation> {
|
||||
|
||||
private final String jvmVersion;
|
||||
private final GarbageCollector garbageCollector;
|
||||
|
||||
JvmInformationFactory() {
|
||||
this(null);
|
||||
|
||||
@Inject
|
||||
public JvmInformationProvider(AgentStatCollectorFactory garbageCollector) {
|
||||
this(garbageCollector.getGarbageCollector());
|
||||
}
|
||||
|
||||
public JvmInformationFactory(GarbageCollector garbageCollector) {
|
||||
public JvmInformationProvider() {
|
||||
this((GarbageCollector)null);
|
||||
}
|
||||
|
||||
public JvmInformationProvider(GarbageCollector garbageCollector) {
|
||||
this.jvmVersion = JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION);
|
||||
if (garbageCollector == null) {
|
||||
this.garbageCollector = new UnknownGarbageCollector();
|
||||
@@ -42,7 +52,7 @@ public class JvmInformationFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public JvmInformation createJvmInformation() {
|
||||
public JvmInformation get() {
|
||||
return new JvmInformation(this.jvmVersion, this.garbageCollector.getTypeCode());
|
||||
}
|
||||
}
|
||||
+3
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.receiver.CommandDispatcher;
|
||||
@@ -34,6 +36,7 @@ public class PinpointClientFactoryProvider implements Provider<PinpointClientFac
|
||||
private final AgentInformation agentInformation;
|
||||
private final CommandDispatcher commandDispatcher;
|
||||
|
||||
@Inject
|
||||
public PinpointClientFactoryProvider(ProfilerConfig profilerConfig, AgentInformation agentInformation, CommandDispatcher commandDispatcher) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
|
||||
+3
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClient;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClientFactory;
|
||||
@@ -28,6 +30,7 @@ public class PinpointClientProvider implements Provider<PinpointClient> {
|
||||
private final ProfilerConfig profilerConfig;
|
||||
private final PinpointClientFactory clientFactory;
|
||||
|
||||
@Inject
|
||||
public PinpointClientProvider(ProfilerConfig profilerConfig, PinpointClientFactory clientFactory) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClassPool;
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.context.module.BootstrapJarPaths;
|
||||
import com.navercorp.pinpoint.profiler.context.module.PluginJars;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultPluginContextLoadResult;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultProfilerPluginContext;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginContextLoadResult;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginSetup;
|
||||
import com.navercorp.pinpoint.profiler.plugin.ProfilerPluginLoader;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class PluginContextLoadResultProvider implements Provider<PluginContextLoadResult> {
|
||||
|
||||
|
||||
private final URL[] pluginJars;
|
||||
private final PluginSetup pluginSetup;
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
@Inject
|
||||
public PluginContextLoadResultProvider(ApplicationContext applicationContext, @PluginJars URL[] pluginJars, PluginSetup pluginSetup) {
|
||||
if (applicationContext == null) {
|
||||
throw new NullPointerException("applicationContext must not be null");
|
||||
}
|
||||
if (pluginJars == null) {
|
||||
throw new NullPointerException("pluginJars must not be null");
|
||||
}
|
||||
if (pluginSetup == null) {
|
||||
throw new NullPointerException("pluginSetup must not be null");
|
||||
}
|
||||
this.applicationContext = applicationContext;
|
||||
this.pluginJars = pluginJars;
|
||||
this.pluginSetup = pluginSetup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginContextLoadResult get() {
|
||||
final ProfilerPluginLoader loader = new ProfilerPluginLoader(applicationContext, pluginSetup);
|
||||
List<DefaultProfilerPluginContext> load = loader.load(pluginJars);
|
||||
return new DefaultPluginContextLoadResult(load);
|
||||
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.DefaultPluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.DisabledPluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.PluginMonitorContext;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class PluginMonitorContextProvider implements Provider<PluginMonitorContext> {
|
||||
|
||||
private final boolean traceAgentDataSource;
|
||||
|
||||
@Inject
|
||||
public PluginMonitorContextProvider(ProfilerConfig profilerConfig) {
|
||||
this(profilerConfig.isTraceAgentDataSource());
|
||||
}
|
||||
|
||||
public PluginMonitorContextProvider(boolean traceAgentDataSource) {
|
||||
this.traceAgentDataSource = traceAgentDataSource;
|
||||
}
|
||||
|
||||
|
||||
public PluginMonitorContext get() {
|
||||
if (traceAgentDataSource) {
|
||||
return new DefaultPluginMonitorContext();
|
||||
}
|
||||
|
||||
return new DisabledPluginMonitorContext();
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultPluginSetup;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginSetup;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class PluginSetupProvider implements Provider<PluginSetup> {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Inject
|
||||
public PluginSetupProvider(ApplicationContext applicationContext) {
|
||||
if (applicationContext == null) {
|
||||
throw new NullPointerException("applicationContext must not be null");
|
||||
}
|
||||
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginSetup get() {
|
||||
return new DefaultPluginSetup(applicationContext);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.sampler.Sampler;
|
||||
import com.navercorp.pinpoint.profiler.sampler.SamplerFactory;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class SamplerProvider implements Provider<Sampler> {
|
||||
|
||||
private final ProfilerConfig profilerConfig;
|
||||
|
||||
@Inject
|
||||
public SamplerProvider(ProfilerConfig profilerConfig) {
|
||||
this.profilerConfig = profilerConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sampler get() {
|
||||
boolean samplingEnable = profilerConfig.isSamplingEnable();
|
||||
int samplingRate = profilerConfig.getSamplingRate();
|
||||
|
||||
SamplerFactory samplerFactory = new SamplerFactory();
|
||||
return samplerFactory.createSampler(samplingEnable, samplingRate);
|
||||
}
|
||||
}
|
||||
+11
@@ -16,7 +16,10 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.profiler.AgentInfoSender;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
|
||||
|
||||
@@ -27,10 +30,18 @@ import java.util.List;
|
||||
*/
|
||||
public class ServerMetaDataHolderProvider implements Provider<ServerMetaDataHolder> {
|
||||
|
||||
private final AgentInfoSender agentInfoSender;
|
||||
|
||||
@Inject
|
||||
public ServerMetaDataHolderProvider(AgentInfoSender agentInfoSender) {
|
||||
this.agentInfoSender = agentInfoSender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerMetaDataHolder get() {
|
||||
List<String> vmArgs = RuntimeMXBeanUtils.getVmArgs();
|
||||
ServerMetaDataHolder serverMetaDataHolder = new DefaultServerMetaDataHolder(vmArgs);
|
||||
serverMetaDataHolder.addListener(agentInfoSender);
|
||||
return serverMetaDataHolder;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -16,8 +16,11 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.module.SpanDataSender;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.BufferedStorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.SpanStorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
|
||||
@@ -32,7 +35,8 @@ public class StorageFactoryProvider implements Provider<StorageFactory> {
|
||||
private final DataSender spanDataSender;
|
||||
private final AgentInformation agentInformation;
|
||||
|
||||
public StorageFactoryProvider(ProfilerConfig profilerConfig, DataSender spanDataSender, AgentInformation agentInformation) {
|
||||
@Inject
|
||||
public StorageFactoryProvider(ProfilerConfig profilerConfig, @SpanDataSender DataSender spanDataSender, AgentInformation agentInformation) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
}
|
||||
|
||||
+3
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.profiler.sender.TcpDataSender;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClient;
|
||||
@@ -26,6 +28,7 @@ import com.navercorp.pinpoint.rpc.client.PinpointClient;
|
||||
public class TcpDataSenderProvider implements Provider<EnhancedDataSender> {
|
||||
private final PinpointClient client;
|
||||
|
||||
@Inject
|
||||
public TcpDataSenderProvider(PinpointClient client) {
|
||||
if (client == null) {
|
||||
throw new NullPointerException("client must not be null");
|
||||
|
||||
+3
-1
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.profiler.sender.UdpDataSenderFactory;
|
||||
@@ -34,7 +36,7 @@ public class UdpSpanDataSenderProvider implements Provider<DataSender> {
|
||||
private final int sendBufferSize;
|
||||
private final String senderType;
|
||||
|
||||
|
||||
@Inject
|
||||
public UdpSpanDataSenderProvider(ProfilerConfig profilerConfig) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
|
||||
+3
-1
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.profiler.sender.UdpDataSenderFactory;
|
||||
@@ -34,7 +36,7 @@ public class UdpStatDataSenderProvider implements Provider<DataSender> {
|
||||
private final int sendBufferSize;
|
||||
private final String senderType;
|
||||
|
||||
|
||||
@Inject
|
||||
public UdpStatDataSenderProvider(ProfilerConfig profilerConfig) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
|
||||
+6
-1
@@ -16,7 +16,11 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.metadata;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentId;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentStartTime;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.thrift.dto.TApiMetaData;
|
||||
|
||||
@@ -31,7 +35,8 @@ public class ApiMetaDataCacheService implements ApiMetaDataService {
|
||||
private final long agentStartTime;
|
||||
private final EnhancedDataSender enhancedDataSender;
|
||||
|
||||
public ApiMetaDataCacheService(String agentId, long agentStartTime, EnhancedDataSender enhancedDataSender) {
|
||||
@Inject
|
||||
public ApiMetaDataCacheService(@AgentId String agentId, @AgentStartTime long agentStartTime, EnhancedDataSender enhancedDataSender) {
|
||||
if (agentId == null) {
|
||||
throw new NullPointerException("agentId must not be null");
|
||||
}
|
||||
|
||||
+10
@@ -16,9 +16,13 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.metadata;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ParsingResult;
|
||||
import com.navercorp.pinpoint.profiler.context.CachingSqlNormalizer;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultCachingSqlNormalizer;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentId;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentStartTime;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.thrift.dto.TSqlMetaData;
|
||||
import org.slf4j.Logger;
|
||||
@@ -38,6 +42,12 @@ public class SqlMetaDataCacheService implements SqlMetaDataService {
|
||||
private final long agentStartTime;
|
||||
private final EnhancedDataSender enhancedDataSender;
|
||||
|
||||
@Inject
|
||||
public SqlMetaDataCacheService(ProfilerConfig profilerConfig, @AgentId String agentId,
|
||||
@AgentStartTime long agentStartTime, EnhancedDataSender enhancedDataSender) {
|
||||
this(agentId, agentStartTime, enhancedDataSender, profilerConfig.getJdbcSqlCacheSize());
|
||||
}
|
||||
|
||||
public SqlMetaDataCacheService(String agentId, long agentStartTime, EnhancedDataSender enhancedDataSender, int jdbcSqlCacheSize) {
|
||||
if (agentId == null) {
|
||||
throw new NullPointerException("agentId must not be null");
|
||||
|
||||
+6
-1
@@ -16,6 +16,10 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.metadata;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentId;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentStartTime;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.thrift.dto.TStringMetaData;
|
||||
|
||||
@@ -30,7 +34,8 @@ public class StringMetaDataCacheService implements StringMetaDataService {
|
||||
private final long agentStartTime;
|
||||
private final EnhancedDataSender enhancedDataSender;
|
||||
|
||||
public StringMetaDataCacheService(String agentId, long agentStartTime, EnhancedDataSender enhancedDataSender) {
|
||||
@Inject
|
||||
public StringMetaDataCacheService(@AgentId String agentId, @AgentStartTime long agentStartTime, EnhancedDataSender enhancedDataSender) {
|
||||
if (agentId == null) {
|
||||
throw new NullPointerException("agentId must not be null");
|
||||
}
|
||||
|
||||
+6
-164
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,169 +16,11 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.monitor;
|
||||
|
||||
import com.navercorp.pinpoint.common.util.PinpointThreadFactory;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.AgentStatCollectorFactory;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.activetrace.ActiveTraceMetricCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.cpu.CpuLoadCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.datasource.DataSourceCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.GarbageCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.tps.TransactionMetricCollector;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.thrift.dto.TActiveTrace;
|
||||
import com.navercorp.pinpoint.thrift.dto.TAgentStat;
|
||||
import com.navercorp.pinpoint.thrift.dto.TAgentStatBatch;
|
||||
import com.navercorp.pinpoint.thrift.dto.TCpuLoad;
|
||||
import com.navercorp.pinpoint.thrift.dto.TDataSourceList;
|
||||
import com.navercorp.pinpoint.thrift.dto.TJvmGc;
|
||||
import com.navercorp.pinpoint.thrift.dto.TTransaction;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* AgentStat monitor
|
||||
*
|
||||
* @author harebox
|
||||
* @author hyungil.jeong
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class AgentStatMonitor {
|
||||
|
||||
private static final long DEFAULT_COLLECTION_INTERVAL_MS = 1000 * 5;
|
||||
private static final int DEFAULT_NUM_COLLECTIONS_PER_SEND = 6;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isTrace = logger.isTraceEnabled();
|
||||
private final long collectionIntervalMs;
|
||||
private final int numCollectionsPerBatch;
|
||||
|
||||
private final ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1, new PinpointThreadFactory("Pinpoint-stat-monitor", true));
|
||||
|
||||
private final DataSender dataSender;
|
||||
private final String agentId;
|
||||
private final AgentStatCollectorFactory agentStatCollectorFactory;
|
||||
private final long agentStartTime;
|
||||
|
||||
public AgentStatMonitor(DataSender dataSender, String agentId, long startTime, AgentStatCollectorFactory agentStatCollectorFactory) {
|
||||
this(dataSender, agentId, startTime, agentStatCollectorFactory, DEFAULT_COLLECTION_INTERVAL_MS, DEFAULT_NUM_COLLECTIONS_PER_SEND);
|
||||
}
|
||||
|
||||
public AgentStatMonitor(DataSender dataSender, String agentId, long startTime, AgentStatCollectorFactory agentStatCollectorFactory, long collectionInterval, int numCollectionsPerBatch) {
|
||||
if (dataSender == null) {
|
||||
throw new NullPointerException("dataSender must not be null");
|
||||
}
|
||||
if (agentId == null) {
|
||||
throw new NullPointerException("agentId must not be null");
|
||||
}
|
||||
if (agentStatCollectorFactory == null) {
|
||||
throw new NullPointerException("agentStatCollectorFactory must not be null");
|
||||
}
|
||||
this.dataSender = dataSender;
|
||||
this.agentId = agentId;
|
||||
this.agentStartTime = startTime;
|
||||
this.agentStatCollectorFactory = agentStatCollectorFactory;
|
||||
this.collectionIntervalMs = collectionInterval;
|
||||
this.numCollectionsPerBatch = numCollectionsPerBatch;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
CollectJob job = new CollectJob(this.numCollectionsPerBatch);
|
||||
executor.scheduleAtFixedRate(job, this.collectionIntervalMs, this.collectionIntervalMs, TimeUnit.MILLISECONDS);
|
||||
logger.info("AgentStat monitor started");
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
executor.shutdown();
|
||||
try {
|
||||
executor.awaitTermination(3000, TimeUnit.MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
logger.info("AgentStat monitor stopped");
|
||||
}
|
||||
|
||||
// NotThreadSafe
|
||||
private class CollectJob implements Runnable {
|
||||
|
||||
private final GarbageCollector garbageCollector;
|
||||
private final CpuLoadCollector cpuLoadCollector;
|
||||
private final TransactionMetricCollector transactionMetricCollector;
|
||||
private final ActiveTraceMetricCollector activeTraceMetricCollector;
|
||||
private final DataSourceCollector dataSourceCollector;
|
||||
|
||||
// Not thread safe. For use with single thread ONLY
|
||||
private final int numStatsPerBatch;
|
||||
private int collectCount = 0;
|
||||
private long prevCollectionTimestamp = System.currentTimeMillis();
|
||||
private List<TAgentStat> agentStats;
|
||||
|
||||
private CollectJob(int numStatsPerBatch) {
|
||||
this.garbageCollector = agentStatCollectorFactory.getGarbageCollector();
|
||||
this.cpuLoadCollector = agentStatCollectorFactory.getCpuLoadCollector();
|
||||
this.transactionMetricCollector = agentStatCollectorFactory.getTransactionMetricCollector();
|
||||
this.activeTraceMetricCollector = agentStatCollectorFactory.getActiveTraceMetricCollector();
|
||||
this.dataSourceCollector = agentStatCollectorFactory.getDataSourceCollector();
|
||||
this.numStatsPerBatch = numStatsPerBatch;
|
||||
this.agentStats = new ArrayList<TAgentStat>(this.numStatsPerBatch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final long currentCollectionTimestamp = System.currentTimeMillis();
|
||||
final long collectInterval = currentCollectionTimestamp - this.prevCollectionTimestamp;
|
||||
try {
|
||||
final TAgentStat agentStat = collectAgentStat();
|
||||
agentStat.setTimestamp(currentCollectionTimestamp);
|
||||
agentStat.setCollectInterval(collectInterval);
|
||||
this.agentStats.add(agentStat);
|
||||
if (++this.collectCount >= this.numStatsPerBatch) {
|
||||
sendAgentStats();
|
||||
this.collectCount = 0;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.warn("AgentStat collect failed. Caused:{}", ex.getMessage(), ex);
|
||||
} finally {
|
||||
this.prevCollectionTimestamp = currentCollectionTimestamp;
|
||||
}
|
||||
}
|
||||
|
||||
private TAgentStat collectAgentStat() {
|
||||
final TAgentStat agentStat = new TAgentStat();
|
||||
final TJvmGc gc = garbageCollector.collect();
|
||||
agentStat.setGc(gc);
|
||||
final TCpuLoad cpuLoad = cpuLoadCollector.collect();
|
||||
agentStat.setCpuLoad(cpuLoad);
|
||||
final TTransaction transaction = transactionMetricCollector.collect();
|
||||
agentStat.setTransaction(transaction);
|
||||
final TActiveTrace activeTrace = activeTraceMetricCollector.collect();
|
||||
agentStat.setActiveTrace(activeTrace);
|
||||
final TDataSourceList dataSourceList = dataSourceCollector.collect();
|
||||
agentStat.setDataSourceList(dataSourceList);
|
||||
|
||||
return agentStat;
|
||||
}
|
||||
|
||||
private void sendAgentStats() {
|
||||
// prepare TAgentStat object.
|
||||
// TODO multi thread issue.
|
||||
// If we reuse TAgentStat, there could be concurrency issue because data sender runs in a different thread.
|
||||
final TAgentStatBatch agentStatBatch = new TAgentStatBatch();
|
||||
agentStatBatch.setAgentId(agentId);
|
||||
agentStatBatch.setStartTimestamp(agentStartTime);
|
||||
agentStatBatch.setAgentStats(this.agentStats);
|
||||
// If we reuse agentStats list, there could be concurrency issue because data sender runs in a different
|
||||
// thread.
|
||||
// So create new list.
|
||||
this.agentStats = new ArrayList<TAgentStat>(this.numStatsPerBatch);
|
||||
if (isTrace) {
|
||||
logger.trace("collect agentStat:{}", agentStatBatch);
|
||||
}
|
||||
dataSender.send(agentStatBatch);
|
||||
}
|
||||
}
|
||||
public interface AgentStatMonitor {
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
}
|
||||
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.monitor;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.navercorp.pinpoint.common.util.PinpointThreadFactory;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentId;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentStartTime;
|
||||
import com.navercorp.pinpoint.profiler.context.module.StatDataSender;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.AgentStatCollectorFactory;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.activetrace.ActiveTraceMetricCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.cpu.CpuLoadCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.datasource.DataSourceCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.GarbageCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.tps.TransactionMetricCollector;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.thrift.dto.TActiveTrace;
|
||||
import com.navercorp.pinpoint.thrift.dto.TAgentStat;
|
||||
import com.navercorp.pinpoint.thrift.dto.TAgentStatBatch;
|
||||
import com.navercorp.pinpoint.thrift.dto.TCpuLoad;
|
||||
import com.navercorp.pinpoint.thrift.dto.TDataSourceList;
|
||||
import com.navercorp.pinpoint.thrift.dto.TJvmGc;
|
||||
import com.navercorp.pinpoint.thrift.dto.TTransaction;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* AgentStat monitor
|
||||
*
|
||||
* @author harebox
|
||||
* @author hyungil.jeong
|
||||
*/
|
||||
public class DefaultAgentStatMonitor implements AgentStatMonitor {
|
||||
|
||||
private static final long DEFAULT_COLLECTION_INTERVAL_MS = 1000 * 5;
|
||||
private static final int DEFAULT_NUM_COLLECTIONS_PER_SEND = 6;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isTrace = logger.isTraceEnabled();
|
||||
private final long collectionIntervalMs;
|
||||
private final int numCollectionsPerBatch;
|
||||
|
||||
private final ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1, new PinpointThreadFactory("Pinpoint-stat-monitor", true));
|
||||
|
||||
private final DataSender dataSender;
|
||||
private final String agentId;
|
||||
private final AgentStatCollectorFactory agentStatCollectorFactory;
|
||||
private final long agentStartTime;
|
||||
|
||||
@Inject
|
||||
public DefaultAgentStatMonitor(@StatDataSender DataSender dataSender, @AgentId String agentId, @AgentStartTime long startTime, AgentStatCollectorFactory agentStatCollectorFactory) {
|
||||
this(dataSender, agentId, startTime, agentStatCollectorFactory, DEFAULT_COLLECTION_INTERVAL_MS, DEFAULT_NUM_COLLECTIONS_PER_SEND);
|
||||
}
|
||||
|
||||
public DefaultAgentStatMonitor(DataSender dataSender, String agentId, long startTime, AgentStatCollectorFactory agentStatCollectorFactory, long collectionInterval, int numCollectionsPerBatch) {
|
||||
if (dataSender == null) {
|
||||
throw new NullPointerException("dataSender must not be null");
|
||||
}
|
||||
if (agentId == null) {
|
||||
throw new NullPointerException("agentId must not be null");
|
||||
}
|
||||
if (agentStatCollectorFactory == null) {
|
||||
throw new NullPointerException("agentStatCollectorFactory must not be null");
|
||||
}
|
||||
this.dataSender = dataSender;
|
||||
this.agentId = agentId;
|
||||
this.agentStartTime = startTime;
|
||||
this.agentStatCollectorFactory = agentStatCollectorFactory;
|
||||
this.collectionIntervalMs = collectionInterval;
|
||||
this.numCollectionsPerBatch = numCollectionsPerBatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
CollectJob job = new CollectJob(this.numCollectionsPerBatch);
|
||||
executor.scheduleAtFixedRate(job, this.collectionIntervalMs, this.collectionIntervalMs, TimeUnit.MILLISECONDS);
|
||||
logger.info("AgentStat monitor started");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
executor.shutdown();
|
||||
try {
|
||||
executor.awaitTermination(3000, TimeUnit.MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
logger.info("AgentStat monitor stopped");
|
||||
}
|
||||
|
||||
// NotThreadSafe
|
||||
private class CollectJob implements Runnable {
|
||||
|
||||
private final GarbageCollector garbageCollector;
|
||||
private final CpuLoadCollector cpuLoadCollector;
|
||||
private final TransactionMetricCollector transactionMetricCollector;
|
||||
private final ActiveTraceMetricCollector activeTraceMetricCollector;
|
||||
private final DataSourceCollector dataSourceCollector;
|
||||
|
||||
// Not thread safe. For use with single thread ONLY
|
||||
private final int numStatsPerBatch;
|
||||
private int collectCount = 0;
|
||||
private long prevCollectionTimestamp = System.currentTimeMillis();
|
||||
private List<TAgentStat> agentStats;
|
||||
|
||||
private CollectJob(int numStatsPerBatch) {
|
||||
this.garbageCollector = agentStatCollectorFactory.getGarbageCollector();
|
||||
this.cpuLoadCollector = agentStatCollectorFactory.getCpuLoadCollector();
|
||||
this.transactionMetricCollector = agentStatCollectorFactory.getTransactionMetricCollector();
|
||||
this.activeTraceMetricCollector = agentStatCollectorFactory.getActiveTraceMetricCollector();
|
||||
this.dataSourceCollector = agentStatCollectorFactory.getDataSourceCollector();
|
||||
this.numStatsPerBatch = numStatsPerBatch;
|
||||
this.agentStats = new ArrayList<TAgentStat>(this.numStatsPerBatch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final long currentCollectionTimestamp = System.currentTimeMillis();
|
||||
final long collectInterval = currentCollectionTimestamp - this.prevCollectionTimestamp;
|
||||
try {
|
||||
final TAgentStat agentStat = collectAgentStat();
|
||||
agentStat.setTimestamp(currentCollectionTimestamp);
|
||||
agentStat.setCollectInterval(collectInterval);
|
||||
this.agentStats.add(agentStat);
|
||||
if (++this.collectCount >= this.numStatsPerBatch) {
|
||||
sendAgentStats();
|
||||
this.collectCount = 0;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.warn("AgentStat collect failed. Caused:{}", ex.getMessage(), ex);
|
||||
} finally {
|
||||
this.prevCollectionTimestamp = currentCollectionTimestamp;
|
||||
}
|
||||
}
|
||||
|
||||
private TAgentStat collectAgentStat() {
|
||||
final TAgentStat agentStat = new TAgentStat();
|
||||
final TJvmGc gc = garbageCollector.collect();
|
||||
agentStat.setGc(gc);
|
||||
final TCpuLoad cpuLoad = cpuLoadCollector.collect();
|
||||
agentStat.setCpuLoad(cpuLoad);
|
||||
final TTransaction transaction = transactionMetricCollector.collect();
|
||||
agentStat.setTransaction(transaction);
|
||||
final TActiveTrace activeTrace = activeTraceMetricCollector.collect();
|
||||
agentStat.setActiveTrace(activeTrace);
|
||||
final TDataSourceList dataSourceList = dataSourceCollector.collect();
|
||||
agentStat.setDataSourceList(dataSourceList);
|
||||
|
||||
return agentStat;
|
||||
}
|
||||
|
||||
private void sendAgentStats() {
|
||||
// prepare TAgentStat object.
|
||||
// TODO multi thread issue.
|
||||
// If we reuse TAgentStat, there could be concurrency issue because data sender runs in a different thread.
|
||||
final TAgentStatBatch agentStatBatch = new TAgentStatBatch();
|
||||
agentStatBatch.setAgentId(agentId);
|
||||
agentStatBatch.setStartTimestamp(agentStartTime);
|
||||
agentStatBatch.setAgentStats(this.agentStats);
|
||||
// If we reuse agentStats list, there could be concurrency issue because data sender runs in a different
|
||||
// thread.
|
||||
// So create new list.
|
||||
this.agentStats = new ArrayList<TAgentStat>(this.numStatsPerBatch);
|
||||
if (isTrace) {
|
||||
logger.trace("collect agentStat:{}", agentStatBatch);
|
||||
}
|
||||
dataSender.send(agentStatBatch);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+9
-178
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,192 +16,23 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.monitor.codahale;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.context.TransactionCounter;
|
||||
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.DataSourceMonitorWrapper;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.DefaultPluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.PluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.PluginMonitorWrapperLocator;
|
||||
import com.navercorp.pinpoint.profiler.monitor.MonitorName;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.activetrace.ActiveTraceMetricCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.activetrace.DefaultActiveTraceMetricCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.activetrace.metric.ActiveTraceMetricSet;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.cpu.CpuLoadCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.cpu.DefaultCpuLoadCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.cpu.metric.CpuLoadMetricSet;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.datasource.DataSourceCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.datasource.DefaultDataSourceCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.datasource.metric.DataSourceMetricSet;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.CmsCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.CmsDetailedMetricsCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.G1Collector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.G1DetailedMetricsCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.GarbageCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.ParallelCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.ParallelDetailedMetricsCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.SerialCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.SerialDetailedMetricsCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.UnknownGarbageCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.tps.DefaultTransactionMetricCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.tps.TransactionMetricCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.tps.metric.TransactionMetricSet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static com.navercorp.pinpoint.profiler.monitor.codahale.MetricMonitorValues.*;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author harebox
|
||||
* @author hyungil.jeong
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class AgentStatCollectorFactory {
|
||||
public interface AgentStatCollectorFactory {
|
||||
GarbageCollector getGarbageCollector();
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
CpuLoadCollector getCpuLoadCollector();
|
||||
|
||||
private final MetricMonitorRegistry monitorRegistry;
|
||||
private final GarbageCollector garbageCollector;
|
||||
private final CpuLoadCollector cpuLoadCollector;
|
||||
private final TransactionMetricCollector transactionMetricCollector;
|
||||
private final ActiveTraceMetricCollector activeTraceMetricCollector;
|
||||
private final DataSourceCollector dataSourceCollector;
|
||||
TransactionMetricCollector getTransactionMetricCollector();
|
||||
|
||||
public AgentStatCollectorFactory(ProfilerConfig profilerConfig, ActiveTraceRepository activeTraceRepository, TransactionCounter transactionCounter, PluginMonitorContext pluginMonitorContext) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
}
|
||||
// if (activeTraceRepository == null) {
|
||||
// throw new NullPointerException("activeTraceRepository must not be null");
|
||||
// }
|
||||
if (transactionCounter == null) {
|
||||
throw new NullPointerException("transactionCounter must not be null");
|
||||
}
|
||||
// if (pluginMonitorContext == null) {
|
||||
// throw new NullPointerException("pluginMonitorContext must not be null");
|
||||
// }
|
||||
this.monitorRegistry = createRegistry();
|
||||
this.garbageCollector = createGarbageCollector(profilerConfig.isProfilerJvmCollectDetailedMetrics());
|
||||
this.cpuLoadCollector = createCpuLoadCollector(profilerConfig.getProfilerJvmVendorName());
|
||||
this.transactionMetricCollector = createTransactionMetricCollector(transactionCounter);
|
||||
this.activeTraceMetricCollector = createActiveTraceCollector(activeTraceRepository, profilerConfig.isTraceAgentActiveThread());
|
||||
this.dataSourceCollector = createDataSourceCollector(pluginMonitorContext);
|
||||
}
|
||||
|
||||
private MetricMonitorRegistry createRegistry() {
|
||||
final MetricMonitorRegistry monitorRegistry = new MetricMonitorRegistry();
|
||||
return monitorRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* create with garbage collector types based on metric registry keys
|
||||
*/
|
||||
private GarbageCollector createGarbageCollector(boolean collectDetailedMetrics) {
|
||||
MetricMonitorRegistry registry = this.monitorRegistry;
|
||||
registry.registerJvmMemoryMonitor(new MonitorName(MetricMonitorValues.JVM_MEMORY));
|
||||
registry.registerJvmGcMonitor(new MonitorName(MetricMonitorValues.JVM_GC));
|
||||
|
||||
Collection<String> keys = registry.getRegistry().getNames();
|
||||
GarbageCollector garbageCollectorToReturn = new UnknownGarbageCollector();
|
||||
|
||||
if (collectDetailedMetrics) {
|
||||
if (keys.contains(JVM_GC_SERIAL_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new SerialDetailedMetricsCollector(registry);
|
||||
} else if (keys.contains(JVM_GC_PS_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new ParallelDetailedMetricsCollector(registry);
|
||||
} else if (keys.contains(JVM_GC_CMS_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new CmsDetailedMetricsCollector(registry);
|
||||
} else if (keys.contains(JVM_GC_G1_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new G1DetailedMetricsCollector(registry);
|
||||
}
|
||||
} else {
|
||||
if (keys.contains(JVM_GC_SERIAL_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new SerialCollector(registry);
|
||||
} else if (keys.contains(JVM_GC_PS_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new ParallelCollector(registry);
|
||||
} else if (keys.contains(JVM_GC_CMS_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new CmsCollector(registry);
|
||||
} else if (keys.contains(JVM_GC_G1_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new G1Collector(registry);
|
||||
}
|
||||
}
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("found : {}", garbageCollectorToReturn);
|
||||
}
|
||||
return garbageCollectorToReturn;
|
||||
}
|
||||
|
||||
private CpuLoadCollector createCpuLoadCollector(String vendorName) {
|
||||
CpuLoadMetricSet cpuLoadMetricSet = this.monitorRegistry.registerCpuLoadMonitor(new MonitorName(MetricMonitorValues.CPU_LOAD), vendorName);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("loaded : {}", cpuLoadMetricSet);
|
||||
}
|
||||
return new DefaultCpuLoadCollector(cpuLoadMetricSet);
|
||||
}
|
||||
|
||||
private TransactionMetricCollector createTransactionMetricCollector(TransactionCounter transactionCounter) {
|
||||
if (transactionCounter == null) {
|
||||
return TransactionMetricCollector.EMPTY_TRANSACTION_METRIC_COLLECTOR;
|
||||
}
|
||||
|
||||
MonitorName monitorName = new MonitorName(MetricMonitorValues.TRANSACTION);
|
||||
TransactionMetricSet transactionMetricSet = this.monitorRegistry.registerTpsMonitor(monitorName, transactionCounter);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("loaded : {}", transactionMetricSet);
|
||||
}
|
||||
return new DefaultTransactionMetricCollector(transactionMetricSet);
|
||||
|
||||
}
|
||||
|
||||
private ActiveTraceMetricCollector createActiveTraceCollector(ActiveTraceRepository activeTraceRepository, boolean isTraceAgentActiveThread) {
|
||||
if (!isTraceAgentActiveThread) {
|
||||
return ActiveTraceMetricCollector.EMPTY_ACTIVE_TRACE_COLLECTOR;
|
||||
}
|
||||
|
||||
if (activeTraceRepository != null) {
|
||||
ActiveTraceMetricSet activeTraceMetricSet = this.monitorRegistry.registerActiveTraceMetricSet(new MonitorName(MetricMonitorValues.ACTIVE_TRACE), activeTraceRepository);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("loaded : {}", activeTraceMetricSet);
|
||||
}
|
||||
return new DefaultActiveTraceMetricCollector(activeTraceMetricSet);
|
||||
} else {
|
||||
logger.warn("agent set to trace active threads but no ActiveTraceLocator found");
|
||||
}
|
||||
return ActiveTraceMetricCollector.EMPTY_ACTIVE_TRACE_COLLECTOR;
|
||||
}
|
||||
|
||||
private DataSourceCollector createDataSourceCollector(PluginMonitorContext pluginMonitorContext) {
|
||||
if (pluginMonitorContext instanceof DefaultPluginMonitorContext) {
|
||||
PluginMonitorWrapperLocator<DataSourceMonitorWrapper> dataSourceMonitorLocator = ((DefaultPluginMonitorContext) pluginMonitorContext).getDataSourceMonitorLocator();
|
||||
if (dataSourceMonitorLocator != null) {
|
||||
DataSourceMetricSet dataSourceMetricSet = this.monitorRegistry.registerDataSourceMonitor(new MonitorName(MetricMonitorValues.DATASOURCE), dataSourceMonitorLocator);
|
||||
return new DefaultDataSourceCollector(dataSourceMetricSet);
|
||||
}
|
||||
}
|
||||
return DataSourceCollector.EMPTY_DATASOURCE_COLLECTOR;
|
||||
}
|
||||
|
||||
public GarbageCollector getGarbageCollector() {
|
||||
return this.garbageCollector;
|
||||
}
|
||||
|
||||
public CpuLoadCollector getCpuLoadCollector() {
|
||||
return this.cpuLoadCollector;
|
||||
}
|
||||
|
||||
public TransactionMetricCollector getTransactionMetricCollector() {
|
||||
return this.transactionMetricCollector;
|
||||
}
|
||||
|
||||
public ActiveTraceMetricCollector getActiveTraceMetricCollector() {
|
||||
return this.activeTraceMetricCollector;
|
||||
}
|
||||
|
||||
public DataSourceCollector getDataSourceCollector() {
|
||||
return this.dataSourceCollector;
|
||||
}
|
||||
ActiveTraceMetricCollector getActiveTraceMetricCollector();
|
||||
|
||||
DataSourceCollector getDataSourceCollector();
|
||||
}
|
||||
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.monitor.codahale;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.context.TransactionCounter;
|
||||
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.DataSourceMonitorWrapper;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.DefaultPluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.PluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.PluginMonitorWrapperLocator;
|
||||
import com.navercorp.pinpoint.profiler.monitor.MonitorName;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.activetrace.ActiveTraceMetricCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.activetrace.DefaultActiveTraceMetricCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.activetrace.metric.ActiveTraceMetricSet;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.cpu.CpuLoadCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.cpu.DefaultCpuLoadCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.cpu.metric.CpuLoadMetricSet;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.datasource.DataSourceCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.datasource.DefaultDataSourceCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.datasource.metric.DataSourceMetricSet;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.CmsCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.CmsDetailedMetricsCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.G1Collector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.G1DetailedMetricsCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.GarbageCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.ParallelCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.ParallelDetailedMetricsCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.SerialCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.SerialDetailedMetricsCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.gc.UnknownGarbageCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.tps.DefaultTransactionMetricCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.tps.TransactionMetricCollector;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.tps.metric.TransactionMetricSet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static com.navercorp.pinpoint.profiler.monitor.codahale.MetricMonitorValues.*;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author harebox
|
||||
* @author hyungil.jeong
|
||||
*/
|
||||
public class DefaultAgentStatCollectorFactory implements AgentStatCollectorFactory {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final MetricMonitorRegistry monitorRegistry;
|
||||
private final GarbageCollector garbageCollector;
|
||||
private final CpuLoadCollector cpuLoadCollector;
|
||||
private final TransactionMetricCollector transactionMetricCollector;
|
||||
private final ActiveTraceMetricCollector activeTraceMetricCollector;
|
||||
private final DataSourceCollector dataSourceCollector;
|
||||
|
||||
@Inject
|
||||
public DefaultAgentStatCollectorFactory(ProfilerConfig profilerConfig, ActiveTraceRepository activeTraceRepository, TransactionCounter transactionCounter, PluginMonitorContext pluginMonitorContext) {
|
||||
if (profilerConfig == null) {
|
||||
throw new NullPointerException("profilerConfig must not be null");
|
||||
}
|
||||
// if (activeTraceRepository == null) {
|
||||
// throw new NullPointerException("activeTraceRepository must not be null");
|
||||
// }
|
||||
if (transactionCounter == null) {
|
||||
throw new NullPointerException("transactionCounter must not be null");
|
||||
}
|
||||
// if (pluginMonitorContext == null) {
|
||||
// throw new NullPointerException("pluginMonitorContext must not be null");
|
||||
// }
|
||||
this.monitorRegistry = createRegistry();
|
||||
this.garbageCollector = createGarbageCollector(profilerConfig.isProfilerJvmCollectDetailedMetrics());
|
||||
this.cpuLoadCollector = createCpuLoadCollector(profilerConfig.getProfilerJvmVendorName());
|
||||
this.transactionMetricCollector = createTransactionMetricCollector(transactionCounter);
|
||||
this.activeTraceMetricCollector = createActiveTraceCollector(activeTraceRepository, profilerConfig.isTraceAgentActiveThread());
|
||||
this.dataSourceCollector = createDataSourceCollector(pluginMonitorContext);
|
||||
}
|
||||
|
||||
private MetricMonitorRegistry createRegistry() {
|
||||
final MetricMonitorRegistry monitorRegistry = new MetricMonitorRegistry();
|
||||
return monitorRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* create with garbage collector types based on metric registry keys
|
||||
*/
|
||||
private GarbageCollector createGarbageCollector(boolean collectDetailedMetrics) {
|
||||
MetricMonitorRegistry registry = this.monitorRegistry;
|
||||
registry.registerJvmMemoryMonitor(new MonitorName(MetricMonitorValues.JVM_MEMORY));
|
||||
registry.registerJvmGcMonitor(new MonitorName(MetricMonitorValues.JVM_GC));
|
||||
|
||||
Collection<String> keys = registry.getRegistry().getNames();
|
||||
GarbageCollector garbageCollectorToReturn = new UnknownGarbageCollector();
|
||||
|
||||
if (collectDetailedMetrics) {
|
||||
if (keys.contains(JVM_GC_SERIAL_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new SerialDetailedMetricsCollector(registry);
|
||||
} else if (keys.contains(JVM_GC_PS_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new ParallelDetailedMetricsCollector(registry);
|
||||
} else if (keys.contains(JVM_GC_CMS_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new CmsDetailedMetricsCollector(registry);
|
||||
} else if (keys.contains(JVM_GC_G1_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new G1DetailedMetricsCollector(registry);
|
||||
}
|
||||
} else {
|
||||
if (keys.contains(JVM_GC_SERIAL_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new SerialCollector(registry);
|
||||
} else if (keys.contains(JVM_GC_PS_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new ParallelCollector(registry);
|
||||
} else if (keys.contains(JVM_GC_CMS_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new CmsCollector(registry);
|
||||
} else if (keys.contains(JVM_GC_G1_OLDGEN_COUNT)) {
|
||||
garbageCollectorToReturn = new G1Collector(registry);
|
||||
}
|
||||
}
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("found : {}", garbageCollectorToReturn);
|
||||
}
|
||||
return garbageCollectorToReturn;
|
||||
}
|
||||
|
||||
private CpuLoadCollector createCpuLoadCollector(String vendorName) {
|
||||
CpuLoadMetricSet cpuLoadMetricSet = this.monitorRegistry.registerCpuLoadMonitor(new MonitorName(MetricMonitorValues.CPU_LOAD), vendorName);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("loaded : {}", cpuLoadMetricSet);
|
||||
}
|
||||
return new DefaultCpuLoadCollector(cpuLoadMetricSet);
|
||||
}
|
||||
|
||||
private TransactionMetricCollector createTransactionMetricCollector(TransactionCounter transactionCounter) {
|
||||
if (transactionCounter == null) {
|
||||
return TransactionMetricCollector.EMPTY_TRANSACTION_METRIC_COLLECTOR;
|
||||
}
|
||||
|
||||
MonitorName monitorName = new MonitorName(MetricMonitorValues.TRANSACTION);
|
||||
TransactionMetricSet transactionMetricSet = this.monitorRegistry.registerTpsMonitor(monitorName, transactionCounter);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("loaded : {}", transactionMetricSet);
|
||||
}
|
||||
return new DefaultTransactionMetricCollector(transactionMetricSet);
|
||||
|
||||
}
|
||||
|
||||
private ActiveTraceMetricCollector createActiveTraceCollector(ActiveTraceRepository activeTraceRepository, boolean isTraceAgentActiveThread) {
|
||||
if (!isTraceAgentActiveThread) {
|
||||
return ActiveTraceMetricCollector.EMPTY_ACTIVE_TRACE_COLLECTOR;
|
||||
}
|
||||
|
||||
if (activeTraceRepository != null) {
|
||||
ActiveTraceMetricSet activeTraceMetricSet = this.monitorRegistry.registerActiveTraceMetricSet(new MonitorName(MetricMonitorValues.ACTIVE_TRACE), activeTraceRepository);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("loaded : {}", activeTraceMetricSet);
|
||||
}
|
||||
return new DefaultActiveTraceMetricCollector(activeTraceMetricSet);
|
||||
} else {
|
||||
logger.warn("agent set to trace active threads but no ActiveTraceLocator found");
|
||||
}
|
||||
return ActiveTraceMetricCollector.EMPTY_ACTIVE_TRACE_COLLECTOR;
|
||||
}
|
||||
|
||||
private DataSourceCollector createDataSourceCollector(PluginMonitorContext pluginMonitorContext) {
|
||||
if (pluginMonitorContext instanceof DefaultPluginMonitorContext) {
|
||||
PluginMonitorWrapperLocator<DataSourceMonitorWrapper> dataSourceMonitorLocator = ((DefaultPluginMonitorContext) pluginMonitorContext).getDataSourceMonitorLocator();
|
||||
if (dataSourceMonitorLocator != null) {
|
||||
DataSourceMetricSet dataSourceMetricSet = this.monitorRegistry.registerDataSourceMonitor(new MonitorName(MetricMonitorValues.DATASOURCE), dataSourceMonitorLocator);
|
||||
return new DefaultDataSourceCollector(dataSourceMetricSet);
|
||||
}
|
||||
}
|
||||
return DataSourceCollector.EMPTY_DATASOURCE_COLLECTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GarbageCollector getGarbageCollector() {
|
||||
return this.garbageCollector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CpuLoadCollector getCpuLoadCollector() {
|
||||
return this.cpuLoadCollector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransactionMetricCollector getTransactionMetricCollector() {
|
||||
return this.transactionMetricCollector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActiveTraceMetricCollector getActiveTraceMetricCollector() {
|
||||
return this.activeTraceMetricCollector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceCollector getDataSourceCollector() {
|
||||
return this.dataSourceCollector;
|
||||
}
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class DefaultPluginContextLoadResult implements PluginContextLoadResult {
|
||||
private final List<DefaultProfilerPluginContext> pluginContextList;
|
||||
|
||||
public DefaultPluginContextLoadResult(List<DefaultProfilerPluginContext> pluginContextList) {
|
||||
this.pluginContextList = pluginContextList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DefaultProfilerPluginContext> getProfilerPluginContextList() {
|
||||
return pluginContextList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.plugin;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.GuardInstrumentContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplate;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplateAware;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.instrument.ClassInjector;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class DefaultPluginSetup implements PluginSetup {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
|
||||
public DefaultPluginSetup(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultProfilerPluginContext setupPlugin(ProfilerPlugin plugin, ClassInjector classInjector) {
|
||||
|
||||
final DefaultProfilerPluginContext context = new DefaultProfilerPluginContext(applicationContext, classInjector);
|
||||
final GuardProfilerPluginContext guard = new GuardProfilerPluginContext(context);
|
||||
final GuardInstrumentContext guardInstrumentContext = preparePlugin(plugin, context);
|
||||
try {
|
||||
// WARN external plugin api
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("{} Plugin setup", plugin.getClass().getName());
|
||||
}
|
||||
plugin.setup(guard);
|
||||
} finally {
|
||||
guard.close();
|
||||
guardInstrumentContext.close();
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
private GuardInstrumentContext preparePlugin(ProfilerPlugin plugin, InstrumentContext context) {
|
||||
|
||||
final GuardInstrumentContext guardInstrumentContext = new GuardInstrumentContext(context);
|
||||
if (plugin instanceof TransformTemplateAware) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("{}.setTransformTemplate", plugin.getClass().getName());
|
||||
}
|
||||
final TransformTemplate transformTemplate = new TransformTemplate(guardInstrumentContext);
|
||||
((TransformTemplateAware) plugin).setTransformTemplate(transformTemplate);
|
||||
}
|
||||
return guardInstrumentContext;
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -23,6 +23,7 @@ import java.util.List;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.DynamicTransformTrigger;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClassPool;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext;
|
||||
@@ -33,7 +34,6 @@ import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback
|
||||
import com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScope;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.ApplicationTypeDetector;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext;
|
||||
import com.navercorp.pinpoint.profiler.DynamicTransformService;
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import com.navercorp.pinpoint.profiler.context.scope.ConcurrentPool;
|
||||
import com.navercorp.pinpoint.profiler.context.scope.InterceptorScopeFactory;
|
||||
@@ -83,7 +83,7 @@ public class DefaultProfilerPluginContext implements ProfilerPluginSetupContext,
|
||||
if (context == null) {
|
||||
throw new IllegalStateException("TraceContext is not created yet");
|
||||
}
|
||||
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ public class DefaultProfilerPluginContext implements ProfilerPluginSetupContext,
|
||||
|
||||
final ClassFileTransformerGuardDelegate classFileTransformerGuardDelegate = new ClassFileTransformerGuardDelegate(this, transformCallback);
|
||||
|
||||
final DynamicTransformService dynamicTransformService = applicationContext.getDynamicTransformService();
|
||||
final DynamicTransformTrigger dynamicTransformService = applicationContext.getDynamicTransformTrigger();
|
||||
dynamicTransformService.addClassFileTransformer(classLoader, targetClassName, classFileTransformerGuardDelegate);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public class DefaultProfilerPluginContext implements ProfilerPluginSetupContext,
|
||||
|
||||
final ClassFileTransformerGuardDelegate classFileTransformerGuardDelegate = new ClassFileTransformerGuardDelegate(this, transformCallback);
|
||||
|
||||
final DynamicTransformService dynamicTransformService = applicationContext.getDynamicTransformService();
|
||||
final DynamicTransformTrigger dynamicTransformService = applicationContext.getDynamicTransformTrigger();
|
||||
dynamicTransformService.retransform(target, classFileTransformerGuardDelegate);
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -14,11 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context.provider;
|
||||
package com.navercorp.pinpoint.profiler.plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public interface Provider<T> {
|
||||
T get();
|
||||
public interface PluginContextLoadResult {
|
||||
List<DefaultProfilerPluginContext> getProfilerPluginContextList();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.plugin;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
|
||||
import com.navercorp.pinpoint.profiler.instrument.ClassInjector;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public interface PluginSetup {
|
||||
DefaultProfilerPluginContext setupPlugin(ProfilerPlugin plugin, ClassInjector classInjector);
|
||||
}
|
||||
+11
-41
@@ -16,6 +16,7 @@ package com.navercorp.pinpoint.profiler.plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
@@ -26,10 +27,8 @@ import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.GuardInstrumentContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplate;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplateAware;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClassPool;
|
||||
import com.navercorp.pinpoint.bootstrap.util.StringUtils;
|
||||
import com.navercorp.pinpoint.profiler.context.ApplicationContext;
|
||||
import org.slf4j.Logger;
|
||||
@@ -46,17 +45,20 @@ import com.navercorp.pinpoint.profiler.instrument.JarProfilerPluginClassInjector
|
||||
*/
|
||||
public class ProfilerPluginLoader {
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
private final ClassNameFilter profilerPackageFilter = new PinpointProfilerPackageSkipFilter();
|
||||
|
||||
public ProfilerPluginLoader(ApplicationContext applicationContext) {
|
||||
private final PluginSetup pluginSetup;
|
||||
|
||||
public ProfilerPluginLoader(ApplicationContext applicationContext, PluginSetup pluginSetup) {
|
||||
if (applicationContext == null) {
|
||||
throw new NullPointerException("applicationContext must not be null");
|
||||
}
|
||||
this.applicationContext = applicationContext;
|
||||
this.pluginSetup = pluginSetup;
|
||||
}
|
||||
|
||||
|
||||
public List<DefaultProfilerPluginContext> load(URL[] pluginJars) {
|
||||
List<DefaultProfilerPluginContext> pluginContexts = new ArrayList<DefaultProfilerPluginContext>(pluginJars.length);
|
||||
List<String> disabled = applicationContext.getProfilerConfig().getDisabledPlugins();
|
||||
@@ -82,7 +84,8 @@ public class ProfilerPluginLoader {
|
||||
logger.info("Loading plugin:{} pluginPackage:{}", plugin.getClass().getName(), plugin);
|
||||
|
||||
PluginConfig pluginConfig = new PluginConfig(jar, plugin, applicationContext.getInstrumentation(), applicationContext.getClassPool(), applicationContext.getBootstrapJarPaths(), pluginFilterChain);
|
||||
final DefaultProfilerPluginContext context = setupPlugin(pluginConfig);
|
||||
final ClassInjector classInjector = new JarProfilerPluginClassInjector(pluginConfig);
|
||||
final DefaultProfilerPluginContext context = pluginSetup.setupPlugin(plugin, classInjector);
|
||||
pluginContexts.add(context);
|
||||
}
|
||||
}
|
||||
@@ -137,37 +140,4 @@ public class ProfilerPluginLoader {
|
||||
}
|
||||
|
||||
|
||||
private GuardInstrumentContext preparePlugin(ProfilerPlugin plugin, InstrumentContext context) {
|
||||
|
||||
final GuardInstrumentContext guardInstrumentContext = new GuardInstrumentContext(context);
|
||||
if (plugin instanceof TransformTemplateAware) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("{}.setTransformTemplate", plugin.getClass().getName());
|
||||
}
|
||||
final TransformTemplate transformTemplate = new TransformTemplate(guardInstrumentContext);
|
||||
((TransformTemplateAware) plugin).setTransformTemplate(transformTemplate);
|
||||
}
|
||||
return guardInstrumentContext;
|
||||
}
|
||||
|
||||
private DefaultProfilerPluginContext setupPlugin(PluginConfig pluginConfig) {
|
||||
final ClassInjector classInjector = new JarProfilerPluginClassInjector(pluginConfig);
|
||||
final DefaultProfilerPluginContext context = new DefaultProfilerPluginContext(applicationContext, classInjector);
|
||||
|
||||
final GuardProfilerPluginContext guardPluginContext = new GuardProfilerPluginContext(context);
|
||||
final GuardInstrumentContext guardInstrumentContext = preparePlugin(pluginConfig.getPlugin(), context);
|
||||
try {
|
||||
// WARN external plugin api
|
||||
final ProfilerPlugin plugin = pluginConfig.getPlugin();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("{} Plugin setup", plugin.getClass().getName());
|
||||
}
|
||||
plugin.setup(guardPluginContext);
|
||||
} finally {
|
||||
guardPluginContext.close();
|
||||
guardInstrumentContext.close();
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.receiver;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.navercorp.pinpoint.rpc.MessageListener;
|
||||
import com.navercorp.pinpoint.rpc.PinpointSocket;
|
||||
import com.navercorp.pinpoint.rpc.packet.RequestPacket;
|
||||
@@ -42,6 +43,7 @@ public class CommandDispatcher implements MessageListener, ServerStreamChannelMe
|
||||
|
||||
private final ProfilerCommandServiceLocator commandServiceLocator;
|
||||
|
||||
@Inject
|
||||
public CommandDispatcher(ProfilerCommandServiceLocator commandServiceLocator) {
|
||||
if (commandServiceLocator == null) {
|
||||
throw new NullPointerException("commandServiceLocator may not be null");
|
||||
|
||||
+13
-3
@@ -21,6 +21,10 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.context.module.AgentServiceType;
|
||||
import com.navercorp.pinpoint.profiler.plugin.PluginContextLoadResult;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -42,7 +46,12 @@ public class ApplicationServerTypeResolver {
|
||||
private final ApplicationServerTypePluginResolver resolver;
|
||||
private final List<ApplicationTypeDetector> detectors = new ArrayList<ApplicationTypeDetector>();
|
||||
|
||||
public ApplicationServerTypeResolver(List<DefaultProfilerPluginContext> plugins, ServiceType defaultType, List<String> orderedDetectors) {
|
||||
@Inject
|
||||
public ApplicationServerTypeResolver(PluginContextLoadResult plugins, @AgentServiceType ServiceType defaultType, ProfilerConfig profilerConfig) {
|
||||
this(plugins, defaultType, profilerConfig.getApplicationTypeDetectOrder());
|
||||
}
|
||||
|
||||
public ApplicationServerTypeResolver(PluginContextLoadResult plugins, @AgentServiceType ServiceType defaultType, List<String> orderedDetectors) {
|
||||
if (isValidApplicationServerType(defaultType)) {
|
||||
this.defaultType = defaultType;
|
||||
} else {
|
||||
@@ -58,9 +67,10 @@ public class ApplicationServerTypeResolver {
|
||||
this.resolver = new ApplicationServerTypePluginResolver(this.detectors);
|
||||
}
|
||||
|
||||
private Map<String, ApplicationTypeDetector> getRegisteredServerTypeDetectors(List<DefaultProfilerPluginContext> plugins) {
|
||||
private Map<String, ApplicationTypeDetector> getRegisteredServerTypeDetectors(PluginContextLoadResult plugins) {
|
||||
Map<String, ApplicationTypeDetector> registeredDetectors = new HashMap<String, ApplicationTypeDetector>();
|
||||
for (DefaultProfilerPluginContext context : plugins) {
|
||||
List<DefaultProfilerPluginContext> profilerPluginContextList = plugins.getProfilerPluginContextList();
|
||||
for (DefaultProfilerPluginContext context : profilerPluginContextList) {
|
||||
for (ApplicationTypeDetector detector : context.getApplicationTypeDetectors()) {
|
||||
registeredDetectors.put(detector.getClass().getName(), detector);
|
||||
}
|
||||
|
||||
@@ -473,7 +473,7 @@ public class AgentInfoSenderTest {
|
||||
}
|
||||
|
||||
private AgentInformation getAgentInfo() {
|
||||
AgentInformation agentInfo = new AgentInformation("agentId", "appName", System.currentTimeMillis(), 1111, "hostname", "127.0.0.1", ServiceType.USER,
|
||||
AgentInformation agentInfo = new DefaultAgentInformation("agentId", "appName", System.currentTimeMillis(), 1111, "hostname", "127.0.0.1", ServiceType.USER,
|
||||
JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION), Version.VERSION);
|
||||
return agentInfo;
|
||||
}
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.navercorp.pinpoint.bootstrap.AgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.DefaultAgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService;
|
||||
import com.navercorp.pinpoint.common.service.DefaultServiceTypeRegistryService;
|
||||
import com.navercorp.pinpoint.profiler.AgentInfoSender;
|
||||
import com.navercorp.pinpoint.profiler.context.module.SpanDataSender;
|
||||
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.profiler.util.TestInterceptorRegistryBinder;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class DefaultApplicationContextTest {
|
||||
@Test
|
||||
public void test() {
|
||||
ProfilerConfig profilerConfig = new DefaultProfilerConfig();
|
||||
InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder();
|
||||
AgentOption agentOption = new DefaultAgentOption(new DummyInstrumentation(),
|
||||
"mockAgent", "mockApplicationName", profilerConfig, new URL[0],
|
||||
null, new DefaultServiceTypeRegistryService(), new DefaultAnnotationKeyRegistryService());
|
||||
|
||||
DefaultApplicationContext applicationContext = new DefaultApplicationContext(agentOption, binder);
|
||||
|
||||
Injector injector = applicationContext.getInjector();
|
||||
AgentInfoSender instance1 = injector.getInstance(AgentInfoSender.class);
|
||||
AgentInfoSender instance2 = injector.getInstance(AgentInfoSender.class);
|
||||
Assert.assertSame(instance1, instance2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -28,12 +28,12 @@ import com.navercorp.pinpoint.profiler.context.TransactionCounter.SamplingType;
|
||||
*/
|
||||
public class DefaultTransactionCounterTest {
|
||||
|
||||
private IdGenerator idGenerator;
|
||||
private AtomicIdGenerator idGenerator;
|
||||
private TransactionCounter transactionCounter;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.idGenerator = new IdGenerator();
|
||||
this.idGenerator = new AtomicIdGenerator();
|
||||
this.transactionCounter = new DefaultTransactionCounter(this.idGenerator);
|
||||
}
|
||||
|
||||
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2017 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import java.lang.instrument.ClassDefinition;
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.instrument.UnmodifiableClassException;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class DummyInstrumentation implements Instrumentation {
|
||||
@Override
|
||||
public void addTransformer(ClassFileTransformer transformer, boolean canRetransform) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTransformer(ClassFileTransformer transformer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeTransformer(ClassFileTransformer transformer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRetransformClassesSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retransformClasses(Class<?>... classes) throws UnmodifiableClassException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRedefineClassesSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redefineClasses(ClassDefinition... definitions) throws ClassNotFoundException, UnmodifiableClassException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModifiableClass(Class<?> theClass) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getAllLoadedClasses() {
|
||||
return new Class[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getInitiatedClasses(ClassLoader loader) {
|
||||
return new Class[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getObjectSize(Object objectToSize) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendToBootstrapClassLoaderSearch(JarFile jarfile) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendToSystemClassLoaderSearch(JarFile jarfile) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNativeMethodPrefixSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNativeMethodPrefix(ClassFileTransformer transformer, String prefix) {
|
||||
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -24,6 +24,7 @@ import com.navercorp.pinpoint.bootstrap.sampler.Sampler;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.PluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.context.provider.PluginMonitorContextProvider;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.LogStorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataCacheService;
|
||||
@@ -46,7 +47,7 @@ public class MockTraceContextFactory {
|
||||
|
||||
private final StorageFactory storageFactory;
|
||||
|
||||
private final IdGenerator idGenerator;
|
||||
private final AtomicIdGenerator idGenerator;
|
||||
private final Sampler sampler;
|
||||
private final ActiveTraceRepository activeTraceRepository;
|
||||
|
||||
@@ -81,12 +82,12 @@ public class MockTraceContextFactory {
|
||||
final SamplerFactory samplerFactory = new SamplerFactory();
|
||||
this.sampler = createSampler(profilerConfig, samplerFactory);
|
||||
|
||||
this.idGenerator = new IdGenerator();
|
||||
this.idGenerator = new AtomicIdGenerator();
|
||||
this.activeTraceRepository = newActiveTraceRepository();
|
||||
|
||||
final TraceFactoryBuilder traceFactoryBuilder = new DefaultTraceFactoryBuilder(storageFactory, sampler, idGenerator, activeTraceRepository);
|
||||
final PluginMonitorContextBuilder pluginMonitorContextBuilder = new PluginMonitorContextBuilder(TRACE_DATASOURCE);
|
||||
this.pluginMonitorContext = pluginMonitorContextBuilder.build();
|
||||
final PluginMonitorContextProvider pluginMonitorContextBuilder = new PluginMonitorContextProvider(TRACE_DATASOURCE);
|
||||
this.pluginMonitorContext = pluginMonitorContextBuilder.get();
|
||||
|
||||
this.serverMetaDataHolder = new DefaultServerMetaDataHolder(RuntimeMXBeanUtils.getVmArgs());
|
||||
|
||||
|
||||
+2
-4
@@ -21,9 +21,7 @@ import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanChunkFactory;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanEvent;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgentInformation;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -37,7 +35,7 @@ import java.util.List;
|
||||
public class SpanChunkFactoryTest {
|
||||
@Test
|
||||
public void create() {
|
||||
AgentInformation agentInformation = new AgentInformation("agentId", "applicationName", 0,0, "machineName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
AgentInformation agentInformation = new DefaultAgentInformation("agentId", "applicationName", 0,0, "machineName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION), Version.VERSION);
|
||||
SpanChunkFactory spanChunkFactory = new SpanChunkFactory(agentInformation);
|
||||
|
||||
|
||||
+2
-2
@@ -21,13 +21,13 @@ import com.navercorp.pinpoint.common.Version;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgentInformation;
|
||||
|
||||
/**
|
||||
* TODO duplicate com.navercorp.pinpoint.test.TestAgentInformation
|
||||
* @author HyunGil Jeong
|
||||
*/
|
||||
public class TestAgentInformation extends AgentInformation {
|
||||
public class TestAgentInformation extends DefaultAgentInformation {
|
||||
|
||||
private static final String AGENT_ID = "test-agent";
|
||||
private static final String APPLICATION_NAME = "TEST_APPLICATION";
|
||||
|
||||
+2
-2
@@ -21,10 +21,10 @@ import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanChunkFactory;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanEvent;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.BufferedStorage;
|
||||
import com.navercorp.pinpoint.profiler.sender.CountingDataSender;
|
||||
|
||||
import org.junit.Assert;
|
||||
@@ -33,7 +33,7 @@ import org.junit.Test;
|
||||
|
||||
public class BufferedStorageTest {
|
||||
|
||||
private AgentInformation agentInformation = new AgentInformation("agentId", "applicationName", 0, 1, "hostName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
private AgentInformation agentInformation = new DefaultAgentInformation("agentId", "applicationName", 0, 1, "hostName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION), Version.VERSION);
|
||||
private SpanChunkFactory spanChunkFactory = new SpanChunkFactory(agentInformation);
|
||||
private CountingDataSender countingDataSender = new CountingDataSender();
|
||||
|
||||
+4
-3
@@ -18,13 +18,14 @@ package com.navercorp.pinpoint.profiler.monitor.codahale.gc;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.profiler.context.AtomicIdGenerator;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultTransactionCounter;
|
||||
import com.navercorp.pinpoint.profiler.context.IdGenerator;
|
||||
import com.navercorp.pinpoint.profiler.context.TransactionCounter;
|
||||
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.DefaultPluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.context.monitor.PluginMonitorContext;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.AgentStatCollectorFactory;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.DefaultAgentStatCollectorFactory;
|
||||
import com.navercorp.pinpoint.thrift.dto.TJvmGc;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
@@ -43,11 +44,11 @@ public class GarbageCollectorFactoryTest {
|
||||
}
|
||||
|
||||
ActiveTraceRepository activeTraceRepository = new ActiveTraceRepository();
|
||||
IdGenerator idGenerator = new IdGenerator();
|
||||
AtomicIdGenerator idGenerator = new AtomicIdGenerator();
|
||||
TransactionCounter transactionCounter = new DefaultTransactionCounter(idGenerator);
|
||||
PluginMonitorContext pluginMonitorContext = new DefaultPluginMonitorContext();
|
||||
|
||||
return new AgentStatCollectorFactory(profilerConfig, activeTraceRepository, transactionCounter, pluginMonitorContext);
|
||||
return new DefaultAgentStatCollectorFactory(profilerConfig, activeTraceRepository, transactionCounter, pluginMonitorContext);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -21,6 +21,7 @@ import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultTraceId;
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanChunk;
|
||||
@@ -50,7 +51,7 @@ public class SpanStreamSendDataSerializerTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
AgentInformation agentInformation = new AgentInformation("agentId", "applicationName", 0, 0, "machineName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
AgentInformation agentInformation = new DefaultAgentInformation("agentId", "applicationName", 0, 0, "machineName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION), Version.VERSION);
|
||||
spanChunkFactory = new SpanChunkFactory(agentInformation);
|
||||
}
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@ import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanChunk;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanChunkFactory;
|
||||
@@ -39,7 +40,7 @@ public class SpanChunkStreamSendDataPlanerTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
AgentInformation agentInformation = new AgentInformation("agentId", "applicationName", 0, 0, "machineName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
AgentInformation agentInformation = new DefaultAgentInformation("agentId", "applicationName", 0, 0, "machineName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION), Version.VERSION);
|
||||
|
||||
HeaderTBaseSerializerPoolFactory serializerFactory = new HeaderTBaseSerializerPoolFactory(true, 1000, true);
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@ import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultTraceId;
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanChunkFactory;
|
||||
@@ -39,7 +40,7 @@ public class SpanStreamSendDataPlanerTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
AgentInformation agentInformation = new AgentInformation("agentId", "applicationName", 0, 0, "machineName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
AgentInformation agentInformation = new DefaultAgentInformation("agentId", "applicationName", 0, 0, "machineName", "127.0.0.1", ServiceType.STAND_ALONE,
|
||||
JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION), Version.VERSION);
|
||||
|
||||
HeaderTBaseSerializerPoolFactory serializerFactory = new HeaderTBaseSerializerPoolFactory(true, 1000, true);
|
||||
|
||||
Reference in New Issue
Block a user