Search in sources :

Example 16 with InstrumentMethod

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

the class ThriftPlugin method addTProtocolInterceptors.

private void addTProtocolInterceptors(ThriftPluginConfig config, String tProtocolClassName) {
    final boolean traceThriftClient = config.traceThriftClient();
    final boolean traceThriftProcessor = config.traceThriftProcessor();
    final String targetClassName = tProtocolClassName;
    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);
            // client
            if (traceThriftClient) {
                // TProtocol.writeFieldStop()
                final InstrumentMethod writeFieldStop = target.getDeclaredMethod("writeFieldStop");
                if (writeFieldStop != null) {
                    String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.client.TProtocolWriteFieldStopInterceptor";
                    writeFieldStop.addInterceptor(interceptor);
                }
            }
            // processor
            if (traceThriftProcessor) {
                target.addField(ThriftConstants.FIELD_ACCESSOR_SERVER_MARKER_FLAG);
                // TProtocol.readFieldBegin()
                final InstrumentMethod readFieldBegin = target.getDeclaredMethod("readFieldBegin");
                if (readFieldBegin != null) {
                    String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadFieldBeginInterceptor";
                    readFieldBegin.addInterceptor(interceptor);
                }
                // TProtocol.readBool, TProtocol.readBinary, TProtocol.readI16, TProtocol.readI64
                final List<InstrumentMethod> readTTypes = target.getDeclaredMethods(MethodFilters.name("readBool", "readBinary", "readI16", "readI64"));
                if (readTTypes != null) {
                    String tTypeCommonInterceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadTTypeInterceptor";
                    for (InstrumentMethod readTType : readTTypes) {
                        if (readTType != null) {
                            readTType.addInterceptor(tTypeCommonInterceptor);
                        }
                    }
                }
                // TProtocol.readMessageEnd()
                final InstrumentMethod readMessageEnd = target.getDeclaredMethod("readMessageEnd");
                if (readMessageEnd != null) {
                    String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadMessageEndInterceptor";
                    readMessageEnd.addInterceptor(interceptor);
                }
                // for async processors
                target.addField(ThriftConstants.FIELD_ACCESSOR_ASYNC_MARKER_FLAG);
                // TProtocol.readMessageBegin()
                final InstrumentMethod readMessageBegin = target.getDeclaredMethod("readMessageBegin");
                if (readMessageBegin != null) {
                    String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadMessageBeginInterceptor";
                    readMessageBegin.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) List(java.util.List)

Example 17 with InstrumentMethod

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

the class ThriftPlugin method addTAsyncClientManagerEditor.

private void addTAsyncClientManagerEditor() {
    final String targetClassName = "org.apache.thrift.async.TAsyncClientManager";
    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);
            // TAsyncClientManager.call(TAsyncMethodCall)
            final InstrumentMethod call = target.getDeclaredMethod("call", "org.apache.thrift.async.TAsyncMethodCall");
            if (call != null) {
                String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.client.async.TAsyncClientManagerCallInterceptor";
                call.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 18 with InstrumentMethod

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

the class ThriftPlugin method addTServiceClientEditor.

private void addTServiceClientEditor(ThriftPluginConfig config) {
    final boolean traceServiceArgs = config.traceThriftServiceArgs();
    final boolean traceServiceResult = config.traceThriftServiceResult();
    final String targetClassName = "org.apache.thrift.TServiceClient";
    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);
            // TServiceClient.sendBase(String, TBase)
            final InstrumentMethod sendBase = target.getDeclaredMethod("sendBase", "java.lang.String", "org.apache.thrift.TBase");
            if (sendBase != null) {
                String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.client.TServiceClientSendBaseInterceptor";
                sendBase.addInterceptor(interceptor, va(traceServiceArgs));
            }
            // TServiceClient.receiveBase(TBase, String)
            final InstrumentMethod receiveBase = target.getDeclaredMethod("receiveBase", "org.apache.thrift.TBase", "java.lang.String");
            if (receiveBase != null) {
                String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.client.TServiceClientReceiveBaseInterceptor";
                receiveBase.addInterceptor(interceptor, va(traceServiceResult));
            }
            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 19 with InstrumentMethod

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

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

Aggregations

InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)33 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)29 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)21 Instrumentor (com.navercorp.pinpoint.bootstrap.instrument.Instrumentor)19 TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)19 ProtectionDomain (java.security.ProtectionDomain)19 Test (org.junit.Test)9 ApiMetaDataService (com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService)6 AroundInterceptor3 (com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor3)4 InstrumentContext (com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext)3 MethodFilter (com.navercorp.pinpoint.bootstrap.instrument.MethodFilter)3 ObjectFactory (com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory)3 InstrumentEngine (com.navercorp.pinpoint.profiler.instrument.InstrumentEngine)3 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)2 List (java.util.List)2 AsyncTraceIdAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)1 MethodDescriptor (com.navercorp.pinpoint.bootstrap.context.MethodDescriptor)1 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)1 AroundInterceptor0 (com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor0)1 Interceptor (com.navercorp.pinpoint.bootstrap.interceptor.Interceptor)1