Search in sources :

Example 1 with ArgsArrayInterceptor

use of com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor in project pinpoint by naver.

the class ASMMethodNodeTest method addInterceptor.

@Test
public void addInterceptor() throws Exception {
    final int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
    final String targetClassName = "com.navercorp.pinpoint.profiler.instrument.mock.NormalClass";
    final ASMClass declaringClass = mock(ASMClass.class);
    when(declaringClass.getName()).thenReturn(targetClassName);
    final ObjectBinderFactory objectBinderFactory = mock(ObjectBinderFactory.class);
    ASMClassNodeLoader.TestClassLoader classLoader = ASMClassNodeLoader.getClassLoader();
    classLoader.setTrace(false);
    classLoader.setVerify(false);
    classLoader.setTargetClassName(targetClassName);
    classLoader.setCallbackHandler(new ASMClassNodeLoader.CallbackHandler() {

        @Override
        public void handle(ClassNode classNode) {
            List<MethodNode> methodNodes = classNode.methods;
            for (MethodNode methodNode : methodNodes) {
                ASMMethod method = new ASMMethod(objectBinderFactory, pluginContext, apiMetaDataService, interceptorRegistryBinder, declaringClass, methodNode);
                try {
                    method.addInterceptor(interceptorId);
                } catch (InstrumentException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    Class<?> clazz = classLoader.loadClass(targetClassName);
    Method method = clazz.getDeclaredMethod("sum", int.class);
    assertEquals(55, method.invoke(clazz.newInstance(), 10));
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) ArgsArrayInterceptor(com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor) ObjectBinderFactory(com.navercorp.pinpoint.profiler.objectfactory.ObjectBinderFactory) Method(java.lang.reflect.Method) MethodNode(org.objectweb.asm.tree.MethodNode) List(java.util.List) Test(org.junit.Test)

Example 2 with ArgsArrayInterceptor

use of com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor in project pinpoint by naver.

the class ASMMethodNodeAdapterTest method isVisited.

@Test
public void isVisited() throws Exception {
    // init
    final int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
    final InterceptorDefinition interceptorDefinition = new InterceptorDefinitionFactory().createInterceptorDefinition(ArgsArrayInterceptor.class);
    final String targetClassName = "com.navercorp.pinpoint.profiler.instrument.mock.ArgsClass";
    final MethodNode methodNode = ASMClassNodeLoader.get(targetClassName, "arg");
    ASMMethodNodeAdapter adapter = new ASMMethodNodeAdapter(JavaAssistUtils.javaNameToJvmName(targetClassName), methodNode);
    assertEquals(false, adapter.hasInterceptor());
    adapter.addBeforeInterceptor(interceptorId, interceptorDefinition, -1);
    assertEquals(true, adapter.hasInterceptor());
}
Also used : InterceptorDefinition(com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorDefinition) MethodNode(org.objectweb.asm.tree.MethodNode) ArgsArrayInterceptor(com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor) JointPoint(com.navercorp.pinpoint.bootstrap.instrument.aspect.JointPoint) InterceptorDefinitionFactory(com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorDefinitionFactory) Test(org.junit.Test)

Example 3 with ArgsArrayInterceptor

use of com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor in project pinpoint by naver.

the class ASMMethodVariablesTest method initInterceptorLocalVariables.

@Test
public void initInterceptorLocalVariables() throws Exception {
    MethodNode methodNode = ASMClassNodeLoader.get("com.navercorp.pinpoint.profiler.instrument.mock.ConstructorChildClass", "<init>");
    ASMMethodVariables variables = new ASMMethodVariables("com/navercorp/pinpoint/profiler/instrument/mock/ConstructorChildClass", methodNode);
    assertNull(variables.getEnterInsnNode());
    assertNull(variables.getEnterInsnNode());
    InterceptorRegistryBinder interceptorRegistryBinder = new DefaultInterceptorRegistryBinder();
    int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
    final InterceptorDefinition interceptorDefinition = new InterceptorDefinitionFactory().createInterceptorDefinition(ArgsArrayInterceptor.class);
    InsnList instructions = new InsnList();
    boolean first = variables.initInterceptorLocalVariables(instructions, interceptorId, interceptorDefinition, -1);
    assertEquals(true, first);
    assertNotNull(variables.getEnterInsnNode());
    assertNotNull(variables.getEnterInsnNode());
}
Also used : InterceptorDefinition(com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorDefinition) DefaultInterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.DefaultInterceptorRegistryBinder) InterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder) DefaultInterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.DefaultInterceptorRegistryBinder) ArgsArrayInterceptor(com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor) InterceptorDefinitionFactory(com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorDefinitionFactory) Test(org.junit.Test)

Example 4 with ArgsArrayInterceptor

use of com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor in project pinpoint by naver.

the class ASMMethodVariablesTest method hasInterceptor.

@Test
public void hasInterceptor() throws Exception {
    InterceptorRegistryBinder interceptorRegistryBinder = new DefaultInterceptorRegistryBinder();
    int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
    final InterceptorDefinition interceptorDefinition = new InterceptorDefinitionFactory().createInterceptorDefinition(ArgsArrayInterceptor.class);
    final ClassNode classNode = ASMClassNodeLoader.get("com.navercorp.pinpoint.profiler.instrument.mock.ArgsClass");
    List<MethodNode> methodNodes = classNode.methods;
    for (MethodNode methodNode : methodNodes) {
        ASMMethodNodeAdapter methodNodeAdapter = new ASMMethodNodeAdapter(classNode.name, methodNode);
        assertEquals(false, methodNodeAdapter.hasInterceptor());
        methodNodeAdapter.addBeforeInterceptor(interceptorId, interceptorDefinition, -1);
        assertEquals(true, methodNodeAdapter.hasInterceptor());
    }
}
Also used : InterceptorDefinition(com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorDefinition) DefaultInterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.DefaultInterceptorRegistryBinder) InterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder) DefaultInterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.DefaultInterceptorRegistryBinder) ArgsArrayInterceptor(com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor) InterceptorDefinitionFactory(com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorDefinitionFactory) Test(org.junit.Test)

Example 5 with ArgsArrayInterceptor

use of com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor in project pinpoint by naver.

the class ASMMethodNodeAdapterAddInterceptorTest method addArgsArrayInterceptor.

@Test
public void addArgsArrayInterceptor() throws Exception {
    int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
    addInterceptor(interceptorId, ArgsArrayInterceptor.class);
}
Also used : ArgsArrayInterceptor(com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor) Test(org.junit.Test)

Aggregations

ArgsArrayInterceptor (com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor)5 Test (org.junit.Test)5 InterceptorDefinition (com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorDefinition)3 InterceptorDefinitionFactory (com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorDefinitionFactory)3 DefaultInterceptorRegistryBinder (com.navercorp.pinpoint.profiler.interceptor.registry.DefaultInterceptorRegistryBinder)2 InterceptorRegistryBinder (com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder)2 MethodNode (org.objectweb.asm.tree.MethodNode)2 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)1 JointPoint (com.navercorp.pinpoint.bootstrap.instrument.aspect.JointPoint)1 ObjectBinderFactory (com.navercorp.pinpoint.profiler.objectfactory.ObjectBinderFactory)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 ClassNode (org.objectweb.asm.tree.ClassNode)1