Search in sources :

Example 16 with TracedMethod

use of com.newrelic.agent.bridge.TracedMethod in project newrelic-java-agent by newrelic.

the class FlyweightTraceMethodVisitor method onEveryExit.

/**
 * This code is injected at every exit instruction, whether a return or an ATHROW.
 *
 * @see Transaction#finishFlyweightTracer(TracedMethod, long, long, String, String, String, String, String[])
 */
private void onEveryExit() {
    Label skip = super.newLabel();
    super.loadLocal(parentTracerLocal);
    super.ifNull(skip);
    BridgeUtils.getCurrentTransactionOrNull(this);
    super.ifNull(skip);
    BridgeUtils.getCurrentTransaction(this);
    BytecodeGenProxyBuilder<Transaction> builder = BytecodeGenProxyBuilder.newBuilder(Transaction.class, this, true);
    Variables loader = builder.getVariables();
    String[] rollupMetricNames;
    if (rollupMetricNamesCacheId >= 0) {
        rollupMetricNames = loader.load(String[].class, new Runnable() {

            @Override
            public void run() {
                getStatic(BridgeUtils.AGENT_BRIDGE_TYPE, BridgeUtils.INSTRUMENTATION_FIELD_NAME, BridgeUtils.INSTRUMENTATION_TYPE);
                BytecodeGenProxyBuilder.newBuilder(Instrumentation.class, FlyweightTraceMethodVisitor.this, true).build().getCachedObject(rollupMetricNamesCacheId);
                checkCast(Type.getType(String[].class));
            }
        });
    } else {
        rollupMetricNames = null;
    }
    // -1 and -2 are identifiers that tell the ApiBuilder's proxy to (-1) load a local variable and (-2) call
    // System.nanoTime when those values are
    // encountered
    long startTime = loader.loadLocal(startTimeLocal, Type.LONG_TYPE, -1L);
    long loadEndTime = loader.load(-2l, new Runnable() {

        @Override
        public void run() {
            invokeStatic(Type.getType(System.class), new Method("nanoTime", Type.LONG_TYPE, new Type[0]));
        }
    });
    Transaction transactionApi = builder.build();
    transactionApi.finishFlyweightTracer(loader.loadLocal(parentTracerLocal, TracedMethod.class), startTime, loadEndTime, className, this.method.getName(), this.methodDesc, loader.loadLocal(metricNameLocal, String.class), rollupMetricNames);
    super.visitLabel(skip);
}
Also used : Variables(com.newrelic.agent.util.asm.Variables) Transaction(com.newrelic.agent.bridge.Transaction) Label(org.objectweb.asm.Label) TracedMethod(com.newrelic.agent.bridge.TracedMethod) Method(org.objectweb.asm.commons.Method) TracedMethod(com.newrelic.agent.bridge.TracedMethod)

Aggregations

TracedMethod (com.newrelic.agent.bridge.TracedMethod)16 Trace (com.newrelic.api.agent.Trace)8 Transaction (com.newrelic.agent.bridge.Transaction)6 Test (org.junit.Test)4 Method (org.objectweb.asm.commons.Method)4 ExitTracer (com.newrelic.agent.bridge.ExitTracer)2 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)2 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)2 Tracer (com.newrelic.agent.tracers.Tracer)2 MetricState (com.nr.agent.instrumentation.httpurlconnection.MetricState)2 IOException (java.io.IOException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Label (org.objectweb.asm.Label)2 Type (org.objectweb.asm.Type)2 AdviceAdapter (org.objectweb.asm.commons.AdviceAdapter)2 Instrumentation (com.newrelic.agent.bridge.Instrumentation)1 PublicApi (com.newrelic.agent.bridge.PublicApi)1 TracedActivity (com.newrelic.agent.bridge.TracedActivity)1 PointCut (com.newrelic.agent.instrumentation.PointCut)1 Variables (com.newrelic.agent.util.asm.Variables)1