Skip to content

Commit 8238ebe

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[sdk] Move async stack trace fragment iteration from UI to sdk
This should have been implemented on the sdk/ layer in the first place. We move it now so we can reuse it for the new StackTrace abstraction. [email protected] Bug: 433162438 Change-Id: I95b6d8b5fed0e571a9e820e29c730945209aa2cc Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6772976 Reviewed-by: Philip Pfaffe <[email protected]> Commit-Queue: Simon Zünd <[email protected]>
1 parent 052d2e3 commit 8238ebe

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed

front_end/core/sdk/DebuggerModel.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,45 @@ export class DebuggerModel extends SDKModel<EventTypes> {
972972
((arg0: CallFrame, arg1: EvaluationOptions) => Promise<EvaluationResult|null>)|null {
973973
return this.evaluateOnCallFrameCallback;
974974
}
975+
976+
/**
977+
* Iterates the async stack trace parents.
978+
*
979+
* Retrieving cross-target async stack fragments requires CDP interaction, so this is an async generator.
980+
*
981+
* Important: This iterator will not yield the "synchronous" part of the stack trace, only the async parent chain.
982+
*/
983+
async *
984+
iterateAsyncParents(stackTraceOrPausedDetails: Protocol.Runtime.StackTrace|DebuggerPausedDetails):
985+
AsyncGenerator<Protocol.Runtime.StackTrace> {
986+
// We make `DebuggerPausedDetails` look like a stack trace. We are only interested in `parent` and `parentId` in any case.
987+
let stackTrace: Protocol.Runtime.StackTrace = stackTraceOrPausedDetails instanceof DebuggerPausedDetails ?
988+
{
989+
callFrames: [],
990+
parent: stackTraceOrPausedDetails.asyncStackTrace,
991+
parentId: stackTraceOrPausedDetails.asyncStackTraceId
992+
} :
993+
stackTraceOrPausedDetails;
994+
995+
while (true) {
996+
if (stackTrace.parent) {
997+
stackTrace = stackTrace.parent;
998+
} else if (stackTrace.parentId) {
999+
const model: DebuggerModel|null = stackTrace.parentId.debuggerId ?
1000+
await DebuggerModel.modelForDebuggerId(stackTrace.parentId.debuggerId) :
1001+
this;
1002+
const maybeStackTrace = await model?.fetchAsyncStackTrace(stackTrace.parentId);
1003+
if (!maybeStackTrace) {
1004+
return;
1005+
}
1006+
stackTrace = maybeStackTrace;
1007+
} else {
1008+
return;
1009+
}
1010+
1011+
yield stackTrace;
1012+
}
1013+
}
9751014
}
9761015

9771016
const debuggerIdToModel = new Map<string, DebuggerModel>();

front_end/panels/sources/CallStackSidebarPane.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -241,34 +241,20 @@ export class CallStackSidebarPane extends UI.View.SimpleView implements UI.Conte
241241
UI.Tooltip.Tooltip.install(this.callFrameWarningsElement, Array.from(uniqueWarnings).join('\n'));
242242
}
243243

244-
let debuggerModel = details.debuggerModel;
245-
let asyncStackTraceId = details.asyncStackTraceId;
246-
let asyncStackTrace: Protocol.Runtime.StackTrace|undefined|null = details.asyncStackTrace;
247244
let previousStackTrace: Protocol.Runtime.CallFrame[]|SDK.DebuggerModel.CallFrame[] = details.callFrames;
248-
for (let {maxAsyncStackChainDepth} = this; maxAsyncStackChainDepth > 0; --maxAsyncStackChainDepth) {
249-
if (!asyncStackTrace) {
250-
if (!asyncStackTraceId) {
251-
break;
252-
}
253-
if (asyncStackTraceId.debuggerId) {
254-
const dm = await SDK.DebuggerModel.DebuggerModel.modelForDebuggerId(asyncStackTraceId.debuggerId);
255-
if (!dm) {
256-
break;
257-
}
258-
debuggerModel = dm;
259-
}
260-
asyncStackTrace = await debuggerModel.fetchAsyncStackTrace(asyncStackTraceId);
261-
if (!asyncStackTrace) {
262-
break;
263-
}
264-
}
245+
let {maxAsyncStackChainDepth} = this;
246+
let asyncStackTrace: Protocol.Runtime.StackTrace|null = null;
247+
for await (asyncStackTrace of details.debuggerModel.iterateAsyncParents(details)) {
265248
const title = UI.UIUtils.asyncStackTraceLabel(asyncStackTrace.description, previousStackTrace);
266249
items.push(...await Item.createItemsForAsyncStack(
267-
title, debuggerModel, asyncStackTrace.callFrames, this.locationPool, this.refreshItem.bind(this)));
250+
title, details.debuggerModel, asyncStackTrace.callFrames, this.locationPool, this.refreshItem.bind(this)));
268251
previousStackTrace = asyncStackTrace.callFrames;
269-
asyncStackTraceId = asyncStackTrace.parentId;
270-
asyncStackTrace = asyncStackTrace.parent;
252+
253+
if (--maxAsyncStackChainDepth <= 0) {
254+
break;
255+
}
271256
}
257+
272258
this.showMoreMessageElement.classList.toggle('hidden', !asyncStackTrace);
273259
this.items.replaceAll(items);
274260
for (const item of this.items) {

0 commit comments

Comments
 (0)