Skip to content

Commit 29348c7

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Include url-level breakdown in ThirdParties insight model
This is needed for sub-items in Lighthouse. Bug: 388723721 Change-Id: I1674ce4de3684a6776eb5d4778d89dd66c13b1fc Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6245118 Commit-Queue: Connor Clark <[email protected]> Commit-Queue: Adam Raine <[email protected]> Reviewed-by: Adam Raine <[email protected]> Auto-Submit: Connor Clark <[email protected]>
1 parent dc49e2d commit 29348c7

File tree

4 files changed

+90
-11
lines changed

4 files changed

+90
-11
lines changed

front_end/models/trace/extras/ThirdParties.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,39 @@ describeWithEnvironment('ThirdParties', function() {
2121
['localhost', {mainThreadTime: 26381, transferSize: 751}],
2222
['Google Fonts', {mainThreadTime: 0, transferSize: 0}],
2323
]);
24+
25+
assert.deepEqual([...thirdPartySummary.byUrl.entries()], [
26+
['extensions::SafeBuiltins', {mainThreadTime: 1448, transferSize: 0}],
27+
['http://localhost:8080/', {mainThreadTime: 21674, transferSize: 751}],
28+
['http://localhost:8080/blocking.js', {mainThreadTime: 2451, transferSize: 0}],
29+
['http://localhost:8080/module.js', {mainThreadTime: 2256, transferSize: 0}],
30+
['https://fonts.googleapis.com/css2?family=Orelega+One&display=swap', {mainThreadTime: 0, transferSize: 0}],
31+
['http://localhost:8080/styles.css', {mainThreadTime: 0, transferSize: 0}],
32+
[
33+
'https://fonts.gstatic.com/s/orelegaone/v1/3qTpojOggD2XtAdFb-QXZFt93kY.woff2',
34+
{mainThreadTime: 0, transferSize: 0}
35+
],
36+
]);
37+
38+
const urls = [...thirdPartySummary.urlsByEntity.entries()].map(([entity, urls]) => [entity.name, [...urls]]);
39+
assert.deepEqual(urls, [
40+
[
41+
'localhost',
42+
[
43+
'http://localhost:8080/',
44+
'http://localhost:8080/blocking.js',
45+
'http://localhost:8080/module.js',
46+
'http://localhost:8080/styles.css',
47+
]
48+
],
49+
[
50+
'Google Fonts',
51+
[
52+
'https://fonts.googleapis.com/css2?family=Orelega+One&display=swap',
53+
'https://fonts.gstatic.com/s/orelegaone/v1/3qTpojOggD2XtAdFb-QXZFt93kY.woff2',
54+
]
55+
],
56+
]);
2457
});
2558

2659
it('works even without network requests', async function() {
@@ -34,6 +67,25 @@ describeWithEnvironment('ThirdParties', function() {
3467
// Since network requests were not given, there is no transfer size.
3568
['localhost', {mainThreadTime: 26381, transferSize: 0}],
3669
]);
70+
71+
assert.deepEqual([...thirdPartySummary.byUrl.entries()], [
72+
['extensions::SafeBuiltins', {mainThreadTime: 1448, transferSize: 0}],
73+
['http://localhost:8080/', {mainThreadTime: 21674, transferSize: 0}],
74+
['http://localhost:8080/blocking.js', {mainThreadTime: 2451, transferSize: 0}],
75+
['http://localhost:8080/module.js', {mainThreadTime: 2256, transferSize: 0}],
76+
]);
77+
78+
const urls = [...thirdPartySummary.urlsByEntity.entries()].map(([entity, urls]) => [entity.name, [...urls]]);
79+
assert.deepEqual(urls, [
80+
[
81+
'localhost',
82+
[
83+
'http://localhost:8080/',
84+
'http://localhost:8080/blocking.js',
85+
'http://localhost:8080/module.js',
86+
]
87+
],
88+
]);
3789
});
3890

3991
it('partial trace bounds', async function() {

front_end/models/trace/extras/ThirdParties.ts

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,46 @@ export interface Summary {
1616

1717
export interface ThirdPartySummary {
1818
byEntity: Map<Entity, Summary>;
19-
byEvent: Map<Types.Events.Event, Summary>;
19+
byUrl: Map<string, Summary>;
20+
urlsByEntity: Map<Entity, Set<string>>;
2021
eventsByEntity: Map<Entity, Types.Events.Event[]>;
2122
madeUpEntityCache: Map<string, Entity>;
2223
}
2324

24-
function getOrMakeSummary(thirdPartySummary: ThirdPartySummary, event: Types.Events.Event, url: string): Summary|null {
25+
function getOrMakeSummaryByEntity(
26+
thirdPartySummary: ThirdPartySummary, event: Types.Events.Event, url: string): Summary|null {
2527
const entity = ThirdPartyWeb.ThirdPartyWeb.getEntity(url) ??
2628
Handlers.Helpers.makeUpEntity(thirdPartySummary.madeUpEntityCache, url);
2729
if (!entity) {
2830
return null;
2931
}
3032

33+
const urls = thirdPartySummary.urlsByEntity.get(entity) ?? new Set();
34+
urls.add(url);
35+
thirdPartySummary.urlsByEntity.set(entity, urls);
36+
3137
const events = thirdPartySummary.eventsByEntity.get(entity) ?? [];
3238
events.push(event);
3339
thirdPartySummary.eventsByEntity.set(entity, events);
3440

3541
let summary = thirdPartySummary.byEntity.get(entity);
3642
if (summary) {
37-
thirdPartySummary.byEvent.set(event, summary);
3843
return summary;
3944
}
4045

4146
summary = {transferSize: 0, mainThreadTime: Types.Timing.Micro(0)};
4247
thirdPartySummary.byEntity.set(entity, summary);
43-
thirdPartySummary.byEvent.set(event, summary);
48+
return summary;
49+
}
50+
51+
function getOrMakeSummaryByURL(thirdPartySummary: ThirdPartySummary, url: string): Summary|null {
52+
let summary = thirdPartySummary.byUrl.get(url);
53+
if (summary) {
54+
return summary;
55+
}
56+
57+
summary = {transferSize: 0, mainThreadTime: Types.Timing.Micro(0)};
58+
thirdPartySummary.byUrl.set(url, summary);
4459
return summary;
4560
}
4661

@@ -73,7 +88,12 @@ function collectMainThreadActivity(
7388
continue;
7489
}
7590

76-
const summary = getOrMakeSummary(thirdPartySummary, event, url);
91+
let summary = getOrMakeSummaryByEntity(thirdPartySummary, event, url);
92+
if (summary) {
93+
summary.mainThreadTime = (summary.mainThreadTime + node.selfTime) as Types.Timing.Micro;
94+
}
95+
96+
summary = getOrMakeSummaryByURL(thirdPartySummary, url);
7797
if (summary) {
7898
summary.mainThreadTime = (summary.mainThreadTime + node.selfTime) as Types.Timing.Micro;
7999
}
@@ -87,7 +107,13 @@ function collectNetworkActivity(
87107
thirdPartySummary: ThirdPartySummary, requests: Types.Events.SyntheticNetworkRequest[]): void {
88108
for (const request of requests) {
89109
const url = request.args.data.url;
90-
const summary = getOrMakeSummary(thirdPartySummary, request, url);
110+
111+
let summary = getOrMakeSummaryByEntity(thirdPartySummary, request, url);
112+
if (summary) {
113+
summary.transferSize += request.args.data.encodedDataLength;
114+
}
115+
116+
summary = getOrMakeSummaryByURL(thirdPartySummary, url);
91117
if (summary) {
92118
summary.transferSize += request.args.data.encodedDataLength;
93119
}
@@ -102,7 +128,8 @@ export function summarizeThirdParties(
102128
networkRequests: Types.Events.SyntheticNetworkRequest[]): ThirdPartySummary {
103129
const thirdPartySummary: ThirdPartySummary = {
104130
byEntity: new Map(),
105-
byEvent: new Map(),
131+
byUrl: new Map(),
132+
urlsByEntity: new Map(),
106133
eventsByEntity: new Map(),
107134
madeUpEntityCache: new Map(),
108135
};
@@ -141,7 +168,7 @@ function getSummaryMapWithMapping(
141168
byEntity.set(entity, entitySummary);
142169
}
143170

144-
return {byEntity, byEvent, eventsByEntity, madeUpEntityCache: new Map()};
171+
return {byEntity, eventsByEntity, madeUpEntityCache: new Map(), byUrl: new Map(), urlsByEntity: new Map()};
145172
}
146173

147174
// TODO(crbug.com/352244718): Remove or refactor to use summarizeThirdParties/collectMainThreadActivity/etc.

front_end/models/trace/insights/ThirdParties.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export const UIStrings = {
3030
columnThirdParty: 'Third party',
3131
/** Label for a column in a data table; entries will be the download size of a web resource in kilobytes. */
3232
columnTransferSize: 'Transfer size',
33-
/** Label for a table column that displays how much time each row spent blocking other work on the main thread, entries will be the number of milliseconds spent. */
34-
columnBlockingTime: 'Blocking time',
33+
/** Label for a table column that displays how much time each row spent running on the main thread, entries will be the number of milliseconds spent. */
34+
columnMainThreadTimeTime: 'Main thread time',
3535
/**
3636
* @description Text block indicating that no third party content was detected on the page
3737
*/

front_end/panels/timeline/components/insights/ThirdParties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class ThirdParties extends BaseInsightComponent<ThirdPartiesInsightModel>
9696
<devtools-performance-table
9797
.data=${{
9898
insight: this,
99-
headers: [i18nString(UIStrings.columnThirdParty), i18nString(UIStrings.columnBlockingTime)],
99+
headers: [i18nString(UIStrings.columnThirdParty), i18nString(UIStrings.columnMainThreadTimeTime)],
100100
rows: topMainThreadTimeEntries.map(([entity, summary]) => ({
101101
values: [
102102
entity.name,

0 commit comments

Comments
 (0)