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());
}
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());
}
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);
}
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);
}
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;
}
Aggregations