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/ex2/Instrumentation.java

44 lines
1.2 KiB
Java
Raw Normal View History

2023-01-02 09:46:59 +00:00
package ex2;
2023-01-02 14:18:34 +00:00
import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.annotation.ThreadLocal;
import ch.usi.dag.disl.dynamiccontext.DynamicContext;
import ch.usi.dag.disl.marker.BodyMarker;
import ch.usi.dag.disl.marker.BytecodeMarker;
2023-01-02 09:46:59 +00:00
public class Instrumentation {
2023-01-02 14:18:34 +00:00
@ThreadLocal
static long readCount;
@ThreadLocal
static long writeCount;
@Before(marker = BytecodeMarker.class, args = "getfield")
static void beforeGetField() {
readCount++;
}
@Before(marker = BytecodeMarker.class, args = "putfield")
static void beforePutField() {
writeCount++;
}
@After(marker = BodyMarker.class,
scope = "void run()",
guard = IsTriviallyThreadGuard.class)
static void onThreadExit() {
Profiler.increment(readCount, writeCount);
}
@After(marker = BodyMarker.class,
scope = "void run()",
guard = IsNotTriviallyThreadGuard.class)
static void onThreadExit(final DynamicContext dc) {
if (Profiler.isThread(dc.getThis().getClass())) {
Profiler.increment(readCount, writeCount);
}
}
2023-01-02 09:46:59 +00:00
}