Skip to content

Commit 4cda60e

Browse files
and-oliDevtools-frontend LUCI CQ
authored andcommitted
[RPP] use authored names when possible in FunctionCall details
Fixed: 383489148 Change-Id: Ifc011c298e77af84207634a39dfd63bde892e4b2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6089108 Commit-Queue: Andres Olivares <[email protected]> Reviewed-by: Jack Franklin <[email protected]>
1 parent 8c9f04c commit 4cda60e

File tree

4 files changed

+77
-15
lines changed

4 files changed

+77
-15
lines changed

front_end/models/trace/helpers/Trace.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ export function stackTraceForEvent(event: Types.Events.Event): Types.Events.Call
4141
if (Types.Events.isSyntheticUserTiming(event)) {
4242
return stackTraceForEvent(event.rawSourceEvent);
4343
}
44+
if (Types.Events.isFunctionCall(event)) {
45+
const data = event.args.data;
46+
if (!data) {
47+
return null;
48+
}
49+
const {columnNumber, lineNumber, url, scriptId, functionName} = data;
50+
if (lineNumber === undefined || functionName === undefined || columnNumber === undefined ||
51+
scriptId === undefined || url === undefined) {
52+
return null;
53+
}
54+
return [{columnNumber, lineNumber, url, scriptId, functionName}];
55+
}
4456
return null;
4557
}
4658

@@ -397,6 +409,7 @@ export function getZeroIndexedStackTraceForEvent(event: Types.Events.Event): Typ
397409
switch (event.name) {
398410
case Types.Events.Name.SCHEDULE_STYLE_RECALCULATION:
399411
case Types.Events.Name.INVALIDATE_LAYOUT:
412+
case Types.Events.Name.FUNCTION_CALL:
400413
case Types.Events.Name.UPDATE_LAYOUT_TREE: {
401414
return makeZeroBasedCallFrame(callFrame);
402415
}

front_end/models/trace/types/TraceEvents.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,13 +2627,8 @@ export function isV8Compile(event: Event): event is V8Compile {
26272627
export interface FunctionCall extends Complete {
26282628
name: Name.FUNCTION_CALL;
26292629
args: Args&{
2630-
data?: {
2630+
data?: Partial<CallFrame>& {
26312631
frame?: string,
2632-
columnNumber?: number,
2633-
lineNumber?: number,
2634-
functionName?: string,
2635-
scriptId?: number,
2636-
url?: string,
26372632
},
26382633
};
26392634
}

front_end/panels/timeline/TimelineUIUtils.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,59 @@ describeWithMockConnection('TimelineUIUtils', function() {
270270
assert.exists(stackTraceData);
271271
assert.isTrue(stackTraceData[0].startsWith('someFunction @'));
272272
});
273+
it('maps to the authored name and script of a function call', async function() {
274+
const {script} = await loadBasicSourceMapExample(target);
275+
const [lineNumber, columnNumber, ts, dur, pid, tid] =
276+
[0, 51, 10, 100, Trace.Types.Events.ProcessID(1), Trace.Types.Events.ThreadID(1)];
277+
const profileCall = makeProfileCall('function', ts, dur, pid, tid);
278+
279+
profileCall.callFrame = {
280+
columnNumber,
281+
functionName: 'minified',
282+
lineNumber: 0,
283+
scriptId: script.scriptId,
284+
url: 'file://gen.js',
285+
};
286+
287+
const functionCall = makeCompleteEvent(Trace.Types.Events.Name.FUNCTION_CALL, ts, dur, '', pid, tid) as
288+
Trace.Types.Events.FunctionCall;
289+
functionCall.args = {
290+
data: {
291+
// line and column number of function calls have an offset
292+
// from CPU profile values.
293+
columnNumber: columnNumber + 1,
294+
lineNumber: lineNumber + 1,
295+
functionName: 'minified',
296+
scriptId: script.scriptId,
297+
url: 'file://gen.js',
298+
},
299+
};
300+
const workersData: Trace.Handlers.ModelHandlers.Workers.WorkersData = {
301+
workerSessionIdEvents: [],
302+
workerIdByThread: new Map(),
303+
workerURLById: new Map(),
304+
};
305+
// This only includes data used in the SourceMapsResolver and
306+
// TimelineUIUtils
307+
const parsedTrace = getBaseTraceParseModelData({
308+
Samples: makeMockSamplesHandlerData([profileCall]),
309+
Workers: workersData,
310+
Renderer: makeMockRendererHandlerData([functionCall]),
311+
});
312+
313+
const resolver = new Timeline.Utils.SourceMapsResolver.SourceMapsResolver(parsedTrace);
314+
await resolver.install();
315+
316+
const details = await Timeline.TimelineUIUtils.TimelineUIUtils.buildTraceEventDetails(
317+
parsedTrace,
318+
functionCall,
319+
new Components.Linkifier.Linkifier(),
320+
false,
321+
);
322+
const detailsData = getRowDataForDetailsElement(details).at(0);
323+
assert.exists(detailsData);
324+
assert.deepEqual(detailsData, {title: 'Function', value: 'someFunction @ gen.js:1:52'});
325+
});
273326
});
274327
describe('adjusting timestamps for events and navigations', function() {
275328
it('adjusts the time for a DCL event after a navigation', async function() {

front_end/panels/timeline/TimelineUIUtils.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -576,17 +576,19 @@ type LinkifyLocationOptions = {
576576

577577
export class TimelineUIUtils {
578578
static frameDisplayName(frame: Protocol.Runtime.CallFrame): string {
579+
const maybeResolvedData = Utils.SourceMapsResolver.SourceMapsResolver.resolvedCodeLocationForCallFrame(frame);
580+
const functionName = maybeResolvedData?.name || frame.functionName;
579581
if (!Trace.Extras.TimelineJSProfile.TimelineJSProfileProcessor.isNativeRuntimeFrame(frame)) {
580-
return UI.UIUtils.beautifyFunctionName(frame.functionName);
582+
return UI.UIUtils.beautifyFunctionName(functionName);
581583
}
582-
const nativeGroup = Trace.Extras.TimelineJSProfile.TimelineJSProfileProcessor.nativeGroup(frame.functionName);
584+
const nativeGroup = Trace.Extras.TimelineJSProfile.TimelineJSProfileProcessor.nativeGroup(functionName);
583585
switch (nativeGroup) {
584586
case Trace.Extras.TimelineJSProfile.TimelineJSProfileProcessor.NativeGroups.COMPILE:
585587
return i18nString(UIStrings.compile);
586588
case Trace.Extras.TimelineJSProfile.TimelineJSProfileProcessor.NativeGroups.PARSE:
587589
return i18nString(UIStrings.parse);
588590
}
589-
return frame.functionName;
591+
return functionName;
590592
}
591593

592594
static testContentMatching(
@@ -903,19 +905,18 @@ export class TimelineUIUtils {
903905
details = document.createElement('span');
904906

905907
// FunctionCall events have an args.data that could be a CallFrame, if all the details are present, so we check for that.
906-
if (Trace.Types.Events.isFunctionCall(event) && event.args.data &&
907-
Trace.Types.Events.objectIsCallFrame(event.args.data)) {
908+
const callFrame = Trace.Helpers.Trace.getZeroIndexedStackTraceForEvent(event)?.at(0);
909+
if (Trace.Types.Events.isFunctionCall(event) && callFrame) {
908910
UI.UIUtils.createTextChild(
909911
details,
910912
TimelineUIUtils.frameDisplayName(
911-
{...event.args.data, scriptId: String(event.args.data.scriptId) as Protocol.Runtime.ScriptId}));
913+
{...callFrame, scriptId: String(callFrame.scriptId) as Protocol.Runtime.ScriptId}));
912914
}
913-
const {lineNumber, columnNumber} = Trace.Helpers.Trace.getZeroIndexedLineAndColumnForEvent(event);
914915
const location = this.linkifyLocation({
915916
scriptId: unsafeEventData['scriptId'],
916917
url: unsafeEventData['url'],
917-
lineNumber: lineNumber || 0,
918-
columnNumber,
918+
lineNumber: callFrame?.lineNumber || 0,
919+
columnNumber: callFrame?.columnNumber,
919920
target,
920921
isFreshRecording,
921922
linkifier,

0 commit comments

Comments
 (0)