Search in sources :

Example 11 with Interceptor

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

the class AnnotatedInterceptorFactoryTest method test0.

@Test
public void test0() throws Exception {
    AnnotatedInterceptorFactory factory = newAnnotatedInterceptorFactory();
    Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), TestInterceptor0.class.getName(), null, null, null, instrumentClass, instrumentMethod);
    assertEquals(TestInterceptor0.class, interceptor.getClass());
}
Also used : TestInterceptor0(com.navercorp.pinpoint.profiler.plugin.TestInterceptors.TestInterceptor0) Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor) AnnotatedInterceptorFactory(com.navercorp.pinpoint.profiler.interceptor.factory.AnnotatedInterceptorFactory) Test(org.junit.Test)

Example 12 with Interceptor

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

the class JavassistClassTest method testBeforeAddInterceptor.

@Test
public void testBeforeAddInterceptor() throws Exception {
    final TestClassLoader loader = getTestClassLoader();
    final String javassistClassName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
    loader.addTransformer(javassistClassName, new TransformCallback() {

        @Override
        public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
            try {
                logger.info("modify className:{} cl:{}", className, classLoader);
                InstrumentClass aClass = instrumentor.getInstrumentClass(classLoader, javassistClassName, classfileBuffer);
                String methodName = "callA";
                InstrumentMethod callaMethod = aClass.getDeclaredMethod(methodName);
                callaMethod.addInterceptor("com.navercorp.pinpoint.test.javasssit.TestBeforeInterceptor");
                byte[] bytes = aClass.toBytecode();
                return bytes;
            } catch (Throwable e) {
                e.printStackTrace();
                throw new RuntimeException(e.getMessage(), e);
            }
        }
    });
    Class<?> testObjectClazz = loader.loadClass(javassistClassName);
    final String methodName = "callA";
    logger.info("class:{}", testObjectClazz.toString());
    logger.info("class cl:{}", testObjectClazz.getClassLoader());
    final Object testObject = testObjectClazz.newInstance();
    Method callA = testObjectClazz.getMethod(methodName);
    callA.invoke(testObject);
    Interceptor interceptor = getInterceptor(loader, 0);
    assertEqualsIntField(interceptor, "call", 1);
    assertEqualsObjectField(interceptor, "className", "com.navercorp.pinpoint.test.javasssit.mock.TestObject");
    assertEqualsObjectField(interceptor, "methodName", methodName);
    assertEqualsObjectField(interceptor, "args", null);
    assertEqualsObjectField(interceptor, "target", testObject);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) Method(java.lang.reflect.Method) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) TestClassLoader(com.navercorp.pinpoint.test.classloader.TestClassLoader) TestClassLoader(com.navercorp.pinpoint.test.classloader.TestClassLoader) Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor) Test(org.junit.Test)

Example 13 with Interceptor

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

the class JavassistClassTest method testAddAfterInterceptor.

@Ignore
@Test
public void testAddAfterInterceptor() throws Exception {
    final TestClassLoader loader = getTestClassLoader();
    final String testClassObject = "com.navercorp.pinpoint.test.javasssit.mock.TestObject2";
    loader.addTransformer(testClassObject, new TransformCallback() {

        @Override
        public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
            try {
                logger.info("modify cl:{}", classLoader);
                InstrumentClass aClass = instrumentor.getInstrumentClass(classLoader, testClassObject, classfileBuffer);
                String methodName = "callA";
                aClass.getDeclaredMethod(methodName).addInterceptor("com.navercorp.pinpoint.profiler.interceptor.TestAfterInterceptor");
                String methodName2 = "callB";
                aClass.getDeclaredMethod(methodName2).addInterceptor("com.navercorp.pinpoint.profiler.interceptor.TestAfterInterceptor");
                return aClass.toBytecode();
            } catch (InstrumentException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
    });
    Class<?> testObjectClazz = loader.loadClass(testClassObject);
    final String methodName = "callA";
    logger.info("class:{}", testObjectClazz.toString());
    final Object testObject = testObjectClazz.newInstance();
    Method callA = testObjectClazz.getMethod(methodName);
    Object result = callA.invoke(testObject);
    Interceptor interceptor = getInterceptor(loader, 0);
    assertEqualsIntField(interceptor, "call", 1);
    assertEqualsObjectField(interceptor, "className", testClassObject);
    assertEqualsObjectField(interceptor, "methodName", methodName);
    assertEqualsObjectField(interceptor, "args", null);
    assertEqualsObjectField(interceptor, "target", testObject);
    assertEqualsObjectField(interceptor, "result", result);
    final String methodName2 = "callB";
    Method callBMethod = testObject.getClass().getMethod(methodName2);
    callBMethod.invoke(testObject);
    Interceptor interceptor2 = getInterceptor(loader, 1);
    assertEqualsIntField(interceptor2, "call", 1);
    assertEqualsObjectField(interceptor2, "className", testClassObject);
    assertEqualsObjectField(interceptor2, "methodName", methodName2);
    assertEqualsObjectField(interceptor2, "args", null);
    assertEqualsObjectField(interceptor2, "target", testObject);
    assertEqualsObjectField(interceptor2, "result", null);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) Method(java.lang.reflect.Method) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) TestClassLoader(com.navercorp.pinpoint.test.classloader.TestClassLoader) TestClassLoader(com.navercorp.pinpoint.test.classloader.TestClassLoader) Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with Interceptor

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

the class JavassistClassTest method getInterceptor.

private Interceptor getInterceptor(final TestClassLoader loader, int index) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
    Class<?> interceptorClazz = loader.loadClass("com.navercorp.pinpoint.test.javasssit.TestInterceptors");
    Method getMethod = interceptorClazz.getMethod("get", int.class);
    Interceptor interceptor = (Interceptor) getMethod.invoke(null, index);
    return interceptor;
}
Also used : InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) Method(java.lang.reflect.Method) Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor)

Example 15 with Interceptor

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

the class ASMMethod method addInterceptor0.

private int addInterceptor0(String interceptorClassName, Object[] constructorArgs, InterceptorScope scope, ExecutionPolicy executionPolicy) throws InstrumentException {
    final ScopeInfo scopeInfo = resolveScopeInfo(interceptorClassName, scope, executionPolicy);
    final Interceptor interceptor = createInterceptor(interceptorClassName, scopeInfo, constructorArgs);
    final int interceptorId = this.interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(interceptor);
    addInterceptor0(interceptor, interceptorId);
    return interceptorId;
}
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