Search in sources :

Example 41 with InstrumentClass

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

the class ThriftPlugin method addTBaseProcessorEditor.

private void addTBaseProcessorEditor() {
    final String targetClassName = "org.apache.thrift.TBaseProcessor";
    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);
            // TBaseProcessor.process(TProtocol, TProtocol)
            final InstrumentMethod process = target.getDeclaredMethod("process", "org.apache.thrift.protocol.TProtocol", "org.apache.thrift.protocol.TProtocol");
            if (process != null) {
                String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.server.TBaseProcessorProcessInterceptor";
                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 42 with InstrumentClass

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

the class ThriftPlugin method addFrameBufferEditor.

private void addFrameBufferEditor() {
    final String targetClassName = "org.apache.thrift.server.AbstractNonblockingServer$FrameBuffer";
    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.addGetter(ThriftConstants.FIELD_GETTER_T_NON_BLOCKING_TRANSPORT, ThriftConstants.FRAME_BUFFER_FIELD_TRANS_);
            // [THRIFT-1972] - 0.9.1 added a field for the wrapper around trans_ field, while getting rid of getInputTransport() method
            if (target.hasField(ThriftConstants.FRAME_BUFFER_FIELD_IN_TRANS_)) {
                target.addGetter(ThriftConstants.FIELD_GETTER_T_TRANSPORT, ThriftConstants.FRAME_BUFFER_FIELD_IN_TRANS_);
                // AbstractNonblockingServer$FrameBuffer(TNonblockingTransport, SelectionKey, AbstractSelectThread)
                final InstrumentMethod constructor = target.getConstructor(// inner class - implicit reference to outer class instance
                "org.apache.thrift.server.AbstractNonblockingServer", "org.apache.thrift.transport.TNonblockingTransport", "java.nio.channels.SelectionKey", "org.apache.thrift.server.AbstractNonblockingServer$AbstractSelectThread");
                if (constructor != null) {
                    String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.server.nonblocking.FrameBufferConstructInterceptor";
                    constructor.addInterceptor(interceptor);
                }
            }
            // 0.8.0, 0.9.0 doesn't have a separate trans_ field - hook getInputTransport() method
            if (target.hasMethod("getInputTransport", "org.apache.thrift.transport.TTransport")) {
                // AbstractNonblockingServer$FrameBuffer.getInputTransport(TTransport)
                final InstrumentMethod getInputTransport = target.getDeclaredMethod("getInputTransport", "org.apache.thrift.transport.TTransport");
                if (getInputTransport != null) {
                    String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.server.nonblocking.FrameBufferGetInputTransportInterceptor";
                    getInputTransport.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 43 with InstrumentClass

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

the class ThriftPlugin method addProcessFunctionEditor.

private void addProcessFunctionEditor() {
    final String targetClassName = "org.apache.thrift.ProcessFunction";
    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);
            // ProcessFunction.process(int, TProtocol, TProtocol, I)
            final InstrumentMethod process = target.getDeclaredMethod("process", "int", "org.apache.thrift.protocol.TProtocol", "org.apache.thrift.protocol.TProtocol", "java.lang.Object");
            if (process != null) {
                String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.server.ProcessFunctionProcessInterceptor";
                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 44 with InstrumentClass

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass 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 45 with InstrumentClass

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass 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)

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