Search in sources :

Example 36 with TransformCallback

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

the class ThriftPlugin method addTNonblockingSocketEditor.

private void addTNonblockingSocketEditor() {
    final String targetClassName = "org.apache.thrift.transport.TNonblockingSocket";
    transformTemplate.transform(targetClassName, 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, className, classfileBuffer);
            target.addField(ThriftConstants.FIELD_ACCESSOR_SOCKET);
            target.addField(ThriftConstants.FIELD_ACCESSOR_SOCKET_ADDRESS);
            // TNonblockingSocket(SocketChannel, int, SocketAddress)
            final InstrumentMethod constructor = target.getConstructor("java.nio.channels.SocketChannel", "int", "java.net.SocketAddress");
            if (constructor != null) {
                String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.transport.TNonblockingSocketConstructInterceptor";
                constructor.addInterceptor(interceptor);
            }
            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 37 with TransformCallback

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

the class OraclePlugin method addStatementTransformer.

private void addStatementTransformer() {
    TransformCallback transformer = new TransformCallback() {

        @Override
        public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
            if (className.equals(CLASS_STATEMENT)) {
                if (instrumentor.exist(loader, CLASS_STATEMENT_WRAPPER)) {
                    return null;
                }
            }
            InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
            target.addField("com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor");
            target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.StatementExecuteQueryInterceptor", OracleConstants.ORACLE_SCOPE);
            target.addScopedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.StatementExecuteUpdateInterceptor", OracleConstants.ORACLE_SCOPE);
            return target.toBytecode();
        }
    };
    transformTemplate.transform(CLASS_STATEMENT, transformer);
    transformTemplate.transform(CLASS_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 38 with TransformCallback

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

the class ThriftPlugin method addTTransportEditor.

private void addTTransportEditor(String tTransportClassName, final String tTransportInterceptorFqcn, final String[]... parameterTypeGroups) {
    final String targetClassName = tTransportClassName;
    transformTemplate.transform(targetClassName, 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, className, classfileBuffer);
            target.addField(ThriftConstants.FIELD_ACCESSOR_SOCKET);
            for (String[] parameterTypeGroup : parameterTypeGroups) {
                final InstrumentMethod constructor = target.getConstructor(parameterTypeGroup);
                if (constructor != null) {
                    constructor.addInterceptor(tTransportInterceptorFqcn);
                }
            }
            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 39 with TransformCallback

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

the class ThriftPlugin method addTBaseAsyncProcessorEditor.

private void addTBaseAsyncProcessorEditor() {
    final String targetClassName = "org.apache.thrift.TBaseAsyncProcessor";
    transformTemplate.transform(targetClassName, 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, className, classfileBuffer);
            target.addField(ThriftConstants.FIELD_ACCESSOR_SERVER_MARKER_FLAG);
            target.addField(ThriftConstants.FIELD_ACCESSOR_ASYNC_MARKER_FLAG);
            // TBaseAsyncProcessor.process(AbstractNonblockingServer$AsyncFrameBuffer)
            final InstrumentMethod process = target.getDeclaredMethod("process", "org.apache.thrift.server.AbstractNonblockingServer$AsyncFrameBuffer");
            if (process != null) {
                String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.server.async.TBaseAsyncProcessorProcessInterceptor";
                process.addInterceptor(interceptor);
            }
            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 40 with TransformCallback

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

the class ThriftPlugin method addTAsyncMethodCallEditor.

private void addTAsyncMethodCallEditor() {
    final String targetClassName = "org.apache.thrift.async.TAsyncMethodCall";
    transformTemplate.transform(targetClassName, 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, className, classfileBuffer);
            target.addField(AsyncTraceIdAccessor.class.getName());
            target.addField(ThriftConstants.FIELD_ACCESSOR_SOCKET_ADDRESS);
            target.addGetter(ThriftConstants.FIELD_GETTER_T_NON_BLOCKING_TRANSPORT, ThriftConstants.T_ASYNC_METHOD_CALL_FIELD_TRANSPORT);
            // TAsyncMethodCall(TAsyncClient, TProtocolFactory, TNonblockingTransport, AsyncMethodCallback<T>, boolean)
            final InstrumentMethod constructor = target.getConstructor("org.apache.thrift.async.TAsyncClient", "org.apache.thrift.protocol.TProtocolFactory", "org.apache.thrift.transport.TNonblockingTransport", "org.apache.thrift.async.AsyncMethodCallback", "boolean");
            if (constructor != null) {
                String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.client.async.TAsyncMethodCallConstructInterceptor";
                constructor.addInterceptor(interceptor);
            }
            // TAsyncMethodCall.cleanUpAndFireCallback(SelectionKey)
            final InstrumentMethod cleanUpAndFireCallback = target.getDeclaredMethod("cleanUpAndFireCallback", "java.nio.channels.SelectionKey");
            if (cleanUpAndFireCallback != null) {
                String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.client.async.TAsyncMethodCallCleanUpAndFireCallbackInterceptor";
                cleanUpAndFireCallback.addInterceptor(interceptor);
            }
            // TAsyncMethodCall.onError(Exception)
            final InstrumentMethod onError = target.getDeclaredMethod("onError", "java.lang.Exception");
            if (onError != null) {
                String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.client.async.TAsyncMethodCallOnErrorInterceptor";
                onError.addInterceptor(interceptor);
            }
            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)

Aggregations

TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)45 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)43 Instrumentor (com.navercorp.pinpoint.bootstrap.instrument.Instrumentor)43 ProtectionDomain (java.security.ProtectionDomain)43 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)31 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)21 TestClassLoader (com.navercorp.pinpoint.test.classloader.TestClassLoader)5 Method (java.lang.reflect.Method)5 Test (org.junit.Test)5 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)2 InstrumentContext (com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext)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 PinpointException (com.navercorp.pinpoint.exception.PinpointException)2 GuardInstrumentor (com.navercorp.pinpoint.profiler.instrument.GuardInstrumentor)2 List (java.util.List)2 AsyncContextAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)1 AsyncTraceIdAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)1