Skip to content

Commit b95c59a

Browse files
paulirishDevtools-frontend LUCI CQ
authored andcommitted
RPP: move EntryName & EntryStyles into models/trace
And also rename the module to `Name` and `Styles`. I don't think in the purist sense these belong in models/trace but we need them in a place where the AI model can depend on them without importing UI; and this enables that. It also starts to break down the timeline/utils which has become a bit of a dumping ground. Bypass-Check-License: not new files, just moved existing files Bug: 443001453 Change-Id: I9405287b446196c45a7c9c33e4f0f8e36bee2efc Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6943294 Reviewed-by: Connor Clark <cjamcl@chromium.org> Commit-Queue: Paul Irish <paulirish@chromium.org> Auto-Submit: Jack Franklin <jacktfranklin@chromium.org> Reviewed-by: Paul Irish <paulirish@chromium.org>
1 parent 94e8beb commit b95c59a

31 files changed

+275
-294
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,9 @@ grd_files_unbundled_sources = [
11681168
"front_end/models/trace/EventsSerializer.js",
11691169
"front_end/models/trace/LanternComputationData.js",
11701170
"front_end/models/trace/ModelImpl.js",
1171+
"front_end/models/trace/Name.js",
11711172
"front_end/models/trace/Processor.js",
1173+
"front_end/models/trace/Styles.js",
11721174
"front_end/models/trace/extras/FilmStrip.js",
11731175
"front_end/models/trace/extras/MainThreadActivity.js",
11741176
"front_end/models/trace/extras/ScriptDuplication.js",
@@ -2064,9 +2066,7 @@ grd_files_unbundled_sources = [
20642066
"front_end/panels/timeline/timelineTreeView.css.js",
20652067
"front_end/panels/timeline/utils/AICallTree.js",
20662068
"front_end/panels/timeline/utils/AIContext.js",
2067-
"front_end/panels/timeline/utils/EntryName.js",
20682069
"front_end/panels/timeline/utils/EntryNodes.js",
2069-
"front_end/panels/timeline/utils/EntryStyles.js",
20702070
"front_end/panels/timeline/utils/FreshRecording.js",
20712071
"front_end/panels/timeline/utils/Helpers.js",
20722072
"front_end/panels/timeline/utils/IgnoreList.js",

front_end/models/ai_assistance/agents/PerformanceAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export class PerformanceTraceContext extends ConversationContext<TimelineUtils.A
297297
if (!event) {
298298
return 'unknown';
299299
}
300-
return TimelineUtils.EntryName.nameForEntry(event);
300+
return Trace.Name.forEntry(event);
301301
}
302302

303303
Platform.assertNever(focus, 'Unknown agent focus');

front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class PerformanceTraceFormatter {
154154
frame = Trace.Helpers.Trace.getStackTraceTopCallFrameInEventPayload(event);
155155
}
156156

157-
let source = TimelineUtils.EntryName.nameForEntry(event);
157+
let source = Trace.Name.forEntry(event);
158158
if (frame?.url) {
159159
source += ` (url: ${frame.url}`;
160160
if (frame.lineNumber !== -1) {
@@ -282,9 +282,8 @@ export class PerformanceTraceFormatter {
282282
// Limit to 5, because some insights (namely ThirdParties) can have a huge
283283
// number of related events. Mostly, insights probably don't have more than
284284
// 5.
285-
const eventsString = events.slice(0, 5)
286-
.map(e => TimelineUtils.EntryName.nameForEntry(e) + ' ' + this.serializeEvent(e))
287-
.join(', ');
285+
const eventsString =
286+
events.slice(0, 5).map(e => Trace.Name.forEntry(e) + ' ' + this.serializeEvent(e)).join(', ');
288287
results.push(`- ${insightKey}: ${eventsString}`);
289288
}
290289
return results.join('\n');

front_end/models/trace/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ devtools_module("trace") {
1313
"EventsSerializer.ts",
1414
"LanternComputationData.ts",
1515
"ModelImpl.ts",
16+
"Name.ts",
1617
"Processor.ts",
18+
"Styles.ts",
1719
]
1820

1921
deps = [
@@ -75,6 +77,7 @@ ts_library("unittests") {
7577
"EntityMapper.test.ts",
7678
"EventsSerializer.test.ts",
7779
"ModelImpl.test.ts",
80+
"Name.test.ts",
7881
"Processor.test.ts",
7982
]
8083

front_end/panels/timeline/utils/EntryName.test.ts renamed to front_end/models/trace/Name.test.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,27 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import type * as CPUProfile from '../../../models/cpu_profile/cpu_profile.js';
6-
import * as Trace from '../../../models/trace/trace.js';
7-
import {describeWithEnvironment} from '../../../testing/EnvironmentHelpers.js';
8-
import {allThreadEntriesInTrace, getMainThread} from '../../../testing/TraceHelpers.js';
9-
import {TraceLoader} from '../../../testing/TraceLoader.js';
5+
import type * as CPUProfile from '../../models/cpu_profile/cpu_profile.js';
6+
import {describeWithEnvironment} from '../../testing/EnvironmentHelpers.js';
7+
import {allThreadEntriesInTrace, getMainThread} from '../../testing/TraceHelpers.js';
8+
import {TraceLoader} from '../../testing/TraceLoader.js';
109

11-
import * as Utils from './utils.js';
10+
import * as Trace from './trace.js';
1211

1312
describeWithEnvironment('EntryName', () => {
1413
it('uses the URL for the name of a network request', async function() {
1514
const parsedTrace = await TraceLoader.traceEngine(this, 'web-dev-with-commit.json.gz');
1615
const request = parsedTrace.data.NetworkRequests.byTime.at(0);
1716
assert.isOk(request);
18-
const name = Utils.EntryName.nameForEntry(request);
17+
const name = Trace.Name.forEntry(request);
1918
assert.strictEqual(name, 'web.dev/ (web.dev)');
2019
});
2120

2221
it('uses "Frame" for timeline frames', async function() {
2322
const parsedTrace = await TraceLoader.traceEngine(this, 'web-dev-with-commit.json.gz');
2423
const frame = parsedTrace.data.Frames.frames.at(0);
2524
assert.isOk(frame);
26-
const name = Utils.EntryName.nameForEntry(frame);
25+
const name = Trace.Name.forEntry(frame);
2726
assert.strictEqual(name, 'Frame');
2827
});
2928

@@ -33,22 +32,22 @@ describeWithEnvironment('EntryName', () => {
3332
return Trace.Types.Events.isDispatch(event) && event.args.data.type === 'click';
3433
});
3534
assert.isOk(clickEvent);
36-
const name = Utils.EntryName.nameForEntry(clickEvent);
35+
const name = Trace.Name.forEntry(clickEvent);
3736
assert.strictEqual(name, 'Event: click');
3837
});
3938

4039
it('correctly titles layout shifts', async function() {
4140
const parsedTrace = await TraceLoader.traceEngine(this, 'cls-single-frame.json.gz');
4241
const shifts = parsedTrace.data.LayoutShifts.clusters.flatMap(c => c.events);
43-
const title = Utils.EntryName.nameForEntry(shifts[0]);
42+
const title = Trace.Name.forEntry(shifts[0]);
4443
assert.strictEqual(title, 'Layout shift');
4544
});
4645

4746
it('correctly titles animation events', async function() {
4847
const parsedTrace = await TraceLoader.traceEngine(this, 'animation.json.gz');
4948
const animation = parsedTrace.data.Animations.animations.at(0);
5049
assert.isOk(animation);
51-
const title = Utils.EntryName.nameForEntry(animation);
50+
const title = Trace.Name.forEntry(animation);
5251
assert.strictEqual(title, 'Animation');
5352
});
5453

@@ -57,7 +56,7 @@ describeWithEnvironment('EntryName', () => {
5756
const entry = allThreadEntriesInTrace(parsedTrace).find(e => e.name === Trace.Types.Events.Name.RUN_TASK);
5857
assert.isOk(entry);
5958

60-
const name = Utils.EntryName.nameForEntry(entry, parsedTrace);
59+
const name = Trace.Name.forEntry(entry, parsedTrace);
6160
assert.strictEqual(name, 'Task');
6261
});
6362

@@ -74,7 +73,7 @@ describeWithEnvironment('EntryName', () => {
7473
}
7574
}
7675
assert.isOk(createEvent);
77-
const name = Utils.EntryName.nameForEntry(createEvent, parsedTrace);
76+
const name = Trace.Name.forEntry(createEvent, parsedTrace);
7877
assert.strictEqual(name, 'WebSocket opened: wss://echo.websocket.org/');
7978
});
8079

@@ -83,23 +82,23 @@ describeWithEnvironment('EntryName', () => {
8382
name: Trace.Types.Events.Name.WEB_SOCKET_DESTROY,
8483
} as unknown as Trace.Types.Events.WebSocketDestroy;
8584

86-
const name = Utils.EntryName.nameForEntry(fakeDestroyEvent);
85+
const name = Trace.Name.forEntry(fakeDestroyEvent);
8786
assert.strictEqual(name, 'WebSocket closed');
8887
});
8988

9089
it('returns a custom name for pointer interactions', async function() {
9190
const parsedTrace = await TraceLoader.traceEngine(this, 'slow-interaction-button-click.json.gz');
9291
const firstInteraction = parsedTrace.data.UserInteractions.interactionEvents.at(0);
9392
assert.isOk(firstInteraction);
94-
const name = Utils.EntryName.nameForEntry(firstInteraction);
93+
const name = Trace.Name.forEntry(firstInteraction);
9594
assert.strictEqual(name, 'Pointer');
9695
});
9796

9897
it('returns a custom name for keyboard interactions', async function() {
9998
const parsedTrace = await TraceLoader.traceEngine(this, 'slow-interaction-keydown.json.gz');
10099
const keydownInteraction = parsedTrace.data.UserInteractions.interactionEvents.find(e => e.type === 'keydown');
101100
assert.isOk(keydownInteraction);
102-
const name = Utils.EntryName.nameForEntry(keydownInteraction);
101+
const name = Trace.Name.forEntry(keydownInteraction);
103102
assert.strictEqual(name, 'Keyboard');
104103
});
105104

@@ -110,7 +109,7 @@ describeWithEnvironment('EntryName', () => {
110109
const firstInteraction = {...parsedTrace.data.UserInteractions.interactionEvents[0]};
111110
firstInteraction.type = 'unknown';
112111

113-
const name = Utils.EntryName.nameForEntry(firstInteraction);
112+
const name = Trace.Name.forEntry(firstInteraction);
114113
assert.strictEqual(name, 'Other');
115114
});
116115

@@ -123,7 +122,7 @@ describeWithEnvironment('EntryName', () => {
123122
// reset this to avoid impacting other tests.
124123
const originalProfileNodeName = profileNode.functionName;
125124
profileNode.setFunctionName('testing-profile-name');
126-
const name = Utils.EntryName.nameForEntry(entry, parsedTrace);
125+
const name = Trace.Name.forEntry(entry, parsedTrace);
127126
assert.strictEqual(name, 'testing-profile-name');
128127
profileNode.setFunctionName(originalProfileNodeName);
129128
});
@@ -136,7 +135,7 @@ describeWithEnvironment('EntryName', () => {
136135
// reset this to avoid impacting other tests.
137136
const originalProfileNodeName = profileNode.functionName;
138137
profileNode.setFunctionName('');
139-
const name = Utils.EntryName.nameForEntry(entry, parsedTrace);
138+
const name = Trace.Name.forEntry(entry, parsedTrace);
140139
assert.strictEqual(name, 'performConcurrentWorkOnRoot');
141140
profileNode.setFunctionName(originalProfileNodeName);
142141
});

front_end/panels/timeline/utils/EntryName.ts renamed to front_end/models/trace/Name.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import * as Common from '../../../core/common/common.js';
6-
import * as i18n from '../../../core/i18n/i18n.js';
7-
import * as Trace from '../../../models/trace/trace.js';
5+
import * as Common from '../../core/common/common.js';
6+
import * as i18n from '../../core/i18n/i18n.js';
87

9-
import {getEventStyle} from './EntryStyles.js';
8+
import * as Handlers from './handlers/handlers.js';
9+
import type {ParsedTrace} from './ModelImpl.js';
10+
import {getEventStyle} from './Styles.js';
11+
import * as Types from './types/types.js';
1012

1113
const UIStrings = {
1214
/**
@@ -41,7 +43,7 @@ const UIStrings = {
4143
layoutShift: 'Layout shift',
4244
} as const;
4345

44-
const str_ = i18n.i18n.registerUIStrings('panels/timeline/utils/EntryName.ts', UIStrings);
46+
const str_ = i18n.i18n.registerUIStrings('models/trace/Name.ts', UIStrings);
4547
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
4648

4749
/**
@@ -53,14 +55,14 @@ const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
5355
* custom name is found, we will fallback to the `name` property in the trace
5456
* entry.
5557
*/
56-
export function nameForEntry(
57-
entry: Trace.Types.Events.Event,
58-
parsedTrace?: Trace.TraceModel.ParsedTrace,
58+
export function forEntry(
59+
entry: Types.Events.Event,
60+
parsedTrace?: ParsedTrace,
5961
): string {
60-
if (Trace.Types.Events.isProfileCall(entry)) {
62+
if (Types.Events.isProfileCall(entry)) {
6163
if (parsedTrace) {
6264
const potentialCallName =
63-
Trace.Handlers.ModelHandlers.Samples.getProfileCallFunctionName(parsedTrace.data.Samples, entry);
65+
Handlers.ModelHandlers.Samples.getProfileCallFunctionName(parsedTrace.data.Samples, entry);
6466
// We need this extra check because the call name could be the empty
6567
// string. If it is, we want to fallback.
6668
if (potentialCallName) {
@@ -70,54 +72,54 @@ export function nameForEntry(
7072
return entry.callFrame.functionName || i18nString(UIStrings.anonymous);
7173
}
7274

73-
if (Trace.Types.Events.isLegacyTimelineFrame(entry)) {
75+
if (Types.Events.isLegacyTimelineFrame(entry)) {
7476
return i18n.i18n.lockedString(UIStrings.frame);
7577
}
7678

77-
if (Trace.Types.Events.isDispatch(entry)) {
79+
if (Types.Events.isDispatch(entry)) {
7880
// EventDispatch represent user actions such as clicks, so in this case
7981
// rather than show the event title (which is always just "Event"), we
8082
// add the type ("click") to help the user understand the event.
8183
return i18nString(UIStrings.eventDispatchS, {PH1: entry.args.data.type});
8284
}
83-
if (Trace.Types.Events.isSyntheticNetworkRequest(entry)) {
85+
if (Types.Events.isSyntheticNetworkRequest(entry)) {
8486
const parsedURL = new Common.ParsedURL.ParsedURL(entry.args.data.url);
8587
const text =
8688
parsedURL.isValid ? `${parsedURL.displayName} (${parsedURL.host})` : entry.args.data.url || 'Network request';
8789
return text;
8890
}
8991

90-
if (Trace.Types.Events.isWebSocketCreate(entry)) {
92+
if (Types.Events.isWebSocketCreate(entry)) {
9193
if (entry.args.data.url) {
9294
return i18nString(UIStrings.wsConnectionOpenedWithUrl, {PH1: entry.args.data.url});
9395
}
9496

9597
return i18nString(UIStrings.wsConnectionOpened);
9698
}
9799

98-
if (Trace.Types.Events.isWebSocketDestroy(entry)) {
100+
if (Types.Events.isWebSocketDestroy(entry)) {
99101
return i18nString(UIStrings.wsConnectionClosed);
100102
}
101103

102-
if (Trace.Types.Events.isSyntheticInteraction(entry)) {
104+
if (Types.Events.isSyntheticInteraction(entry)) {
103105
return nameForInteractionEvent(entry);
104106
}
105107

106-
if (Trace.Types.Events.isSyntheticLayoutShift(entry)) {
108+
if (Types.Events.isSyntheticLayoutShift(entry)) {
107109
return i18nString(UIStrings.layoutShift);
108110
}
109111

110-
if (Trace.Types.Events.isSyntheticAnimation(entry) && entry.args.data.beginEvent.args.data.displayName) {
112+
if (Types.Events.isSyntheticAnimation(entry) && entry.args.data.beginEvent.args.data.displayName) {
111113
return entry.args.data.beginEvent.args.data.displayName;
112114
}
113115

114-
const eventStyleCustomName = getEventStyle(entry.name as Trace.Types.Events.Name)?.title;
116+
const eventStyleCustomName = getEventStyle(entry.name as Types.Events.Name)?.title;
115117

116118
return eventStyleCustomName || entry.name;
117119
}
118120

119-
function nameForInteractionEvent(event: Trace.Types.Events.SyntheticInteractionPair): string {
120-
const category = Trace.Handlers.ModelHandlers.UserInteractions.categoryOfInteraction(event);
121+
function nameForInteractionEvent(event: Types.Events.SyntheticInteractionPair): string {
122+
const category = Handlers.ModelHandlers.UserInteractions.categoryOfInteraction(event);
121123
// Because we hide nested interactions, we do not want to show the
122124
// specific type of the interaction that was not hidden, so instead we
123125
// show just the category of that interaction.

0 commit comments

Comments
 (0)