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

49 lines
1.6 KiB
Java
Raw Permalink Normal View History

2023-01-02 09:46:59 +00:00
package ex8;
import ch.usi.dag.disl.annotation.After;
2023-01-09 07:01:15 +00:00
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;
2023-01-09 07:01:15 +00:00
import ch.usi.dag.disl.marker.BytecodeMarker;
import ch.usi.dag.disl.staticcontext.InstructionStaticContext;
2023-01-09 07:01:15 +00:00
import org.objectweb.asm.Opcodes;
2023-01-02 09:46:59 +00:00
public class Instrumentation {
2023-01-09 07:01:15 +00:00
@ThreadLocal
private static long staticCount;
@ThreadLocal
private static long dynamicCount;
@ThreadLocal
private static long specialCount;
@ThreadLocal
private static long virtualCount;
@Before(marker = BytecodeMarker.class,
args = "invokestatic, invokespecial, invokevirtual, invokedynamic")
static void handleInvoke(final InstructionStaticContext isc) {
switch (isc.getOpcode()) {
case Opcodes.INVOKESTATIC -> staticCount++;
case Opcodes.INVOKEDYNAMIC -> dynamicCount++;
case Opcodes.INVOKESPECIAL -> specialCount++;
case Opcodes.INVOKEVIRTUAL -> virtualCount++;
}
}
@After(marker = BodyMarker.class, scope = "void run()", guard = IsNonStaticGuard.class)
static void endThread(final DynamicContext dc) {
if (dc.getThis() instanceof Thread) {
System.out.printf("Thread: %20s - static: %6d - special: %6d - virtual: %6d - dynamic: %6d\n",
((Thread) dc.getThis()).getName(),
staticCount,
specialCount,
virtualCount,
dynamicCount);
2023-01-09 07:01:15 +00:00
}
}
2023-01-02 09:46:59 +00:00
}