Search in sources :

Example 1 with InstrumentContext

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

the class DefaultClassEditorBuilderTest method test.

@Test
public void test() throws Exception {
    InstrumentEngine instrumentEngine = mock(InstrumentEngine.class);
    TraceContext traceContext = mock(TraceContext.class);
    InstrumentClass aClass = mock(InstrumentClass.class);
    InstrumentMethod aMethod = mock(InstrumentMethod.class);
    MethodDescriptor aDescriptor = mock(MethodDescriptor.class);
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    InstrumentContext context = mock(InstrumentContext.class);
    ClassLoader classLoader = getClass().getClassLoader();
    String className = "someClass";
    String methodName = "someMethod";
    byte[] classFileBuffer = new byte[0];
    Class<?>[] parameterTypes = new Class<?>[] { String.class };
    String[] parameterTypeNames = TypeUtils.toClassNames(parameterTypes);
    when(applicationContext.getInstrumentEngine()).thenReturn(instrumentEngine);
    when(applicationContext.getTraceContext()).thenReturn(traceContext);
    when(instrumentEngine.getClass(context, classLoader, className, classFileBuffer)).thenReturn(aClass);
    when(aClass.getDeclaredMethod(methodName, parameterTypeNames)).thenReturn(aMethod);
    when(aMethod.getName()).thenReturn(methodName);
    when(aMethod.getParameterTypes()).thenReturn(parameterTypeNames);
    when(aMethod.getDescriptor()).thenReturn(aDescriptor);
    when(aClass.addInterceptor(eq(methodName), va(eq(parameterTypeNames)))).thenReturn(0);
//        DefaultClassFileTransformerBuilder builder = new DefaultClassFileTransformerBuilder(context, "TargetClass");
//        builder.injectField("some.accessor.Type", "java.util.HashMap");
//        builder.injectGetter("some.getter.Type", "someField");
//
//        MethodTransformerBuilder ib = builder.editMethod(methodName, parameterTypeNames);
//        ib.injectInterceptor("com.navercorp.pinpoint.profiler.plugin.TestInterceptor", "provided");
//
//        ClassFileTransformer transformer = builder.build();
//
//        transformer.transform(classLoader, className, null, null, classFileBuffer);
//
//        verify(aMethod).addScopedInterceptor(eq("com.navercorp.pinpoint.profiler.plugin.TestInterceptor"), eq(va("provided")), (InterceptorScope)isNull(), (ExecutionPolicy)isNull());
//        verify(aClass).addField("some.accessor.Type", "new java.util.HashMap();");
//        verify(aClass).addGetter("some.getter.Type", "someField");
}
Also used : InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) MethodDescriptor(com.navercorp.pinpoint.bootstrap.context.MethodDescriptor) ApplicationContext(com.navercorp.pinpoint.profiler.context.module.ApplicationContext) InstrumentContext(com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentEngine(com.navercorp.pinpoint.profiler.instrument.InstrumentEngine) Test(org.junit.Test)

Example 2 with InstrumentContext

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

the class DefaultPluginSetup method setupPlugin.

@Override
public SetupResult setupPlugin(ProfilerPlugin profilerPlugin, ClassInjector classInjector) {
    final ClassFileTransformerLoader transformerRegistry = new ClassFileTransformerLoader(profilerConfig, dynamicTransformTrigger);
    final DefaultProfilerPluginSetupContext setupContext = new DefaultProfilerPluginSetupContext(profilerConfig);
    final GuardProfilerPluginContext guardSetupContext = new GuardProfilerPluginContext(setupContext);
    final InstrumentContext instrumentContext = new PluginInstrumentContext(profilerConfig, instrumentEngine, dynamicTransformTrigger, classInjector, transformerRegistry);
    final GuardInstrumentContext guardInstrumentContext = preparePlugin(profilerPlugin, instrumentContext);
    try {
        // WARN external plugin api
        if (logger.isInfoEnabled()) {
            logger.info("{} Plugin setup", profilerPlugin.getClass().getName());
        }
        profilerPlugin.setup(guardSetupContext);
    } finally {
        guardSetupContext.close();
        guardInstrumentContext.close();
    }
    SetupResult setupResult = new SetupResult(setupContext, transformerRegistry);
    return setupResult;
}
Also used : GuardInstrumentContext(com.navercorp.pinpoint.profiler.instrument.GuardInstrumentContext) InstrumentContext(com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext) GuardInstrumentContext(com.navercorp.pinpoint.profiler.instrument.GuardInstrumentContext)

Example 3 with InstrumentContext

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

the class JavassistClassTest method testDeclaredMethods.

@Test
public void testDeclaredMethods() throws InstrumentException {
    InstrumentEngine engine = newJavassistEngine();
    InstrumentContext instrumentContext = mock(InstrumentContext.class);
    String testObjectName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
    byte[] testObjectByteCode = readByteCode(testObjectName);
    InstrumentClass testObject = engine.getClass(instrumentContext, null, testObjectName, testObjectByteCode);
    Assert.assertEquals(testObject.getName(), testObjectName);
    int findMethodCount = 0;
    for (InstrumentMethod methodInfo : testObject.getDeclaredMethods()) {
        if (!methodInfo.getName().equals("callA")) {
            continue;
        }
        String[] parameterTypes = methodInfo.getParameterTypes();
        if (parameterTypes == null || parameterTypes.length == 0) {
            findMethodCount++;
        }
    }
    Assert.assertEquals(findMethodCount, 1);
}
Also used : InstrumentContext(com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) InstrumentEngine(com.navercorp.pinpoint.profiler.instrument.InstrumentEngine) Test(org.junit.Test)

Example 4 with InstrumentContext

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

the class JavassistClassTest method hasEnclodingMethod.

@Test
public void hasEnclodingMethod() throws Exception {
    InstrumentEngine engine = newJavassistEngine();
    InstrumentContext instrumentContext = mock(InstrumentContext.class);
    String testObjectName = "com.navercorp.pinpoint.test.javasssit.mock.TestObjectNestedClass";
    byte[] testObjectByteCode = readByteCode(testObjectName);
    InstrumentClass testObject = engine.getClass(instrumentContext, null, testObjectName, testObjectByteCode);
    Assert.assertEquals(testObject.getName(), testObjectName);
    assertEquals(1, testObject.getNestedClasses(ClassFilters.enclosingMethod("enclosingMethod", "java.lang.String", "int")).size());
    assertEquals(0, testObject.getNestedClasses(ClassFilters.enclosingMethod("enclosingMethod", "int")).size());
}
Also used : InstrumentContext(com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentEngine(com.navercorp.pinpoint.profiler.instrument.InstrumentEngine) Test(org.junit.Test)

Example 5 with InstrumentContext

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

the class MockPluginSetup method setupPlugin.

@Override
public SetupResult setupPlugin(ProfilerPlugin plugin, ClassInjector classInjector) {
    final DefaultProfilerPluginSetupContext pluginSetupContext = new DefaultProfilerPluginSetupContext(profilerConfig);
    final GuardProfilerPluginContext guardPluginSetupContext = new GuardProfilerPluginContext(pluginSetupContext);
    ClassFileTransformerLoader classFileTransformerLoader = new ClassFileTransformerLoader(profilerConfig, dynamicTransformTrigger);
    InstrumentContext instrumentContext = new PluginInstrumentContext(profilerConfig, instrumentEngine, dynamicTransformTrigger, classInjector, classFileTransformerLoader);
    try {
        preparePlugin(plugin, instrumentContext);
        plugin.setup(guardPluginSetupContext);
    } finally {
        guardPluginSetupContext.close();
    }
    SetupResult setup = new SetupResult(pluginSetupContext, classFileTransformerLoader);
    return setup;
}
Also used : SetupResult(com.navercorp.pinpoint.profiler.plugin.SetupResult) PluginInstrumentContext(com.navercorp.pinpoint.profiler.plugin.PluginInstrumentContext) InstrumentContext(com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext) PluginInstrumentContext(com.navercorp.pinpoint.profiler.plugin.PluginInstrumentContext) DefaultProfilerPluginSetupContext(com.navercorp.pinpoint.profiler.plugin.DefaultProfilerPluginSetupContext) GuardProfilerPluginContext(com.navercorp.pinpoint.profiler.plugin.GuardProfilerPluginContext) ClassFileTransformerLoader(com.navercorp.pinpoint.profiler.plugin.ClassFileTransformerLoader)

Aggregations

InstrumentContext (com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext)11 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)8 Test (org.junit.Test)8 InstrumentEngine (com.navercorp.pinpoint.profiler.instrument.InstrumentEngine)6 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)3 ClassFileTransformerLoader (com.navercorp.pinpoint.profiler.plugin.ClassFileTransformerLoader)2 PluginInstrumentContext (com.navercorp.pinpoint.profiler.plugin.PluginInstrumentContext)2 MethodDescriptor (com.navercorp.pinpoint.bootstrap.context.MethodDescriptor)1 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)1 ApplicationContext (com.navercorp.pinpoint.profiler.context.module.ApplicationContext)1 GuardInstrumentContext (com.navercorp.pinpoint.profiler.instrument.GuardInstrumentContext)1 ClassInjector (com.navercorp.pinpoint.profiler.instrument.classloading.ClassInjector)1 DebugTransformerClassInjector (com.navercorp.pinpoint.profiler.instrument.classloading.DebugTransformerClassInjector)1 LegacyProfilerPluginClassInjector (com.navercorp.pinpoint.profiler.instrument.classloading.LegacyProfilerPluginClassInjector)1 DefaultProfilerPluginSetupContext (com.navercorp.pinpoint.profiler.plugin.DefaultProfilerPluginSetupContext)1 GuardProfilerPluginContext (com.navercorp.pinpoint.profiler.plugin.GuardProfilerPluginContext)1 SetupResult (com.navercorp.pinpoint.profiler.plugin.SetupResult)1