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/ex11/Profiler.java

29 lines
700 B
Java
Raw Normal View History

package ex11;
import java.util.HashMap;
import java.util.Map;
public final class Profiler {
private static final Map<CallInfo, long[]> count = new HashMap<>();
private static boolean stop = false;
static {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
stop = true;
for (final var entry : count.entrySet()) {
System.out.println(entry.getKey().toString() + "\n#invokes " + entry.getValue()[0] + "\n");
}
}));
}
private Profiler() {
}
public static void registerCall(final CallInfo info) {
if (stop) return;
count.computeIfAbsent(info, ignored -> new long[1])[0]++;
}
}