package ex11; import java.util.HashMap; import java.util.Map; public final class Profiler { private static final Map 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]++; } }