Search in sources :

Example 1 with StatsBase

use of com.newrelic.agent.stats.StatsBase in project newrelic-java-agent by newrelic.

the class TransactionAsyncEdgeCaseTest method testLinkAndExpireSameThreadTwoTracers.

@Test
public void testLinkAndExpireSameThreadTwoTracers() throws InterruptedException {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    TokenImpl token = (TokenImpl) tx.getToken();
    token.linkAndExpire();
    Tracer defaultTracer = TransactionAsyncUtility.createDefaultTracer("mymethod");
    tx.getTransactionActivity().tracerStarted(defaultTracer);
    defaultTracer.finish(Opcodes.RETURN, 0);
    rootTracer.finish(Opcodes.RETURN, 0);
    waitForTransaction();
    Assert.assertNotNull(data);
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, data.getTransactionActivities().size());
    Collection<Tracer> tracers = data.getTracers();
    Assert.assertEquals(2, tracers.size() + 1);
    Iterator<Tracer> it = tracers.iterator();
    while (it.hasNext()) {
        Tracer t = it.next();
        Assert.assertEquals("Custom/mymethod", t.getMetricName());
    }
    Assert.assertEquals("RequestDispatcher", data.getRootTracer().getMetricName());
    Map<String, StatsBase> metrics = stats.getScopedStats().getStatsMap();
    ResponseTimeStatsImpl sb = (ResponseTimeStatsImpl) metrics.get("Custom/mymethod");
    Assert.assertEquals(1, sb.getCallCount());
    sb = (ResponseTimeStatsImpl) metrics.get("RequestDispatcher");
    Assert.assertEquals(1, sb.getCallCount());
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) StatsBase(com.newrelic.agent.stats.StatsBase) ResponseTimeStatsImpl(com.newrelic.agent.stats.ResponseTimeStatsImpl) Test(org.junit.Test)

Example 2 with StatsBase

use of com.newrelic.agent.stats.StatsBase in project newrelic-java-agent by newrelic.

the class TransactionAsyncEdgeCaseTest method testLinkSameThreadTwoTracers.

@Test
public void testLinkSameThreadTwoTracers() throws InterruptedException {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    TokenImpl token = (TokenImpl) tx.getToken();
    Transaction.linkTxOnThread(token);
    Tracer defaultTracer = TransactionAsyncUtility.createDefaultTracer("mymethod");
    tx.getTransactionActivity().tracerStarted(defaultTracer);
    token.expire();
    defaultTracer.finish(Opcodes.RETURN, 0);
    rootTracer.finish(Opcodes.RETURN, 0);
    waitForTransaction();
    Assert.assertNotNull(data);
    Assert.assertNotNull(stats);
    Assert.assertEquals(1, data.getTransactionActivities().size());
    Collection<Tracer> tracers = data.getTracers();
    Assert.assertEquals(2, tracers.size() + 1);
    Iterator<Tracer> it = tracers.iterator();
    while (it.hasNext()) {
        Tracer t = it.next();
        Assert.assertEquals("Custom/mymethod", t.getMetricName());
    }
    Assert.assertEquals("RequestDispatcher", data.getRootTracer().getMetricName());
    Map<String, StatsBase> metrics = stats.getScopedStats().getStatsMap();
    ResponseTimeStatsImpl sb = (ResponseTimeStatsImpl) metrics.get("Custom/mymethod");
    Assert.assertEquals(1, sb.getCallCount());
    sb = (ResponseTimeStatsImpl) metrics.get("RequestDispatcher");
    Assert.assertEquals(1, sb.getCallCount());
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) StatsBase(com.newrelic.agent.stats.StatsBase) ResponseTimeStatsImpl(com.newrelic.agent.stats.ResponseTimeStatsImpl) Test(org.junit.Test)

Example 3 with StatsBase

use of com.newrelic.agent.stats.StatsBase in project newrelic-java-agent by newrelic.

the class AsyncTest method dispatcherTransactionStatsFinished.

@Override
public void dispatcherTransactionStatsFinished(TransactionData transactionData, TransactionStats transactionStats) {
    TransactionStats statsCopy = new TransactionStats();
    try {
        // Create deep copy of transactionStats object
        for (Map.Entry<String, StatsBase> entry : transactionStats.getUnscopedStats().getStatsMap().entrySet()) {
            statsCopy.getUnscopedStats().getStatsMap().put(entry.getKey(), (StatsBase) entry.getValue().clone());
        }
        for (Map.Entry<String, StatsBase> entry : transactionStats.getScopedStats().getStatsMap().entrySet()) {
            statsCopy.getScopedStats().getStatsMap().put(entry.getKey(), (StatsBase) entry.getValue().clone());
        }
    } catch (Exception e) {
        statsCopy = transactionStats;
    }
    timesSet++;
    data = transactionData;
    stats = statsCopy;
    dataList.add(transactionData);
    statsList.add(statsCopy);
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) StatsBase(com.newrelic.agent.stats.StatsBase) Map(java.util.Map)

Example 4 with StatsBase

use of com.newrelic.agent.stats.StatsBase in project newrelic-java-agent by newrelic.

the class InstrumentTestUtils method verifyMetricCount.

public static void verifyMetricCount(String name, int count, List<MetricData> data) {
    boolean foundName = false;
    for (MetricData current : data) {
        if (current.getMetricName().getName().equals(name)) {
            foundName = true;
            StatsBase stats = current.getStats();
            if (stats instanceof CountStats) {
                Assert.assertEquals(name, count, ((CountStats) stats).getCallCount());
            }
        }
    }
    printData(data);
    Assert.assertTrue("Was not able to find metric name " + name, foundName);
}
Also used : CountStats(com.newrelic.agent.stats.CountStats) StatsBase(com.newrelic.agent.stats.StatsBase) MetricData(com.newrelic.agent.MetricData)

Example 5 with StatsBase

use of com.newrelic.agent.stats.StatsBase in project newrelic-java-agent by newrelic.

the class IntrospectorStatsService method convertToTracedMetric.

private Map<String, TracedMetricData> convertToTracedMetric(SimpleStatsEngine currentEngine) {
    Map<String, TracedMetricData> output = Maps.newHashMapWithExpectedSize(currentEngine.getSize());
    for (Entry<String, StatsBase> current : currentEngine.getStatsMap().entrySet()) {
        if (current.getValue() instanceof CountStats) {
            TracedMetricData data = TracedMetricImpl.getTracedMetricFromStatsBase(current.getKey(), (CountStats) current.getValue());
            output.put(current.getKey(), data);
        }
    }
    return output;
}
Also used : TracedMetricData(com.newrelic.agent.introspec.TracedMetricData) CountStats(com.newrelic.agent.stats.CountStats) StatsBase(com.newrelic.agent.stats.StatsBase)

Aggregations

StatsBase (com.newrelic.agent.stats.StatsBase)19 Tracer (com.newrelic.agent.tracers.Tracer)10 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)9 Test (org.junit.Test)9 TokenImpl (com.newrelic.agent.TokenImpl)6 Transaction (com.newrelic.agent.Transaction)6 StartAndThenLink (com.newrelic.agent.TransactionAsyncUtility.StartAndThenLink)6 ResponseTimeStatsImpl (com.newrelic.agent.stats.ResponseTimeStatsImpl)4 CountStats (com.newrelic.agent.stats.CountStats)3 MetricData (com.newrelic.agent.MetricData)2 MockNormalizer (com.newrelic.agent.MockNormalizer)1 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)1 SimpleStatsEngine (com.newrelic.agent.stats.SimpleStatsEngine)1 StatsEngine (com.newrelic.agent.stats.StatsEngine)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1