use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionConversionUtility method createPointCut.
/**
* Converts the xml point cut into a java agent point cut.
*
* @return The point cut object with the matchers set.
*/
private static ExtensionClassAndMethodMatcher createPointCut(Extension extension, final Pointcut cut, final String metricPrefix, final String pName, final Map<String, MethodMapper> classesToMethods, boolean custom, InstrumentationType type, boolean isAttsEnabled) throws XmlException {
ClassMatcher classMatcher;
if (cut.getMethodAnnotation() != null) {
classMatcher = new AllClassesMatcher();
} else {
classMatcher = createClassMatcher(cut, pName);
}
MethodMatcher methodMatcher = createMethodMatcher(cut, pName, classesToMethods);
List<ParameterAttributeName> reportedParams = null;
if (!isAttsEnabled) {
// looks like this could be modified later
reportedParams = new ArrayList<>();
} else {
reportedParams = getParameterAttributeNames(cut.getMethod());
}
return new ExtensionClassAndMethodMatcher(extension, cut, metricPrefix, classMatcher, methodMatcher, custom, reportedParams, type);
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class InstrumentTestUtils method createTransformerAndRetransformSuperclass.
public static void createTransformerAndRetransformSuperclass(String superclassName, String methodName, String methodDesc) throws UnmodifiableClassException {
ExtensionClassAndMethodMatcher pc = InstrumentTestUtils.createSuperclassPointCut(superclassName, methodName, methodDesc);
List<ExtensionClassAndMethodMatcher> list = new LinkedList<>();
list.add(pc);
ServiceFactory.getClassTransformerService().getLocalRetransformer().appendClassMethodMatchers(list);
InstrumentTestUtils.retransformAllMatching(pc);
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class InstrumentTestUtils method createTransformerAndRetransformClass.
public static void createTransformerAndRetransformClass(String className, String methodName, String methodDesc) throws UnmodifiableClassException {
ExtensionClassAndMethodMatcher pc = InstrumentTestUtils.createPointCut(className, methodName, methodDesc);
List<ExtensionClassAndMethodMatcher> list = new LinkedList<>();
list.add(pc);
ServiceFactory.getClassTransformerService().getLocalRetransformer().appendClassMethodMatchers(list);
InstrumentTestUtils.retransformClass(className);
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher 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));
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class InstrumentationMetricsTest method testMultiplePointcutsTransformationMetrics.
@Test
public void testMultiplePointcutsTransformationMetrics() throws Exception {
ServiceFactory.getClassTransformerService().getClassTransformer().getClassNameFilter().addIncludeClass(getClass().getName().replace('.', '/') + "$ClassToRetransform2");
Map<String, Integer> metricData = InstrumentTestUtils.getAndClearMetricData();
// This will load the class also:
String className = ClassToRetransform2Object.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 ClassToRetransform2Object(1).getVal());
Assert.assertEquals(2, new ClassToRetransform2Object(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 ExactMethodMatcher("getVal", "()I"), false, false, false, false, null);
ExtensionClassAndMethodMatcher pc2 = new ExtensionClassAndMethodMatcher(null, null, "Custom", new ExactClassMatcher(className), new ExactMethodMatcher("getVal2", "()I"), false, false, false, false, null);
List<ExtensionClassAndMethodMatcher> list = new LinkedList<>();
list.add(pc1);
list.add(pc2);
ServiceFactory.getClassTransformerService().getLocalRetransformer().appendClassMethodMatchers(list);
InstrumentTestUtils.retransformClass(className);
Assert.assertEquals(1, new ClassToRetransform2Object(1).getVal());
Assert.assertEquals(2, new ClassToRetransform2Object(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));
}
Aggregations