package ex1;

import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.annotation.SyntheticLocal;
import ch.usi.dag.disl.marker.BodyMarker;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;

public class Instrumentation {

    @SyntheticLocal
    static long entryTimestamp;

    @Before(marker = BodyMarker.class, scope = "ex1.MainThread.factorial")
    static void beforeMethod() {
        entryTimestamp = System.nanoTime();
    }

    @After(marker = BodyMarker.class, scope = "ex1.MainThread.factorial")
    static void afterMethod(final MethodStaticContext ctx) {
        final long endTimestamp = System.nanoTime();
        System.out.printf("%s - Execution time for %s: %d ns%n",
                Thread.currentThread().getName(),
                ctx.getUniqueInternalName(),
                endTimestamp - entryTimestamp);
    }
}
