This commit is contained in:
Claudio Maggioni 2023-01-09 19:15:25 +01:00
parent 4fd150441d
commit cc38d2872b
2 changed files with 5 additions and 6 deletions

View File

@ -18,7 +18,6 @@ public class Instrumentation {
Profiler.addUnsafeAllocation();
}
@Before(marker = BodyMarker.class, scope = "sun.misc.Unsafe.allocateInstance")
static void handleUnsafeAllocationsPraiseTheSun() {
Profiler.addUnsafeAllocation();

View File

@ -6,7 +6,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
public final class Profiler {
private static final ConcurrentMap<String, List<String>> callLog = new ConcurrentHashMap<>();
private static final ConcurrentMap<Thread, List<String>> callLog = new ConcurrentHashMap<>();
static {
Runtime.getRuntime().addShutdownHook(new Thread(Profiler::print));
@ -16,16 +16,16 @@ public final class Profiler {
}
public static void logCall(final Thread thread, final String methodName) {
final List<String> list = callLog.computeIfAbsent(thread.getName(), ignored -> new LinkedList<>());
final List<String> list = callLog.computeIfAbsent(thread, ignored -> new LinkedList<>());
// thread safe, as once a thread accesses its own list access to said list is non-concurrent
list.add(methodName);
}
private static void print() {
for (final String threadName : callLog.keySet()) {
System.out.printf("=== %s ===\n", threadName);
callLog.get(threadName).forEach(System.out::println);
for (final Thread thread : callLog.keySet()) {
System.out.printf("=== %s ===\n", thread.getName());
callLog.get(thread).forEach(System.out::println);
}
}
}