Search in sources :

Example 1 with ThreadNameNormalizer

use of com.newrelic.agent.threads.ThreadNameNormalizer in project newrelic-java-agent by newrelic.

the class ProfileTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.start();
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    Map<String, Object> map = new HashMap<>();
    AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(map);
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, map);
    serviceManager.setConfigService(configService);
    TransactionService transactionService = new TransactionService();
    serviceManager.setTransactionService(transactionService);
    threadNameNormalizer = new ThreadNameNormalizer(agentConfig, threadService);
}
Also used : ThreadService(com.newrelic.agent.ThreadService) AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) TransactionService(com.newrelic.agent.TransactionService) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) ThreadNameNormalizer(com.newrelic.agent.threads.ThreadNameNormalizer) BeforeClass(org.junit.BeforeClass)

Example 2 with ThreadNameNormalizer

use of com.newrelic.agent.threads.ThreadNameNormalizer in project newrelic-java-agent by newrelic.

the class ThreadService method doStart.

@Override
protected void doStart() throws Exception {
    threadNameNormalizer = new ThreadNameNormalizer(ServiceFactory.getConfigService().getDefaultAgentConfig(), this);
    AgentConfig config = ServiceFactory.getConfigService().getDefaultAgentConfig();
    if (config.getValue("thread_sampler.enabled", Boolean.TRUE)) {
        long sampleDelayInSeconds = config.getValue("thread_sampler.sample_delay_in_seconds", 60);
        long samplePeriodInSeconds = config.getValue("thread_sampler.sample_period_in_seconds", 60);
        if (samplePeriodInSeconds > 0) {
            ThreadStateSampler threadStateSampler = new ThreadStateSampler(ManagementFactory.getThreadMXBean(), threadNameNormalizer);
            ServiceFactory.getSamplerService().addSampler(threadStateSampler, sampleDelayInSeconds, samplePeriodInSeconds, TimeUnit.SECONDS);
        } else {
            Agent.LOG.log(Level.FINE, "The thread sampler is disabled because the sample period is {}", samplePeriodInSeconds);
        }
    } else {
        Agent.LOG.log(Level.FINE, "The thread sampler is disabled");
    }
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ThreadStateSampler(com.newrelic.agent.threads.ThreadStateSampler) ThreadNameNormalizer(com.newrelic.agent.threads.ThreadNameNormalizer)

Aggregations

AgentConfig (com.newrelic.agent.config.AgentConfig)2 ThreadNameNormalizer (com.newrelic.agent.threads.ThreadNameNormalizer)2 MockServiceManager (com.newrelic.agent.MockServiceManager)1 ThreadService (com.newrelic.agent.ThreadService)1 TransactionService (com.newrelic.agent.TransactionService)1 ConfigService (com.newrelic.agent.config.ConfigService)1 ThreadStateSampler (com.newrelic.agent.threads.ThreadStateSampler)1 HashMap (java.util.HashMap)1 BeforeClass (org.junit.BeforeClass)1