Search in sources :

Example 1 with AllMethodsMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher in project newrelic-java-agent by newrelic.

the class InstrumentationMetricsTest method testMultipleMethodTransformationMetrics.

@Test
public void testMultipleMethodTransformationMetrics() throws Exception {
    ServiceFactory.getClassTransformerService().getClassTransformer().getClassNameFilter().addIncludeClass(getClass().getName().replace('.', '/') + "$ClassToRetransform3");
    Map<String, Integer> metricData = InstrumentTestUtils.getAndClearMetricData();
    // This will load the class also:
    String className = ClassToRetransform3Object.class.getName();
    String constructorMetric = MetricNames.SUPPORTABILITY_INIT + className + "/<init>(I)V";
    String methodMetric1 = MetricNames.SUPPORTABILITY_INIT + className + "/getVal()I";
    String methodMetric2 = MetricNames.SUPPORTABILITY_INIT + className + "/getVal2()I";
    Assert.assertEquals(1, new ClassToRetransform3Object(1).getVal());
    Assert.assertEquals(2, new ClassToRetransform3Object(1).getVal2());
    metricData = InstrumentTestUtils.getAndClearMetricData();
    Assert.assertNull(metricData.get(constructorMetric));
    Assert.assertNull(metricData.get(methodMetric1));
    Assert.assertNull(metricData.get(methodMetric2));
    ExtensionClassAndMethodMatcher pc1 = new ExtensionClassAndMethodMatcher(null, null, "Custom", new ExactClassMatcher(className), new AllMethodsMatcher(), false, false, false, false, null);
    List<ExtensionClassAndMethodMatcher> list = new LinkedList<>();
    list.add(pc1);
    ServiceFactory.getClassTransformerService().getLocalRetransformer().appendClassMethodMatchers(list);
    InstrumentTestUtils.retransformClass(className);
    Assert.assertEquals(1, new ClassToRetransform3Object(1).getVal());
    Assert.assertEquals(2, new ClassToRetransform3Object(1).getVal2());
    metricData = InstrumentTestUtils.getAndClearMetricData();
    Assert.assertNull(metricData.get(constructorMetric));
    Assert.assertEquals(Integer.valueOf(1), metricData.get(methodMetric1));
    Assert.assertEquals(Integer.valueOf(1), metricData.get(methodMetric2));
}
Also used : ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) AllMethodsMatcher(com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with AllMethodsMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher in project newrelic-java-agent by newrelic.

the class OptimizedClassMatcherTest method testSkipObjectMethods_looseMatch.

@Test
public void testSkipObjectMethods_looseMatch() throws IOException {
    ClassMatchVisitorFactory matcher = OptimizedClassMatcherBuilder.newBuilder().addClassMethodMatcher(new DefaultClassAndMethodMatcher(new AllClassesMatcher(), new AllMethodsMatcher())).build();
    Match match = getMatch(matcher, MyObject.class);
    Assert.assertNotNull(match);
    for (Method m : OBJECT_METHODS) {
        Assert.assertFalse(match.getMethods().contains(m));
    }
}
Also used : ClassMatchVisitorFactory(com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory) Method(org.objectweb.asm.commons.Method) AllMethodsMatcher(com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher) Match(com.newrelic.agent.instrumentation.classmatchers.OptimizedClassMatcher.Match) Test(org.junit.Test)

Example 3 with AllMethodsMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher in project newrelic-java-agent by newrelic.

the class ClassTransformerServiceTest method addTraceMatcher.

@Test
public void addTraceMatcher() throws UnmodifiableClassException {
    Assert.assertFalse(TestClass.class.isAnnotationPresent(InstrumentedClass.class));
    ServiceFactory.getClassTransformerService().addTraceMatcher(new DefaultClassAndMethodMatcher(new ExactClassMatcher(Type.getType(ClassTransformerServiceTest.class).getInternalName() + "$TestClass"), new AllMethodsMatcher()), "dude");
    ServiceFactory.getCoreService().getInstrumentation().retransformClasses(TestClass.class);
    Assert.assertTrue(TestClass.class.isAnnotationPresent(InstrumentedClass.class));
}
Also used : ExactClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher) DefaultClassAndMethodMatcher(com.newrelic.agent.instrumentation.classmatchers.DefaultClassAndMethodMatcher) AllMethodsMatcher(com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher) Test(org.junit.Test)

Example 4 with AllMethodsMatcher

use of com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher in project newrelic-java-agent by newrelic.

the class OptimizedClassMatcherTest method before.

@Before
public void before() {
    initializeServiceManager();
    OptimizedClassMatcherBuilder builder = OptimizedClassMatcherBuilder.newBuilder();
    match1 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Collection.class), new ExactMethodMatcher("size", "()I"));
    match2 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(List.class), new ExactMethodMatcher("get", "(I)Ljava/lang/Object;"));
    match3 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(InvocationHandler.class), new ExactMethodMatcher("invoke", "(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;"));
    match4 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Statement.class), new AllMethodsMatcher());
    match5 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Runnable.class), OrMethodMatcher.getMethodMatcher(new NameMethodMatcher("run"), new ExactMethodMatcher("bogus", "()V")));
    match6 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(Map.class), new AccessMethodMatcher(Opcodes.ACC_PUBLIC));
    match7 = new DefaultClassAndMethodMatcher(createInterfaceMatcher(List.class), new ExactMethodMatcher("add", "(Ljava/lang/Object;)Z"));
    annotationMatch = new DefaultClassAndMethodMatcher(new AllClassesMatcher(), new AnnotationMethodMatcher(Type.getType(MyAnnotation.class)));
    // this is a bogus matcher to attempt to throw off match5
    builder.addClassMethodMatcher(new DefaultClassAndMethodMatcher(createInterfaceMatcher(PreparedStatement.class), new NameMethodMatcher("run")));
    builder.addClassMethodMatcher(match1);
    builder.addClassMethodMatcher(match2);
    builder.addClassMethodMatcher(match3);
    builder.addClassMethodMatcher(match4);
    builder.addClassMethodMatcher(match5);
    builder.addClassMethodMatcher(match6);
    builder.addClassMethodMatcher(match7);
    builder.addClassMethodMatcher(annotationMatch);
    this.matcher = builder.build();
}
Also used : NameMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.NameMethodMatcher) AccessMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.AccessMethodMatcher) AnnotationMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) AllMethodsMatcher(com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher) Before(org.junit.Before)

Aggregations

AllMethodsMatcher (com.newrelic.agent.instrumentation.methodmatchers.AllMethodsMatcher)4 Test (org.junit.Test)3 ExactClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher)2 DefaultClassAndMethodMatcher (com.newrelic.agent.instrumentation.classmatchers.DefaultClassAndMethodMatcher)1 Match (com.newrelic.agent.instrumentation.classmatchers.OptimizedClassMatcher.Match)1 ClassMatchVisitorFactory (com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory)1 ExtensionClassAndMethodMatcher (com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher)1 AccessMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.AccessMethodMatcher)1 AnnotationMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.AnnotationMethodMatcher)1 ExactMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher)1 NameMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.NameMethodMatcher)1 LinkedList (java.util.LinkedList)1 Before (org.junit.Before)1 Method (org.objectweb.asm.commons.Method)1