DEV Community

Query Filter
Query Filter

Posted on

bridge40

public static class ProfilerAdvice {
    // FIX 1: Must be PUBLIC so the inlined code in 'com.citigroup' can see it
    public static final Set<String> seenMethods = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());

    @Advice.OnMethodEnter
    static long enter(@Advice.Origin("#t.#m") String methodName) {
        // FIX 2: Use absolute fully qualified path in the inlined code
        if (comet.agent.ProfilerAgent.ProfilerAdvice.seenMethods.add(methodName)) {
            System.out.println(">>> HEARTBEAT: First call detected in " + methodName);
            System.out.flush();
        }
        return System.nanoTime();
    }

    @Advice.OnMethodExit(onThrowable = Throwable.class)
    static void exit(@Advice.Enter long start, @Advice.Origin("#t.#m") String methodName) {
        if (start == 0L) return; 

        long duration = System.nanoTime() - start;

        // FIX 3: Fully qualify 'Stats' and 'metrics' access
        comet.agent.ProfilerAgent.Stats s = comet.agent.ProfilerAgent.metrics.get(methodName);
        if (s == null) {
            comet.agent.ProfilerAgent.metrics.putIfAbsent(methodName, new comet.agent.ProfilerAgent.Stats());
            s = comet.agent.ProfilerAgent.metrics.get(methodName);
        }
        s.record(duration);
    }
}

// FIX 4: Ensure the Stats class and its methods are PUBLIC
public static class Stats {
    public final java.util.concurrent.atomic.LongAdder count = new java.util.concurrent.atomic.LongAdder();
    public final java.util.concurrent.atomic.LongAdder totalTime = new java.util.concurrent.atomic.LongAdder();

    public void record(long nanos) {
        count.increment();
        totalTime.add(nanos);
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)