use of com.newrelic.agent.tracers.DefaultTracer in project newrelic-java-agent by newrelic.
the class TransactionTest method createBasicTracer.
private DefaultTracer createBasicTracer(String id) {
Transaction tx = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), id, "()V");
return new DefaultTracer(tx, sig, this, new SimpleMetricNameFormat("Custom/myname" + id));
}
use of com.newrelic.agent.tracers.DefaultTracer in project newrelic-java-agent by newrelic.
the class SegmentTest method testExclusiveTime.
@Test
public void testExclusiveTime() throws InterruptedException {
DefaultTracer root = (DefaultTracer) makeTransaction();
Assert.assertNotNull(root);
Assert.assertNotNull(root.getTransactionActivity().getTransaction());
final com.newrelic.agent.bridge.TracedActivity tracedActivity = AgentBridge.getAgent().getTransaction().createAndStartTracedActivity();
DefaultTracer underlyingTracer = (DefaultTracer) tracedActivity.getTracedMethod();
Thread.sleep(10);
tracedActivity.end();
// Assuming the exclusive duration of the tracedActivity tracer is correct, verify the parent's exclusive
// duration is calculated correctly
root.performFinishWork(root.getStartTime() + 100, Opcodes.ARETURN, null);
assertTrue(root.getTransactionActivity().getTransaction().isFinished());
assertEquals(100, root.getExclusiveDuration());
assertTrue(underlyingTracer.getExclusiveDuration() >= TimeUnit.MILLISECONDS.toNanos(10));
}
use of com.newrelic.agent.tracers.DefaultTracer in project newrelic-java-agent by newrelic.
the class SegmentTest method testExclusiveTimeAsync.
@Test
public void testExclusiveTimeAsync() throws InterruptedException {
DefaultTracer root = (DefaultTracer) makeTransaction();
Assert.assertNotNull(root);
Assert.assertNotNull(root.getTransactionActivity().getTransaction());
final Segment segment = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Custom Segment");
Thread finishThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
segment.end();
}
});
finishThread.start();
root.performFinishWork(root.getStartTime() + 100, Opcodes.ARETURN, null);
finishThread.join();
// exclusive duration of async tracedActivity tracer should not affect root tracer's exclusive duration
assertTrue(root.getTransactionActivity().getTransaction().isFinished());
assertEquals(100, root.getExclusiveDuration());
}
use of com.newrelic.agent.tracers.DefaultTracer in project newrelic-java-agent by newrelic.
the class TransactionAsyncUtility method createDefaultTracer.
// Create a Tracer for tests that require one.
public static DefaultTracer createDefaultTracer(String methodName) {
Transaction tx = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature("MyClass", methodName, "()V");
DefaultTracer brrt = new DefaultTracer(tx, sig, new Object(), new SimpleMetricNameFormat("Custom/" + methodName));
return brrt;
}
use of com.newrelic.agent.tracers.DefaultTracer in project newrelic-java-agent by newrelic.
the class RequestUriConfigTests method startTracer.
private DefaultTracer startTracer() throws SQLException {
DummyConnection conn = new DummyConnection();
Statement statement = conn.createStatement();
Transaction tx = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
DefaultTracer tracer = new OtherRootTracer(tx, sig, statement, new SimpleMetricNameFormat("metric", "segment", "some uri")) {
@Override
public long getDuration() {
return 100000;
}
};
tx.getTransactionActivity().tracerStarted(tracer);
return tracer;
}
Aggregations