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

51 lines
1.9 KiB
Java
Raw Normal View History

2023-01-02 09:46:59 +00:00
package ex10;
2023-01-09 16:39:09 +00:00
import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.marker.BodyMarker;
import ch.usi.dag.disl.staticcontext.ClassStaticContext;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Set;
2023-01-02 09:46:59 +00:00
public class Instrumentation {
2023-01-09 16:39:09 +00:00
@Before(marker = BodyMarker.class,
scope = "ex10.VideoGamePlayer.*")
static void instrumentCall(final ClassStaticContext csc, final MethodStaticContext msc) {
Profiler.registerInvoke(csc.getName(), msc.thisMethodName());
}
@Before(marker = BodyMarker.class,
scope = "ex10.Player.*")
static void instrumentCallPlayer(final ClassStaticContext csc, final MethodStaticContext msc) {
Profiler.registerInvoke(csc.getName(), msc.thisMethodName());
}
@After(marker = BodyMarker.class,
2023-01-09 17:35:38 +00:00
scope = "void ex10.Main.main",
guard = IsPublicStaticGuard.class)
static void instrumentMain() {
2023-01-09 16:39:09 +00:00
final ClassLoader cls = ClassLoader.getSystemClassLoader();
final List<String> classes = List.of("ex10.Player", "ex10.VideoGamePlayer");
for (final String clazzName : classes) {
try {
final Class<?> clazz = cls.loadClass(clazzName);
final Set<Method> declaredMethods = Set.of(clazz.getDeclaredMethods());
for (final Method m : declaredMethods) {
Profiler.registerDeclare(clazzName, m.toString());
}
for (final Method m : clazz.getMethods()) {
if (declaredMethods.contains(m)) {
continue;
}
Profiler.registerInherited(clazzName, m.toString());
}
} catch (final ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
2023-01-02 09:46:59 +00:00
}