diff --git a/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java b/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java index f499c0cf940d..ac1807874190 100644 --- a/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java +++ b/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java @@ -38,11 +38,12 @@ public class CaptureStorage { return; } try { + Throwable exception = new Throwable(); if (DEBUG) { - System.out.println("capture - " + key); + System.out.println("capture " + getCallerDescriptor(exception) + " - " + key); } Deque currentStacks = CURRENT_STACKS.get(); - CapturedStack stack = createCapturedStack(new Throwable(), currentStacks.isEmpty() ? null : currentStacks.getLast()); + CapturedStack stack = createCapturedStack(exception, currentStacks.isEmpty() ? null : currentStacks.getLast()); WeakKey keyRef = new WeakKey(key); synchronized (HISTORY) { CapturedStack old = STORAGE.put(keyRef, stack); @@ -71,15 +72,17 @@ public class CaptureStorage { CapturedStack stack = STORAGE.get(new WeakKey(key)); Deque currentStacks = CURRENT_STACKS.get(); if (stack != null) { - currentStacks.add(new InsertMatch(stack, getStackTraceDepth(new Throwable()))); + Throwable exception = new Throwable(); + currentStacks.add(new InsertMatch(stack, getStackTraceDepth(exception))); if (DEBUG) { - System.out.println("insert -> " + key + ", stack saved (" + currentStacks.size() + ")"); + System.out.println("insert " + getCallerDescriptor(exception) + " -> " + key + ", stack saved (" + currentStacks.size() + ")"); } } else { currentStacks.add(InsertMatch.EMPTY); if (DEBUG) { - System.out.println("insert -> " + key + ", no stack found (" + currentStacks.size() + ")"); + System.out.println( + "insert " + getCallerDescriptor(new Throwable()) + " -> " + key + ", no stack found (" + currentStacks.size() + ")"); } } } @@ -97,7 +100,8 @@ public class CaptureStorage { Deque currentStacks = CURRENT_STACKS.get(); currentStacks.removeLast(); if (DEBUG) { - System.out.println("insert <- " + key + ", stack removed (" + currentStacks.size() + ")"); + System.out.println( + "insert " + getCallerDescriptor(new Throwable()) + " <- " + key + ", stack removed (" + currentStacks.size() + ")"); } } catch (Exception e) { @@ -234,4 +238,10 @@ public class CaptureStorage { //noinspection CallToPrintStackTrace e.printStackTrace(); } + + private static String getCallerDescriptor(Throwable e) { + StackTraceElement[] stackTrace = e.getStackTrace(); + StackTraceElement caller = stackTrace[stackTrace.length - 2]; + return caller.getClassName() + "." + caller.getMethodName(); + } }