Search in sources :

Example 21 with InstrumentClass

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

the class OraclePlugin method addCallableStatementTransformer.

private void addCallableStatementTransformer() {
    TransformCallback transformer = 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);
            if (className.equals(CLASS_CALLABLE_STATEMENT)) {
                if (instrumentor.exist(loader, CLASS_CALLABLE_STATEMENT_WRAPPER)) {
                    return null;
                }
            }
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor");
            target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.CallableStatementRegisterOutParameterInterceptor", OracleConstants.ORACLE_SCOPE);
            return target.toBytecode();
        }
    };
    transformTemplate.transform(CLASS_CALLABLE_STATEMENT, transformer);
    transformTemplate.transform(CLASS_CALLABLE_STATEMENT_WRAPPER, transformer);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)

Example 22 with InstrumentClass

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

the class MariaDBPlugin method addCallableStatementTransformer.

private void addCallableStatementTransformer() {
    TransformCallback transformer = 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.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor");
            target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.CallableStatementRegisterOutParameterInterceptor", MariaDBConstants.MARIADB_SCOPE);
            return target.toBytecode();
        }
    };
    transformTemplate.transform("org.mariadb.jdbc.AbstractCallableProcedureStatement", transformer);
    transformTemplate.transform("org.mariadb.jdbc.AbstractCallableFunctionStatement", transformer);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)

Example 23 with InstrumentClass

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

the class MariaDBPlugin method addPreparedStatementBindVariableTransformer.

private void addPreparedStatementBindVariableTransformer(final MariaDBConfig config) {
    TransformCallback transformer = 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.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor");
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor");
            if (config.isTraceSqlBindValue()) {
                final PreparedStatementBindingMethodFilter excludes = PreparedStatementBindingMethodFilter.excludes("setRowId", "setNClob", "setSQLXML");
                target.addScopedInterceptor(excludes, "com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementBindVariableInterceptor", MariaDBConstants.MARIADB_SCOPE, ExecutionPolicy.BOUNDARY);
            }
            return target.toBytecode();
        }
    };
    transformTemplate.transform("org.mariadb.jdbc.AbstractMariaDbPrepareStatement", transformer);
    // Class renamed in 1.5.6 - https://github.com/MariaDB/mariadb-connector-j/commit/16c8313960cf4fbc6b2b83136504d1ba9e662919
    transformTemplate.transform("org.mariadb.jdbc.AbstractPrepareStatement", transformer);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) PreparedStatementBindingMethodFilter(com.navercorp.pinpoint.bootstrap.plugin.jdbc.PreparedStatementBindingMethodFilter) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)

Example 24 with InstrumentClass

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

the class JavassistClassTest method testDeclaredMethods.

@Test
public void testDeclaredMethods() throws InstrumentException {
    InstrumentEngine engine = newJavassistEngine();
    InstrumentContext instrumentContext = mock(InstrumentContext.class);
    String testObjectName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
    byte[] testObjectByteCode = readByteCode(testObjectName);
    InstrumentClass testObject = engine.getClass(instrumentContext, null, testObjectName, testObjectByteCode);
    Assert.assertEquals(testObject.getName(), testObjectName);
    int findMethodCount = 0;
    for (InstrumentMethod methodInfo : testObject.getDeclaredMethods()) {
        if (!methodInfo.getName().equals("callA")) {
            continue;
        }
        String[] parameterTypes = methodInfo.getParameterTypes();
        if (parameterTypes == null || parameterTypes.length == 0) {
            findMethodCount++;
        }
    }
    Assert.assertEquals(findMethodCount, 1);
}
Also used : InstrumentContext(com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) InstrumentEngine(com.navercorp.pinpoint.profiler.instrument.InstrumentEngine) Test(org.junit.Test)

Example 25 with InstrumentClass

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

the class JavassistClassTest method hasEnclodingMethod.

@Test
public void hasEnclodingMethod() throws Exception {
    InstrumentEngine engine = newJavassistEngine();
    InstrumentContext instrumentContext = mock(InstrumentContext.class);
    String testObjectName = "com.navercorp.pinpoint.test.javasssit.mock.TestObjectNestedClass";
    byte[] testObjectByteCode = readByteCode(testObjectName);
    InstrumentClass testObject = engine.getClass(instrumentContext, null, testObjectName, testObjectByteCode);
    Assert.assertEquals(testObject.getName(), testObjectName);
    assertEquals(1, testObject.getNestedClasses(ClassFilters.enclosingMethod("enclosingMethod", "java.lang.String", "int")).size());
    assertEquals(0, testObject.getNestedClasses(ClassFilters.enclosingMethod("enclosingMethod", "int")).size());
}
Also used : InstrumentContext(com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentEngine(com.navercorp.pinpoint.profiler.instrument.InstrumentEngine) Test(org.junit.Test)

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