use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class DatastoreInstanceCrossAgentTests method createTracerInTransaction.
private DefaultTracer createTracerInTransaction() {
Transaction tx = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "method", "()V");
DefaultTracer tracer = new OtherRootTracer(tx, sig, this, new SimpleMetricNameFormat("test"));
tx.getTransactionActivity().tracerStarted(tracer);
tx.setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, true, "custom", "foo");
Assert.assertEquals(0, AgentHelper.getChildren(tracer).size());
return tracer;
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class DefaultSqlTracerTest method newInstanceDBTracer.
private DefaultSqlTracer newInstanceDBTracer(String sql, final Connection connection, final String dbVendor, final String dbVendorName) throws SQLException {
Transaction transaction = Transaction.getTransaction(true);
ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
DefaultSqlTracer result = new OtherRootSqlTracer(transaction, sig, null, new SimpleMetricNameFormat(null), DefaultTracer.DEFAULT_TRACER_FLAGS, System.nanoTime());
transaction.getTransactionActivity().tracerStarted(result);
final JdbcDatabaseVendor jdbcDatabaseVendor = new JdbcDatabaseVendor(dbVendor, dbVendorName, true) {
@Override
public DatastoreVendor getDatastoreVendor() {
return DatastoreVendor.MySQL;
}
};
ConnectionFactory connectionFactory = new ConnectionFactory() {
@Override
public Connection getConnection() throws SQLException {
return connection;
}
@Override
public DatabaseVendor getDatabaseVendor() {
return jdbcDatabaseVendor;
}
};
result.setConnectionFactory(connectionFactory);
result.setRawSql(sql);
result.provideConnection(connection);
result.setConnectionFactory(connectionFactory);
// prevent "Inconsistent state! ..." errors
AgentHelper.setLastTracer(result);
return result;
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method exclusiveTime.
@Test
public void exclusiveTime() throws Exception {
Transaction tx = Transaction.getTransaction();
long parentDuration = 100;
long childDuration = 100;
int childCount = 3;
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
DefaultTracer parentTracer = new OtherRootTracer(tx, sig, this, new SimpleMetricNameFormat("test"));
tx.getTransactionActivity().tracerStarted(parentTracer);
assertEquals(0, AgentHelper.getChildren(parentTracer).size());
long actualChildDuratioNanos = 0;
synchronized (this) {
wait(parentDuration);
for (int i = 0; i < childCount; i++) {
DefaultTracer kid = new DefaultTracer(tx, sig, this);
tx.getTransactionActivity().tracerStarted(kid);
wait(childDuration);
kid.finish(Opcodes.RETURN, null);
// parentTracer.childTracerFinished(kid);
actualChildDuratioNanos += kid.getDuration();
}
}
parentTracer.finish(Opcodes.RETURN, null);
Assert.assertTrue(parentTracer.getDurationInMilliseconds() >= parentDuration);
Assert.assertNotSame(parentTracer.getExclusiveDuration(), parentTracer.getDuration());
assertEquals(actualChildDuratioNanos, parentTracer.getDuration() - parentTracer.getExclusiveDuration());
assertEquals(childCount, AgentHelper.getChildren(parentTracer).size());
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method startSqlTracer.
private SqlTracer startSqlTracer(final String sql, final long duration) 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;");
SqlTracer sqlTracer = new OtherRootSqlTracer(tx, sig, statement, new SimpleMetricNameFormat(null)) {
@Override
public long getDuration() {
return duration;
}
@Override
public Object getSql() {
return sql;
}
};
sqlTracer.setConnectionFactory(new ConnectionFactory() {
@Override
public Connection getConnection() throws SQLException {
return null;
}
@Override
public DatabaseVendor getDatabaseVendor() {
return UnknownDatabaseVendor.INSTANCE;
}
});
sqlTracer.setRawSql(sql);
tx.getTransactionActivity().tracerStarted(sqlTracer);
return sqlTracer;
}
use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat in project newrelic-java-agent by newrelic.
the class BoundedConcurrentCacheTest method createSqlTracer.
public SqlTracer createSqlTracer(RandomSql sql) {
SqlTracer defaultSqlTracer = new DefaultSqlTracer(tx, cms, new Object(), new SimpleMetricNameFormat("BoundedConcurrentCacheTest"), TracerFlags.GENERATE_SCOPED_METRIC);
defaultSqlTracer.setRawSql(sql.getSql());
return defaultSqlTracer;
}
Aggregations