This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
AJP/DiSLProject2022/src-profiler/ex1/Instrumentation.java

27 lines
896 B
Java

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);
}
}