Search in sources :

Example 6 with InstrumentContext

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

the class JavassistClassTest method getNestedClasses.

@Test
public void getNestedClasses() 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);
    // find class name condition.
    final String targetClassName = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObjectNestedClass$InstanceInner";
    for (InstrumentClass c : testObject.getNestedClasses(ClassFilters.name(targetClassName))) {
        assertEquals(targetClassName, c.getName());
    }
    // find enclosing method condition.
    assertEquals(2, testObject.getNestedClasses(ClassFilters.enclosingMethod("annonymousInnerClass")).size());
    // find interface condition.
    assertEquals(2, testObject.getNestedClasses(ClassFilters.interfaze("java.util.concurrent.Callable")).size());
    // find enclosing method & interface condition.
    assertEquals(1, testObject.getNestedClasses(ClassFilters.chain(ClassFilters.enclosingMethod("annonymousInnerClass"), ClassFilters.interfaze("java.util.concurrent.Callable"))).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 7 with InstrumentContext

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

the class JavassistClassTest method testClassHierarchy.

@Test
public void testClassHierarchy() 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);
    String testObjectSuperClass = testObject.getSuperClass();
    Assert.assertEquals("java.lang.Object", testObjectSuperClass);
    String[] testObjectSuperClassInterfaces = testObject.getInterfaces();
    Assert.assertEquals(testObjectSuperClassInterfaces.length, 0);
    final String classHierarchyTestMockName = "com.navercorp.pinpoint.test.javasssit.mock.ClassHierarchyTestMock";
    byte[] classHierarchyTestMockByteCode = readByteCode(classHierarchyTestMockName);
    InstrumentClass classHierarchyObject = engine.getClass(instrumentContext, null, classHierarchyTestMockName, classHierarchyTestMockByteCode);
    String hierarchySuperClass = classHierarchyObject.getSuperClass();
    Assert.assertEquals("java.util.HashMap", hierarchySuperClass);
    String[] hierarchyInterfaces = classHierarchyObject.getInterfaces();
    Assert.assertEquals(hierarchyInterfaces.length, 2);
    Assert.assertEquals(hierarchyInterfaces[0], "java.lang.Runnable");
    Assert.assertEquals(hierarchyInterfaces[1], "java.lang.Comparable");
}
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 8 with InstrumentContext

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

the class JavassistClassTest method testDeclaredMethod.

@Test
public void testDeclaredMethod() 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);
    InstrumentMethod declaredMethod = testObject.getDeclaredMethod("callA");
    Assert.assertNotNull(declaredMethod);
}
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 9 with InstrumentContext

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

the class DebugTransformerRegistry method newDebugTransformer.

private DebugTransformer newDebugTransformer(ProfilerConfig profilerConfig, InstrumentEngine instrumentEngine, DynamicTransformTrigger dynamicTransformTrigger) {
    ClassInjector classInjector = newClassInjector(profilerConfig);
    ClassFileTransformerLoader transformerRegistry = new ClassFileTransformerLoader(profilerConfig, dynamicTransformTrigger);
    InstrumentContext debugContext = new PluginInstrumentContext(profilerConfig, instrumentEngine, dynamicTransformTrigger, classInjector, transformerRegistry);
    return new DebugTransformer(instrumentEngine, debugContext);
}
Also used : PluginInstrumentContext(com.navercorp.pinpoint.profiler.plugin.PluginInstrumentContext) InstrumentContext(com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext) PluginInstrumentContext(com.navercorp.pinpoint.profiler.plugin.PluginInstrumentContext) ClassFileTransformerLoader(com.navercorp.pinpoint.profiler.plugin.ClassFileTransformerLoader) LegacyProfilerPluginClassInjector(com.navercorp.pinpoint.profiler.instrument.classloading.LegacyProfilerPluginClassInjector) ClassInjector(com.navercorp.pinpoint.profiler.instrument.classloading.ClassInjector) DebugTransformerClassInjector(com.navercorp.pinpoint.profiler.instrument.classloading.DebugTransformerClassInjector)

Example 10 with InstrumentContext

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

the class JavassistEngineTest method testGetClass_transform.

@Test
public void testGetClass_transform() throws Exception {
    InstrumentEngine instrumentEngine = newJavassistEngine();
    InstrumentContext instrumentContext = mock(InstrumentContext.class);
    final byte[] transformByteCode = getTransformByteCode();
    final InstrumentClass transformClass = instrumentEngine.getClass(instrumentContext, null, mock, transformByteCode);
    Assert.assertNotNull(transformClass.getDeclaredMethod("test"));
    Assert.assertNotNull("transform method", transformClass.getDeclaredMethod("transformMethod"));
}
Also used : InstrumentContext(com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) Test(org.junit.Test)

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