fix
This commit is contained in:
parent
4fd150441d
commit
cc38d2872b
2 changed files with 5 additions and 6 deletions
|
@ -18,7 +18,6 @@ public class Instrumentation {
|
||||||
Profiler.addUnsafeAllocation();
|
Profiler.addUnsafeAllocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Before(marker = BodyMarker.class, scope = "sun.misc.Unsafe.allocateInstance")
|
@Before(marker = BodyMarker.class, scope = "sun.misc.Unsafe.allocateInstance")
|
||||||
static void handleUnsafeAllocationsPraiseTheSun() {
|
static void handleUnsafeAllocationsPraiseTheSun() {
|
||||||
Profiler.addUnsafeAllocation();
|
Profiler.addUnsafeAllocation();
|
||||||
|
|
|
@ -6,7 +6,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
public final class Profiler {
|
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 {
|
static {
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(Profiler::print));
|
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) {
|
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
|
// thread safe, as once a thread accesses its own list access to said list is non-concurrent
|
||||||
list.add(methodName);
|
list.add(methodName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void print() {
|
private static void print() {
|
||||||
for (final String threadName : callLog.keySet()) {
|
for (final Thread thread : callLog.keySet()) {
|
||||||
System.out.printf("=== %s ===\n", threadName);
|
System.out.printf("=== %s ===\n", thread.getName());
|
||||||
callLog.get(threadName).forEach(System.out::println);
|
callLog.get(thread).forEach(System.out::println);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue