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 : clazz.getMethods()) {
|
|
|
|
if (declaredMethods.contains(m)) {
|
2023-01-09 17:42:06 +00:00
|
|
|
Profiler.registerDeclared(clazzName, m.toString());
|
|
|
|
} else {
|
|
|
|
Profiler.registerInherited(clazzName, m.toString());
|
2023-01-09 16:39:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (final ClassNotFoundException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-02 09:46:59 +00:00
|
|
|
}
|