Skip to content

Commit 3036661

Browse files
and-oliDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Add some comments to stack trace utils in the RPP codebase
To prevent confusion about when to use which. Bug: 374732385 Change-Id: I71dded6bfbd7a1689d70f1f704d301b18e889d71 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6091589 Auto-Submit: Andres Olivares <[email protected]> Reviewed-by: Nancy Li <[email protected]> Commit-Queue: Andres Olivares <[email protected]>
1 parent ed48187 commit 3036661

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

front_end/models/trace/extras/StackTraceForEvent.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export const stackTraceForEventInTrace =
1414
export function clearCacheForTrace(parsedTrace: Handlers.Types.ParsedTrace): void {
1515
stackTraceForEventInTrace.delete(parsedTrace);
1616
}
17+
/**
18+
* This util builds a stack trace that includes async calls for a given
19+
* event. It leverages data we collect from sampling to deduce sync
20+
* stacks and trace event instrumentation on the V8 debugger to stitch
21+
* them together.
22+
*/
1723
export function get(event: Types.Events.Event, parsedTrace: Handlers.Types.ParsedTrace): Protocol.Runtime.StackTrace|
1824
null {
1925
let cacheForTrace = stackTraceForEventInTrace.get(parsedTrace);

front_end/models/trace/helpers/Trace.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ type MatchingPairableAsyncEvents = {
1818
};
1919

2020
/**
21-
* Extracts the raw stack trace of known trace events. Most likely than
21+
* Extracts the raw stack trace in known trace events. Most likely than
2222
* not you want to use `getZeroIndexedStackTraceForEvent`, which returns
2323
* the stack with zero based numbering. Since some trace events are
2424
* one based this function can yield unexpected results when used
2525
* indiscriminately.
26+
*
27+
* Note: this only returns the stack trace contained in the payload of
28+
* an event, which only contains the synchronous portion of the call
29+
* stack. If you want to obtain the whole stack trace you might need to
30+
* use the @see Trace.Extras.StackTraceForEvent util.
2631
*/
27-
export function stackTraceForEvent(event: Types.Events.Event): Types.Events.CallFrame[]|null {
32+
export function stackTraceInEvent(event: Types.Events.Event): Types.Events.CallFrame[]|null {
2833
if (event.args?.data?.stackTrace) {
2934
return event.args.data.stackTrace;
3035
}
@@ -35,10 +40,10 @@ export function stackTraceForEvent(event: Types.Events.Event): Types.Events.Call
3540
return event.args.beginData?.stackTrace || null;
3641
}
3742
if (Types.Extensions.isSyntheticExtensionEntry(event)) {
38-
return stackTraceForEvent(event.rawSourceEvent);
43+
return stackTraceInEvent(event.rawSourceEvent);
3944
}
4045
if (Types.Events.isSyntheticUserTiming(event)) {
41-
return stackTraceForEvent(event.rawSourceEvent);
46+
return stackTraceInEvent(event.rawSourceEvent);
4247
}
4348
if (Types.Events.isFunctionCall(event)) {
4449
const data = event.args.data;
@@ -398,9 +403,14 @@ export function getZeroIndexedLineAndColumnForEvent(event: Types.Events.Event):
398403
* that are 1 or 0 indexed.
399404
* This function knows which events return 1 indexed numbers and normalizes
400405
* them. The UI expects 0 indexed line numbers, so that is what we return.
406+
*
407+
* Note: this only returns the stack trace contained in the payload of
408+
* an event, which only contains the synchronous portion of the call
409+
* stack. If you want to obtain the whole stack trace you might need to
410+
* use the @see Trace.Extras.StackTraceForEvent util.
401411
*/
402412
export function getZeroIndexedStackTraceForEvent(event: Types.Events.Event): Types.Events.CallFrame[]|null {
403-
const stack = stackTraceForEvent(event);
413+
const stack = stackTraceInEvent(event);
404414
if (!stack) {
405415
return null;
406416
}

front_end/panels/timeline/components/NetworkRequestDetails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export class NetworkRequestDetails extends HTMLElement {
229229
return null;
230230
}
231231

232-
const hasStackTrace = Trace.Helpers.Trace.stackTraceForEvent(this.#networkRequest) !== null;
232+
const hasStackTrace = Trace.Helpers.Trace.stackTraceInEvent(this.#networkRequest) !== null;
233233

234234
// If we have a stack trace, that is the most reliable way to get the initiator data and display a link to the source.
235235
if (hasStackTrace) {

0 commit comments

Comments
 (0)