Search in sources :

Example 1 with IdGenerator

use of com.navercorp.pinpoint.profiler.context.id.IdGenerator in project pinpoint by naver.

the class ThroughputSamplerTest method newTraceSampler.

private TraceSampler newTraceSampler(int throughput) {
    IdGenerator atomicIdGenerator = new AtomicIdGenerator();
    Sampler trueSampler = TrueSampler.INSTANCE;
    TraceSampler basicSampler = new BasicTraceSampler(atomicIdGenerator, trueSampler);
    return new RateLimitTraceSampler(throughput, 0, atomicIdGenerator, basicSampler);
}
Also used : TraceSampler(com.navercorp.pinpoint.bootstrap.sampler.TraceSampler) Sampler(com.navercorp.pinpoint.bootstrap.sampler.Sampler) TraceSampler(com.navercorp.pinpoint.bootstrap.sampler.TraceSampler) IdGenerator(com.navercorp.pinpoint.profiler.context.id.IdGenerator) AtomicIdGenerator(com.navercorp.pinpoint.profiler.context.id.AtomicIdGenerator) AtomicIdGenerator(com.navercorp.pinpoint.profiler.context.id.AtomicIdGenerator)

Example 2 with IdGenerator

use of com.navercorp.pinpoint.profiler.context.id.IdGenerator in project pinpoint by naver.

the class DefaultTraceContextTest method transactionCountTest.

@Test
public void transactionCountTest() {
    final int samplingRate = 5;
    final ProfilerConfig profilerConfig = getProfilerConfig();
    Mockito.when((profilerConfig.readInt(CountingSamplerFactory.LEGACY_SAMPLING_RATE_NAME, -1))).thenReturn(samplingRate);
    Mockito.when((profilerConfig.readBoolean(SamplerConfig.SAMPLER_ENABLE_NAME, true))).thenReturn(true);
    DefaultApplicationContext customContext = MockTraceContextFactory.newMockApplicationContext(profilerConfig);
    customContext.start();
    final TraceContext traceContext = customContext.getTraceContext();
    IdGenerator idGenerator = customContext.getInjector().getInstance(IdGenerator.class);
    final TransactionCounter transactionCounter = new DefaultTransactionCounter(idGenerator);
    final long newTransactionCount = 22L;
    @SuppressWarnings("unused") final long expectedSampledNewCount = newTransactionCount / samplingRate + (newTransactionCount % samplingRate > 0 ? 1 : 0);
    final long expectedUnsampledNewCount = newTransactionCount - expectedSampledNewCount;
    for (int i = 0; i < newTransactionCount; i++) {
        traceContext.newTraceObject();
        traceContext.removeTraceObject();
    }
    final long expectedSampledContinuationCount = 5L;
    for (int i = 0; i < expectedSampledContinuationCount; i++) {
        traceContext.continueTraceObject(new DefaultTraceId("agentId", 0L, i));
        traceContext.removeTraceObject();
    }
    final long expectedUnsampledContinuationCount = 10L;
    for (int i = 0; i < expectedUnsampledContinuationCount; i++) {
        traceContext.disableSampling();
        traceContext.removeTraceObject();
    }
    customContext.close();
    final long expectedTotalTransactionCount = expectedSampledNewCount + expectedUnsampledNewCount + expectedSampledContinuationCount + expectedUnsampledContinuationCount;
    Assert.assertEquals(expectedSampledNewCount, transactionCounter.getSampledNewCount());
    Assert.assertEquals(expectedUnsampledNewCount, transactionCounter.getUnSampledNewCount());
    Assert.assertEquals(expectedSampledContinuationCount, transactionCounter.getSampledContinuationCount());
    Assert.assertEquals(expectedUnsampledContinuationCount, transactionCounter.getUnSampledContinuationCount());
    Assert.assertEquals(expectedTotalTransactionCount, transactionCounter.getTotalTransactionCount());
}
Also used : DefaultApplicationContext(com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext) DefaultTransactionCounter(com.navercorp.pinpoint.profiler.context.id.DefaultTransactionCounter) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) ProfilerConfig(com.navercorp.pinpoint.bootstrap.config.ProfilerConfig) DefaultProfilerConfig(com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) DefaultTransactionCounter(com.navercorp.pinpoint.profiler.context.id.DefaultTransactionCounter) TransactionCounter(com.navercorp.pinpoint.profiler.context.id.TransactionCounter) IdGenerator(com.navercorp.pinpoint.profiler.context.id.IdGenerator) Test(org.junit.Test)

Aggregations

IdGenerator (com.navercorp.pinpoint.profiler.context.id.IdGenerator)2 DefaultProfilerConfig (com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig)1 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)1 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)1 Sampler (com.navercorp.pinpoint.bootstrap.sampler.Sampler)1 TraceSampler (com.navercorp.pinpoint.bootstrap.sampler.TraceSampler)1 AtomicIdGenerator (com.navercorp.pinpoint.profiler.context.id.AtomicIdGenerator)1 DefaultTraceId (com.navercorp.pinpoint.profiler.context.id.DefaultTraceId)1 DefaultTransactionCounter (com.navercorp.pinpoint.profiler.context.id.DefaultTransactionCounter)1 TransactionCounter (com.navercorp.pinpoint.profiler.context.id.TransactionCounter)1 DefaultApplicationContext (com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext)1 Test (org.junit.Test)1