Search in sources :

Example 21 with InstrumentMethod

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

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

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

the class BeanMethodTransformer method doInTransform.

@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
    try {
        final InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
        if (!target.isInterceptable()) {
            return null;
        }
        final List<InstrumentMethod> methodList = target.getDeclaredMethods(METHOD_FILTER);
        for (InstrumentMethod method : methodList) {
            addInterceptor(method);
        }
        return target.toBytecode();
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn("Failed to spring beans modify. Cause:{}", e.getMessage(), e);
        }
        return null;
    }
}
Also used : InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)

Example 24 with InstrumentMethod

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

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

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