Search in sources :

Example 1 with InstrumentMatcherCacheConfig

use of com.navercorp.pinpoint.profiler.instrument.config.InstrumentMatcherCacheConfig in project pinpoint by naver.

the class DefaultTransformerMatcherTest method matchClass.

@Test
public void matchClass() throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InstrumentMatcherCacheConfig config = new DefaultInstrumentMatcherCacheConfig();
    TransformerMatcher matcher = new DefaultTransformerMatcher(config);
    InternalClassMetadata stringClassMetadata = readClassMetadata(classLoader, String.class.getName());
    InternalClassMetadata threadClassMetadata = readClassMetadata(classLoader, Thread.class.getName());
    InternalClassMetadata inputStreamClassMetadata = readClassMetadata(classLoader, InputStream.class.getName());
    MatcherOperand operand = null;
    // single operand.
    operand = new ClassInternalNameMatcherOperand("java/lang/String");
    boolean result = matcher.match(classLoader, operand, stringClassMetadata);
    assertTrue(result);
    // not matched.
    operand = new ClassInternalNameMatcherOperand("java/io/InputStream");
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertFalse(result);
    // and operator
    // package AND interface
    operand = new PackageInternalNameMatcherOperand("java/lang").and(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false));
    // java.lang.Thread
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertTrue(result);
    // java.lang.String
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertFalse(result);
    // or operator
    // package OR interface
    operand = new PackageInternalNameMatcherOperand("java/lang").or(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false));
    // java.lang.Thread
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertTrue(result);
    // java.lang.String
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertTrue(result);
    // not operator
    // NOT interface.
    operand = new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false);
    operand = operand.not();
    // java.lang.Thread
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertFalse(result);
    // java.lang.String
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertTrue(result);
    // complex operator
    // (class or interface) AND (class or interface) ==> class, interface
    operand = new ClassInternalNameMatcherOperand("java/lang/String").or(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false));
    operand = operand.and(new ClassInternalNameMatcherOperand("java/lang/Thread").or(new InterfaceInternalNameMatcherOperand("java/lang/Comparable", false)));
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertTrue(result);
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertTrue(result);
    // (class AND interface) OR (class AND interface) ==> class, class
    operand = new ClassInternalNameMatcherOperand("java/lang/String").and(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false));
    operand = operand.or(new ClassInternalNameMatcherOperand("java/lang/Thread").and(new InterfaceInternalNameMatcherOperand("java/lang/Comparable", false)));
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertFalse(result);
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertFalse(result);
    // package AND (interface OR annotation) ==> package
    operand = new PackageInternalNameMatcherOperand("java/lang");
    operand = operand.and(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false).or(new AnnotationInternalNameMatcherOperand("java/lang/Override", false)));
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertFalse(result);
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertTrue(result);
    // class OR (interface AND NOT annotation)
    operand = new ClassInternalNameMatcherOperand("java/lang/String");
    operand = operand.or(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false).and(new AnnotationInternalNameMatcherOperand("java/lang/Override", false).not()));
    result = matcher.match(classLoader, operand, stringClassMetadata);
    assertTrue(result);
    result = matcher.match(classLoader, operand, threadClassMetadata);
    assertTrue(result);
}
Also used : InterfaceInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand) SuperClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.SuperClassInternalNameMatcherOperand) ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand) InterfaceInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand) MatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand) AnnotationInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.AnnotationInternalNameMatcherOperand) PackageInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand) InputStream(java.io.InputStream) PackageInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand) DefaultInstrumentMatcherCacheConfig(com.navercorp.pinpoint.profiler.instrument.config.DefaultInstrumentMatcherCacheConfig) InstrumentMatcherCacheConfig(com.navercorp.pinpoint.profiler.instrument.config.InstrumentMatcherCacheConfig) DefaultInstrumentMatcherCacheConfig(com.navercorp.pinpoint.profiler.instrument.config.DefaultInstrumentMatcherCacheConfig) InternalClassMetadata(com.navercorp.pinpoint.profiler.instrument.classreading.InternalClassMetadata) AnnotationInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.AnnotationInternalNameMatcherOperand) SuperClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.SuperClassInternalNameMatcherOperand) ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand) Test(org.junit.Test)

Example 2 with InstrumentMatcherCacheConfig

use of com.navercorp.pinpoint.profiler.instrument.config.InstrumentMatcherCacheConfig in project pinpoint by naver.

the class DefaultTransformerMatcherTest method considerHierarchy.

@Test
public void considerHierarchy() throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InstrumentMatcherCacheConfig config = new DefaultInstrumentMatcherCacheConfig();
    TransformerMatcher matcher = new DefaultTransformerMatcher(config);
    boolean result = false;
    InternalClassMetadata stringClassMetadata = readClassMetadata(classLoader, String.class.getName());
    InternalClassMetadata threadClassMetadata = readClassMetadata(classLoader, Thread.class.getName());
    InternalClassMetadata extendsThreadClassMetadata = readClassMetadata(classLoader, ExtendsThread.class.getName());
    InternalClassMetadata extendsExtendsThreadClassMetadata = readClassMetadata(classLoader, ExtendsExtendsThread.class.getName());
    InternalClassMetadata hasMetaAnnotationClassMetadata = readClassMetadata(classLoader, HasMetaAnnotation.class.getName());
    InternalClassMetadata hasMetaMetaAnnotationClassMetadata = readClassMetadata(classLoader, HasMetaMetaAnnotation.class.getName());
    // interface
    InterfaceInternalNameMatcherOperand interfaceMatcherOperand = new InterfaceInternalNameMatcherOperand("java/lang/Runnable", true);
    result = matcher.match(classLoader, interfaceMatcherOperand, extendsThreadClassMetadata);
    assertTrue(result);
    result = matcher.match(classLoader, interfaceMatcherOperand, threadClassMetadata);
    assertTrue(result);
    result = matcher.match(classLoader, interfaceMatcherOperand, stringClassMetadata);
    assertFalse(result);
    result = matcher.match(classLoader, interfaceMatcherOperand, extendsExtendsThreadClassMetadata);
    assertTrue(result);
    // super
    SuperClassInternalNameMatcherOperand superMatcherOperand = new SuperClassInternalNameMatcherOperand("java/lang/Thread", true);
    result = matcher.match(classLoader, superMatcherOperand, extendsExtendsThreadClassMetadata);
    assertTrue(result);
    result = matcher.match(classLoader, superMatcherOperand, extendsThreadClassMetadata);
    assertTrue(result);
    result = matcher.match(classLoader, superMatcherOperand, threadClassMetadata);
    assertFalse(result);
    result = matcher.match(classLoader, superMatcherOperand, stringClassMetadata);
    assertFalse(result);
    // annotation
    AnnotationInternalNameMatcherOperand annotationMatcherOperand = new AnnotationInternalNameMatcherOperand("javax/annotation/Resource", true);
    result = matcher.match(classLoader, annotationMatcherOperand, hasMetaAnnotationClassMetadata);
    assertTrue(result);
    result = matcher.match(classLoader, annotationMatcherOperand, hasMetaMetaAnnotationClassMetadata);
    assertTrue(result);
    result = matcher.match(classLoader, annotationMatcherOperand, stringClassMetadata);
    assertFalse(result);
    result = matcher.match(classLoader, annotationMatcherOperand, threadClassMetadata);
    assertFalse(result);
}
Also used : InterfaceInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand) SuperClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.SuperClassInternalNameMatcherOperand) DefaultInstrumentMatcherCacheConfig(com.navercorp.pinpoint.profiler.instrument.config.DefaultInstrumentMatcherCacheConfig) InstrumentMatcherCacheConfig(com.navercorp.pinpoint.profiler.instrument.config.InstrumentMatcherCacheConfig) DefaultInstrumentMatcherCacheConfig(com.navercorp.pinpoint.profiler.instrument.config.DefaultInstrumentMatcherCacheConfig) InternalClassMetadata(com.navercorp.pinpoint.profiler.instrument.classreading.InternalClassMetadata) AnnotationInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.AnnotationInternalNameMatcherOperand) Test(org.junit.Test)

Example 3 with InstrumentMatcherCacheConfig

use of com.navercorp.pinpoint.profiler.instrument.config.InstrumentMatcherCacheConfig in project pinpoint by naver.

the class ConfigModule method configure.

@Override
protected void configure() {
    logger.info("configure {}", this.getClass().getSimpleName());
    binder().requireExplicitBindings();
    binder().requireAtInjectOnConstructors();
    binder().disableCircularProxies();
    ProfilerConfig profilerConfig = agentOption.getProfilerConfig();
    bind(ProfilerConfig.class).toInstance(profilerConfig);
    Properties properties = profilerConfig.getProperties();
    ConfigurationLoader configurationLoader = new ConfigurationLoader(properties);
    ContextConfig contextConfig = new DefaultContextConfig();
    configurationLoader.load(contextConfig);
    logger.info("{}", contextConfig);
    bind(ContextConfig.class).toInstance(contextConfig);
    bindConstants(contextConfig);
    PluginLoadingConfig pluginLoadingConfig = new DefaultPluginLoadingConfig();
    configurationLoader.load(pluginLoadingConfig);
    logger.info("{}", pluginLoadingConfig);
    bind(PluginLoadingConfig.class).toInstance(pluginLoadingConfig);
    InstrumentConfig instrumentConfig = new DefaultInstrumentConfig();
    configurationLoader.load(instrumentConfig);
    logger.info("{}", instrumentConfig);
    bind(InstrumentConfig.class).toInstance(instrumentConfig);
    InstrumentMatcherCacheConfig instrumentMatcherCacheConfig = new DefaultInstrumentMatcherCacheConfig();
    configurationLoader.load(instrumentMatcherCacheConfig);
    logger.info("{}", instrumentMatcherCacheConfig);
    bind(InstrumentMatcherCacheConfig.class).toInstance(instrumentMatcherCacheConfig);
    MonitorConfig monitorConfig = new DefaultMonitorConfig();
    configurationLoader.load(monitorConfig);
    logger.info("{}", monitorConfig);
    bind(MonitorConfig.class).toInstance(monitorConfig);
    bind(TransportModule.class).toInstance(profilerConfig.getTransportModule());
    bind(Instrumentation.class).toInstance(agentOption.getInstrumentation());
    bind(InterceptorRegistryBinder.class).toProvider(InterceptorRegistryBinderProvider.class).in(Scopes.SINGLETON);
    TypeLiteral<List<String>> pluginJarFile = new TypeLiteral<List<String>>() {
    };
    bind(pluginJarFile).annotatedWith(PluginJarPaths.class).toInstance(agentOption.getPluginJars());
    TypeLiteral<List<PluginJar>> pluginJars = new TypeLiteral<List<PluginJar>>() {
    };
    bind(pluginJars).annotatedWith(PluginJars.class).toProvider(PluginJarsProvider.class).in(Scopes.SINGLETON);
    bindBootstrapCoreInformation();
    bindAgentInformation(agentOption.getAgentId(), agentOption.getAgentName(), agentOption.getApplicationName(), agentOption.isContainer());
    bindShutdownHook(contextConfig);
}
Also used : PluginJarPaths(com.navercorp.pinpoint.profiler.context.module.PluginJarPaths) TransportModule(com.navercorp.pinpoint.bootstrap.config.TransportModule) ProfilerConfig(com.navercorp.pinpoint.bootstrap.config.ProfilerConfig) InterceptorRegistryBinderProvider(com.navercorp.pinpoint.profiler.context.provider.InterceptorRegistryBinderProvider) Instrumentation(java.lang.instrument.Instrumentation) DefaultInstrumentMatcherCacheConfig(com.navercorp.pinpoint.profiler.instrument.config.DefaultInstrumentMatcherCacheConfig) DefaultMonitorConfig(com.navercorp.pinpoint.profiler.context.monitor.config.DefaultMonitorConfig) Properties(java.util.Properties) DefaultPluginLoadingConfig(com.navercorp.pinpoint.profiler.plugin.config.DefaultPluginLoadingConfig) PluginLoadingConfig(com.navercorp.pinpoint.profiler.plugin.config.PluginLoadingConfig) ContextConfig(com.navercorp.pinpoint.profiler.context.config.ContextConfig) DefaultContextConfig(com.navercorp.pinpoint.profiler.context.config.DefaultContextConfig) DefaultInstrumentMatcherCacheConfig(com.navercorp.pinpoint.profiler.instrument.config.DefaultInstrumentMatcherCacheConfig) InstrumentMatcherCacheConfig(com.navercorp.pinpoint.profiler.instrument.config.InstrumentMatcherCacheConfig) PluginJar(com.navercorp.pinpoint.profiler.plugin.PluginJar) TypeLiteral(com.google.inject.TypeLiteral) PluginJarsProvider(com.navercorp.pinpoint.profiler.context.provider.plugin.PluginJarsProvider) InstrumentConfig(com.navercorp.pinpoint.profiler.instrument.config.InstrumentConfig) DefaultInstrumentConfig(com.navercorp.pinpoint.profiler.instrument.config.DefaultInstrumentConfig) DefaultPluginLoadingConfig(com.navercorp.pinpoint.profiler.plugin.config.DefaultPluginLoadingConfig) List(java.util.List) DefaultContextConfig(com.navercorp.pinpoint.profiler.context.config.DefaultContextConfig) DefaultInstrumentConfig(com.navercorp.pinpoint.profiler.instrument.config.DefaultInstrumentConfig) MonitorConfig(com.navercorp.pinpoint.profiler.context.monitor.config.MonitorConfig) DefaultMonitorConfig(com.navercorp.pinpoint.profiler.context.monitor.config.DefaultMonitorConfig)

Aggregations

DefaultInstrumentMatcherCacheConfig (com.navercorp.pinpoint.profiler.instrument.config.DefaultInstrumentMatcherCacheConfig)3 InstrumentMatcherCacheConfig (com.navercorp.pinpoint.profiler.instrument.config.InstrumentMatcherCacheConfig)3 AnnotationInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.AnnotationInternalNameMatcherOperand)2 InterfaceInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand)2 SuperClassInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.SuperClassInternalNameMatcherOperand)2 InternalClassMetadata (com.navercorp.pinpoint.profiler.instrument.classreading.InternalClassMetadata)2 Test (org.junit.Test)2 TypeLiteral (com.google.inject.TypeLiteral)1 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)1 TransportModule (com.navercorp.pinpoint.bootstrap.config.TransportModule)1 ClassInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand)1 MatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand)1 PackageInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand)1 ContextConfig (com.navercorp.pinpoint.profiler.context.config.ContextConfig)1 DefaultContextConfig (com.navercorp.pinpoint.profiler.context.config.DefaultContextConfig)1 PluginJarPaths (com.navercorp.pinpoint.profiler.context.module.PluginJarPaths)1 DefaultMonitorConfig (com.navercorp.pinpoint.profiler.context.monitor.config.DefaultMonitorConfig)1 MonitorConfig (com.navercorp.pinpoint.profiler.context.monitor.config.MonitorConfig)1 InterceptorRegistryBinderProvider (com.navercorp.pinpoint.profiler.context.provider.InterceptorRegistryBinderProvider)1 PluginJarsProvider (com.navercorp.pinpoint.profiler.context.provider.plugin.PluginJarsProvider)1