Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[debug] Lazily update frames of all threads in all-stop mode #7281

Merged
merged 1 commit into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/debug/src/browser/debug-session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ export class DebugSession implements CompositeTreeElement {
}
}),
this.on('stopped', async ({ body }) => {
// Update thread list
await this.updateThreads(body);

// Update current thread's frames immediately
await this.updateFrames();
}),
this.on('thread', ({ body: { reason, threadId } }) => {
Expand Down Expand Up @@ -221,6 +224,9 @@ export class DebugSession implements CompositeTreeElement {
this.fireDidChange();
if (thread) {
this.toDisposeOnCurrentThread.push(thread.onDidChanged(() => this.fireDidChange()));

// If this thread is missing stack frame information, then load that.
this.updateFrames();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to update frames whenever current thread is changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the comment says,

If this thread is missing stack frame information, then load that.

On a breakpoint or other stop, we clear all threads' frames and only load the current thread's stackframes. When you switch thread it's going to be empty. Which is good, because fetching all stackframes on stop would be slow on a large number of threads.

Copy link
Member

@akosyakov akosyakov Mar 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that we should update only according to stop logic, if we do it propertly then by the time when someone changes a thread frames will be already there or at least updating. This code should not be necessary.

}
}

Expand Down Expand Up @@ -465,7 +471,7 @@ export class DebugSession implements CompositeTreeElement {

protected async updateFrames(): Promise<void> {
const thread = this._currentThread;
if (!thread || thread.frameCount) {
if (!thread || thread.pendingFrameCount || thread.frameCount) {
return;
}
if (this.capabilities.supportsDelayedStackTraceLoading) {
Expand Down
27 changes: 26 additions & 1 deletion packages/debug/src/browser/model/debug-thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/

import * as React from 'react';
import { Event, Emitter } from '@theia/core';
import { CancellationTokenSource, Emitter, Event } from '@theia/core';
import { DebugProtocol } from 'vscode-debugprotocol/lib/debugProtocol';
import { TreeElement } from '@theia/core/lib/browser/source-tree';
import { DebugStackFrame } from './debug-stack-frame';
Expand Down Expand Up @@ -140,18 +140,33 @@ export class DebugThread extends DebugThreadData implements TreeElement {
}

protected pendingFetch = Promise.resolve<DebugStackFrame[]>([]);
protected _pendingFetchCount: number = 0;
protected pendingFetchCancel = new CancellationTokenSource();
async fetchFrames(levels: number = 20): Promise<DebugStackFrame[]> {
const cancel = this.pendingFetchCancel.token;
this._pendingFetchCount += 1;

return this.pendingFetch = this.pendingFetch.then(async () => {
try {
const start = this.frameCount;
const frames = await this.doFetchFrames(start, levels);
if (cancel.isCancellationRequested) {
return [];
}
return this.doUpdateFrames(frames);
} catch (e) {
console.error(e);
return [];
} finally {
if (!cancel.isCancellationRequested) {
this._pendingFetchCount -= 1;
}
}
});
}
get pendingFrameCount(): number {
return this._pendingFetchCount;
}
protected async doFetchFrames(startFrame: number, levels: number): Promise<DebugProtocol.StackFrame[]> {
try {
const response = await this.session.sendRequest('stackTrace',
Expand Down Expand Up @@ -181,7 +196,17 @@ export class DebugThread extends DebugThreadData implements TreeElement {
return [...result.values()];
}
protected clearFrames(): void {
// Clear all frames
this._frames.clear();

// Cancel all request promises
this.pendingFetchCancel.cancel();
this.pendingFetchCancel = new CancellationTokenSource();

// Empty all current requests
this.pendingFetch = Promise.resolve([]);
this._pendingFetchCount = 0;

this.updateCurrentFrame();
}
protected updateCurrentFrame(): void {
Expand Down