@paulirish/trace_engine 0.0.24 → 0.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/core/platform/TypedArrayUtilities.d.ts +7 -0
  2. package/core/platform/TypedArrayUtilities.js +41 -0
  3. package/core/platform/TypedArrayUtilities.js.map +1 -1
  4. package/core/platform/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  5. package/core/platform/platform-tsconfig.json +0 -1
  6. package/generated/protocol.d.ts +73 -18
  7. package/models/cpu_profile/cpu_profile-tsconfig.json +0 -1
  8. package/models/cpu_profile/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  9. package/models/trace/LanternComputationData.d.ts +8 -0
  10. package/models/trace/LanternComputationData.js +368 -0
  11. package/models/trace/LanternComputationData.js.map +1 -0
  12. package/models/trace/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  13. package/models/trace/extras/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  14. package/models/trace/extras/extras-tsconfig.json +0 -1
  15. package/models/trace/handlers/AuctionWorkletsHandler.js +1 -1
  16. package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -1
  17. package/models/trace/handlers/EnhancedTracesHandler.d.ts +46 -0
  18. package/models/trace/handlers/EnhancedTracesHandler.js +137 -0
  19. package/models/trace/handlers/EnhancedTracesHandler.js.map +1 -0
  20. package/models/trace/handlers/LayoutShiftsHandler.d.ts +1 -1
  21. package/models/trace/handlers/LayoutShiftsHandler.js +3 -3
  22. package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
  23. package/models/trace/handlers/MetaHandler.js +39 -13
  24. package/models/trace/handlers/MetaHandler.js.map +1 -1
  25. package/models/trace/handlers/ModelHandlers.d.ts +1 -0
  26. package/models/trace/handlers/ModelHandlers.js +1 -0
  27. package/models/trace/handlers/ModelHandlers.js.map +1 -1
  28. package/models/trace/handlers/NetworkRequestsHandler.js +2 -2
  29. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
  30. package/models/trace/handlers/PageLoadMetricsHandler.d.ts +1 -2
  31. package/models/trace/handlers/PageLoadMetricsHandler.js +2 -35
  32. package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -1
  33. package/models/trace/handlers/ScreenshotsHandler.js +1 -2
  34. package/models/trace/handlers/ScreenshotsHandler.js.map +1 -1
  35. package/models/trace/handlers/UserInteractionsHandler.d.ts +6 -0
  36. package/models/trace/handlers/UserInteractionsHandler.js +17 -2
  37. package/models/trace/handlers/UserInteractionsHandler.js.map +1 -1
  38. package/models/trace/handlers/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  39. package/models/trace/handlers/handlers-tsconfig.json +1 -1
  40. package/models/trace/helpers/SyntheticEvents.d.ts +1 -0
  41. package/models/trace/helpers/SyntheticEvents.js +12 -0
  42. package/models/trace/helpers/SyntheticEvents.js.map +1 -1
  43. package/models/trace/helpers/Timing.d.ts +17 -6
  44. package/models/trace/helpers/Timing.js +17 -76
  45. package/models/trace/helpers/Timing.js.map +1 -1
  46. package/models/trace/helpers/Trace.js +1 -2
  47. package/models/trace/helpers/Trace.js.map +1 -1
  48. package/models/trace/helpers/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  49. package/models/trace/helpers/helpers-tsconfig.json +0 -1
  50. package/models/trace/insights/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  51. package/models/trace/insights/insights-tsconfig.json +0 -1
  52. package/models/trace/lantern/BaseNode.d.ts +91 -0
  53. package/models/trace/lantern/BaseNode.js +268 -0
  54. package/models/trace/lantern/BaseNode.js.map +1 -0
  55. package/models/trace/lantern/CPUNode.d.ts +24 -0
  56. package/models/trace/lantern/CPUNode.js +64 -0
  57. package/models/trace/lantern/CPUNode.js.map +1 -0
  58. package/models/trace/lantern/LanternError.d.ts +3 -0
  59. package/models/trace/lantern/LanternError.js +7 -0
  60. package/models/trace/lantern/LanternError.js.map +1 -0
  61. package/models/trace/lantern/MetricsModule.d.ts +11 -0
  62. package/models/trace/lantern/MetricsModule.js +14 -0
  63. package/models/trace/lantern/MetricsModule.js.map +1 -0
  64. package/models/trace/lantern/NetworkNode.d.ts +22 -0
  65. package/models/trace/lantern/NetworkNode.js +83 -0
  66. package/models/trace/lantern/NetworkNode.js.map +1 -0
  67. package/models/trace/lantern/PageDependencyGraph.d.ts +43 -0
  68. package/models/trace/lantern/PageDependencyGraph.js +509 -0
  69. package/models/trace/lantern/PageDependencyGraph.js.map +1 -0
  70. package/models/trace/lantern/SimulationModule.d.ts +17 -0
  71. package/models/trace/lantern/SimulationModule.js +13 -0
  72. package/models/trace/lantern/SimulationModule.js.map +1 -0
  73. package/models/trace/lantern/bundle-tsconfig.json +1 -0
  74. package/models/trace/lantern/devtools_entrypoint-bundle-typescript-tsconfig.json +42 -0
  75. package/models/trace/lantern/lantern-tsconfig.json +64 -0
  76. package/models/trace/lantern/lantern.d.ts +29 -0
  77. package/models/trace/lantern/lantern.js +33 -0
  78. package/models/trace/lantern/lantern.js.map +1 -0
  79. package/models/trace/lantern/metrics/FirstContentfulPaint.d.ts +42 -0
  80. package/models/trace/lantern/metrics/FirstContentfulPaint.js +137 -0
  81. package/models/trace/lantern/metrics/FirstContentfulPaint.js.map +1 -0
  82. package/models/trace/lantern/metrics/Interactive.d.ts +12 -0
  83. package/models/trace/lantern/metrics/Interactive.js +68 -0
  84. package/models/trace/lantern/metrics/Interactive.js.map +1 -0
  85. package/models/trace/lantern/metrics/LargestContentfulPaint.d.ts +16 -0
  86. package/models/trace/lantern/metrics/LargestContentfulPaint.js +70 -0
  87. package/models/trace/lantern/metrics/LargestContentfulPaint.js.map +1 -0
  88. package/models/trace/lantern/metrics/MaxPotentialFID.d.ts +14 -0
  89. package/models/trace/lantern/metrics/MaxPotentialFID.js +49 -0
  90. package/models/trace/lantern/metrics/MaxPotentialFID.js.map +1 -0
  91. package/models/trace/lantern/metrics/Metric.d.ts +26 -0
  92. package/models/trace/lantern/metrics/Metric.js +71 -0
  93. package/models/trace/lantern/metrics/Metric.js.map +1 -0
  94. package/models/trace/lantern/metrics/SpeedIndex.d.ts +25 -0
  95. package/models/trace/lantern/metrics/SpeedIndex.js +102 -0
  96. package/models/trace/lantern/metrics/SpeedIndex.js.map +1 -0
  97. package/models/trace/lantern/metrics/TBTUtils.d.ts +31 -0
  98. package/models/trace/lantern/metrics/TBTUtils.js +65 -0
  99. package/models/trace/lantern/metrics/TBTUtils.js.map +1 -0
  100. package/models/trace/lantern/metrics/TotalBlockingTime.d.ts +16 -0
  101. package/models/trace/lantern/metrics/TotalBlockingTime.js +79 -0
  102. package/models/trace/lantern/metrics/TotalBlockingTime.js.map +1 -0
  103. package/models/trace/lantern/metrics/metrics.d.ts +15 -0
  104. package/models/trace/lantern/metrics/metrics.js +12 -0
  105. package/models/trace/lantern/metrics/metrics.js.map +1 -0
  106. package/models/trace/lantern/simulation/ConnectionPool.d.ts +26 -0
  107. package/models/trace/lantern/simulation/ConnectionPool.js +116 -0
  108. package/models/trace/lantern/simulation/ConnectionPool.js.map +1 -0
  109. package/models/trace/lantern/simulation/Constants.d.ts +31 -0
  110. package/models/trace/lantern/simulation/Constants.js +43 -0
  111. package/models/trace/lantern/simulation/Constants.js.map +1 -0
  112. package/models/trace/lantern/simulation/DNSCache.d.ts +22 -0
  113. package/models/trace/lantern/simulation/DNSCache.js +48 -0
  114. package/models/trace/lantern/simulation/DNSCache.js.map +1 -0
  115. package/models/trace/lantern/simulation/NetworkAnalyzer.d.ts +112 -0
  116. package/models/trace/lantern/simulation/NetworkAnalyzer.js +486 -0
  117. package/models/trace/lantern/simulation/NetworkAnalyzer.js.map +1 -0
  118. package/models/trace/lantern/simulation/SimulationTimingMap.d.ts +71 -0
  119. package/models/trace/lantern/simulation/SimulationTimingMap.js +134 -0
  120. package/models/trace/lantern/simulation/SimulationTimingMap.js.map +1 -0
  121. package/models/trace/lantern/simulation/Simulator.d.ts +82 -0
  122. package/models/trace/lantern/simulation/Simulator.js +449 -0
  123. package/models/trace/lantern/simulation/Simulator.js.map +1 -0
  124. package/models/trace/lantern/simulation/TCPConnection.d.ts +48 -0
  125. package/models/trace/lantern/simulation/TCPConnection.js +158 -0
  126. package/models/trace/lantern/simulation/TCPConnection.js.map +1 -0
  127. package/models/trace/lantern/simulation/simulation.d.ts +21 -0
  128. package/models/trace/lantern/simulation/simulation.js +11 -0
  129. package/models/trace/lantern/simulation/simulation.js.map +1 -0
  130. package/models/trace/lantern/types/lantern.d.ts +205 -0
  131. package/models/trace/lantern/types/lantern.js +5 -0
  132. package/models/trace/lantern/types/lantern.js.map +1 -0
  133. package/models/trace/root-causes/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  134. package/models/trace/root-causes/root-causes-tsconfig.json +0 -1
  135. package/models/trace/trace-tsconfig.json +4 -1
  136. package/models/trace/trace.d.ts +3 -1
  137. package/models/trace/trace.js +3 -1
  138. package/models/trace/trace.js.map +1 -1
  139. package/models/trace/types/Extensions.d.ts +2 -3
  140. package/models/trace/types/Extensions.js +2 -11
  141. package/models/trace/types/Extensions.js.map +1 -1
  142. package/models/trace/types/File.d.ts +28 -5
  143. package/models/trace/types/File.js +36 -1
  144. package/models/trace/types/File.js.map +1 -1
  145. package/models/trace/types/TraceEvents.d.ts +50 -0
  146. package/models/trace/types/TraceEvents.js +33 -0
  147. package/models/trace/types/TraceEvents.js.map +1 -1
  148. package/models/trace/types/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  149. package/models/trace/types/types-tsconfig.json +0 -1
  150. package/package.json +1 -1
@@ -0,0 +1,368 @@
1
+ // Copyright 2024 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ import * as Handlers from './handlers/handlers.js';
5
+ import * as Lantern from './lantern/lantern.js';
6
+ function createProcessedNavigation(traceEngineData) {
7
+ const Meta = traceEngineData.Meta;
8
+ const frameId = Meta.mainFrameId;
9
+ const scoresByNav = traceEngineData.PageLoadMetrics.metricScoresByFrameId.get(frameId);
10
+ if (!scoresByNav) {
11
+ throw new Error('missing metric scores for main frame');
12
+ }
13
+ const lastNavigationId = Meta.mainFrameNavigations.at(-1)?.args.data?.navigationId;
14
+ const scores = lastNavigationId && scoresByNav.get(lastNavigationId);
15
+ if (!scores) {
16
+ throw new Error('missing metric scores for specified navigation');
17
+ }
18
+ const getTimestampOrUndefined = (metric) => {
19
+ const metricScore = scores.get(metric);
20
+ if (!metricScore?.event) {
21
+ return;
22
+ }
23
+ return metricScore.event.ts;
24
+ };
25
+ const getTimestamp = (metric) => {
26
+ const metricScore = scores.get(metric);
27
+ if (!metricScore?.event) {
28
+ throw new Error(`missing metric: ${metric}`);
29
+ }
30
+ return metricScore.event.ts;
31
+ };
32
+ return {
33
+ timestamps: {
34
+ firstContentfulPaint: getTimestamp("FCP" /* Handlers.ModelHandlers.PageLoadMetrics.MetricName.FCP */),
35
+ largestContentfulPaint: getTimestampOrUndefined("LCP" /* Handlers.ModelHandlers.PageLoadMetrics.MetricName.LCP */),
36
+ },
37
+ };
38
+ }
39
+ function createParsedUrl(url) {
40
+ if (typeof url === 'string') {
41
+ url = new URL(url);
42
+ }
43
+ return {
44
+ scheme: url.protocol.split(':')[0],
45
+ // Intentional, DevTools uses different terminology
46
+ host: url.hostname,
47
+ securityOrigin: url.origin,
48
+ };
49
+ }
50
+ /**
51
+ * Returns a map of `pid` -> `tid[]`.
52
+ */
53
+ function findWorkerThreads(trace) {
54
+ // TODO: WorkersHandler in TraceEngine needs to be updated to also include `pid` (only had `tid`).
55
+ const workerThreads = new Map();
56
+ const workerCreationEvents = ['ServiceWorker thread', 'DedicatedWorker thread'];
57
+ for (const event of trace.traceEvents) {
58
+ if (event.name !== 'thread_name' || !event.args.name) {
59
+ continue;
60
+ }
61
+ if (!workerCreationEvents.includes(event.args.name)) {
62
+ continue;
63
+ }
64
+ const tids = workerThreads.get(event.pid);
65
+ if (tids) {
66
+ tids.push(event.tid);
67
+ }
68
+ else {
69
+ workerThreads.set(event.pid, [event.tid]);
70
+ }
71
+ }
72
+ return workerThreads;
73
+ }
74
+ function createLanternRequest(traceEngineData, workerThreads, request) {
75
+ if (request.args.data.connectionId === undefined || request.args.data.connectionReused === undefined) {
76
+ throw new Error('Trace is too old');
77
+ }
78
+ let url;
79
+ try {
80
+ url = new URL(request.args.data.url);
81
+ }
82
+ catch (e) {
83
+ return;
84
+ }
85
+ const timing = request.args.data.timing ? {
86
+ // These two timings are not included in the trace.
87
+ workerFetchStart: -1,
88
+ workerRespondWithSettled: -1,
89
+ ...request.args.data.timing,
90
+ } :
91
+ undefined;
92
+ const networkRequestTime = timing ? timing.requestTime * 1000 : request.args.data.syntheticData.downloadStart / 1000;
93
+ let fromWorker = false;
94
+ const tids = workerThreads.get(request.pid);
95
+ if (tids?.includes(request.tid)) {
96
+ fromWorker = true;
97
+ }
98
+ // TraceEngine collects worker thread ids in a different manner than `workerThreads` does.
99
+ // AFAIK these should be equivalent, but in case they are not let's also check this for now.
100
+ if (traceEngineData.Workers.workerIdByThread.has(request.tid)) {
101
+ fromWorker = true;
102
+ }
103
+ // `initiator` in the trace does not contain the stack trace for JS-initiated
104
+ // requests. Instead, that is stored in the `stackTrace` property of the SyntheticNetworkRequest.
105
+ // There are some minor differences in the fields, accounted for here.
106
+ // Most importantly, there seems to be fewer frames in the trace than the equivalent
107
+ // events over the CDP. This results in less accuracy in determining the initiator request,
108
+ // which means less edges in the graph, which mean worse results.
109
+ // TODO: Should fix in Chromium.
110
+ const initiator = request.args.data.initiator ?? { type: "other" /* Protocol.Network.InitiatorType.Other */ };
111
+ if (request.args.data.stackTrace) {
112
+ const callFrames = request.args.data.stackTrace.map(f => {
113
+ return {
114
+ scriptId: String(f.scriptId),
115
+ url: f.url,
116
+ lineNumber: f.lineNumber - 1,
117
+ columnNumber: f.columnNumber - 1,
118
+ functionName: f.functionName,
119
+ };
120
+ });
121
+ initiator.stack = { callFrames };
122
+ // Note: there is no `parent` to set ...
123
+ }
124
+ let resourceType = request.args.data.resourceType;
125
+ if (request.args.data.initiator?.fetchType === 'xmlhttprequest') {
126
+ // @ts-expect-error yes XHR is a valid ResourceType. TypeScript const enums are so unhelpful.
127
+ resourceType = 'XHR';
128
+ }
129
+ else if (request.args.data.initiator?.fetchType === 'fetch') {
130
+ // @ts-expect-error yes Fetch is a valid ResourceType. TypeScript const enums are so unhelpful.
131
+ resourceType = 'Fetch';
132
+ }
133
+ // TODO: set decodedBodyLength for data urls in Trace Engine.
134
+ let resourceSize = request.args.data.decodedBodyLength ?? 0;
135
+ if (url.protocol === 'data:' && resourceSize === 0) {
136
+ const needle = 'base64,';
137
+ const index = url.pathname.indexOf(needle);
138
+ if (index !== -1) {
139
+ resourceSize = atob(url.pathname.substring(index + needle.length)).length;
140
+ }
141
+ }
142
+ return {
143
+ rawRequest: request,
144
+ requestId: request.args.data.requestId,
145
+ connectionId: request.args.data.connectionId,
146
+ connectionReused: request.args.data.connectionReused,
147
+ url: request.args.data.url,
148
+ protocol: request.args.data.protocol,
149
+ parsedURL: createParsedUrl(url),
150
+ documentURL: request.args.data.requestingFrameUrl,
151
+ rendererStartTime: request.ts / 1000,
152
+ networkRequestTime,
153
+ responseHeadersEndTime: request.args.data.syntheticData.downloadStart / 1000,
154
+ networkEndTime: request.args.data.syntheticData.finishTime / 1000,
155
+ transferSize: request.args.data.encodedDataLength,
156
+ resourceSize,
157
+ fromDiskCache: request.args.data.syntheticData.isDiskCached,
158
+ fromMemoryCache: request.args.data.syntheticData.isMemoryCached,
159
+ isLinkPreload: request.args.data.isLinkPreload,
160
+ finished: request.args.data.finished,
161
+ failed: request.args.data.failed,
162
+ statusCode: request.args.data.statusCode,
163
+ initiator,
164
+ timing,
165
+ resourceType,
166
+ mimeType: request.args.data.mimeType,
167
+ priority: request.args.data.priority,
168
+ frameId: request.args.data.frame,
169
+ fromWorker,
170
+ // Set later.
171
+ redirects: undefined,
172
+ redirectSource: undefined,
173
+ redirectDestination: undefined,
174
+ initiatorRequest: undefined,
175
+ };
176
+ }
177
+ /**
178
+ * @param request The request to find the initiator of
179
+ */
180
+ function chooseInitiatorRequest(request, requestsByURL) {
181
+ if (request.redirectSource) {
182
+ return request.redirectSource;
183
+ }
184
+ const initiatorURL = Lantern.PageDependencyGraph.getNetworkInitiators(request)[0];
185
+ let candidates = requestsByURL.get(initiatorURL) || [];
186
+ // The (valid) initiator must come before the initiated request.
187
+ candidates = candidates.filter(c => {
188
+ return c.responseHeadersEndTime <= request.rendererStartTime && c.finished && !c.failed;
189
+ });
190
+ if (candidates.length > 1) {
191
+ // Disambiguate based on prefetch. Prefetch requests have type 'Other' and cannot
192
+ // initiate requests, so we drop them here.
193
+ const nonPrefetchCandidates = candidates.filter(cand => cand.resourceType !== Lantern.NetworkRequestTypes.Other);
194
+ if (nonPrefetchCandidates.length) {
195
+ candidates = nonPrefetchCandidates;
196
+ }
197
+ }
198
+ if (candidates.length > 1) {
199
+ // Disambiguate based on frame. It's likely that the initiator comes from the same frame.
200
+ const sameFrameCandidates = candidates.filter(cand => cand.frameId === request.frameId);
201
+ if (sameFrameCandidates.length) {
202
+ candidates = sameFrameCandidates;
203
+ }
204
+ }
205
+ if (candidates.length > 1 && request.initiator.type === 'parser') {
206
+ // Filter to just Documents when initiator type is parser.
207
+ const documentCandidates = candidates.filter(cand => cand.resourceType === Lantern.NetworkRequestTypes.Document);
208
+ if (documentCandidates.length) {
209
+ candidates = documentCandidates;
210
+ }
211
+ }
212
+ if (candidates.length > 1) {
213
+ // If all real loads came from successful preloads (url preloaded and
214
+ // loads came from the cache), filter to link rel=preload request(s).
215
+ const linkPreloadCandidates = candidates.filter(c => c.isLinkPreload);
216
+ if (linkPreloadCandidates.length) {
217
+ const nonPreloadCandidates = candidates.filter(c => !c.isLinkPreload);
218
+ const allPreloaded = nonPreloadCandidates.every(c => c.fromDiskCache || c.fromMemoryCache);
219
+ if (nonPreloadCandidates.length && allPreloaded) {
220
+ candidates = linkPreloadCandidates;
221
+ }
222
+ }
223
+ }
224
+ // Only return an initiator if the result is unambiguous.
225
+ return candidates.length === 1 ? candidates[0] : null;
226
+ }
227
+ function linkInitiators(lanternRequests) {
228
+ const requestsByURL = new Map();
229
+ for (const request of lanternRequests) {
230
+ const requests = requestsByURL.get(request.url) || [];
231
+ requests.push(request);
232
+ requestsByURL.set(request.url, requests);
233
+ }
234
+ for (const request of lanternRequests) {
235
+ const initiatorRequest = chooseInitiatorRequest(request, requestsByURL);
236
+ if (initiatorRequest) {
237
+ request.initiatorRequest = initiatorRequest;
238
+ }
239
+ }
240
+ }
241
+ function createNetworkRequests(trace, traceEngineData) {
242
+ const workerThreads = findWorkerThreads(trace);
243
+ const lanternRequests = [];
244
+ for (const request of traceEngineData.NetworkRequests.byTime) {
245
+ const lanternRequest = createLanternRequest(traceEngineData, workerThreads, request);
246
+ if (lanternRequest) {
247
+ lanternRequests.push(lanternRequest);
248
+ }
249
+ }
250
+ // TraceEngine consolidates all redirects into a single request object, but lantern needs
251
+ // an entry for each redirected request.
252
+ for (const request of [...lanternRequests]) {
253
+ if (!request.rawRequest) {
254
+ continue;
255
+ }
256
+ const redirects = request.rawRequest.args.data.redirects;
257
+ if (!redirects.length) {
258
+ continue;
259
+ }
260
+ const requestChain = [];
261
+ for (const redirect of redirects) {
262
+ const redirectedRequest = structuredClone(request);
263
+ redirectedRequest.networkRequestTime = redirect.ts / 1000;
264
+ redirectedRequest.rendererStartTime = redirectedRequest.networkRequestTime;
265
+ redirectedRequest.networkEndTime = (redirect.ts + redirect.dur) / 1000;
266
+ redirectedRequest.responseHeadersEndTime = redirectedRequest.networkEndTime;
267
+ redirectedRequest.timing = {
268
+ requestTime: redirectedRequest.networkRequestTime / 1000,
269
+ receiveHeadersStart: redirectedRequest.responseHeadersEndTime,
270
+ receiveHeadersEnd: redirectedRequest.responseHeadersEndTime,
271
+ proxyStart: -1,
272
+ proxyEnd: -1,
273
+ dnsStart: -1,
274
+ dnsEnd: -1,
275
+ connectStart: -1,
276
+ connectEnd: -1,
277
+ sslStart: -1,
278
+ sslEnd: -1,
279
+ sendStart: -1,
280
+ sendEnd: -1,
281
+ workerStart: -1,
282
+ workerReady: -1,
283
+ workerFetchStart: -1,
284
+ workerRespondWithSettled: -1,
285
+ pushStart: -1,
286
+ pushEnd: -1,
287
+ };
288
+ redirectedRequest.url = redirect.url;
289
+ redirectedRequest.parsedURL = createParsedUrl(redirect.url);
290
+ // TODO: TraceEngine is not retaining the actual status code.
291
+ redirectedRequest.statusCode = 302;
292
+ redirectedRequest.resourceType = undefined;
293
+ // TODO: TraceEngine is not retaining transfer size of redirected request.
294
+ redirectedRequest.transferSize = 400;
295
+ requestChain.push(redirectedRequest);
296
+ lanternRequests.push(redirectedRequest);
297
+ }
298
+ requestChain.push(request);
299
+ for (let i = 0; i < requestChain.length; i++) {
300
+ const request = requestChain[i];
301
+ if (i > 0) {
302
+ request.redirectSource = requestChain[i - 1];
303
+ request.redirects = requestChain.slice(0, i);
304
+ }
305
+ if (i !== requestChain.length - 1) {
306
+ request.redirectDestination = requestChain[i + 1];
307
+ }
308
+ }
309
+ // Apply the `:redirect` requestId convention: only redirects[0].requestId is the actual
310
+ // requestId, all the rest have n occurences of `:redirect` as a suffix.
311
+ for (let i = 1; i < requestChain.length; i++) {
312
+ requestChain[i].requestId = `${requestChain[i - 1].requestId}:redirect`;
313
+ }
314
+ }
315
+ linkInitiators(lanternRequests);
316
+ // This would already be sorted by rendererStartTime, if not for the redirect unwrapping done
317
+ // above.
318
+ return lanternRequests.sort((a, b) => a.rendererStartTime - b.rendererStartTime);
319
+ }
320
+ function collectMainThreadEvents(trace, traceEngineData) {
321
+ const Meta = traceEngineData.Meta;
322
+ const mainFramePids = Meta.mainFrameNavigations.length ? new Set(Meta.mainFrameNavigations.map(nav => nav.pid)) :
323
+ Meta.topLevelRendererIds;
324
+ const rendererPidToTid = new Map();
325
+ for (const pid of mainFramePids) {
326
+ const threads = Meta.threadsInProcess.get(pid) ?? [];
327
+ let found = false;
328
+ for (const [tid, thread] of threads) {
329
+ if (thread.args.name === 'CrRendererMain') {
330
+ rendererPidToTid.set(pid, tid);
331
+ found = true;
332
+ break;
333
+ }
334
+ }
335
+ if (found) {
336
+ continue;
337
+ }
338
+ // `CrRendererMain` can be missing if chrome is launched with the `--single-process` flag.
339
+ // In this case, page tasks will be run in the browser thread.
340
+ for (const [tid, thread] of threads) {
341
+ if (thread.args.name === 'CrBrowserMain') {
342
+ rendererPidToTid.set(pid, tid);
343
+ found = true;
344
+ break;
345
+ }
346
+ }
347
+ }
348
+ return trace.traceEvents.filter(e => rendererPidToTid.get(e.pid) === e.tid);
349
+ }
350
+ function createGraph(requests, trace, traceEngineData, url) {
351
+ const mainThreadEvents = collectMainThreadEvents(trace, traceEngineData);
352
+ // url defines the initial request that the Lantern graph starts at (the root node) and the
353
+ // main document request. These are equal if there are no redirects.
354
+ if (!url) {
355
+ url = {
356
+ requestedUrl: requests[0].url,
357
+ mainDocumentUrl: '',
358
+ };
359
+ let request = requests[0];
360
+ while (request.redirectDestination) {
361
+ request = request.redirectDestination;
362
+ }
363
+ url.mainDocumentUrl = request.url;
364
+ }
365
+ return Lantern.PageDependencyGraph.createGraph(mainThreadEvents, requests, url);
366
+ }
367
+ export { createProcessedNavigation, createNetworkRequests, createGraph, };
368
+ //# sourceMappingURL=LanternComputationData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LanternComputationData.js","sourceRoot":"","sources":["../../../../../../front_end/models/trace/LanternComputationData.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAI7B,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAKhD,SAAS,yBAAyB,CAAC,eAA8C;IAE/E,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC;IAClC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC;IACjC,MAAM,WAAW,GAAG,eAAe,CAAC,eAAe,CAAC,qBAAqB,C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AG,CAAC;IACpC,CAAC;IAED,OAAO,OAAO,CAAC,mBAAmB,CAAC,WAAW,CAAC,gBAAgB,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;AAClF,CAAC;AAED,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,WAAW,GACZ,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Protocol from '../../generated/protocol.js';\n\nimport * as Handlers from './handlers/handlers.js';\nimport * as Lantern from './lantern/lantern.js';\nimport type * as Types from './types/types.js';\n\ntype NetworkRequest = Lantern.NetworkRequest<Types.TraceEvents.SyntheticNetworkRequest>;\n\nfunction createProcessedNavigation(traceEngineData: Handlers.Types.TraceParseData):\n Lantern.Simulation.ProcessedNavigation {\n const Meta = traceEngineData.Meta;\n const frameId = Meta.mainFrameId;\n const scoresByNav = traceEngineData.PageLoadMetrics.metricScoresByFrameId.get(frameId);\n if (!scoresByNav) {\n throw new Error('missing metric scores for main frame');\n }\n\n const lastNavigationId = Meta.mainFrameNavigations.at(-1)?.args.data?.navigationId;\n const scores = lastNavigationId && scoresByNav.get(lastNavigationId);\n if (!scores) {\n throw new Error('missing metric scores for specified navigation');\n }\n\n const getTimestampOrUndefined =\n (metric: Handlers.ModelHandlers.PageLoadMetrics.MetricName): Types.Timing.MicroSeconds|undefined => {\n const metricScore = scores.get(metric);\n if (!metricScore?.event) {\n return;\n }\n return metricScore.event.ts;\n };\n const getTimestamp = (metric: Handlers.ModelHandlers.PageLoadMetrics.MetricName): Types.Timing.MicroSeconds => {\n const metricScore = scores.get(metric);\n if (!metricScore?.event) {\n throw new Error(`missing metric: ${metric}`);\n }\n return metricScore.event.ts;\n };\n return {\n timestamps: {\n firstContentfulPaint: getTimestamp(Handlers.ModelHandlers.PageLoadMetrics.MetricName.FCP),\n largestContentfulPaint: getTimestampOrUndefined(Handlers.ModelHandlers.PageLoadMetrics.MetricName.LCP),\n },\n };\n}\n\nfunction createParsedUrl(url: URL|string): Lantern.ParsedURL {\n if (typeof url === 'string') {\n url = new URL(url);\n }\n return {\n scheme: url.protocol.split(':')[0],\n // Intentional, DevTools uses different terminology\n host: url.hostname,\n securityOrigin: url.origin,\n };\n}\n\n/**\n * Returns a map of `pid` -> `tid[]`.\n */\nfunction findWorkerThreads(trace: Lantern.Trace): Map<number, number[]> {\n // TODO: WorkersHandler in TraceEngine needs to be updated to also include `pid` (only had `tid`).\n const workerThreads = new Map();\n const workerCreationEvents = ['ServiceWorker thread', 'DedicatedWorker thread'];\n\n for (const event of trace.traceEvents) {\n if (event.name !== 'thread_name' || !event.args.name) {\n continue;\n }\n if (!workerCreationEvents.includes(event.args.name)) {\n continue;\n }\n\n const tids = workerThreads.get(event.pid);\n if (tids) {\n tids.push(event.tid);\n } else {\n workerThreads.set(event.pid, [event.tid]);\n }\n }\n\n return workerThreads;\n}\n\nfunction createLanternRequest(\n traceEngineData: Handlers.Types.TraceParseData, workerThreads: Map<number, number[]>,\n request: Types.TraceEvents.SyntheticNetworkRequest): NetworkRequest|undefined {\n if (request.args.data.connectionId === undefined || request.args.data.connectionReused === undefined) {\n throw new Error('Trace is too old');\n }\n\n let url;\n try {\n url = new URL(request.args.data.url);\n } catch (e) {\n return;\n }\n\n const timing = request.args.data.timing ? {\n // These two timings are not included in the trace.\n workerFetchStart: -1,\n workerRespondWithSettled: -1,\n ...request.args.data.timing,\n } :\n undefined;\n\n const networkRequestTime = timing ? timing.requestTime * 1000 : request.args.data.syntheticData.downloadStart / 1000;\n\n let fromWorker = false;\n const tids = workerThreads.get(request.pid);\n if (tids?.includes(request.tid)) {\n fromWorker = true;\n }\n\n // TraceEngine collects worker thread ids in a different manner than `workerThreads` does.\n // AFAIK these should be equivalent, but in case they are not let's also check this for now.\n if (traceEngineData.Workers.workerIdByThread.has(request.tid)) {\n fromWorker = true;\n }\n\n // `initiator` in the trace does not contain the stack trace for JS-initiated\n // requests. Instead, that is stored in the `stackTrace` property of the SyntheticNetworkRequest.\n // There are some minor differences in the fields, accounted for here.\n // Most importantly, there seems to be fewer frames in the trace than the equivalent\n // events over the CDP. This results in less accuracy in determining the initiator request,\n // which means less edges in the graph, which mean worse results.\n // TODO: Should fix in Chromium.\n const initiator: Lantern.NetworkRequest['initiator'] =\n request.args.data.initiator ?? {type: Protocol.Network.InitiatorType.Other};\n if (request.args.data.stackTrace) {\n const callFrames = request.args.data.stackTrace.map(f => {\n return {\n scriptId: String(f.scriptId) as Protocol.Runtime.ScriptId,\n url: f.url,\n lineNumber: f.lineNumber - 1,\n columnNumber: f.columnNumber - 1,\n functionName: f.functionName,\n };\n });\n initiator.stack = {callFrames};\n // Note: there is no `parent` to set ...\n }\n\n let resourceType = request.args.data.resourceType;\n if (request.args.data.initiator?.fetchType === 'xmlhttprequest') {\n // @ts-expect-error yes XHR is a valid ResourceType. TypeScript const enums are so unhelpful.\n resourceType = 'XHR';\n } else if (request.args.data.initiator?.fetchType === 'fetch') {\n // @ts-expect-error yes Fetch is a valid ResourceType. TypeScript const enums are so unhelpful.\n resourceType = 'Fetch';\n }\n\n // TODO: set decodedBodyLength for data urls in Trace Engine.\n let resourceSize = request.args.data.decodedBodyLength ?? 0;\n if (url.protocol === 'data:' && resourceSize === 0) {\n const needle = 'base64,';\n const index = url.pathname.indexOf(needle);\n if (index !== -1) {\n resourceSize = atob(url.pathname.substring(index + needle.length)).length;\n }\n }\n\n return {\n rawRequest: request,\n requestId: request.args.data.requestId,\n connectionId: request.args.data.connectionId,\n connectionReused: request.args.data.connectionReused,\n url: request.args.data.url,\n protocol: request.args.data.protocol,\n parsedURL: createParsedUrl(url),\n documentURL: request.args.data.requestingFrameUrl,\n rendererStartTime: request.ts / 1000,\n networkRequestTime,\n responseHeadersEndTime: request.args.data.syntheticData.downloadStart / 1000,\n networkEndTime: request.args.data.syntheticData.finishTime / 1000,\n transferSize: request.args.data.encodedDataLength,\n resourceSize,\n fromDiskCache: request.args.data.syntheticData.isDiskCached,\n fromMemoryCache: request.args.data.syntheticData.isMemoryCached,\n isLinkPreload: request.args.data.isLinkPreload,\n finished: request.args.data.finished,\n failed: request.args.data.failed,\n statusCode: request.args.data.statusCode,\n initiator,\n timing,\n resourceType,\n mimeType: request.args.data.mimeType,\n priority: request.args.data.priority,\n frameId: request.args.data.frame,\n fromWorker,\n // Set later.\n redirects: undefined,\n redirectSource: undefined,\n redirectDestination: undefined,\n initiatorRequest: undefined,\n };\n}\n\n/**\n * @param request The request to find the initiator of\n */\nfunction chooseInitiatorRequest(request: NetworkRequest, requestsByURL: Map<string, NetworkRequest[]>): NetworkRequest|\n null {\n if (request.redirectSource) {\n return request.redirectSource;\n }\n\n const initiatorURL = Lantern.PageDependencyGraph.getNetworkInitiators(request)[0];\n let candidates = requestsByURL.get(initiatorURL) || [];\n // The (valid) initiator must come before the initiated request.\n candidates = candidates.filter(c => {\n return c.responseHeadersEndTime <= request.rendererStartTime && c.finished && !c.failed;\n });\n if (candidates.length > 1) {\n // Disambiguate based on prefetch. Prefetch requests have type 'Other' and cannot\n // initiate requests, so we drop them here.\n const nonPrefetchCandidates = candidates.filter(cand => cand.resourceType !== Lantern.NetworkRequestTypes.Other);\n if (nonPrefetchCandidates.length) {\n candidates = nonPrefetchCandidates;\n }\n }\n if (candidates.length > 1) {\n // Disambiguate based on frame. It's likely that the initiator comes from the same frame.\n const sameFrameCandidates = candidates.filter(cand => cand.frameId === request.frameId);\n if (sameFrameCandidates.length) {\n candidates = sameFrameCandidates;\n }\n }\n if (candidates.length > 1 && request.initiator.type === 'parser') {\n // Filter to just Documents when initiator type is parser.\n const documentCandidates = candidates.filter(cand => cand.resourceType === Lantern.NetworkRequestTypes.Document);\n if (documentCandidates.length) {\n candidates = documentCandidates;\n }\n }\n if (candidates.length > 1) {\n // If all real loads came from successful preloads (url preloaded and\n // loads came from the cache), filter to link rel=preload request(s).\n const linkPreloadCandidates = candidates.filter(c => c.isLinkPreload);\n if (linkPreloadCandidates.length) {\n const nonPreloadCandidates = candidates.filter(c => !c.isLinkPreload);\n const allPreloaded = nonPreloadCandidates.every(c => c.fromDiskCache || c.fromMemoryCache);\n if (nonPreloadCandidates.length && allPreloaded) {\n candidates = linkPreloadCandidates;\n }\n }\n }\n\n // Only return an initiator if the result is unambiguous.\n return candidates.length === 1 ? candidates[0] : null;\n}\n\nfunction linkInitiators(lanternRequests: NetworkRequest[]): void {\n const requestsByURL: Map<string, NetworkRequest[]> = new Map();\n for (const request of lanternRequests) {\n const requests = requestsByURL.get(request.url) || [];\n requests.push(request);\n requestsByURL.set(request.url, requests);\n }\n\n for (const request of lanternRequests) {\n const initiatorRequest = chooseInitiatorRequest(request, requestsByURL);\n if (initiatorRequest) {\n request.initiatorRequest = initiatorRequest;\n }\n }\n}\n\nfunction createNetworkRequests(trace: Lantern.Trace, traceEngineData: Handlers.Types.TraceParseData): NetworkRequest[] {\n const workerThreads = findWorkerThreads(trace);\n\n const lanternRequests: NetworkRequest[] = [];\n for (const request of traceEngineData.NetworkRequests.byTime) {\n const lanternRequest = createLanternRequest(traceEngineData, workerThreads, request);\n if (lanternRequest) {\n lanternRequests.push(lanternRequest);\n }\n }\n\n // TraceEngine consolidates all redirects into a single request object, but lantern needs\n // an entry for each redirected request.\n for (const request of [...lanternRequests]) {\n if (!request.rawRequest) {\n continue;\n }\n\n const redirects = request.rawRequest.args.data.redirects;\n if (!redirects.length) {\n continue;\n }\n\n const requestChain = [];\n for (const redirect of redirects) {\n const redirectedRequest = structuredClone(request);\n\n redirectedRequest.networkRequestTime = redirect.ts / 1000;\n redirectedRequest.rendererStartTime = redirectedRequest.networkRequestTime;\n\n redirectedRequest.networkEndTime = (redirect.ts + redirect.dur) / 1000;\n redirectedRequest.responseHeadersEndTime = redirectedRequest.networkEndTime;\n\n redirectedRequest.timing = {\n requestTime: redirectedRequest.networkRequestTime / 1000,\n receiveHeadersStart: redirectedRequest.responseHeadersEndTime,\n receiveHeadersEnd: redirectedRequest.responseHeadersEndTime,\n proxyStart: -1,\n proxyEnd: -1,\n dnsStart: -1,\n dnsEnd: -1,\n connectStart: -1,\n connectEnd: -1,\n sslStart: -1,\n sslEnd: -1,\n sendStart: -1,\n sendEnd: -1,\n workerStart: -1,\n workerReady: -1,\n workerFetchStart: -1,\n workerRespondWithSettled: -1,\n pushStart: -1,\n pushEnd: -1,\n };\n\n redirectedRequest.url = redirect.url;\n redirectedRequest.parsedURL = createParsedUrl(redirect.url);\n // TODO: TraceEngine is not retaining the actual status code.\n redirectedRequest.statusCode = 302;\n redirectedRequest.resourceType = undefined;\n // TODO: TraceEngine is not retaining transfer size of redirected request.\n redirectedRequest.transferSize = 400;\n requestChain.push(redirectedRequest);\n lanternRequests.push(redirectedRequest);\n }\n requestChain.push(request);\n\n for (let i = 0; i < requestChain.length; i++) {\n const request = requestChain[i];\n if (i > 0) {\n request.redirectSource = requestChain[i - 1];\n request.redirects = requestChain.slice(0, i);\n }\n if (i !== requestChain.length - 1) {\n request.redirectDestination = requestChain[i + 1];\n }\n }\n\n // Apply the `:redirect` requestId convention: only redirects[0].requestId is the actual\n // requestId, all the rest have n occurences of `:redirect` as a suffix.\n for (let i = 1; i < requestChain.length; i++) {\n requestChain[i].requestId = `${requestChain[i - 1].requestId}:redirect`;\n }\n }\n\n linkInitiators(lanternRequests);\n\n // This would already be sorted by rendererStartTime, if not for the redirect unwrapping done\n // above.\n return lanternRequests.sort((a, b) => a.rendererStartTime - b.rendererStartTime);\n}\n\nfunction collectMainThreadEvents(\n trace: Lantern.Trace, traceEngineData: Handlers.Types.TraceParseData): Lantern.TraceEvent[] {\n const Meta = traceEngineData.Meta;\n const mainFramePids = Meta.mainFrameNavigations.length ? new Set(Meta.mainFrameNavigations.map(nav => nav.pid)) :\n Meta.topLevelRendererIds;\n\n const rendererPidToTid = new Map();\n for (const pid of mainFramePids) {\n const threads = Meta.threadsInProcess.get(pid) ?? [];\n\n let found = false;\n for (const [tid, thread] of threads) {\n if (thread.args.name === 'CrRendererMain') {\n rendererPidToTid.set(pid, tid);\n found = true;\n break;\n }\n }\n\n if (found) {\n continue;\n }\n\n // `CrRendererMain` can be missing if chrome is launched with the `--single-process` flag.\n // In this case, page tasks will be run in the browser thread.\n for (const [tid, thread] of threads) {\n if (thread.args.name === 'CrBrowserMain') {\n rendererPidToTid.set(pid, tid);\n found = true;\n break;\n }\n }\n }\n\n return trace.traceEvents.filter(e => rendererPidToTid.get(e.pid) === e.tid);\n}\n\nfunction createGraph(\n requests: Lantern.NetworkRequest[], trace: Lantern.Trace, traceEngineData: Handlers.Types.TraceParseData,\n url?: Lantern.Simulation.URL): Lantern.Node<Types.TraceEvents.SyntheticNetworkRequest> {\n const mainThreadEvents = collectMainThreadEvents(trace, traceEngineData);\n\n // url defines the initial request that the Lantern graph starts at (the root node) and the\n // main document request. These are equal if there are no redirects.\n if (!url) {\n url = {\n requestedUrl: requests[0].url,\n mainDocumentUrl: '',\n };\n\n let request = requests[0];\n while (request.redirectDestination) {\n request = request.redirectDestination;\n }\n url.mainDocumentUrl = request.url;\n }\n\n return Lantern.PageDependencyGraph.createGraph(mainThreadEvents, requests, url);\n}\n\nexport {\n createProcessedNavigation,\n createNetworkRequests,\n createGraph,\n};\n"]}
@@ -32,7 +32,6 @@
32
32
  "../../../../../../front_end/models/trace/trace.ts",
33
33
  "../../../../../../front_end/legacy/legacy-defs.d.ts",
34
34
  "../../../../../../front_end/global_typings/global_defs.d.ts",
35
- "../../../../../../front_end/global_typings/request_idle_callback.d.ts",
36
35
  "../../../../../../node_modules/@types/filesystem/index.d.ts"
37
36
  ],
38
37
  "references": [
@@ -32,7 +32,6 @@
32
32
  "../../../../../../../front_end/models/trace/extras/extras.ts",
33
33
  "../../../../../../../front_end/legacy/legacy-defs.d.ts",
34
34
  "../../../../../../../front_end/global_typings/global_defs.d.ts",
35
- "../../../../../../../front_end/global_typings/request_idle_callback.d.ts",
36
35
  "../../../../../../../node_modules/@types/filesystem/index.d.ts"
37
36
  ],
38
37
  "references": [
@@ -36,7 +36,6 @@
36
36
  "../../../../../../../front_end/models/trace/extras/URLForEntry.ts",
37
37
  "../../../../../../../front_end/legacy/legacy-defs.d.ts",
38
38
  "../../../../../../../front_end/global_typings/global_defs.d.ts",
39
- "../../../../../../../front_end/global_typings/request_idle_callback.d.ts",
40
39
  "../../../../../../../node_modules/@types/filesystem/index.d.ts"
41
40
  ],
42
41
  "references": [
@@ -84,7 +84,7 @@ function workletType(input) {
84
84
  * regardless of the type of event.
85
85
  */
86
86
  function makeSyntheticEventBase(event) {
87
- return Helpers.SyntheticEvents.SyntheticEventsManager.getActiveManager()
87
+ return Helpers.SyntheticEvents.SyntheticEventsManager
88
88
  .registerSyntheticBasedEvent({
89
89
  rawSourceEvent: event,
90
90
  name: 'SyntheticAuctionWorkletEvent',
@@ -1 +1 @@
1
- {"version":3,"file":"AuctionWorkletsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/AuctionWorkletsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,sBAAsB,GACuE,IAAI,GAAG,EAAE,CAAC;AAC7G,MAAM,qBAAqB,GACuE,IAAI,GAAG,EAAE,CAAC;AAE5G,gFAAgF;AAChF,MAAM,sBAAsB,GACxB,IAAI,GAAG,EAAE,CAAC;AAEd,0EAA0E;AAC1E,qCAAqC;AACrC,qEAAqE;AACrE,6EAA6E;AAC7E,qCAAqC;AACrC,+EAA+E;AAC/E,+EAA+E;AAC/E,MAAM,cAAc,GAA6E,IAAI,GAAG,EAAE,CAAC;AAC3G,MAAM,eAAe,GAA6E,IAAI,GAAG,EAAE,CAAC;AAE5G,MAAM,UAAU,KAAK;IACnB,sBAAsB,CAAC,KAAK,EAAE,CAAC;IAC/B,qBAAqB,CAAC,KAAK,EAAE,CA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qBAAqB,EAAE,YAAY;wBACnC,aAAa,EAAE,sBAAsB;wBACrC,cAAc,EAAE,aAAa;qBAC9B;iBACF;aACF,CAAC;YACF,IAAI,aAAa,EAAE,CAAC;gBAClB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,GAAG,aAAa,CAAC;YAChE,CAAC;QACH,CAAC;aAAM,IAAI,aAAa,EAAE,CAAC;YACzB,cAAc,GAAG;gBACf,GAAG,sBAAsB,CAAC,aAAa,CAAC;gBACxC,IAAI,EAAE;oBACJ,IAAI,EAAE;wBACJ,oBAAoB,EAAE,aAAa;wBACnC,aAAa,EAAE,sBAAsB;wBACrC,cAAc,EAAE,aAAa;qBAC9B;iBACF;aACF,CAAC;YACF,IAAI,YAAY,EAAE,CAAC;gBACjB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,GAAG,YAAY,CAAC;YAChE,CAAC;QACH,CAAC;QACD,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;YAC5B,SAAS;QACX,CAAC;QACD,sBAAsB,CAAC,GAAG,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAClD,CAAC;AACH,CAAC;AAMD,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,QAAQ,EAAE,IAAI,GAAG,CAAC,sBAAsB,CAAC;KAC1C,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2023 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\n/**\n * There are two metadata events that we care about.\n * => AuctionWorkletRunningInProcess tells us which process the Auction Worklet\n * has taken to run in.\n * => AuctionWorkletDoneWithProcess tells us when the worklet is done with that\n * process. This is less useful - but in the future we might want to surface\n * this information so we still parse and return the event.\n *\n * It is important to note that the top level PID on these events is NOT the\n * PID that the worklet is running on; instead we have to look at its\n * args.data.pid property, which is the PID of the process that it is running\n * on.\n *\n * For any given RunningInProcess event, we would typically expect to see a\n * DoneWithProcess event, however this is not guaranteed, especially as users\n * can record any chunk of time in DevTools.\n *\n * Similarly, it is also possible to see a DoneWithProcess event without a\n * RunningInProcess event, if the user started recording after the auction\n * worklets started. Therefore we are happy to create\n * SyntheticAuctionWorkletEvents as long as we see just one of these events.\n *\n * If we do get two events and need to pair them, we can use the\n * args.data.target property, which is a string ID shared by both\n * events.\n */\nconst runningInProcessEvents:\n Map<Types.TraceEvents.ProcessID, Types.TraceEvents.TraceEventAuctionWorkletRunningInProcess> = new Map();\nconst doneWithProcessEvents:\n Map<Types.TraceEvents.ProcessID, Types.TraceEvents.TraceEventAuctionWorkletDoneWithProcess> = new Map();\n\n// Keyed by the PID defined in `args.data.pid` on AuctionWorklet trace events..\nconst createdSyntheticEvents: Map<Types.TraceEvents.ProcessID, Types.TraceEvents.SyntheticAuctionWorkletEvent> =\n new Map();\n\n// Each AuctonWorklet takes over a process and has 2 threads (that we care\n// about and want to show as tracks):\n// 1. A CrUtilityMain thread which is known as the \"control process\".\n// 2. A AuctionV8HelperThread which is the actual auction worklet and will be\n// either a \"Seller\" or a \"Bidder\"\n// To detect these we look for the metadata thread_name events. We key these by\n// PID so that we can easily look them up later without having to loop through.\nconst utilityThreads: Map<Types.TraceEvents.ProcessID, Types.TraceEvents.TraceEventThreadName> = new Map();\nconst v8HelperThreads: Map<Types.TraceEvents.ProcessID, Types.TraceEvents.TraceEventThreadName> = new Map();\n\nexport function reset(): void {\n runningInProcessEvents.clear();\n doneWithProcessEvents.clear();\n createdSyntheticEvents.clear();\n utilityThreads.clear();\n v8HelperThreads.clear();\n}\n\nexport function handleEvent(event: Types.TraceEvents.TraceEventData): void {\n if (Types.TraceEvents.isTraceEventAuctionWorkletRunningInProcess(event)) {\n runningInProcessEvents.set(event.args.data.pid, event);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventAuctionWorkletDoneWithProcess(event)) {\n doneWithProcessEvents.set(event.args.data.pid, event);\n return;\n }\n\n if (Types.TraceEvents.isThreadName(event)) {\n if (event.args.name === 'auction_worklet.CrUtilityMain') {\n utilityThreads.set(event.pid, event);\n return;\n }\n if (event.args.name === 'AuctionV8HelperThread') {\n v8HelperThreads.set(event.pid, event);\n }\n }\n}\n\nfunction workletType(input: string): Types.TraceEvents.AuctionWorkletType {\n switch (input) {\n case 'seller':\n return Types.TraceEvents.AuctionWorkletType.SELLER;\n case 'bidder':\n return Types.TraceEvents.AuctionWorkletType.BIDDER;\n default:\n return Types.TraceEvents.AuctionWorkletType.UNKNOWN;\n }\n}\n\n/**\n * We cannot make the full event without knowing the type of event, but we can\n * create everything other than the `args` field, as those are identical\n * regardless of the type of event.\n */\nfunction makeSyntheticEventBase(event: Types.TraceEvents.TraceEventAuctionWorkletDoneWithProcess|\n Types.TraceEvents.TraceEventAuctionWorkletRunningInProcess):\n Omit<Types.TraceEvents.SyntheticAuctionWorkletEvent, 'args'> {\n return Helpers.SyntheticEvents.SyntheticEventsManager.getActiveManager()\n .registerSyntheticBasedEvent<Omit<Types.TraceEvents.SyntheticAuctionWorkletEvent, 'args'>>({\n rawSourceEvent: event,\n name: 'SyntheticAuctionWorkletEvent',\n s: Types.TraceEvents.TraceEventScope.THREAD,\n cat: event.cat,\n tid: event.tid,\n ts: event.ts,\n ph: Types.TraceEvents.Phase.INSTANT,\n pid: event.args.data.pid,\n host: event.args.data.host,\n target: event.args.data.target,\n type: workletType(event.args.data.type),\n });\n}\n\nexport async function finalize(): Promise<void> {\n // Loop through the utility threads we found to create the worklet events. We\n // expect each worklet to have a utility thread, so we can use them as the\n // root of our list of worklets.\n for (const [pid, utilityThreadNameEvent] of utilityThreads) {\n const v8HelperEvent = v8HelperThreads.get(pid);\n if (!v8HelperEvent) {\n // Bad trace data - AuctionWorklets are expected to always have both threads.\n continue;\n }\n\n const runningEvent = runningInProcessEvents.get(pid);\n const doneWithEvent = doneWithProcessEvents.get(pid);\n\n // We can create a worklet from either the runningEvent or doneWithEvent -\n // we do not need both. We cannot express that to TypeScript with an early\n // return here, so instead we set the event initially to null, and then\n // create it from either the running event or the doneWith event. If it is\n // still null after this, that means neither event was found, and we drop\n // the worklet as we do not have enough information to create the synthetic\n // event.\n\n let syntheticEvent: Types.TraceEvents.SyntheticAuctionWorkletEvent|null = null;\n\n if (runningEvent) {\n syntheticEvent = {\n ...makeSyntheticEventBase(runningEvent),\n args: {\n data: {\n runningInProcessEvent: runningEvent,\n utilityThread: utilityThreadNameEvent,\n v8HelperThread: v8HelperEvent,\n },\n },\n };\n if (doneWithEvent) {\n syntheticEvent.args.data.doneWithProcessEvent = doneWithEvent;\n }\n } else if (doneWithEvent) {\n syntheticEvent = {\n ...makeSyntheticEventBase(doneWithEvent),\n args: {\n data: {\n doneWithProcessEvent: doneWithEvent,\n utilityThread: utilityThreadNameEvent,\n v8HelperThread: v8HelperEvent,\n },\n },\n };\n if (runningEvent) {\n syntheticEvent.args.data.runningInProcessEvent = runningEvent;\n }\n }\n if (syntheticEvent === null) {\n continue;\n }\n createdSyntheticEvents.set(pid, syntheticEvent);\n }\n}\n\nexport interface AuctionWorkletsData {\n worklets: Map<Types.TraceEvents.ProcessID, Types.TraceEvents.SyntheticAuctionWorkletEvent>;\n}\n\nexport function data(): AuctionWorkletsData {\n return {\n worklets: new Map(createdSyntheticEvents),\n };\n}\n"]}
1
+ {"version":3,"file":"AuctionWorkletsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/AuctionWorkletsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,sBAAsB,GACuE,IAAI,GAAG,EAAE,CAAC;AAC7G,MAAM,qBAAqB,GACuE,IAAI,GAAG,EAAE,CAAC;AAE5G,gFAAgF;AAChF,MAAM,sBAAsB,GACxB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,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAErD,0EAA0E;QAC1E,0EAA0E;QAC1E,uEAAuE;QACvE,0EAA0E;QAC1E,yEAAyE;QACzE,2EAA2E;QAC3E,SAAS;QAET,IAAI,cAAc,GAAwD,IAAI,CAAC;QAE/E,IAAI,YAAY,EAAE,CAAC;YACjB,cAAc,GAAG;gBACf,GAAG,sBAAsB,CAAC,YAAY,CAAC;gBACvC,IAAI,EAAE;oBACJ,IAAI,EAAE;wBACJ,qBAAqB,EAAE,YAAY;wBACnC,aAAa,EAAE,sBAAsB;wBACrC,cAAc,EAAE,aAAa;qBAC9B;iBACF;aACF,CAAC;YACF,IAAI,aAAa,EAAE,CAAC;gBAClB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,GAAG,aAAa,CAAC;YAChE,CAAC;QACH,CAAC;aAAM,IAAI,aAAa,EAAE,CAAC;YACzB,cAAc,GAAG;gBACf,GAAG,sBAAsB,CAAC,aAAa,CAAC;gBACxC,IAAI,EAAE;oBACJ,IAAI,EAAE;wBACJ,oBAAoB,EAAE,aAAa;wBACnC,aAAa,EAAE,sBAAsB;wBACrC,cAAc,EAAE,aAAa;qBAC9B;iBACF;aACF,CAAC;YACF,IAAI,YAAY,EAAE,CAAC;gBACjB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,GAAG,YAAY,CAAC;YAChE,CAAC;QACH,CAAC;QACD,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;YAC5B,SAAS;QACX,CAAC;QACD,sBAAsB,CAAC,GAAG,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAClD,CAAC;AACH,CAAC;AAMD,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,QAAQ,EAAE,IAAI,GAAG,CAAC,sBAAsB,CAAC;KAC1C,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2023 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\n/**\n * There are two metadata events that we care about.\n * => AuctionWorkletRunningInProcess tells us which process the Auction Worklet\n * has taken to run in.\n * => AuctionWorkletDoneWithProcess tells us when the worklet is done with that\n * process. This is less useful - but in the future we might want to surface\n * this information so we still parse and return the event.\n *\n * It is important to note that the top level PID on these events is NOT the\n * PID that the worklet is running on; instead we have to look at its\n * args.data.pid property, which is the PID of the process that it is running\n * on.\n *\n * For any given RunningInProcess event, we would typically expect to see a\n * DoneWithProcess event, however this is not guaranteed, especially as users\n * can record any chunk of time in DevTools.\n *\n * Similarly, it is also possible to see a DoneWithProcess event without a\n * RunningInProcess event, if the user started recording after the auction\n * worklets started. Therefore we are happy to create\n * SyntheticAuctionWorkletEvents as long as we see just one of these events.\n *\n * If we do get two events and need to pair them, we can use the\n * args.data.target property, which is a string ID shared by both\n * events.\n */\nconst runningInProcessEvents:\n Map<Types.TraceEvents.ProcessID, Types.TraceEvents.TraceEventAuctionWorkletRunningInProcess> = new Map();\nconst doneWithProcessEvents:\n Map<Types.TraceEvents.ProcessID, Types.TraceEvents.TraceEventAuctionWorkletDoneWithProcess> = new Map();\n\n// Keyed by the PID defined in `args.data.pid` on AuctionWorklet trace events..\nconst createdSyntheticEvents: Map<Types.TraceEvents.ProcessID, Types.TraceEvents.SyntheticAuctionWorkletEvent> =\n new Map();\n\n// Each AuctonWorklet takes over a process and has 2 threads (that we care\n// about and want to show as tracks):\n// 1. A CrUtilityMain thread which is known as the \"control process\".\n// 2. A AuctionV8HelperThread which is the actual auction worklet and will be\n// either a \"Seller\" or a \"Bidder\"\n// To detect these we look for the metadata thread_name events. We key these by\n// PID so that we can easily look them up later without having to loop through.\nconst utilityThreads: Map<Types.TraceEvents.ProcessID, Types.TraceEvents.TraceEventThreadName> = new Map();\nconst v8HelperThreads: Map<Types.TraceEvents.ProcessID, Types.TraceEvents.TraceEventThreadName> = new Map();\n\nexport function reset(): void {\n runningInProcessEvents.clear();\n doneWithProcessEvents.clear();\n createdSyntheticEvents.clear();\n utilityThreads.clear();\n v8HelperThreads.clear();\n}\n\nexport function handleEvent(event: Types.TraceEvents.TraceEventData): void {\n if (Types.TraceEvents.isTraceEventAuctionWorkletRunningInProcess(event)) {\n runningInProcessEvents.set(event.args.data.pid, event);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventAuctionWorkletDoneWithProcess(event)) {\n doneWithProcessEvents.set(event.args.data.pid, event);\n return;\n }\n\n if (Types.TraceEvents.isThreadName(event)) {\n if (event.args.name === 'auction_worklet.CrUtilityMain') {\n utilityThreads.set(event.pid, event);\n return;\n }\n if (event.args.name === 'AuctionV8HelperThread') {\n v8HelperThreads.set(event.pid, event);\n }\n }\n}\n\nfunction workletType(input: string): Types.TraceEvents.AuctionWorkletType {\n switch (input) {\n case 'seller':\n return Types.TraceEvents.AuctionWorkletType.SELLER;\n case 'bidder':\n return Types.TraceEvents.AuctionWorkletType.BIDDER;\n default:\n return Types.TraceEvents.AuctionWorkletType.UNKNOWN;\n }\n}\n\n/**\n * We cannot make the full event without knowing the type of event, but we can\n * create everything other than the `args` field, as those are identical\n * regardless of the type of event.\n */\nfunction makeSyntheticEventBase(event: Types.TraceEvents.TraceEventAuctionWorkletDoneWithProcess|\n Types.TraceEvents.TraceEventAuctionWorkletRunningInProcess):\n Omit<Types.TraceEvents.SyntheticAuctionWorkletEvent, 'args'> {\n return Helpers.SyntheticEvents.SyntheticEventsManager\n .registerSyntheticBasedEvent<Omit<Types.TraceEvents.SyntheticAuctionWorkletEvent, 'args'>>({\n rawSourceEvent: event,\n name: 'SyntheticAuctionWorkletEvent',\n s: Types.TraceEvents.TraceEventScope.THREAD,\n cat: event.cat,\n tid: event.tid,\n ts: event.ts,\n ph: Types.TraceEvents.Phase.INSTANT,\n pid: event.args.data.pid,\n host: event.args.data.host,\n target: event.args.data.target,\n type: workletType(event.args.data.type),\n });\n}\n\nexport async function finalize(): Promise<void> {\n // Loop through the utility threads we found to create the worklet events. We\n // expect each worklet to have a utility thread, so we can use them as the\n // root of our list of worklets.\n for (const [pid, utilityThreadNameEvent] of utilityThreads) {\n const v8HelperEvent = v8HelperThreads.get(pid);\n if (!v8HelperEvent) {\n // Bad trace data - AuctionWorklets are expected to always have both threads.\n continue;\n }\n\n const runningEvent = runningInProcessEvents.get(pid);\n const doneWithEvent = doneWithProcessEvents.get(pid);\n\n // We can create a worklet from either the runningEvent or doneWithEvent -\n // we do not need both. We cannot express that to TypeScript with an early\n // return here, so instead we set the event initially to null, and then\n // create it from either the running event or the doneWith event. If it is\n // still null after this, that means neither event was found, and we drop\n // the worklet as we do not have enough information to create the synthetic\n // event.\n\n let syntheticEvent: Types.TraceEvents.SyntheticAuctionWorkletEvent|null = null;\n\n if (runningEvent) {\n syntheticEvent = {\n ...makeSyntheticEventBase(runningEvent),\n args: {\n data: {\n runningInProcessEvent: runningEvent,\n utilityThread: utilityThreadNameEvent,\n v8HelperThread: v8HelperEvent,\n },\n },\n };\n if (doneWithEvent) {\n syntheticEvent.args.data.doneWithProcessEvent = doneWithEvent;\n }\n } else if (doneWithEvent) {\n syntheticEvent = {\n ...makeSyntheticEventBase(doneWithEvent),\n args: {\n data: {\n doneWithProcessEvent: doneWithEvent,\n utilityThread: utilityThreadNameEvent,\n v8HelperThread: v8HelperEvent,\n },\n },\n };\n if (runningEvent) {\n syntheticEvent.args.data.runningInProcessEvent = runningEvent;\n }\n }\n if (syntheticEvent === null) {\n continue;\n }\n createdSyntheticEvents.set(pid, syntheticEvent);\n }\n}\n\nexport interface AuctionWorkletsData {\n worklets: Map<Types.TraceEvents.ProcessID, Types.TraceEvents.SyntheticAuctionWorkletEvent>;\n}\n\nexport function data(): AuctionWorkletsData {\n return {\n worklets: new Map(createdSyntheticEvents),\n };\n}\n"]}
@@ -0,0 +1,46 @@
1
+ import * as Types from '../types/types.js';
2
+ export declare const EnhancedTracesVersion: number;
3
+ export interface Script {
4
+ scriptId: number;
5
+ isolate: string;
6
+ url: string;
7
+ executionContextId: number;
8
+ startLine: number;
9
+ startColumn: number;
10
+ endLine: number;
11
+ endColumn: number;
12
+ hash: string;
13
+ isModule?: boolean;
14
+ hasSourceUrl?: boolean;
15
+ sourceMapUrl?: string;
16
+ length?: number;
17
+ sourceText?: string;
18
+ }
19
+ export interface ExecutionContextAuxData {
20
+ frameId?: string;
21
+ isDefault?: boolean;
22
+ type?: string;
23
+ }
24
+ export interface ExecutionContext {
25
+ id: number;
26
+ origin: string;
27
+ v8Context?: string;
28
+ auxData?: ExecutionContextAuxData;
29
+ }
30
+ export interface Target {
31
+ id: string;
32
+ type: string;
33
+ url: string;
34
+ pid?: number;
35
+ isolate?: string;
36
+ }
37
+ export interface EnhancedTracesData {
38
+ targets: Target[];
39
+ executionContexts: ExecutionContext[];
40
+ scripts: Script[];
41
+ }
42
+ export declare function initialize(): void;
43
+ export declare function reset(): void;
44
+ export declare function handleEvent(event: Types.TraceEvents.TraceEventData): void;
45
+ export declare function finalize(): Promise<void>;
46
+ export declare function data(): EnhancedTracesData;