mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-11 05:45:57 +10:00
[#49] Created arcus plugin project
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface SimpleAfterInterceptor extends Interceptor {
|
||||
void after(Object target, Object[] args, Object result, Throwable throwable);
|
||||
}
|
||||
+1
-4
@@ -3,9 +3,6 @@ package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface SimpleAroundInterceptor extends Interceptor {
|
||||
public interface SimpleAroundInterceptor extends SimpleBeforeInterceptor, SimpleAfterInterceptor {
|
||||
|
||||
void before(Object target, Object[] args);
|
||||
|
||||
void after(Object target, Object[] args, Object result, Throwable throwable);
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
public interface SimpleBeforeInterceptor extends Interceptor {
|
||||
void before(Object target, Object[] args);
|
||||
}
|
||||
+4
-19
@@ -1,33 +1,23 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.List;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.nhn.pinpoint.exception.PinpointException;
|
||||
|
||||
public class BasicClassEditor implements DedicatedClassEditor {
|
||||
private final ByteCodeInstrumentor instrumentor;
|
||||
|
||||
private final String targetClassName;
|
||||
|
||||
public class BasicClassEditor implements ClassEditor {
|
||||
private final List<MetadataInjector> metadataInjectors;
|
||||
private final List<InterceptorInjector> interceptorInjectors;
|
||||
|
||||
|
||||
public BasicClassEditor(ByteCodeInstrumentor instrumentor, String targetClassName, List<MetadataInjector> metadataInjectors, List<InterceptorInjector> interceptorInjectors) {
|
||||
this.instrumentor = instrumentor;
|
||||
this.targetClassName = targetClassName;
|
||||
public BasicClassEditor(List<MetadataInjector> metadataInjectors, List<InterceptorInjector> interceptorInjectors) {
|
||||
this.metadataInjectors = metadataInjectors;
|
||||
this.interceptorInjectors = interceptorInjectors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] edit(ClassLoader classLoader, String className, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
|
||||
public byte[] edit(ClassLoader classLoader, InstrumentClass target) {
|
||||
try {
|
||||
InstrumentClass target = instrumentor.getClass(classLoader, className, classFileBuffer);
|
||||
|
||||
for (MetadataInjector injector : metadataInjectors) {
|
||||
injector.inject(classLoader, target);
|
||||
}
|
||||
@@ -38,12 +28,7 @@ public class BasicClassEditor implements DedicatedClassEditor {
|
||||
|
||||
return target.toBytecode();
|
||||
} catch (Throwable t) {
|
||||
throw new PinpointException("Fail to edit class: " + targetClassName, t);
|
||||
throw new PinpointException("Fail to edit class", t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetClassName() {
|
||||
return targetClassName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import java.security.ProtectionDomain;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
|
||||
public interface ClassEditor {
|
||||
public byte[] edit(ClassLoader classLoader, String className, ProtectionDomain protectionDomain, byte[] classFileBuffer);
|
||||
public byte[] edit(ClassLoader classLoader, InstrumentClass target);
|
||||
}
|
||||
|
||||
+47
-22
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.MethodFilter;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.Interceptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.TraceValue;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.MetadataInitializationStrategy.ByConstructor;
|
||||
|
||||
@@ -13,18 +14,22 @@ public class ClassEditorBuilder {
|
||||
private final ByteCodeInstrumentor instrumentor;
|
||||
private final TraceContext traceContext;
|
||||
|
||||
private final String targetClassName;
|
||||
|
||||
private final List<InterceptorBuilder> interceptorBuilders = new ArrayList<InterceptorBuilder>();
|
||||
private final List<MetadataBuilder> metadataBuilders = new ArrayList<MetadataBuilder>();
|
||||
|
||||
public ClassEditorBuilder(ByteCodeInstrumentor instrumentor, TraceContext traceContext, String targetClassName) {
|
||||
private Condition condition;
|
||||
|
||||
public ClassEditorBuilder(ByteCodeInstrumentor instrumentor, TraceContext traceContext) {
|
||||
this.instrumentor = instrumentor;
|
||||
this.traceContext = traceContext;
|
||||
this.targetClassName = targetClassName;
|
||||
}
|
||||
|
||||
public ClassEditorBuilder editWhen(Condition condition) {
|
||||
this.condition = condition;
|
||||
return this;
|
||||
}
|
||||
|
||||
public InterceptorBuilder intercept(String methodName, String... parameterTypes) {
|
||||
public InterceptorBuilder intercept(String methodName, Class<?>... parameterTypes) {
|
||||
InterceptorBuilder interceptorBuilder = new InterceptorBuilder(methodName, parameterTypes, null);
|
||||
interceptorBuilders.add(interceptorBuilder);
|
||||
return interceptorBuilder;
|
||||
@@ -36,14 +41,14 @@ public class ClassEditorBuilder {
|
||||
return interceptorBuilder;
|
||||
}
|
||||
|
||||
public InterceptorBuilder interceptConstructor(String... parameterTypes) {
|
||||
public InterceptorBuilder interceptConstructor(Class<?>... parameterTypes) {
|
||||
InterceptorBuilder interceptorBuilder = new InterceptorBuilder(null, parameterTypes, null);
|
||||
interceptorBuilders.add(interceptorBuilder);
|
||||
return interceptorBuilder;
|
||||
}
|
||||
|
||||
public MetadataBuilder inject(Class<? extends TraceValue> metadataAccessor) {
|
||||
MetadataBuilder metadataBuilder = new MetadataBuilder(metadataAccessor);
|
||||
public MetadataBuilder inject(Class<? extends TraceValue> metadataType) {
|
||||
MetadataBuilder metadataBuilder = new MetadataBuilder(metadataType);
|
||||
metadataBuilders.add(metadataBuilder);
|
||||
return metadataBuilder;
|
||||
}
|
||||
@@ -61,7 +66,13 @@ public class ClassEditorBuilder {
|
||||
interceptorInjectors.add(builder.build());
|
||||
}
|
||||
|
||||
return new BasicClassEditor(instrumentor, targetClassName, metadataInjectors, interceptorInjectors);
|
||||
ClassEditor editor = new BasicClassEditor(metadataInjectors, interceptorInjectors);
|
||||
|
||||
if (condition != null) {
|
||||
editor = new ConditionalClassEditor(condition, editor);
|
||||
}
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
public class InterceptorBuilder {
|
||||
@@ -69,15 +80,16 @@ public class ClassEditorBuilder {
|
||||
private final String[] parameterTypes;
|
||||
private final MethodFilter filter;
|
||||
|
||||
private String interceptorClassName;
|
||||
private Class<? extends Interceptor> interceptorClass;
|
||||
private Condition condition;
|
||||
private String scopeName;
|
||||
private Object[] constructorArguments;
|
||||
private ParameterExtractorFactory parameterExtractorFactory;
|
||||
private boolean singleton;
|
||||
|
||||
public InterceptorBuilder(String methodName, String[] parameterTypes, MethodFilter filter) {
|
||||
public InterceptorBuilder(String methodName, Class<?>[] parameterTypes, MethodFilter filter) {
|
||||
this.methodName = methodName;
|
||||
this.parameterTypes = parameterTypes;
|
||||
this.parameterTypes = TypeUtils.toClassNames(parameterTypes);
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@@ -86,8 +98,8 @@ public class ClassEditorBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public InterceptorBuilder with(String interceptorClassName) {
|
||||
this.interceptorClassName = interceptorClassName;
|
||||
public InterceptorBuilder with(Class<? extends Interceptor> interceptorClass) {
|
||||
this.interceptorClass = interceptorClass;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -106,25 +118,38 @@ public class ClassEditorBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public InterceptorBuilder when(Condition condition) {
|
||||
this.condition = condition;
|
||||
return this;
|
||||
}
|
||||
|
||||
private InterceptorInjector build() {
|
||||
InterceptorFactory interceptorFactory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, constructorArguments, parameterExtractorFactory, scopeName);
|
||||
InterceptorFactory interceptorFactory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClass, constructorArguments, parameterExtractorFactory, scopeName);
|
||||
|
||||
InterceptorInjector injector;
|
||||
|
||||
if (filter != null) {
|
||||
return new FilteringInterceptorInjector(filter, interceptorFactory, singleton);
|
||||
injector = new FilteringInterceptorInjector(filter, interceptorFactory, singleton);
|
||||
} else if (methodName != null) {
|
||||
return new DedicatedInterceptorInjector(methodName, parameterTypes, interceptorFactory);
|
||||
injector = new DedicatedInterceptorInjector(methodName, parameterTypes, interceptorFactory);
|
||||
} else {
|
||||
return new ConstructorInterceptorInjector(parameterTypes, interceptorFactory);
|
||||
injector = new ConstructorInterceptorInjector(parameterTypes, interceptorFactory);
|
||||
}
|
||||
|
||||
if (condition != null) {
|
||||
injector = new ConditionalInterceptorInjector(condition, injector);
|
||||
}
|
||||
|
||||
return injector;
|
||||
}
|
||||
}
|
||||
|
||||
public class MetadataBuilder {
|
||||
private final Class<? extends TraceValue> metadataAccessor;
|
||||
private final Class<? extends TraceValue> metadataType;
|
||||
private MetadataInitializationStrategy initializationStrategy;
|
||||
|
||||
public MetadataBuilder(Class<? extends TraceValue> metadataAccessor) {
|
||||
this.metadataAccessor = metadataAccessor;
|
||||
public MetadataBuilder(Class<? extends TraceValue> metadataType) {
|
||||
this.metadataType = metadataType;
|
||||
}
|
||||
|
||||
public MetadataBuilder initializeWithDefaultConstructorOf(String className) {
|
||||
@@ -133,7 +158,7 @@ public class ClassEditorBuilder {
|
||||
}
|
||||
|
||||
private MetadataInjector build() {
|
||||
return new DefaultMetadataInjector(metadataAccessor, initializationStrategy);
|
||||
return new DefaultMetadataInjector(metadataType, initializationStrategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
public interface ClassEditorFactory {
|
||||
public ClassEditor get(ProfilerPluginContext context);
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
public class ClassEditorFactoryMapping {
|
||||
private final String targetClassName;
|
||||
private final String editorFactoryClassName;
|
||||
|
||||
public ClassEditorFactoryMapping(String targetClassName, String editorFactoryClassName) {
|
||||
this.targetClassName = targetClassName;
|
||||
this.editorFactoryClassName = editorFactoryClassName;
|
||||
}
|
||||
|
||||
public String getTargetClassName() {
|
||||
return targetClassName;
|
||||
}
|
||||
|
||||
public String getEditorFactoryClassName() {
|
||||
return editorFactoryClassName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
|
||||
public interface Condition {
|
||||
public boolean check(InstrumentClass target);
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
|
||||
public class ConditionalClassEditor implements ClassEditor {
|
||||
private final Condition condition;
|
||||
private final ClassEditor delegate;
|
||||
|
||||
public ConditionalClassEditor(Condition condition, ClassEditor delegate) {
|
||||
this.condition = condition;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] edit(ClassLoader classLoader, InstrumentClass target) {
|
||||
if (condition.check(target)) {
|
||||
return delegate.edit(classLoader, target);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentException;
|
||||
|
||||
public class ConditionalInterceptorInjector implements InterceptorInjector {
|
||||
private final Condition condition;
|
||||
private final InterceptorInjector delegate;
|
||||
|
||||
public ConditionalInterceptorInjector(Condition condition, InterceptorInjector delegate) {
|
||||
this.condition = condition;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(ClassLoader classLoader, InstrumentClass target) throws InstrumentException {
|
||||
if (condition.check(target)) {
|
||||
delegate.inject(classLoader, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-15
@@ -22,17 +22,17 @@ public class DefaultInterceptorFactory implements InterceptorFactory {
|
||||
private final ByteCodeInstrumentor instrumentor;
|
||||
private final TraceContext traceContext;
|
||||
|
||||
private final String interceptorClassName;
|
||||
private final Class<? extends Interceptor> interceptorClass;
|
||||
private final Object[] providedArguments;
|
||||
|
||||
private final ParameterExtractorFactory parameterExtractorFactory;
|
||||
private final String scopeName;
|
||||
|
||||
|
||||
public DefaultInterceptorFactory(ByteCodeInstrumentor instrumentor, TraceContext traceContext, String interceptorClassName, Object[] providedArguments, ParameterExtractorFactory parameterExtractorFactory, String scopeName) {
|
||||
public DefaultInterceptorFactory(ByteCodeInstrumentor instrumentor, TraceContext traceContext, Class<? extends Interceptor> interceptorClass, Object[] providedArguments, ParameterExtractorFactory parameterExtractorFactory, String scopeName) {
|
||||
this.instrumentor = instrumentor;
|
||||
this.traceContext = traceContext;
|
||||
this.interceptorClassName = interceptorClassName;
|
||||
this.interceptorClass = interceptorClass;
|
||||
this.providedArguments = providedArguments == null ? NO_ARGS : providedArguments;
|
||||
this.parameterExtractorFactory = parameterExtractorFactory;
|
||||
this.scopeName = scopeName;
|
||||
@@ -50,17 +50,6 @@ public class DefaultInterceptorFactory implements InterceptorFactory {
|
||||
}
|
||||
|
||||
private Interceptor createInstance(TraceContext traceContext, ClassLoader classLoader, InstrumentClass target, MethodInfo targetMethod) {
|
||||
Class<?> interceptorClass;
|
||||
try {
|
||||
interceptorClass = classLoader.loadClass(interceptorClassName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new PinpointException("Cannot find interceptor class: " + interceptorClassName, e);
|
||||
}
|
||||
|
||||
if (!Interceptor.class.isAssignableFrom(interceptorClass)) {
|
||||
throw new PinpointException("Given class " + interceptorClassName + " is not implementing Interceptor");
|
||||
}
|
||||
|
||||
Constructor<?>[] constructors = interceptorClass.getConstructors();
|
||||
Arrays.sort(constructors, CONSTRUCTOR_COMPARATOR);
|
||||
|
||||
@@ -73,7 +62,7 @@ public class DefaultInterceptorFactory implements InterceptorFactory {
|
||||
}
|
||||
}
|
||||
|
||||
throw new PinpointException("Cannot find suitable constructor for " + interceptorClassName);
|
||||
throw new PinpointException("Cannot find suitable constructor for " + interceptorClass.getName());
|
||||
}
|
||||
|
||||
private Object invokeConstructor(Constructor<?> constructor, Object[] arguments) {
|
||||
|
||||
+5
-5
@@ -7,22 +7,22 @@ import com.nhn.pinpoint.bootstrap.plugin.MetadataInitializationStrategy.ByConstr
|
||||
|
||||
public class DefaultMetadataInjector implements MetadataInjector {
|
||||
|
||||
private final Class<? extends TraceValue> metadataAccessorType;
|
||||
private final Class<? extends TraceValue> metadataType;
|
||||
private final MetadataInitializationStrategy strategy;
|
||||
|
||||
public DefaultMetadataInjector(Class<? extends TraceValue> metadataAccessorType, MetadataInitializationStrategy strategy) {
|
||||
this.metadataAccessorType = metadataAccessorType;
|
||||
public DefaultMetadataInjector(Class<? extends TraceValue> metadataType, MetadataInitializationStrategy strategy) {
|
||||
this.metadataType = metadataType;
|
||||
this.strategy = strategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(ClassLoader classLoader, InstrumentClass target) throws InstrumentException {
|
||||
if (strategy == null) {
|
||||
target.addTraceValue(metadataAccessorType);
|
||||
target.addTraceValue(metadataType);
|
||||
} else {
|
||||
if (strategy instanceof ByConstructor) {
|
||||
String javaExpression = "new " + ((ByConstructor)strategy).getClassName() + "();";
|
||||
target.addTraceValue(metadataAccessorType, javaExpression);
|
||||
target.addTraceValue(metadataType, javaExpression);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported strategy: " + strategy);
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PluginClassLoaderFactory {
|
||||
private final URL[] pluginJars;
|
||||
private final ConcurrentHashMap<ClassLoader, ClassLoader> cache = new ConcurrentHashMap<ClassLoader, ClassLoader>();
|
||||
|
||||
public PluginClassLoaderFactory(URL[] pluginJars) {
|
||||
this.pluginJars = pluginJars;
|
||||
}
|
||||
|
||||
public ClassLoader get(ClassLoader loader) {
|
||||
ClassLoader forPlugin = cache.get(loader);
|
||||
|
||||
if (forPlugin != null) {
|
||||
return forPlugin;
|
||||
}
|
||||
|
||||
ClassLoader newInstance = new URLClassLoader(pluginJars, loader);
|
||||
ClassLoader inCache = cache.putIfAbsent(loader, newInstance);
|
||||
|
||||
return inCache == null ? newInstance : inCache;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,5 +3,5 @@ package com.nhn.pinpoint.bootstrap.plugin;
|
||||
import java.util.List;
|
||||
|
||||
public interface ProfilerPlugin {
|
||||
public List<ClassEditor> getClassEditors(ProfilerPluginContext context);
|
||||
public List<ClassEditorFactoryMapping> getClassEditorMappings(ProfilerPluginContext context);
|
||||
}
|
||||
|
||||
+7
-2
@@ -1,5 +1,6 @@
|
||||
package com.nhn.pinpoint.bootstrap.plugin;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
|
||||
|
||||
@@ -12,8 +13,12 @@ public class ProfilerPluginContext {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
|
||||
public ClassEditorBuilder getClassEditorBuilderFor(String targetClassName) {
|
||||
return new ClassEditorBuilder(instrumentor, traceContext, targetClassName);
|
||||
public ClassEditorBuilder newClassEditorBuilder() {
|
||||
return new ClassEditorBuilder(instrumentor, traceContext);
|
||||
}
|
||||
|
||||
public ProfilerConfig getConfig() {
|
||||
return traceContext.getProfilerConfig();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,4 +24,15 @@ public abstract class TypeUtils {
|
||||
|
||||
throw new IllegalArgumentException("Unexpected argument: " + primitive);
|
||||
}
|
||||
|
||||
public static String[] toClassNames(Class<?>... classes) {
|
||||
int length = classes.length;
|
||||
String[] result = new String[length];
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
result[i] = classes[i].getName();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-11
@@ -26,27 +26,25 @@ public class ClassEditorBuilderTest {
|
||||
Scope aScope = mock(Scope.class);
|
||||
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
String targetClassName = "com.nhn.pinpoint.bootstrap.plugin.Foo";
|
||||
String methodName = "someMethod";
|
||||
String[] parameterTypes = new String[] { "java.lang.String" };
|
||||
Class<?>[] parameterTypes = new Class<?>[] { String.class };
|
||||
String[] parameterTypeNames = TypeUtils.toClassNames(parameterTypes);
|
||||
String scopeName = "test";
|
||||
byte[] classFileBuffer = BytecodeUtils.getClassFile(classLoader, targetClassName);
|
||||
|
||||
when(instrumentor.getClass(classLoader, targetClassName, classFileBuffer)).thenReturn(aClass);
|
||||
|
||||
when(instrumentor.getScope(scopeName)).thenReturn(aScope);
|
||||
when(aClass.getDeclaredMethod(methodName, parameterTypes)).thenReturn(aMethod);
|
||||
when(aClass.getDeclaredMethod(methodName, parameterTypeNames)).thenReturn(aMethod);
|
||||
when(aMethod.getName()).thenReturn(methodName);
|
||||
when(aMethod.getParameterTypes()).thenReturn(parameterTypes);
|
||||
when(aClass.addInterceptor(eq(methodName), eq(parameterTypes), isA(Interceptor.class))).thenReturn(0);
|
||||
when(aMethod.getParameterTypes()).thenReturn(parameterTypeNames);
|
||||
when(aClass.addInterceptor(eq(methodName), eq(parameterTypeNames), isA(Interceptor.class))).thenReturn(0);
|
||||
|
||||
|
||||
ProfilerPluginContext helper = new ProfilerPluginContext(instrumentor, traceContext);
|
||||
ClassEditorBuilder builder = helper.getClassEditorBuilderFor(targetClassName);
|
||||
builder.intercept(methodName, parameterTypes).with("com.nhn.pinpoint.bootstrap.plugin.TestInterceptor").constructedWith("provided").in(scopeName);
|
||||
ClassEditorBuilder builder = helper.newClassEditorBuilder();
|
||||
builder.intercept(methodName, parameterTypes).with(TestInterceptor.class).constructedWith("provided").in(scopeName);
|
||||
builder.inject(TestMetadata.class).initializeWithDefaultConstructorOf("java.util.HashMap");
|
||||
ClassEditor editor = builder.build();
|
||||
|
||||
editor.edit(classLoader, targetClassName, null, classFileBuffer);
|
||||
editor.edit(classLoader, aClass);
|
||||
|
||||
verify(aClass).addInterceptor(eq(methodName), isA(String[].class), isA(Interceptor.class));
|
||||
verify(aClass).addTraceValue(TestMetadata.class, "new java.util.HashMap();");
|
||||
|
||||
+28
-43
@@ -16,6 +16,9 @@ import com.nhn.pinpoint.bootstrap.instrument.MethodInfo;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.Interceptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.ParameterExtractor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.TestInterceptors.TestInterceptor0;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.TestInterceptors.TestInterceptor1;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.TestInterceptors.TestInterceptor2;
|
||||
import com.nhn.pinpoint.exception.PinpointException;
|
||||
|
||||
public class DefaultInterceptorFactoryTest {
|
||||
@@ -36,44 +39,39 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test0() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor0";
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, null, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor0.class, null, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor0.class, interceptor.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor0";
|
||||
Object[] args = new Object[] { "arg0" };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor0.class, args, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor0.class, interceptor.getClass());
|
||||
assertEquals(args[0], getField(interceptor, "field0"));
|
||||
}
|
||||
|
||||
@Test(expected = PinpointException.class)
|
||||
public void test2() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor0";
|
||||
Object[] args = new Object[] { 1 };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor0.class, args, null, null);
|
||||
factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1";
|
||||
Object[] args = new Object[] { "arg0", (byte)1, (short)2, (float)3.0 };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor1.class, args, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor1.class, interceptor.getClass());
|
||||
assertEquals(args[0], getField(interceptor, "field0"));
|
||||
assertEquals(args[1], getField(interceptor, "field1"));
|
||||
assertEquals(args[2], getField(interceptor, "field2"));
|
||||
@@ -82,13 +80,12 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test4() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1";
|
||||
Object[] args = new Object[] { (byte)1, (short)2, (float)3.0, "arg0" };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor1.class, args, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor1.class, interceptor.getClass());
|
||||
assertEquals(args[3], getField(interceptor, "field0"));
|
||||
assertEquals(args[0], getField(interceptor, "field1"));
|
||||
assertEquals(args[1], getField(interceptor, "field2"));
|
||||
@@ -97,13 +94,12 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test5() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1";
|
||||
Object[] args = new Object[] { (short)2, (float)3.0, "arg0", (byte)1 };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor1.class, args, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor1.class, interceptor.getClass());
|
||||
assertEquals(args[2], getField(interceptor, "field0"));
|
||||
assertEquals(args[3], getField(interceptor, "field1"));
|
||||
assertEquals(args[0], getField(interceptor, "field2"));
|
||||
@@ -112,13 +108,12 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test6() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1";
|
||||
Object[] args = new Object[] { (float)3.0, (short)2, (byte)1, "arg0" };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor1.class, args, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor1.class, interceptor.getClass());
|
||||
assertEquals(args[3], getField(interceptor, "field0"));
|
||||
assertEquals(args[2], getField(interceptor, "field1"));
|
||||
assertEquals(args[1], getField(interceptor, "field2"));
|
||||
@@ -127,30 +122,26 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test(expected=PinpointException.class)
|
||||
public void test7() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1";
|
||||
Object[] args = new Object[] { (double)3.0, (short)2, (byte)1, "arg0" };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor1.class, args, null, null);
|
||||
factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
}
|
||||
|
||||
@Test(expected=PinpointException.class)
|
||||
public void test8() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor1";
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, null, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor1.class, null, null, null);
|
||||
factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test9() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2";
|
||||
Object[] args = new Object[] { "arg0", 1, 2.0, true, 3L };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, extractorFactory, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor2.class, args, extractorFactory, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor2.class, interceptor.getClass());
|
||||
assertEquals(args[0], getField(interceptor, "field0"));
|
||||
assertEquals(args[1], getField(interceptor, "field1"));
|
||||
assertEquals(args[2], getField(interceptor, "field2"));
|
||||
@@ -163,13 +154,12 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test10() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2";
|
||||
Object[] args = new Object[] { "arg0", 1, 2.0 };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, extractorFactory, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor2.class, args, extractorFactory, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor2.class, interceptor.getClass());
|
||||
assertEquals(args[0], getField(interceptor, "field0"));
|
||||
assertEquals(args[1], getField(interceptor, "field1"));
|
||||
assertEquals(args[2], getField(interceptor, "field2"));
|
||||
@@ -182,13 +172,12 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test11() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2";
|
||||
Object[] args = new Object[] { "arg0", 1 };
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, args, extractorFactory, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor2.class, args, extractorFactory, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor2.class, interceptor.getClass());
|
||||
assertEquals(args[0], getField(interceptor, "field0"));
|
||||
assertEquals(args[1], getField(interceptor, "field1"));
|
||||
assertEquals(0.0, getField(interceptor, "field2"));
|
||||
@@ -201,12 +190,10 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test12() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2";
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, null, extractorFactory, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor2.class, null, extractorFactory, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor2.class, interceptor.getClass());
|
||||
assertEquals(null, getField(interceptor, "field0"));
|
||||
assertEquals(0, getField(interceptor, "field1"));
|
||||
assertEquals(0.0, getField(interceptor, "field2"));
|
||||
@@ -219,12 +206,10 @@ public class DefaultInterceptorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void test13() throws Exception {
|
||||
String interceptorClassName = "com.nhn.pinpoint.bootstrap.plugin.TestInterceptors$TestInterceptor2";
|
||||
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, interceptorClassName, null, null, null);
|
||||
DefaultInterceptorFactory factory = new DefaultInterceptorFactory(instrumentor, traceContext, TestInterceptor2.class, null, null, null);
|
||||
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), aClass, aMethod);
|
||||
|
||||
assertEquals(interceptorClassName, interceptor.getClass().getName());
|
||||
assertEquals(TestInterceptor2.class, interceptor.getClass());
|
||||
assertEquals(null, getField(interceptor, "field0"));
|
||||
assertEquals(0, getField(interceptor, "field1"));
|
||||
assertEquals(0.0, getField(interceptor, "field2"));
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
/.settings/
|
||||
/.project
|
||||
@@ -0,0 +1,4 @@
|
||||
/target/
|
||||
/.settings/
|
||||
/.classpath
|
||||
/.project
|
||||
@@ -0,0 +1,101 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.nhn.pinpoint</groupId>
|
||||
<artifactId>pinpoint-plugins</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pinpoint-arcus-plugin</artifactId>
|
||||
<name>pinpoint arcus plugin</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.nhn.pinpoint</groupId>
|
||||
<artifactId>pinpoint-bootstrap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.nhn.pinpoint</groupId>
|
||||
<artifactId>pinpoint-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>arcus</groupId>
|
||||
<artifactId>arcus-client</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging depedencies -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<!-- commons-logging-adapter -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${basedir}/src/main/java</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources</directory>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>${basedir}/src/main/resources-${env}</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>${basedir}/src/test/java</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</testResource>
|
||||
<testResource>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/test/resources</directory>
|
||||
</testResource>
|
||||
</testResources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<inherited>true</inherited>
|
||||
<configuration>
|
||||
<debug>true</debug>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<outputDirectory>${pinpiont-plugin-dir}</outputDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.nhn.pinpoint.plugin.arcus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.MethodInfo;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.ParameterExtractor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorBuilder;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorFactoryMapping;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.Condition;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ParameterExtractorFactory;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPlugin;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPluginContext;
|
||||
|
||||
// TODO split arcus plugin and memcached plugin
|
||||
public class ArcusPlugin implements ProfilerPlugin {
|
||||
@Override
|
||||
public List<ClassEditorFactoryMapping> getClassEditorMappings(ProfilerPluginContext context) {
|
||||
boolean arcus = context.getConfig().isArucs();
|
||||
boolean memcached = context.getConfig().isMemcached();
|
||||
|
||||
List<ClassEditorFactoryMapping> editors = new ArrayList<ClassEditorFactoryMapping>();
|
||||
|
||||
if (arcus) {
|
||||
editors.add(new ClassEditorFactoryMapping("net.spy.memcached.ArcusClient", "com.nhn.pinpoint.plugin.arcus.ArcusClientEditorFactory"));
|
||||
editors.add(new ClassEditorFactoryMapping("net.spy.memcached.internal.CollectionFuture", "com.nhn.pinpoint.plugin.arcus.FutureEditorFactory"));
|
||||
}
|
||||
|
||||
if (arcus || memcached) {
|
||||
editors.add(new ClassEditorFactoryMapping("net.spy.memcached.protocol.BaseOperationImpl", "com.nhn.pinpoint.plugin.arcus.BaseOperationImplEditorFactory"));
|
||||
editors.add(new ClassEditorFactoryMapping("net.spy.memcached.CacheManager", "com.nhn.pinpoint.plugin.arcus.BaseCacheManagerEditorFactory"));
|
||||
|
||||
editors.add(new ClassEditorFactoryMapping("net.spy.memcached.internal.GetFuture", "com.nhn.pinpoint.plugin.arcus.FutureEditorFactory"));
|
||||
editors.add(new ClassEditorFactoryMapping("net.spy.memcached.internal.ImmediateFuture", "com.nhn.pinpoint.plugin.arcus.FutureEditorFactory"));
|
||||
editors.add(new ClassEditorFactoryMapping("net.spy.memcached.internal.OperationFuture", "com.nhn.pinpoint.plugin.arcus.FutureEditorFactory"));
|
||||
|
||||
editors.add(new ClassEditorFactoryMapping("net.spy.memcached.plugin.FrontCacheGetFuture", "com.nhn.pinpoint.plugin.arcus.FrontCacheGetFutureEditorFactory"));
|
||||
editors.add(new ClassEditorFactoryMapping("net.spy.memcached.plugin.FrontCacheMemcachedClient", "com.nhn.pinpoint.plugin.arcus.FrontCacheMemcachedClientEditorFactory"));
|
||||
editors.add(new ClassEditorFactoryMapping("net.spy.memcached.MemcachedClient", "com.nhn.pinpoint.plugin.arcus.MemcachedClientEditorFactory"));
|
||||
}
|
||||
|
||||
return editors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.nhn.pinpoint.plugin.arcus;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.MethodInfo;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.ParameterExtractor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ParameterExtractorFactory;
|
||||
|
||||
public abstract class Commons {
|
||||
private Commons() {}
|
||||
|
||||
public static final String ARCUS_SCOPE = "ArcusScope";
|
||||
|
||||
public static final ParameterExtractorFactory ARCUS_KEY_EXTRACTOR_FACTORY = new ParameterExtractorFactory() {
|
||||
|
||||
@Override
|
||||
public ParameterExtractor get(InstrumentClass targetClass, MethodInfo targetMethod) {
|
||||
final int index = ParameterUtils.findFirstString(targetMethod, 3);
|
||||
|
||||
if (index != -1) {
|
||||
return new IndexParameterExtractor(index);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
package com.nhn.pinpoint.plugin.arcus;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.ParameterExtractor;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus;
|
||||
package com.nhn.pinpoint.plugin.arcus;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.MethodInfo;
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.nhn.pinpoint.plugin.arcus.accessor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.TraceValue;
|
||||
|
||||
public interface CacheKeyAccessor extends TraceValue {
|
||||
public String __getCacheKey();
|
||||
public void __setCacheKey(String cacheKey);
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.nhn.pinpoint.plugin.arcus.accessor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.TraceValue;
|
||||
|
||||
public interface CacheNameAccessor extends TraceValue {
|
||||
public String __getCacheName();
|
||||
public void __setCacheName(String cacheName);
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.nhn.pinpoint.plugin.arcus.accessor;
|
||||
|
||||
import net.spy.memcached.ops.Operation;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.TraceValue;
|
||||
|
||||
public interface OperationAccessor extends TraceValue {
|
||||
public Operation __getOperation();
|
||||
public void __setOperation(Operation operation);
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.nhn.pinpoint.plugin.arcus.accessor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.TraceValue;
|
||||
|
||||
public interface ServiceCodeAccessor extends TraceValue {
|
||||
public void __setServiceCode(String serviceCode);
|
||||
public String __getServiceCode();
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.nhn.pinpoint.plugin.arcus.editor;
|
||||
|
||||
import net.spy.memcached.CacheManager;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorBuilder;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorFactory;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.Condition;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPluginContext;
|
||||
import com.nhn.pinpoint.plugin.arcus.Commons;
|
||||
import com.nhn.pinpoint.plugin.arcus.filter.ArcusMethodFilter;
|
||||
import com.nhn.pinpoint.plugin.arcus.interceptor.ApiInterceptor;
|
||||
import com.nhn.pinpoint.plugin.arcus.interceptor.SetCacheManagerInterceptor;
|
||||
|
||||
public class ArcusClientEditorFactory implements ClassEditorFactory {
|
||||
|
||||
@Override
|
||||
public ClassEditor get(ProfilerPluginContext context) {
|
||||
boolean traceArcusKey = context.getConfig().isArucsKeyTrace();
|
||||
ClassEditorBuilder builder = context.newClassEditorBuilder();
|
||||
|
||||
builder.editWhen(new Condition() {
|
||||
|
||||
@Override
|
||||
public boolean check(InstrumentClass target) {
|
||||
return target.hasMethod("addOp", "(Ljava/lang/String;Lnet/spy/memcached/ops/OperationAccessor;)Lnet/spy/memcached/ops/OperationAccessor;");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
builder.intercept("setCacheManager", CacheManager.class).with(SetCacheManagerInterceptor.class);
|
||||
|
||||
builder.interceptMethodsFilteredBy(new ArcusMethodFilter())
|
||||
.with(ApiInterceptor.class)
|
||||
.in(Commons.ARCUS_SCOPE)
|
||||
.using(traceArcusKey ? Commons.ARCUS_KEY_EXTRACTOR_FACTORY : null);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.nhn.pinpoint.plugin.arcus.editor;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import net.spy.memcached.ConnectionFactoryBuilder;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorBuilder;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorFactory;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPluginContext;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.ServiceCodeAccessor;
|
||||
import com.nhn.pinpoint.plugin.arcus.interceptor.CacheManagerConstructInterceptor;
|
||||
|
||||
public class BaseCacheManagerEditorFactory implements ClassEditorFactory {
|
||||
|
||||
@Override
|
||||
public ClassEditor get(ProfilerPluginContext context) {
|
||||
ClassEditorBuilder builder = context.newClassEditorBuilder();
|
||||
|
||||
builder.inject(ServiceCodeAccessor.class);
|
||||
builder.interceptConstructor(String.class, String.class, ConnectionFactoryBuilder.class, CountDownLatch.class, int.class, int.class)
|
||||
.with(CacheManagerConstructInterceptor.class);
|
||||
|
||||
return builder.build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.nhn.pinpoint.plugin.arcus.editor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorBuilder;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorFactory;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPluginContext;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.ServiceCodeAccessor;
|
||||
|
||||
public class BaseOperationImplEditorFactory implements ClassEditorFactory {
|
||||
|
||||
@Override
|
||||
public ClassEditor get(ProfilerPluginContext context) {
|
||||
ClassEditorBuilder builder = context.newClassEditorBuilder();
|
||||
builder.inject(ServiceCodeAccessor.class);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.nhn.pinpoint.plugin.arcus.editor;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.sf.ehcache.Element;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorBuilder;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorFactory;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPluginContext;
|
||||
import com.nhn.pinpoint.plugin.arcus.Commons;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.CacheKeyAccessor;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.CacheNameAccessor;
|
||||
import com.nhn.pinpoint.plugin.arcus.interceptor.FrontCacheGetFutureConstructInterceptor;
|
||||
import com.nhn.pinpoint.plugin.arcus.interceptor.FrontCacheGetFutureGetInterceptor;
|
||||
|
||||
public class FrontCacheGetFutureEditorFactory implements ClassEditorFactory {
|
||||
|
||||
@Override
|
||||
public ClassEditor get(ProfilerPluginContext context) {
|
||||
ClassEditorBuilder builder = context.newClassEditorBuilder();
|
||||
|
||||
builder.inject(CacheNameAccessor.class);
|
||||
builder.inject(CacheKeyAccessor.class);
|
||||
|
||||
builder.interceptConstructor(Element.class).with(FrontCacheGetFutureConstructInterceptor.class);
|
||||
builder.intercept("get", long.class, TimeUnit.class).with(FrontCacheGetFutureGetInterceptor.class).in(Commons.ARCUS_SCOPE);
|
||||
builder.intercept("get").with(FrontCacheGetFutureGetInterceptor.class).in(Commons.ARCUS_SCOPE);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.nhn.pinpoint.plugin.arcus.editor;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorBuilder;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorFactory;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.Condition;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPluginContext;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.TypeUtils;
|
||||
import com.nhn.pinpoint.plugin.arcus.Commons;
|
||||
import com.nhn.pinpoint.plugin.arcus.filter.FrontCacheMemcachedMethodFilter;
|
||||
import com.nhn.pinpoint.plugin.arcus.interceptor.ApiInterceptor;
|
||||
|
||||
public class FrontCacheMemcachedClientEditorFactory implements ClassEditorFactory {
|
||||
|
||||
@Override
|
||||
public ClassEditor get(ProfilerPluginContext context) {
|
||||
boolean traceArcusKey = context.getConfig().isArucsKeyTrace();
|
||||
ClassEditorBuilder builder = context.newClassEditorBuilder();
|
||||
|
||||
builder.editWhen(new Condition() {
|
||||
|
||||
@Override
|
||||
public boolean check(InstrumentClass target) {
|
||||
return target.hasDeclaredMethod("putFrontCache", TypeUtils.toClassNames(String.class, Future.class, long.class));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
builder.interceptMethodsFilteredBy(new FrontCacheMemcachedMethodFilter())
|
||||
.with(ApiInterceptor.class)
|
||||
.in(Commons.ARCUS_SCOPE)
|
||||
.using(traceArcusKey ? Commons.ARCUS_KEY_EXTRACTOR_FACTORY : null);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.nhn.pinpoint.plugin.arcus.editor;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorBuilder;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorFactory;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPluginContext;
|
||||
import com.nhn.pinpoint.plugin.arcus.Commons;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.OperationAccessor;
|
||||
import com.nhn.pinpoint.plugin.arcus.interceptor.FutureGetInterceptor;
|
||||
import com.nhn.pinpoint.plugin.arcus.interceptor.FutureSetOperationInterceptor;
|
||||
|
||||
public class FutureEditorFactory implements ClassEditorFactory {
|
||||
|
||||
@Override
|
||||
public ClassEditor get(ProfilerPluginContext context) {
|
||||
ClassEditorBuilder builder = context.newClassEditorBuilder();
|
||||
|
||||
builder.inject(OperationAccessor.class);
|
||||
|
||||
builder.intercept("setOperation", net.spy.memcached.ops.Operation.class).with(FutureSetOperationInterceptor.class);
|
||||
|
||||
builder.intercept("get", long.class, TimeUnit.class).with(FutureGetInterceptor.class).in(Commons.ARCUS_SCOPE);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.nhn.pinpoint.plugin.arcus.editor;
|
||||
|
||||
import net.spy.memcached.ops.Operation;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorBuilder;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorFactory;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.Condition;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPluginContext;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.TypeUtils;
|
||||
import com.nhn.pinpoint.plugin.arcus.Commons;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.ServiceCodeAccessor;
|
||||
import com.nhn.pinpoint.plugin.arcus.filter.MemcachedMethodFilter;
|
||||
import com.nhn.pinpoint.plugin.arcus.interceptor.AddOpInterceptor;
|
||||
import com.nhn.pinpoint.plugin.arcus.interceptor.ApiInterceptor;
|
||||
|
||||
public class MemcachedClientEditorFactory implements ClassEditorFactory {
|
||||
|
||||
@Override
|
||||
public ClassEditor get(ProfilerPluginContext context) {
|
||||
boolean traceArcusKey = context.getConfig().isArucsKeyTrace();
|
||||
ClassEditorBuilder builder = context.newClassEditorBuilder();
|
||||
|
||||
builder.editWhen(new Condition() {
|
||||
|
||||
@Override
|
||||
public boolean check(InstrumentClass target) {
|
||||
return target.hasDeclaredMethod("addOp", TypeUtils.toClassNames(String.class, Operation.class));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
builder.inject(ServiceCodeAccessor.class);
|
||||
|
||||
builder.intercept("addOp", String.class, Operation.class).with(AddOpInterceptor.class);
|
||||
|
||||
builder.interceptMethodsFilteredBy(new MemcachedMethodFilter())
|
||||
.with(ApiInterceptor.class)
|
||||
.in(Commons.ARCUS_SCOPE)
|
||||
.using(traceArcusKey ? Commons.ARCUS_KEY_EXTRACTOR_FACTORY : null);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus;
|
||||
package com.nhn.pinpoint.plugin.arcus.filter;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus;
|
||||
package com.nhn.pinpoint.plugin.arcus.filter;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus;
|
||||
package com.nhn.pinpoint.plugin.arcus.filter;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
+6
-14
@@ -1,37 +1,29 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
package com.nhn.pinpoint.plugin.arcus.interceptor;
|
||||
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import net.spy.memcached.ops.Operation;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.util.MetaObject;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.ServiceCodeAccessor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
* @author emeroad
|
||||
*/
|
||||
public class AddOpInterceptor implements SimpleAroundInterceptor, TargetClassLoader {
|
||||
public class AddOpInterceptor implements SimpleAroundInterceptor {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MetaObject<String> getServiceCode = new MetaObject<String>("__getServiceCode");
|
||||
private MetaObject<String> setServiceCode = new MetaObject<String>("__setServiceCode", String.class);
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
if (isDebug) {
|
||||
logger.beforeInterceptor(target, args);
|
||||
}
|
||||
|
||||
String serviceCode = getServiceCode.invoke(target);
|
||||
Operation op = (Operation) args[1];
|
||||
|
||||
setServiceCode.invoke(op, serviceCode);
|
||||
String serviceCode = ((ServiceCodeAccessor)target).__getServiceCode();
|
||||
((ServiceCodeAccessor)args[1]).__setServiceCode(serviceCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
+14
-19
@@ -1,30 +1,28 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
package com.nhn.pinpoint.plugin.arcus.interceptor;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.RecordableTrace;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.*;
|
||||
import net.spy.memcached.MemcachedNode;
|
||||
import net.spy.memcached.ops.Operation;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.RecordableTrace;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.ParameterExtractor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SpanEventSimpleAroundInterceptor;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.bootstrap.util.MetaObject;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.OperationAccessor;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.ServiceCodeAccessor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class ApiInterceptor extends SpanEventSimpleAroundInterceptor implements ParameterExtractorSupport, TargetClassLoader {
|
||||
public class ApiInterceptor extends SpanEventSimpleAroundInterceptor {
|
||||
private final ParameterExtractor parameterExtractor;
|
||||
|
||||
|
||||
private MetaObject<Object> getOperation = new MetaObject<Object>("__getOperation");
|
||||
private MetaObject<Object> getServiceCode = new MetaObject<Object>("__getServiceCode");
|
||||
|
||||
private ParameterExtractor parameterExtractor;
|
||||
|
||||
public ApiInterceptor() {
|
||||
public ApiInterceptor(ParameterExtractor parameterExtractor) {
|
||||
super(ApiInterceptor.class);
|
||||
this.parameterExtractor = parameterExtractor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,7 +43,8 @@ public class ApiInterceptor extends SpanEventSimpleAroundInterceptor implements
|
||||
|
||||
// find the target node
|
||||
if (result instanceof Future) {
|
||||
Operation op = (Operation) getOperation.invoke(((Future<?>)result));
|
||||
Operation op = ((OperationAccessor)result).__getOperation();
|
||||
|
||||
if (op != null) {
|
||||
MemcachedNode handlingNode = op.getHandlingNode();
|
||||
SocketAddress socketAddress = handlingNode.getSocketAddress();
|
||||
@@ -59,7 +58,8 @@ public class ApiInterceptor extends SpanEventSimpleAroundInterceptor implements
|
||||
}
|
||||
|
||||
// determine the service type
|
||||
String serviceCode = (String) getServiceCode.invoke(target);
|
||||
String serviceCode = ((ServiceCodeAccessor)target).__getServiceCode();
|
||||
|
||||
if (serviceCode != null) {
|
||||
trace.recordDestinationId(serviceCode);
|
||||
trace.recordServiceType(ServiceType.ARCUS);
|
||||
@@ -70,9 +70,4 @@ public class ApiInterceptor extends SpanEventSimpleAroundInterceptor implements
|
||||
|
||||
trace.markAfterTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParameterExtractor(ParameterExtractor parameterExtractor) {
|
||||
this.parameterExtractor = parameterExtractor;
|
||||
}
|
||||
}
|
||||
+6
-14
@@ -1,34 +1,26 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
package com.nhn.pinpoint.plugin.arcus.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAfterInterceptor;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.nhn.pinpoint.bootstrap.util.MetaObject;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.ServiceCodeAccessor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
* @author emeroad
|
||||
*/
|
||||
public class CacheManagerConstructInterceptor implements SimpleAroundInterceptor {
|
||||
public class CacheManagerConstructInterceptor implements SimpleAfterInterceptor {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MetaObject<Object> setServiceCode = new MetaObject<Object>("__setServiceCode", String.class);
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
if (isDebug) {
|
||||
logger.afterInterceptor(target, args, result, throwable);
|
||||
}
|
||||
|
||||
setServiceCode.invoke(target, (String) args[1]);
|
||||
|
||||
((ServiceCodeAccessor)target).__setServiceCode((String) args[1]);
|
||||
}
|
||||
}
|
||||
+10
-16
@@ -1,15 +1,17 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
package com.nhn.pinpoint.plugin.arcus.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
|
||||
import net.sf.ehcache.Element;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAfterInterceptor;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.nhn.pinpoint.bootstrap.util.MetaObject;
|
||||
import net.sf.ehcache.Element;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.CacheKeyAccessor;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.CacheNameAccessor;
|
||||
|
||||
/**
|
||||
* @author harebox
|
||||
*/
|
||||
public class FrontCacheGetFutureConstructInterceptor implements SimpleAroundInterceptor {
|
||||
public class FrontCacheGetFutureConstructInterceptor implements SimpleAfterInterceptor {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
@@ -17,14 +19,6 @@ public class FrontCacheGetFutureConstructInterceptor implements SimpleAroundInte
|
||||
// TODO This should be extracted from FrontCacheMemcachedClient.
|
||||
private static final String DEFAULT_FRONTCACHE_NAME = "front";
|
||||
|
||||
private MetaObject<Object> setCacheName = new MetaObject<Object>("__setCacheName", String.class);
|
||||
private MetaObject<Object> setCacheKey = new MetaObject<Object>("__setCacheKey", String.class);
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
if (isDebug) {
|
||||
@@ -32,11 +26,11 @@ public class FrontCacheGetFutureConstructInterceptor implements SimpleAroundInte
|
||||
}
|
||||
|
||||
try {
|
||||
setCacheName.invoke(target, DEFAULT_FRONTCACHE_NAME);
|
||||
|
||||
((CacheNameAccessor)target).__setCacheName(DEFAULT_FRONTCACHE_NAME);
|
||||
|
||||
if (args[0] instanceof Element) {
|
||||
Element element = (Element) args[0];
|
||||
setCacheKey.invoke(target, element.getObjectKey());
|
||||
((CacheKeyAccessor)target).__setCacheKey((String)element.getObjectKey());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("failed to add metadata: {}", e);
|
||||
+13
-22
@@ -1,26 +1,29 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
package com.nhn.pinpoint.plugin.arcus.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.Trace;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.*;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.nhn.pinpoint.bootstrap.util.MetaObject;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.CacheNameAccessor;
|
||||
|
||||
/**
|
||||
* @author harebox
|
||||
*/
|
||||
public class FrontCacheGetFutureGetInterceptor implements SimpleAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport, TargetClassLoader {
|
||||
public class FrontCacheGetFutureGetInterceptor implements SimpleAroundInterceptor {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MetaObject<Object> getCacheName = new MetaObject<Object>("__getCacheName");
|
||||
private MetaObject<Object> getCacheKey = new MetaObject<Object>("__getCacheKey");
|
||||
|
||||
private MethodDescriptor methodDescriptor;
|
||||
private TraceContext traceContext;
|
||||
private final MethodDescriptor methodDescriptor;
|
||||
private final TraceContext traceContext;
|
||||
|
||||
public FrontCacheGetFutureGetInterceptor(MethodDescriptor methodDescriptor, TraceContext traceContext) {
|
||||
this.methodDescriptor = methodDescriptor;
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
@@ -56,7 +59,7 @@ public class FrontCacheGetFutureGetInterceptor implements SimpleAroundIntercepto
|
||||
// // annotate it.
|
||||
// }
|
||||
|
||||
String cacheName = (String) getCacheName.invoke(target);
|
||||
String cacheName = ((CacheNameAccessor)target).__getCacheName();
|
||||
if (cacheName != null) {
|
||||
trace.recordDestinationId(cacheName);
|
||||
}
|
||||
@@ -67,16 +70,4 @@ public class FrontCacheGetFutureGetInterceptor implements SimpleAroundIntercepto
|
||||
trace.traceBlockEnd();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.methodDescriptor = descriptor;
|
||||
this.traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTraceContext(TraceContext traceContext) {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
|
||||
}
|
||||
+20
-24
@@ -1,32 +1,40 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
package com.nhn.pinpoint.plugin.arcus.interceptor;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.*;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import net.spy.memcached.MemcachedNode;
|
||||
import net.spy.memcached.ops.Operation;
|
||||
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.bootstrap.context.Trace;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.ByteCodeMethodDescriptorSupport;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.TraceContextSupport;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.nhn.pinpoint.bootstrap.util.MetaObject;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.OperationAccessor;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.ServiceCodeAccessor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class FutureGetInterceptor implements SimpleAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport, TargetClassLoader {
|
||||
public class FutureGetInterceptor implements SimpleAroundInterceptor {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MetaObject<Object> getOperation = new MetaObject<Object>("__getOperation");
|
||||
private MetaObject<Object> getServiceCode = new MetaObject<Object>("__getServiceCode");
|
||||
private final MethodDescriptor methodDescriptor;
|
||||
private final TraceContext traceContext;
|
||||
|
||||
private MethodDescriptor methodDescriptor;
|
||||
private TraceContext traceContext;
|
||||
public FutureGetInterceptor(MethodDescriptor methodDescriptor, TraceContext traceContext) {
|
||||
this.methodDescriptor = methodDescriptor;
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
@@ -61,7 +69,7 @@ public class FutureGetInterceptor implements SimpleAroundInterceptor, ByteCodeMe
|
||||
// trace.recordAttribute(AnnotationKey.ARCUS_COMMAND, annotation);
|
||||
|
||||
// find the target node
|
||||
final Operation op = (Operation) getOperation.invoke(target);
|
||||
final Operation op = ((OperationAccessor)target).__getOperation();
|
||||
if (op != null) {
|
||||
MemcachedNode handlingNode = op.getHandlingNode();
|
||||
if (handlingNode != null) {
|
||||
@@ -78,7 +86,7 @@ public class FutureGetInterceptor implements SimpleAroundInterceptor, ByteCodeMe
|
||||
}
|
||||
|
||||
// determine the service type
|
||||
String serviceCode = (String) getServiceCode.invoke((Operation)op);
|
||||
String serviceCode = ((ServiceCodeAccessor)op).__getServiceCode();
|
||||
if (serviceCode != null) {
|
||||
trace.recordDestinationId(serviceCode);
|
||||
trace.recordServiceType(ServiceType.ARCUS_FUTURE_GET);
|
||||
@@ -100,16 +108,4 @@ public class FutureGetInterceptor implements SimpleAroundInterceptor, ByteCodeMe
|
||||
trace.traceBlockEnd();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.methodDescriptor = descriptor;
|
||||
this.traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTraceContext(TraceContext traceContext) {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.nhn.pinpoint.plugin.arcus.interceptor;
|
||||
|
||||
import net.spy.memcached.ops.Operation;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleBeforeInterceptor;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.OperationAccessor;
|
||||
|
||||
|
||||
/**
|
||||
* @author harebox
|
||||
* @author emeroad
|
||||
*/
|
||||
public class FutureSetOperationInterceptor implements SimpleBeforeInterceptor {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
if (isDebug) {
|
||||
logger.beforeInterceptor(target, args);
|
||||
}
|
||||
|
||||
((OperationAccessor)target).__setOperation((Operation) args[0]);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.nhn.pinpoint.plugin.arcus.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleBeforeInterceptor;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.nhn.pinpoint.plugin.arcus.accessor.ServiceCodeAccessor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
* @author emeroad
|
||||
*/
|
||||
public class SetCacheManagerInterceptor implements SimpleBeforeInterceptor {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
if (isDebug) {
|
||||
logger.beforeInterceptor(target, args);
|
||||
}
|
||||
|
||||
String serviceCode = ((ServiceCodeAccessor)args[0]).__getServiceCode();
|
||||
((ServiceCodeAccessor)target).__setServiceCode(serviceCode);
|
||||
}
|
||||
}
|
||||
+8
-6
@@ -1,6 +1,6 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -11,18 +11,20 @@ import net.spy.memcached.MemcachedClient;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.nhn.pinpoint.profiler.interceptor.DefaultMethodDescriptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
import com.nhn.pinpoint.profiler.modifier.BaseInterceptorTest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
import com.nhn.pinpoint.plugin.arcus.IndexParameterExtractor;
|
||||
import com.nhn.pinpoint.plugin.arcus.interceptor.ApiInterceptor;
|
||||
import com.nhn.pinpoint.profiler.interceptor.DefaultMethodDescriptor;
|
||||
import com.nhn.pinpoint.test.interceptor.BaseInterceptorTest;
|
||||
|
||||
public class ApiInterceptorTest extends BaseInterceptorTest {
|
||||
|
||||
static final Logger logger = LoggerFactory.getLogger(ApiInterceptorTest.class);
|
||||
|
||||
ApiInterceptor interceptor = new ApiInterceptor();
|
||||
ApiInterceptor interceptor = new ApiInterceptor(new IndexParameterExtractor(0));
|
||||
MemcachedClient client = mock(MockMemcachedClient.class);
|
||||
|
||||
@Before
|
||||
+16
-19
@@ -1,8 +1,7 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -24,16 +23,18 @@ import net.spy.memcached.protocol.ascii.AsciiMemcachedNodeImpl;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.nhn.pinpoint.profiler.modifier.BaseInterceptorTest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.nhn.pinpoint.plugin.arcus.interceptor.FutureGetInterceptor;
|
||||
import com.nhn.pinpoint.test.interceptor.BaseInterceptorTest;
|
||||
import com.nhn.pinpoint.test.mock.MockTraceContextFactory;
|
||||
|
||||
public class FutureGetInterceptorTest extends BaseInterceptorTest {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(FutureGetInterceptorTest.class);
|
||||
|
||||
FutureGetInterceptor interceptor = new FutureGetInterceptor();
|
||||
FutureGetInterceptor interceptor = new FutureGetInterceptor(null, new MockTraceContextFactory().create());
|
||||
|
||||
@Before
|
||||
public void beforeEach() {
|
||||
@@ -42,26 +43,22 @@ public class FutureGetInterceptorTest extends BaseInterceptorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessful() {
|
||||
public void testSuccessful() throws IOException {
|
||||
Long timeout = 1000L;
|
||||
TimeUnit unit = TimeUnit.MILLISECONDS;
|
||||
|
||||
MockOperationFuture future = mock(MockOperationFuture.class);
|
||||
MockOperation operation = mock(MockOperation.class);
|
||||
|
||||
try {
|
||||
when(operation.getException()).thenReturn(null);
|
||||
when(operation.isCancelled()).thenReturn(false);
|
||||
when(future.__getOperation()).thenReturn(operation);
|
||||
when(operation.getException()).thenReturn(null);
|
||||
when(operation.isCancelled()).thenReturn(false);
|
||||
when(future.__getOperation()).thenReturn(operation);
|
||||
|
||||
MemcachedNode node = getMockMemcachedNode();
|
||||
when(operation.getHandlingNode()).thenReturn(node);
|
||||
|
||||
interceptor.before(future, new Object[] { timeout, unit });
|
||||
interceptor.after(future, new Object[] { timeout, unit }, null, null);
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
MemcachedNode node = getMockMemcachedNode();
|
||||
when(operation.getHandlingNode()).thenReturn(node);
|
||||
|
||||
interceptor.before(future, new Object[] { timeout, unit });
|
||||
interceptor.after(future, new Object[] { timeout, unit }, null, null);
|
||||
}
|
||||
|
||||
private MemcachedNode getMockMemcachedNode() throws IOException {
|
||||
@@ -0,0 +1,22 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.nhn.pinpoint</groupId>
|
||||
<artifactId>pom</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pinpoint-plugins</artifactId>
|
||||
<name>pinpoint-plugins</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>arcus</module>
|
||||
</modules>
|
||||
<dependencies>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
</build>
|
||||
</project>
|
||||
@@ -138,6 +138,11 @@
|
||||
<classifier>classes</classifier>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.nhn.pinpoint</groupId>
|
||||
<artifactId>pinpoint-test</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
|
||||
+8
-11
@@ -9,11 +9,10 @@ import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.Agent;
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.DedicatedClassEditor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorFactoryMapping;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.PluginClassLoaderFactory;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPlugin;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPluginContext;
|
||||
import com.nhn.pinpoint.profiler.modifier.AbstractModifier;
|
||||
@@ -131,9 +130,6 @@ public class ClassFileTransformerDispatcher implements ClassFileTransformer {
|
||||
// rpc
|
||||
modifierRepository.addConnectorModifier();
|
||||
|
||||
// arcus, memcached
|
||||
modifierRepository.addArcusModifier();
|
||||
|
||||
// bloc 3.x
|
||||
modifierRepository.addBLOC3Modifier();
|
||||
|
||||
@@ -168,14 +164,15 @@ public class ClassFileTransformerDispatcher implements ClassFileTransformer {
|
||||
}
|
||||
|
||||
private void loadPlugins(DefaultModifierRegistry modifierRepository) {
|
||||
String pluginPath = agent.getAgentPath() + File.separatorChar + "plugin";
|
||||
PluginLoader loader = PluginLoader.get(pluginPath);
|
||||
PluginClassLoaderFactory classLoaderFactory = new PluginClassLoaderFactory(loader.getPluginJars());
|
||||
List<ProfilerPlugin> plugins = loader.loadPlugins();
|
||||
ProfilerPluginContext pluginContext = new ProfilerPluginContext(byteCodeInstrumentor, agent.getTraceContext());
|
||||
List<ProfilerPlugin> plugins = new PluginLoader().load(agent.getAgentPath() + File.separatorChar + "plugin");
|
||||
|
||||
for (ProfilerPlugin plugin : plugins) {
|
||||
for (ClassEditor editor : plugin.getClassEditors(pluginContext)) {
|
||||
if (editor instanceof DedicatedClassEditor) {
|
||||
modifierRepository.addModifier(new ClassEditorAdaptor(byteCodeInstrumentor, agent, (DedicatedClassEditor)editor));
|
||||
}
|
||||
for (ClassEditorFactoryMapping mapping : plugin.getClassEditorMappings(pluginContext)) {
|
||||
modifierRepository.addModifier(new ClassEditorAdaptor(byteCodeInstrumentor, agent, mapping, pluginContext, classLoaderFactory));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import com.nhn.pinpoint.profiler.context.storage.SpanStorageFactory;
|
||||
import com.nhn.pinpoint.profiler.context.storage.StorageFactory;
|
||||
import com.nhn.pinpoint.profiler.interceptor.bci.JavaAssistByteCodeInstrumentor;
|
||||
import com.nhn.pinpoint.profiler.logging.Slf4jLoggerBinder;
|
||||
import com.nhn.pinpoint.profiler.modifier.arcus.ArcusMethodFilter;
|
||||
import com.nhn.pinpoint.profiler.monitor.AgentStatMonitor;
|
||||
import com.nhn.pinpoint.profiler.receiver.CommandDispatcher;
|
||||
import com.nhn.pinpoint.profiler.sampler.SamplerFactory;
|
||||
@@ -159,7 +158,6 @@ public class DefaultAgent implements Agent {
|
||||
}
|
||||
|
||||
private void preLoadClass() {
|
||||
logger.debug("preLoadClass:{}", new ArcusMethodFilter().getClass().getName());
|
||||
logger.debug("preLoadClass:{}", PreparedStatementUtils.class.getName(), PreparedStatementUtils.findBindVariableSetMethod());
|
||||
}
|
||||
|
||||
|
||||
-61
@@ -1,22 +1,12 @@
|
||||
package com.nhn.pinpoint.profiler.modifier;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.Agent;
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPlugin;
|
||||
import com.nhn.pinpoint.profiler.ClassFileRetransformer;
|
||||
import com.nhn.pinpoint.profiler.modifier.arcus.ArcusClientModifier;
|
||||
import com.nhn.pinpoint.profiler.modifier.arcus.BaseOperationModifier;
|
||||
import com.nhn.pinpoint.profiler.modifier.arcus.CacheManagerModifier;
|
||||
import com.nhn.pinpoint.profiler.modifier.arcus.CollectionFutureModifier;
|
||||
import com.nhn.pinpoint.profiler.modifier.arcus.GetFutureModifier;
|
||||
import com.nhn.pinpoint.profiler.modifier.arcus.ImmediateFutureModifier;
|
||||
import com.nhn.pinpoint.profiler.modifier.arcus.MemcachedClientModifier;
|
||||
import com.nhn.pinpoint.profiler.modifier.arcus.OperationFutureModifier;
|
||||
import com.nhn.pinpoint.profiler.modifier.bloc.handler.HTTPHandlerModifier;
|
||||
import com.nhn.pinpoint.profiler.modifier.bloc4.NettyInboundHandlerModifier;
|
||||
import com.nhn.pinpoint.profiler.modifier.bloc4.NpcHandlerModifier;
|
||||
@@ -153,57 +143,6 @@ public class DefaultModifierRegistry implements ModifierRegistry {
|
||||
addModifier(new DefaultHttpRequestRetryHandlerModifier(byteCodeInstrumentor, agent));
|
||||
}
|
||||
|
||||
public void addArcusModifier() {
|
||||
final boolean arcus = profilerConfig.isArucs();
|
||||
boolean memcached;
|
||||
if (arcus) {
|
||||
// arcus가 true일 경우 memcached는 자동으로 true가 되야 한다.
|
||||
memcached = true;
|
||||
} else {
|
||||
memcached = profilerConfig.isMemcached();
|
||||
}
|
||||
|
||||
if (memcached) {
|
||||
BaseOperationModifier baseOperationModifier = new BaseOperationModifier(byteCodeInstrumentor, agent);
|
||||
addModifier(baseOperationModifier);
|
||||
|
||||
MemcachedClientModifier memcachedClientModifier = new MemcachedClientModifier(byteCodeInstrumentor, agent);
|
||||
addModifier(memcachedClientModifier);
|
||||
|
||||
// FrontCacheMemcachedClientModifier frontCacheMemcachedClientModifier = new FrontCacheMemcachedClientModifier(byteCodeInstrumentor, agent);
|
||||
// 관련 수정에 사이드 이펙트가 있이서 일단 disable함.
|
||||
// addModifier(frontCacheMemcachedClientModifier);
|
||||
|
||||
if (arcus) {
|
||||
ArcusClientModifier arcusClientModifier = new ArcusClientModifier(byteCodeInstrumentor, agent);
|
||||
addModifier(arcusClientModifier);
|
||||
// arcus의 Future임
|
||||
CollectionFutureModifier collectionFutureModifier = new CollectionFutureModifier(byteCodeInstrumentor, agent);
|
||||
addModifier(collectionFutureModifier);
|
||||
}
|
||||
|
||||
// future modifier start ---------------------------------------------------
|
||||
|
||||
GetFutureModifier getFutureModifier = new GetFutureModifier(byteCodeInstrumentor, agent);
|
||||
addModifier(getFutureModifier);
|
||||
|
||||
ImmediateFutureModifier immediateFutureModifier = new ImmediateFutureModifier(byteCodeInstrumentor, agent);
|
||||
addModifier(immediateFutureModifier);
|
||||
|
||||
OperationFutureModifier operationFutureModifier = new OperationFutureModifier(byteCodeInstrumentor, agent);
|
||||
addModifier(operationFutureModifier);
|
||||
|
||||
// FrontCacheGetFutureModifier frontCacheGetFutureModifier = new FrontCacheGetFutureModifier(byteCodeInstrumentor, agent);
|
||||
// 관련 수정에 사이드 이펙트가 있이서 일단 disable함.
|
||||
// addModifier(frontCacheGetFutureModifier);
|
||||
|
||||
// future modifier end ---------------------------------------------------
|
||||
|
||||
CacheManagerModifier cacheManagerModifier = new CacheManagerModifier(byteCodeInstrumentor, agent);
|
||||
addModifier(cacheManagerModifier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* BLOC 3.x
|
||||
*/
|
||||
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.Agent;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class CollectionFutureModifier extends AbstractFutureModifier {
|
||||
|
||||
public CollectionFutureModifier(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent) {
|
||||
super(byteCodeInstrumentor, agent);
|
||||
this.logger = LoggerFactory.getLogger(this.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetClass() {
|
||||
return "net/spy/memcached/internal/CollectionFuture";
|
||||
|
||||
}
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.Agent;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class GetFutureModifier extends AbstractFutureModifier {
|
||||
|
||||
public GetFutureModifier(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent) {
|
||||
super(byteCodeInstrumentor, agent);
|
||||
this.logger = LoggerFactory.getLogger(this.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetClass() {
|
||||
return "net/spy/memcached/internal/GetFuture";
|
||||
}
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.Agent;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class ImmediateFutureModifier extends AbstractFutureModifier {
|
||||
|
||||
public ImmediateFutureModifier(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent) {
|
||||
super(byteCodeInstrumentor, agent);
|
||||
this.logger = LoggerFactory.getLogger(this.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetClass() {
|
||||
return "net/spy/memcached/internal/ImmediateFuture";
|
||||
}
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.Agent;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class OperationFutureModifier extends AbstractFutureModifier {
|
||||
|
||||
|
||||
public OperationFutureModifier(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent) {
|
||||
super(byteCodeInstrumentor, agent);
|
||||
this.logger = LoggerFactory.getLogger(this.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetClass() {
|
||||
return "net/spy/memcached/internal/OperationFuture";
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
|
||||
public enum SpyVersion {
|
||||
|
||||
SPYMEMCACHED_2_11,
|
||||
ARCUSCLIENT_1_6,
|
||||
ERROR
|
||||
;
|
||||
|
||||
public SpyVersion identifyWithMemcachedConnection(InstrumentClass aClass) {
|
||||
String className = aClass.getName();
|
||||
if (! "net/spy/memcached/MemcachedConnection".equals(className)) {
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
String[] createConnectionArgs = {"java.util.Collection"};
|
||||
boolean isSpy = aClass.hasDeclaredMethod("createConnection", createConnectionArgs);
|
||||
|
||||
if (isSpy) {
|
||||
return SPYMEMCACHED_2_11;
|
||||
} else {
|
||||
return ARCUSCLIENT_1_6;
|
||||
}
|
||||
}
|
||||
|
||||
public SpyVersion identifyWithMemcachedClient(InstrumentClass aClass) {
|
||||
String className = aClass.getName();
|
||||
if (! "net/spy/memcached/MemcachedClient".equals(className)) {
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
String[] addOpArgs = {"java.lang.String", "net.spy.memcached.ops.Operation"};
|
||||
boolean isArcus = aClass.hasDeclaredMethod("addOp", addOpArgs);
|
||||
|
||||
return SPYMEMCACHED_2_11;
|
||||
}
|
||||
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.profiler.util.DepthScope;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class ArcusScope {
|
||||
public static final DepthScope SCOPE = new DepthScope("ArcusScope");
|
||||
}
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.AsyncTrace;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
|
||||
import com.nhn.pinpoint.profiler.context.DefaultAsyncTrace;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.nhn.pinpoint.bootstrap.util.TimeObject;
|
||||
import net.spy.memcached.protocol.BaseOperationImpl;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.util.MetaObject;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
@Deprecated
|
||||
public class BaseOperationCancelInterceptor implements SimpleAroundInterceptor {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MetaObject getAsyncTrace = new MetaObject("__getAsyncTrace");
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
if (isDebug) {
|
||||
logger.beforeInterceptor(target, args);
|
||||
}
|
||||
|
||||
AsyncTrace asyncTrace = (AsyncTrace) getAsyncTrace.invoke(target);
|
||||
if (asyncTrace == null) {
|
||||
logger.debug("asyncTrace not found ");
|
||||
return;
|
||||
}
|
||||
|
||||
if (asyncTrace.getState() != DefaultAsyncTrace.STATE_INIT) {
|
||||
// 이미 동작 완료된 상태임.
|
||||
return;
|
||||
}
|
||||
|
||||
BaseOperationImpl baseOperation = (BaseOperationImpl) target;
|
||||
if (!baseOperation.isCancelled()) {
|
||||
TimeObject timeObject = (TimeObject) asyncTrace.getAttachObject();
|
||||
timeObject.markCancelTime();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
|
||||
}
|
||||
}
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.Trace;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.TraceContextSupport;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.nhn.pinpoint.bootstrap.util.MetaObject;
|
||||
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
@Deprecated
|
||||
public class BaseOperationConstructInterceptor implements SimpleAroundInterceptor, TraceContextSupport {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MetaObject<Object> setAsyncTrace = new MetaObject<Object>("__setAsyncTrace", Object.class);
|
||||
private TraceContext traceContext;
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
if (isDebug) {
|
||||
logger.afterInterceptor(target, args, result, throwable);
|
||||
}
|
||||
|
||||
Trace trace = traceContext.currentTraceObject();
|
||||
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 일단 이벤트가 세지 않는다는 가정하에 별도 timeout처리가 없음.
|
||||
// AsyncTrace asyncTrace = trace.createAsyncTrace();
|
||||
// asyncTrace.markBeforeTime();
|
||||
//
|
||||
// asyncTrace.setAttachObject(new TimeObject());
|
||||
//
|
||||
// setAsyncTrace.invoke(target, asyncTrace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTraceContext(TraceContext traceContext) {
|
||||
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
}
|
||||
-161
@@ -1,161 +0,0 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.ByteCodeMethodDescriptorSupport;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.TraceContextSupport;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
|
||||
import com.nhn.pinpoint.common.AnnotationKey;
|
||||
import com.nhn.pinpoint.bootstrap.context.AsyncTrace;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.nhn.pinpoint.bootstrap.util.TimeObject;
|
||||
import net.spy.memcached.MemcachedNode;
|
||||
import net.spy.memcached.ops.OperationState;
|
||||
import net.spy.memcached.protocol.BaseOperationImpl;
|
||||
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.bootstrap.util.MetaObject;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
@Deprecated
|
||||
public class BaseOperationTransitionStateInterceptor implements SimpleAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
|
||||
private MetaObject getAsyncTrace = new MetaObject("__getAsyncTrace");
|
||||
private MetaObject getServiceCode = new MetaObject("__getServiceCode");
|
||||
|
||||
private MethodDescriptor methodDescriptor;
|
||||
private TraceContext traceContext;
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
if (isDebug) {
|
||||
logger.beforeInterceptor(target, args);
|
||||
}
|
||||
|
||||
AsyncTrace asyncTrace = (AsyncTrace) getAsyncTrace.invoke(target);
|
||||
if (asyncTrace == null) {
|
||||
if (isDebug) {
|
||||
logger.debug("asyncTrace not found");
|
||||
}
|
||||
return;
|
||||
}
|
||||
// TODO null 체크가 필요하지 않나하는데? 일단 사용하지 않는 interceptor이므로 TODO만 붙여 둔다.
|
||||
OperationState newState = (OperationState) args[0];
|
||||
|
||||
BaseOperationImpl baseOperation = (BaseOperationImpl) target;
|
||||
if (newState == OperationState.READING) {
|
||||
if (isDebug) {
|
||||
logger.debug("event:{} asyncTrace:{}", newState, asyncTrace);
|
||||
}
|
||||
if (asyncTrace.getState() != AsyncTrace.STATE_INIT) {
|
||||
return;
|
||||
}
|
||||
MemcachedNode handlingNode = baseOperation.getHandlingNode();
|
||||
SocketAddress socketAddress = handlingNode.getSocketAddress();
|
||||
if (socketAddress instanceof InetSocketAddress) {
|
||||
InetSocketAddress address = (InetSocketAddress) socketAddress;
|
||||
asyncTrace.recordEndPoint(address.getHostName() + ":" + address.getPort());
|
||||
}
|
||||
|
||||
String serviceCode = (String) getServiceCode.invoke(target);
|
||||
|
||||
if (serviceCode == null) {
|
||||
serviceCode = "UNKNOWN";
|
||||
}
|
||||
|
||||
ServiceType svcType = ServiceType.ARCUS;
|
||||
|
||||
if(serviceCode.equals(ServiceType.MEMCACHED.getDesc())) {
|
||||
svcType = ServiceType.MEMCACHED;
|
||||
}
|
||||
|
||||
asyncTrace.recordServiceType(svcType);
|
||||
// asyncTrace.recordRpcName(baseOperation.getClass().getSimpleName());
|
||||
asyncTrace.recordApi(methodDescriptor);
|
||||
|
||||
asyncTrace.recordDestinationId(serviceCode);
|
||||
|
||||
String cmd = getCommand(baseOperation);
|
||||
// asyncTrace.recordAttribute(AnnotationKey.ARCUS_COMMAND, cmd);
|
||||
|
||||
// TimeObject timeObject = (TimeObject)
|
||||
// asyncTrace.getFrameObject();
|
||||
// timeObject.markSendTime();
|
||||
|
||||
// long createTime = asyncTrace.getBeforeTime();
|
||||
asyncTrace.markAfterTime();
|
||||
// asyncTrace.traceBlockEnd();
|
||||
} else if (newState == OperationState.COMPLETE || isArcusTimeout(newState)) {
|
||||
if (isDebug) {
|
||||
logger.debug("event:{} asyncTrace:{}", newState, asyncTrace);
|
||||
}
|
||||
boolean fire = asyncTrace.fire();
|
||||
if (!fire) {
|
||||
return;
|
||||
}
|
||||
Exception exception = baseOperation.getException();
|
||||
asyncTrace.recordException(exception);
|
||||
|
||||
if (!baseOperation.isCancelled()) {
|
||||
TimeObject timeObject = (TimeObject) asyncTrace.getAttachObject();
|
||||
// asyncTrace.record(Annotation.ClientRecv, timeObject.getSendTime());
|
||||
asyncTrace.markAfterTime();
|
||||
asyncTrace.traceBlockEnd();
|
||||
} else {
|
||||
asyncTrace.recordAttribute(AnnotationKey.EXCEPTION, "cancelled by user");
|
||||
TimeObject timeObject = (TimeObject) asyncTrace.getAttachObject();
|
||||
// asyncTrace.record(Annotation.ClientRecv, timeObject.getCancelTime());
|
||||
asyncTrace.markAfterTime();
|
||||
asyncTrace.traceBlockEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isArcusTimeout(OperationState newState) {
|
||||
if (newState == null) {
|
||||
return false;
|
||||
}
|
||||
// arcus에만 추가된 타입이라. 따로 처리함.
|
||||
return "TIMEDOUT".equals(newState.toString());
|
||||
}
|
||||
|
||||
private String getCommand(BaseOperationImpl baseOperation) {
|
||||
ByteBuffer buffer = baseOperation.getBuffer();
|
||||
if (buffer == null) {
|
||||
return "UNKNOWN";
|
||||
}
|
||||
// System.out.println(buffer.array().length + " po:" + buffer.position()
|
||||
// + " limit:" + buffer.limit() + " remaining"
|
||||
// + buffer.remaining() + " aoffset:" + buffer.arrayOffset());
|
||||
return new String(buffer.array(), UTF8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.methodDescriptor = descriptor;
|
||||
this.traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTraceContext(TraceContext traceContext) {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
}
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import net.spy.memcached.ops.Operation;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.util.MetaObject;
|
||||
|
||||
|
||||
/**
|
||||
* @author harebox
|
||||
* @author emeroad
|
||||
*/
|
||||
public class FutureSetOperationInterceptor implements SimpleAroundInterceptor, TargetClassLoader {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MetaObject<Object> setOperation = new MetaObject<Object>("__setOperation", Operation.class);
|
||||
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
if (isDebug) {
|
||||
logger.beforeInterceptor(target, args);
|
||||
}
|
||||
|
||||
setOperation.invoke(target, (Operation) args[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
}
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.arcus.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import net.spy.memcached.CacheManager;
|
||||
import net.spy.memcached.MemcachedClient;
|
||||
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.util.MetaObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
* @author emeroad
|
||||
*/
|
||||
public class SetCacheManagerInterceptor implements SimpleAroundInterceptor, TargetClassLoader {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
private final boolean isDebug = logger.isDebugEnabled();
|
||||
|
||||
private MetaObject<String> getServiceCode = new MetaObject<String>("__getServiceCode");
|
||||
private MetaObject<String> setServiceCode = new MetaObject<String>("__setServiceCode", String.class);
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
if (isDebug) {
|
||||
logger.beforeInterceptor(target, args);
|
||||
}
|
||||
|
||||
CacheManager cm = (CacheManager) args[0];
|
||||
String serviceCode = getServiceCode.invoke(cm);
|
||||
|
||||
setServiceCode.invoke((MemcachedClient) target, serviceCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
|
||||
}
|
||||
}
|
||||
+40
-6
@@ -4,24 +4,58 @@ import java.security.ProtectionDomain;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.Agent;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.ByteCodeInstrumentor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.DedicatedClassEditor;
|
||||
import com.nhn.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditor;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorFactory;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ClassEditorFactoryMapping;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.PluginClassLoaderFactory;
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPluginContext;
|
||||
import com.nhn.pinpoint.exception.PinpointException;
|
||||
import com.nhn.pinpoint.profiler.modifier.AbstractModifier;
|
||||
|
||||
public class ClassEditorAdaptor extends AbstractModifier {
|
||||
private final DedicatedClassEditor editor;
|
||||
private final ClassEditorFactoryMapping mapping;
|
||||
private final ProfilerPluginContext pluginContext;
|
||||
private final PluginClassLoaderFactory classLoaderFactory;
|
||||
|
||||
|
||||
public ClassEditorAdaptor(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent, DedicatedClassEditor editor) {
|
||||
public ClassEditorAdaptor(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent, ClassEditorFactoryMapping mapping, ProfilerPluginContext pluginContext, PluginClassLoaderFactory classLoaderFactory) {
|
||||
super(byteCodeInstrumentor, agent);
|
||||
this.editor = editor;
|
||||
this.mapping = mapping;
|
||||
this.pluginContext = pluginContext;
|
||||
this.classLoaderFactory = classLoaderFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] modify(ClassLoader classLoader, String className, ProtectionDomain protectionDomain, byte[] classFileBuffer) {
|
||||
return editor.edit(classLoader, className, protectionDomain, classFileBuffer);
|
||||
ClassLoader forPlugin = classLoaderFactory.get(classLoader);
|
||||
|
||||
ClassLoader old = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(forPlugin);
|
||||
|
||||
try {
|
||||
Class<?> editorFactoryClass = forPlugin.loadClass(mapping.getEditorFactoryClassName());
|
||||
|
||||
if (!ClassEditorFactory.class.isAssignableFrom(editorFactoryClass)) {
|
||||
throw new PinpointException("Illegal class editor factory mapping. factory class[" + editorFactoryClass + "] did not implent ClassEditorFactory");
|
||||
}
|
||||
|
||||
ClassEditorFactory editorFactory = (ClassEditorFactory)editorFactoryClass.newInstance();
|
||||
ClassEditor editor = editorFactory.get(pluginContext);
|
||||
|
||||
InstrumentClass target = byteCodeInstrumentor.getClass(classLoader, className, classFileBuffer);
|
||||
|
||||
return editor.edit(classLoader, target);
|
||||
} catch (Exception e) {
|
||||
throw new PinpointException("Fail to invoke plugin class editor for " + mapping.getTargetClassName() + ", editor factory: " + mapping.getEditorFactoryClassName(), e);
|
||||
} finally {
|
||||
Thread.currentThread().setContextClassLoader(old);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetClass() {
|
||||
return editor.getTargetClassName();
|
||||
return mapping.getTargetClassName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,21 +11,27 @@ import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.plugin.ProfilerPlugin;
|
||||
import com.nhn.pinpoint.exception.PinpointException;
|
||||
|
||||
public class PluginLoader {
|
||||
public List<ProfilerPlugin> load(String pluginPath) {
|
||||
File[] jars = findJars(pluginPath);
|
||||
URLClassLoader classLoader = getClassLoader(jars);
|
||||
List<ProfilerPlugin> plugins = loadPlugins(jars, classLoader);
|
||||
|
||||
return plugins;
|
||||
private final URL[] jars;;
|
||||
|
||||
public static PluginLoader get(String pluginPath) {
|
||||
URL[] jars = findJars(pluginPath);
|
||||
return new PluginLoader(jars);
|
||||
}
|
||||
|
||||
|
||||
public PluginLoader(URL[] jars) {
|
||||
this.jars = jars;
|
||||
}
|
||||
|
||||
private List<ProfilerPlugin> loadPlugins(File[] jars, URLClassLoader classLoader) {
|
||||
List<ProfilerPlugin> plugins = new ArrayList<ProfilerPlugin>(jars.length);
|
||||
|
||||
public List<ProfilerPlugin> loadPlugins() {
|
||||
URLClassLoader classLoader = new URLClassLoader(jars, ClassLoader.getSystemClassLoader());
|
||||
ServiceLoader<ProfilerPlugin> loader = ServiceLoader.load(ProfilerPlugin.class, classLoader);
|
||||
|
||||
Iterator<ProfilerPlugin> iterator = loader.iterator();
|
||||
List<ProfilerPlugin> plugins = new ArrayList<ProfilerPlugin>(jars.length);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
plugins.add(iterator.next());
|
||||
@@ -33,24 +39,12 @@ public class PluginLoader {
|
||||
|
||||
return plugins;
|
||||
}
|
||||
|
||||
private URLClassLoader getClassLoader(File[] jars) {
|
||||
URL[] urls = new URL[jars.length];
|
||||
|
||||
for (int i = 0; i < jars.length; i++) {
|
||||
try {
|
||||
urls[i] = jars[i].toURI().toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
URLClassLoader classLoader = new URLClassLoader(urls, ClassLoader.getSystemClassLoader());
|
||||
return classLoader;
|
||||
|
||||
public URL[] getPluginJars() {
|
||||
return jars;
|
||||
}
|
||||
|
||||
private File[] findJars(String pluginPath) {
|
||||
private static URL[] findJars(String pluginPath) {
|
||||
File file = new File(pluginPath);
|
||||
|
||||
File[] jars = file.listFiles(new FilenameFilter() {
|
||||
@@ -60,6 +54,18 @@ public class PluginLoader {
|
||||
return name.endsWith(".jar");
|
||||
}
|
||||
});
|
||||
return jars;
|
||||
|
||||
|
||||
URL[] urls = new URL[jars.length];
|
||||
|
||||
for (int i = 0; i < jars.length; i++) {
|
||||
try {
|
||||
urls[i] = jars[i].toURI().toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
throw new PinpointException("Fail to load plugin jars", e);
|
||||
}
|
||||
}
|
||||
|
||||
return urls;
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.tomcat;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.profiler.context.DefaultTraceContext;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class MockTraceContextFactory {
|
||||
public TraceContext create() {
|
||||
DefaultTraceContext traceContext = new DefaultTraceContext() ;
|
||||
ProfilerConfig profilerConfig = new ProfilerConfig();
|
||||
traceContext.setProfilerConfig(profilerConfig);
|
||||
return traceContext;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/target/
|
||||
/.settings/
|
||||
/.classpath
|
||||
/.project
|
||||
@@ -0,0 +1,91 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.nhn.pinpoint</groupId>
|
||||
<artifactId>pom</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pinpoint-test</artifactId>
|
||||
<name>pinpoint test helper libraries</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.nhn.pinpoint</groupId>
|
||||
<artifactId>pinpoint-profiler</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging depedencies -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<!-- commons-logging-adapter -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${basedir}/src/main/java</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources</directory>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>${basedir}/src/main/resources-${env}</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>${basedir}/src/test/java</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</testResource>
|
||||
<testResource>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/test/resources</directory>
|
||||
</testResource>
|
||||
</testResources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<inherited>true</inherited>
|
||||
<configuration>
|
||||
<debug>true</debug>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<outputDirectory>${pinpiont-plugin-dir}</outputDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+3
-2
@@ -1,18 +1,19 @@
|
||||
package com.nhn.pinpoint.profiler.modifier;
|
||||
package com.nhn.pinpoint.test.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import com.nhn.pinpoint.profiler.context.MockTraceContextFactory;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.ByteCodeMethodDescriptorSupport;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.Interceptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.TraceContextSupport;
|
||||
import com.nhn.pinpoint.profiler.logging.Slf4jLoggerBinder;
|
||||
import com.nhn.pinpoint.test.mock.MockTraceContextFactory;
|
||||
|
||||
public class BaseInterceptorTest {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.nhn.pinpoint.test.mock;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.profiler.context.DefaultTraceContext;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class MockTraceContextFactory {
|
||||
public TraceContext create() {
|
||||
DefaultTraceContext traceContext = new DefaultTraceContext() ;
|
||||
ProfilerConfig profilerConfig = new ProfilerConfig();
|
||||
traceContext.setProfilerConfig(profilerConfig);
|
||||
return traceContext;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user