Пример #1
0
 private static int getInterceptorSize(AgentOption agentOption) {
   if (agentOption == null) {
     return DefaultInterceptorRegistryBinder.DEFAULT_MAX;
   }
   final ProfilerConfig profilerConfig = agentOption.getProfilerConfig();
   return profilerConfig.getInterceptorRegistrySize();
 }
Пример #2
0
 protected List<DefaultProfilerPluginContext> loadPlugins(AgentOption agentOption) {
   final ProfilerPluginLoader loader = new ProfilerPluginLoader(this);
   return loader.load(agentOption.getPluginJars());
 }
Пример #3
0
 public String getBootstrapCoreJar() {
   return agentOption.getBootStrapCoreJarPath();
 }
Пример #4
0
  public DefaultAgent(
      AgentOption agentOption, final InterceptorRegistryBinder interceptorRegistryBinder) {
    if (agentOption == null) {
      throw new NullPointerException("agentOption must not be null");
    }
    if (agentOption.getInstrumentation() == null) {
      throw new NullPointerException("instrumentation must not be null");
    }
    if (agentOption.getProfilerConfig() == null) {
      throw new NullPointerException("profilerConfig must not be null");
    }
    if (agentOption.getServiceTypeRegistryService() == null) {
      throw new NullPointerException("serviceTypeRegistryService must not be null");
    }

    if (interceptorRegistryBinder == null) {
      throw new NullPointerException("interceptorRegistryBinder must not be null");
    }
    logger.info("AgentOption:{}", agentOption);

    this.binder = new Slf4jLoggerBinder();
    bindPLoggerFactory(this.binder);

    this.interceptorRegistryBinder = interceptorRegistryBinder;
    interceptorRegistryBinder.bind();
    this.serviceTypeRegistryService = agentOption.getServiceTypeRegistryService();

    dumpSystemProperties();
    dumpConfig(agentOption.getProfilerConfig());

    changeStatus(AgentStatus.INITIALIZING);

    this.profilerConfig = agentOption.getProfilerConfig();
    this.instrumentation = agentOption.getInstrumentation();
    this.agentOption = agentOption;
    this.classPool =
        new JavassistClassPool(interceptorRegistryBinder, agentOption.getBootStrapCoreJarPath());

    if (logger.isInfoEnabled()) {
      logger.info("DefaultAgent classLoader:{}", this.getClass().getClassLoader());
    }

    pluginContexts = loadPlugins(agentOption);

    this.classFileTransformer = new ClassFileTransformerDispatcher(this, pluginContexts);
    this.dynamicTransformService =
        new DynamicTransformService(instrumentation, classFileTransformer);

    instrumentation.addTransformer(this.classFileTransformer, true);

    String applicationServerTypeString = profilerConfig.getApplicationServerType();
    ServiceType applicationServerType =
        this.serviceTypeRegistryService.findServiceTypeByName(applicationServerTypeString);

    final ApplicationServerTypeResolver typeResolver =
        new ApplicationServerTypeResolver(
            pluginContexts, applicationServerType, profilerConfig.getApplicationTypeDetectOrder());

    final AgentInformationFactory agentInformationFactory = new AgentInformationFactory();
    this.agentInformation = agentInformationFactory.createAgentInformation(typeResolver.resolve());
    logger.info("agentInformation:{}", agentInformation);

    CommandDispatcher commandDispatcher = new CommandDispatcher();

    this.tcpDataSender = createTcpDataSender(commandDispatcher);

    this.serverMetaDataHolder = createServerMetaDataHolder();

    this.spanDataSender =
        createUdpSpanDataSender(
            this.profilerConfig.getCollectorSpanServerPort(),
            "Pinpoint-UdpSpanDataExecutor",
            this.profilerConfig.getSpanDataSenderWriteQueueSize(),
            this.profilerConfig.getSpanDataSenderSocketTimeout(),
            this.profilerConfig.getSpanDataSenderSocketSendBufferSize());
    this.statDataSender =
        createUdpStatDataSender(
            this.profilerConfig.getCollectorStatServerPort(),
            "Pinpoint-UdpStatDataExecutor",
            this.profilerConfig.getStatDataSenderWriteQueueSize(),
            this.profilerConfig.getStatDataSenderSocketTimeout(),
            this.profilerConfig.getStatDataSenderSocketSendBufferSize());

    this.traceContext = createTraceContext();

    addCommandService(commandDispatcher, traceContext);

    this.agentInfoSender =
        new AgentInfoSender.Builder(tcpDataSender, this.agentInformation)
            .sendInterval(profilerConfig.getAgentInfoSendRetryInterval())
            .build();
    this.serverMetaDataHolder.addListener(this.agentInfoSender);

    AgentStatCollectorFactory agentStatCollectorFactory =
        new AgentStatCollectorFactory(
            this.getTransactionCounter(this.traceContext), this.profilerConfig);
    this.agentStatMonitor =
        new AgentStatMonitor(
            this.statDataSender,
            this.agentInformation.getAgentId(),
            this.agentInformation.getStartTime(),
            agentStatCollectorFactory);

    InterceptorInvokerHelper.setPropagateException(
        profilerConfig.isPropagateInterceptorException());
  }