tweak 10
This commit is contained in:
parent
474c6eddb6
commit
14b3fad321
4 changed files with 20 additions and 14 deletions
|
@ -2,13 +2,11 @@ package ex10;
|
|||
|
||||
import ch.usi.dag.disl.annotation.After;
|
||||
import ch.usi.dag.disl.annotation.Before;
|
||||
import ch.usi.dag.disl.dynamiccontext.DynamicContext;
|
||||
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.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -26,8 +24,9 @@ public class Instrumentation {
|
|||
}
|
||||
|
||||
@After(marker = BodyMarker.class,
|
||||
scope = "ex10.Main.main")
|
||||
static void instrumentMain() {
|
||||
scope = "void ex10.Main.main",
|
||||
guard = IsPublicStaticGuard.class)
|
||||
static void instrumentMain() {
|
||||
final ClassLoader cls = ClassLoader.getSystemClassLoader();
|
||||
final List<String> classes = List.of("ex10.Player", "ex10.VideoGamePlayer");
|
||||
for (final String clazzName : classes) {
|
||||
|
|
11
DiSLProject2022/src-profiler/ex10/IsPublicStaticGuard.java
Normal file
11
DiSLProject2022/src-profiler/ex10/IsPublicStaticGuard.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package ex10;
|
||||
|
||||
import ch.usi.dag.disl.annotation.GuardMethod;
|
||||
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
|
||||
|
||||
public class IsPublicStaticGuard {
|
||||
@GuardMethod
|
||||
public static boolean isGuard(final MethodStaticContext msc) {
|
||||
return msc.isMethodPublic() && msc.isMethodStatic();
|
||||
}
|
||||
}
|
|
@ -1,27 +1,24 @@
|
|||
package ex10;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class Profiler {
|
||||
private static final ConcurrentMap<String, Set<String>> methodInvocations = new ConcurrentHashMap<>();
|
||||
|
||||
private static final ConcurrentMap<String, Set<String>> methodDeclarations = new ConcurrentHashMap<>();
|
||||
private static final Map<String, Set<String>> methodDeclarations = new HashMap<>();
|
||||
|
||||
|
||||
private static final ConcurrentMap<String, Set<String>> inheritedMethods = new ConcurrentHashMap<>();
|
||||
private static final Map<String, Set<String>> inheritedMethods = new HashMap<>();
|
||||
|
||||
static {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
for (final String className : methodInvocations.keySet()) {
|
||||
System.out.println("=== Class Name: " + className + " ===");
|
||||
for (final String method : methodDeclarations.get(className)) {
|
||||
for (final String method : methodDeclarations.getOrDefault(className, Set.of())) {
|
||||
System.out.println("Declared: " + method);
|
||||
}
|
||||
for (final String method : inheritedMethods.get(className)) {
|
||||
for (final String method : inheritedMethods.getOrDefault(className, Set.of())) {
|
||||
System.out.println("Inherited: " + method);
|
||||
}
|
||||
for (final String method : methodInvocations.get(className)) {
|
||||
|
@ -35,7 +32,7 @@ public class Profiler {
|
|||
private Profiler() {
|
||||
}
|
||||
|
||||
private static void register(final String className, final String methodName, final ConcurrentMap<String, Set<String>> methods) {
|
||||
private static void register(final String className, final String methodName, final Map<String, Set<String>> methods) {
|
||||
methods.computeIfAbsent(className, ignored -> Collections.synchronizedSet(new HashSet<>()))
|
||||
.add(methodName);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package ex9;
|
|||
|
||||
import ch.usi.dag.disl.annotation.Before;
|
||||
import ch.usi.dag.disl.marker.BodyMarker;
|
||||
import ch.usi.dag.disl.staticcontext.InvocationStaticContext;
|
||||
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
|
||||
|
||||
public class Instrumentation {
|
||||
|
|
Reference in a new issue