Search in sources :

Example 11 with InstrumentClass

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.

the class ActiveMQClientPlugin method addProducerEditor.

private void addProducerEditor(final Filter<String> excludeDestinationFilter) {
    final MethodFilter methodFilter = MethodFilters.chain(MethodFilters.name("send"), MethodFilters.argAt(0, "javax.jms.Destination"), MethodFilters.argAt(1, "javax.jms.Message"));
    transformTemplate.transform(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_PRODUCER_FQCN, new TransformCallback() {

        @Override
        public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
            InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
            target.addGetter(ActiveMQClientConstants.FIELD_GETTER_ACTIVEMQ_SESSION, ActiveMQClientConstants.FIELD_ACTIVEMQ_MESSAGE_PRODUCER_SESSION);
            for (InstrumentMethod method : target.getDeclaredMethods(methodFilter)) {
                try {
                    method.addInterceptor(ActiveMQClientConstants.ACTIVEMQ_MESSAGE_PRODUCER_SEND_INTERCEPTOR_FQCN, va(excludeDestinationFilter));
                } catch (Exception e) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("Unsupported method " + method, e);
                    }
                }
            }
            return target.toBytecode();
        }
    });
}
Also used : ProtectionDomain(java.security.ProtectionDomain) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) MethodFilter(com.navercorp.pinpoint.bootstrap.instrument.MethodFilter) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)

Example 12 with InstrumentClass

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.

the class GsonPlugin method setup.

@Override
public void setup(ProfilerPluginSetupContext context) {
    GsonConfig config = new GsonConfig(context.getConfig());
    logger.debug("[Gson] Initialized config={}", config);
    if (config.isProfile()) {
        transformTemplate.transform("com.google.gson.Gson", new TransformCallback() {

            @Override
            public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
                InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
                for (InstrumentMethod m : target.getDeclaredMethods(MethodFilters.name("fromJson"))) {
                    m.addScopedInterceptor("com.navercorp.pinpoint.plugin.gson.interceptor.FromJsonInterceptor", GSON_SCOPE);
                }
                for (InstrumentMethod m : target.getDeclaredMethods(MethodFilters.name("toJson"))) {
                    m.addScopedInterceptor("com.navercorp.pinpoint.plugin.gson.interceptor.ToJsonInterceptor", GSON_SCOPE);
                }
                return target.toBytecode();
            }
        });
    }
}
Also used : ProtectionDomain(java.security.ProtectionDomain) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)

Example 13 with InstrumentClass

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.

the class DedicatedClassFileTransformer method transform.

@Override
public byte[] transform(ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
    try {
        InstrumentClass target = context.getInstrumentClass(classLoader, className, classfileBuffer);
        recipe.edit(classLoader, target);
        return target.toBytecode();
    } catch (PinpointException e) {
        throw e;
    } catch (Throwable e) {
        String msg = "Fail to invoke plugin class recipe: " + toString();
        throw new PinpointException(msg, e);
    }
}
Also used : PinpointException(com.navercorp.pinpoint.exception.PinpointException) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)

Example 14 with InstrumentClass

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.

the class InvokeAfterCodeGeneratorTest method testGenerate_AroundInterceptor3_NoCatchClause.

@Test
public void testGenerate_AroundInterceptor3_NoCatchClause() throws Exception {
    final Class<AroundInterceptor3> aroundInterceptor3Class = AroundInterceptor3.class;
    final InterceptorDefinition interceptorDefinition = interceptorDefinitionFactory.createInterceptorDefinition(aroundInterceptor3Class);
    final InstrumentClass mockClass = mock(InstrumentClass.class);
    Mockito.when(mockClass.getName()).thenReturn("TestClass");
    final InstrumentMethod mockMethod = mock(InstrumentMethod.class);
    Mockito.when(mockMethod.getName()).thenReturn("TestMethod");
    Mockito.when(mockMethod.getParameterTypes()).thenReturn(new String[] { "java.lang.Object", "java.lang.Object", "java.lang.Object" });
    Mockito.when(mockMethod.getReturnType()).thenReturn("java.lang.Object");
    ApiMetaDataService apiMetaDataService = mock(ApiMetaDataService.class);
    final InvokeAfterCodeGenerator invokeAfterCodeGenerator = new InvokeAfterCodeGenerator(100, interceptorDefinition, mockClass, mockMethod, apiMetaDataService, false, false);
    final String generate = invokeAfterCodeGenerator.generate();
    logger.debug("testGenerate_AroundInterceptor3_NoCatchClause:{}", generate);
    Assert.assertTrue(generate.contains("($w)$1"));
    Assert.assertTrue(generate.contains("($w)$2"));
    Assert.assertTrue(generate.contains("($w)$3"));
    Assert.assertTrue(generate.contains("($w)$_"));
}
Also used : AroundInterceptor3(com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor3) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) ApiMetaDataService(com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService) Test(org.junit.Test)

Example 15 with InstrumentClass

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.

the class MyBatisPlugin method addInterceptorsForSqlSession.

// SqlSession implementations
private void addInterceptorsForSqlSession() {
    final MethodFilter methodFilter = MethodFilters.name("selectOne", "selectList", "selectMap", "select", "insert", "update", "delete");
    final String[] sqlSessionImpls = { "org.apache.ibatis.session.defaults.DefaultSqlSession", "org.mybatis.spring.SqlSessionTemplate" };
    for (final String sqlSession : sqlSessionImpls) {
        transformTemplate.transform(sqlSession, new TransformCallback() {

            @Override
            public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
                final InstrumentClass target = instrumentor.getInstrumentClass(loader, sqlSession, classfileBuffer);
                final List<InstrumentMethod> methodsToTrace = target.getDeclaredMethods(methodFilter);
                for (InstrumentMethod methodToTrace : methodsToTrace) {
                    String sqlSessionOperationInterceptor = "com.navercorp.pinpoint.plugin.mybatis.interceptor.SqlSessionOperationInterceptor";
                    methodToTrace.addScopedInterceptor(sqlSessionOperationInterceptor, MYBATIS_SCOPE, ExecutionPolicy.BOUNDARY);
                }
                return target.toBytecode();
            }
        });
    }
}
Also used : ProtectionDomain(java.security.ProtectionDomain) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) MethodFilter(com.navercorp.pinpoint.bootstrap.instrument.MethodFilter) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) List(java.util.List)

Aggregations

InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)60 Instrumentor (com.navercorp.pinpoint.bootstrap.instrument.Instrumentor)44 ProtectionDomain (java.security.ProtectionDomain)44 TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)42 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)30 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)29 Test (org.junit.Test)18 InstrumentContext (com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext)8 InstrumentEngine (com.navercorp.pinpoint.profiler.instrument.InstrumentEngine)6 ApiMetaDataService (com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService)5 TestClassLoader (com.navercorp.pinpoint.test.classloader.TestClassLoader)5 Method (java.lang.reflect.Method)5 AroundInterceptor3 (com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor3)4 JavassistClassTest (com.navercorp.pinpoint.test.javasssit.JavassistClassTest)3 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)2 MethodFilter (com.navercorp.pinpoint.bootstrap.instrument.MethodFilter)2 Interceptor (com.navercorp.pinpoint.bootstrap.interceptor.Interceptor)2 ObjectFactory (com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory)2 PreparedStatementBindingMethodFilter (com.navercorp.pinpoint.bootstrap.plugin.jdbc.PreparedStatementBindingMethodFilter)2 List (java.util.List)2