capture speedup - request all frames in one request

This commit is contained in:
Egor.Ushakov
2017-03-02 16:56:14 +03:00
parent 5b7c5681c5
commit 810f09603d
3 changed files with 56 additions and 14 deletions
@@ -207,6 +207,44 @@ public final class ThreadReferenceProxyImpl extends ObjectReferenceProxyImpl imp
return myFrameCount;
}
/**
* Same as frames(), but always force full frames refresh if not cached,
* this is useful when you need all frames but do not plan to invoke anything
* as only one request is sent
*/
@NotNull
public List<StackFrameProxyImpl> forceFrames() throws EvaluateException {
DebuggerManagerThreadImpl.assertIsManagerThread();
final ThreadReference threadRef = getThreadReference();
try {
//LOG.assertTrue(threadRef.isSuspended());
checkValid();
if (myFrames == null) {
try {
List<StackFrame> frames = threadRef.frames();
myFrameCount = frames.size();
myFrames = new ArrayList<>(myFrameCount);
myFramesFromBottom.clear();
int idx = 0;
for (StackFrame frame : frames) {
StackFrameProxyImpl frameProxy = new StackFrameProxyImpl(this, frame, myFrameCount - idx);
myFrames.add(frameProxy);
myFramesFromBottom.addFirst(frameProxy);
idx++;
}
}
catch (IncompatibleThreadStateException | InternalException e) {
throw EvaluateExceptionUtil.createEvaluateException(e);
}
}
}
catch (ObjectCollectedException ignored) {
return Collections.emptyList();
}
return myFrames;
}
@NotNull
public List<StackFrameProxyImpl> frames() throws EvaluateException {
DebuggerManagerThreadImpl.assertIsManagerThread();
@@ -74,7 +74,7 @@ public class StackFrameItem {
ThreadReferenceProxyImpl threadReferenceProxy = suspendContext.getThread();
if (threadReferenceProxy != null) {
List<StackFrameItem> res = new ArrayList<>();
for (StackFrameProxyImpl frame : threadReferenceProxy.frames()) {
for (StackFrameProxyImpl frame : threadReferenceProxy.forceFrames()) {
try {
List<XNamedValue> vars = null;
if (withVars) {
@@ -30,6 +30,7 @@ import com.intellij.debugger.engine.events.SuspendContextCommandImpl;
import com.intellij.debugger.impl.DebuggerUtilsEx;
import com.intellij.debugger.jdi.DecompiledLocalVariable;
import com.intellij.debugger.jdi.StackFrameProxyImpl;
import com.intellij.debugger.jdi.ThreadReferenceProxyImpl;
import com.intellij.debugger.memory.utils.StackFrameItem;
import com.intellij.debugger.settings.CapturePoint;
import com.intellij.debugger.settings.DebuggerSettings;
@@ -104,22 +105,25 @@ public class StackCapturingLineBreakpoint extends WildcardMethodBreakpoint {
public boolean processLocatableEvent(SuspendContextCommandImpl action, LocatableEvent event) throws EventProcessingException {
SuspendContextImpl suspendContext = action.getSuspendContext();
if (suspendContext != null) {
StackFrameProxyImpl frameProxy = suspendContext.getFrameProxy();
if (frameProxy != null) {
ThreadReferenceProxyImpl thread = suspendContext.getThread();
if (thread != null) {
DebugProcessImpl process = suspendContext.getDebugProcess();
try {
Map<Object, List<StackFrameItem>> stacks = process.getUserData(CAPTURED_STACKS);
if (stacks == null) {
stacks = new CapturedStacksMap();
process.putUserData(CAPTURED_STACKS, Collections.synchronizedMap(stacks));
}
Value key = myCaptureEvaluator.evaluate(new EvaluationContextImpl(suspendContext, frameProxy));
if (key instanceof ObjectReference) {
List<StackFrameItem> frames = StackFrameItem.createFrames(suspendContext, true);
if (frames.size() > MAX_STACK_LENGTH) {
frames = frames.subList(0, MAX_STACK_LENGTH);
StackFrameProxyImpl frameProxy = ContainerUtil.getFirstItem(thread.forceFrames());
if (frameProxy != null) {
Map<Object, List<StackFrameItem>> stacks = process.getUserData(CAPTURED_STACKS);
if (stacks == null) {
stacks = new CapturedStacksMap();
process.putUserData(CAPTURED_STACKS, Collections.synchronizedMap(stacks));
}
Value key = myCaptureEvaluator.evaluate(new EvaluationContextImpl(suspendContext, frameProxy));
if (key instanceof ObjectReference) {
List<StackFrameItem> frames = StackFrameItem.createFrames(suspendContext, true);
if (frames.size() > MAX_STACK_LENGTH) {
frames = frames.subList(0, MAX_STACK_LENGTH);
}
stacks.put(getKey((ObjectReference)key), frames);
}
stacks.put(getKey((ObjectReference)key), frames);
}
}
catch (EvaluateException e) {