Search in sources :

Example 1 with Interceptor

use of com.navercorp.pinpoint.bootstrap.interceptor.Interceptor in project pinpoint by naver.

the class ASMMethodVariables method initInterceptorVar.

private void initInterceptorVar(final InsnList instructions, final int interceptorId) {
    assertInitializedInterceptorLocalVariables();
    this.interceptorVarIndex = addInterceptorLocalVariable("_$PINPOINT$_interceptor", "Lcom/navercorp/pinpoint/bootstrap/interceptor/Interceptor;");
    push(instructions, interceptorId);
    instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(InterceptorRegistry.class), "getInterceptor", "(I)" + Type.getDescriptor(Interceptor.class), false));
    storeVar(instructions, this.interceptorVarIndex);
    this.resultVarIndex = addInterceptorLocalVariable("_$PINPOINT$_result", "Ljava/lang/Object;");
    loadNull(instructions);
    storeVar(instructions, this.resultVarIndex);
    this.throwableVarIndex = addInterceptorLocalVariable("_$PINPOINT$_throwable", "Ljava/lang/Throwable;");
    loadNull(instructions);
    storeVar(instructions, this.throwableVarIndex);
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor)

Example 2 with Interceptor

use of com.navercorp.pinpoint.bootstrap.interceptor.Interceptor in project pinpoint by naver.

the class ASMMethod method createInterceptor.

private Interceptor createInterceptor(String interceptorClassName, ScopeInfo scopeInfo, Object[] constructorArgs) {
    final ClassLoader classLoader = this.declaringClass.getClassLoader();
    // exception handling.
    final AnnotatedInterceptorFactory factory = objectBinderFactory.newAnnotatedInterceptorFactory(this.pluginContext, true);
    final Interceptor interceptor = factory.getInterceptor(classLoader, interceptorClassName, constructorArgs, scopeInfo.getScope(), scopeInfo.getPolicy(), this.declaringClass, this);
    return interceptor;
}
Also used : Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor) AnnotatedInterceptorFactory(com.navercorp.pinpoint.profiler.interceptor.factory.AnnotatedInterceptorFactory)

Example 3 with Interceptor

use of com.navercorp.pinpoint.bootstrap.interceptor.Interceptor in project pinpoint by naver.

the class AnnotatedInterceptorFactory method getInterceptor.

@Override
public Interceptor getInterceptor(ClassLoader classLoader, String interceptorClassName, Object[] providedArguments, InterceptorScope scope, ExecutionPolicy policy, InstrumentClass target, InstrumentMethod targetMethod) {
    Class<? extends Interceptor> interceptorType = pluginContext.injectClass(classLoader, interceptorClassName);
    if (scope == null) {
        Scope interceptorScope = interceptorType.getAnnotation(Scope.class);
        if (interceptorScope != null) {
            String scopeName = interceptorScope.value();
            scope = pluginContext.getInterceptorScope(scopeName);
            policy = interceptorScope.executionPolicy();
        }
    }
    AutoBindingObjectFactory factory = new AutoBindingObjectFactory(profilerConfig, traceContext, pluginContext, classLoader);
    ObjectFactory objectFactory = ObjectFactory.byConstructor(interceptorClassName, providedArguments);
    InterceptorArgumentProvider interceptorArgumentProvider = new InterceptorArgumentProvider(dataSourceMonitorRegistry, apiMetaDataService, scope, target, targetMethod);
    Interceptor interceptor = (Interceptor) factory.createInstance(objectFactory, interceptorArgumentProvider);
    if (scope != null) {
        if (exceptionHandle) {
            interceptor = wrapByExceptionHandleScope(interceptor, scope, policy == null ? ExecutionPolicy.BOUNDARY : policy);
        } else {
            interceptor = wrapByScope(interceptor, scope, policy == null ? ExecutionPolicy.BOUNDARY : policy);
        }
    } else {
        if (exceptionHandle) {
            interceptor = wrapByExceptionHandle(interceptor);
        }
    }
    return interceptor;
}
Also used : AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) InterceptorScope(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScope) Scope(com.navercorp.pinpoint.bootstrap.interceptor.annotation.Scope) ObjectFactory(com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory) AutoBindingObjectFactory(com.navercorp.pinpoint.profiler.objectfactory.AutoBindingObjectFactory) InterceptorArgumentProvider(com.navercorp.pinpoint.profiler.objectfactory.InterceptorArgumentProvider) ExceptionHandleScopedStaticAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.scope.ExceptionHandleScopedStaticAroundInterceptor) ExceptionHandleScopedInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.scope.ExceptionHandleScopedInterceptor) ExceptionHandleAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.ExceptionHandleAroundInterceptor) Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor) ExceptionHandleStaticAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.ExceptionHandleStaticAroundInterceptor) ScopedInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.scope.ScopedInterceptor) StaticAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.StaticAroundInterceptor) ExceptionHandleScopedApiIdAwareAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.scope.ExceptionHandleScopedApiIdAwareAroundInterceptor) AroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor) ScopedApiIdAwareAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.scope.ScopedApiIdAwareAroundInterceptor) ApiIdAwareAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.ApiIdAwareAroundInterceptor) ScopedStaticAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.scope.ScopedStaticAroundInterceptor) ExceptionHandleApiIdAwareAroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.ExceptionHandleApiIdAwareAroundInterceptor)

Example 4 with Interceptor

use of com.navercorp.pinpoint.bootstrap.interceptor.Interceptor in project pinpoint by naver.

the class JavassistMethod method createInterceptor.

private Interceptor createInterceptor(String interceptorClassName, ScopeInfo scopeInfo, Object[] constructorArgs) {
    ClassLoader classLoader = declaringClass.getClassLoader();
    AnnotatedInterceptorFactory factory = objectBinderFactory.newAnnotatedInterceptorFactory(pluginContext, false);
    Interceptor interceptor = factory.getInterceptor(classLoader, interceptorClassName, constructorArgs, scopeInfo.getScope(), scopeInfo.getPolicy(), declaringClass, this);
    return interceptor;
}
Also used : Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor) AnnotatedInterceptorFactory(com.navercorp.pinpoint.profiler.interceptor.factory.AnnotatedInterceptorFactory)

Example 5 with Interceptor

use of com.navercorp.pinpoint.bootstrap.interceptor.Interceptor in project pinpoint by naver.

the class SampleClass method voidMethod.

public void voidMethod() {
    Interceptor interceptor = new ArgsArrayInterceptor();
    Object[] args = null;
    Object result = null;
    Throwable throwable = null;
    try {
        ((ArgsArrayInterceptor) interceptor).before(this, args);
        ((ArgsArrayInterceptor) interceptor).after(this, args, result, throwable);
    } catch (Throwable t) {
        throwable = t;
        ((ArgsArrayInterceptor) interceptor).after(this, args, result, t);
    }
}
Also used : Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor)

Aggregations

Interceptor (com.navercorp.pinpoint.bootstrap.interceptor.Interceptor)22 AnnotatedInterceptorFactory (com.navercorp.pinpoint.profiler.interceptor.factory.AnnotatedInterceptorFactory)14 Test (org.junit.Test)14 TestInterceptor2 (com.navercorp.pinpoint.profiler.plugin.TestInterceptors.TestInterceptor2)5 TestInterceptor1 (com.navercorp.pinpoint.profiler.plugin.TestInterceptors.TestInterceptor1)4 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)3 TestInterceptor0 (com.navercorp.pinpoint.profiler.plugin.TestInterceptors.TestInterceptor0)3 Method (java.lang.reflect.Method)3 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)2 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)2 Instrumentor (com.navercorp.pinpoint.bootstrap.instrument.Instrumentor)2 TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)2 TestClassLoader (com.navercorp.pinpoint.test.classloader.TestClassLoader)2 ProtectionDomain (java.security.ProtectionDomain)2 ApiIdAwareAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.ApiIdAwareAroundInterceptor)1 AroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor)1 ExceptionHandleApiIdAwareAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.ExceptionHandleApiIdAwareAroundInterceptor)1 ExceptionHandleAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.ExceptionHandleAroundInterceptor)1 ExceptionHandleStaticAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.ExceptionHandleStaticAroundInterceptor)1 StaticAroundInterceptor (com.navercorp.pinpoint.bootstrap.interceptor.StaticAroundInterceptor)1