@paulirish/trace_engine 0.0.38 → 0.0.40
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.
- package/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
- package/core/platform/DevToolsPath.d.ts +30 -9
- package/core/platform/DevToolsPath.js +21 -0
- package/core/platform/DevToolsPath.js.map +1 -1
- package/core/platform/MapUtilities.js +1 -1
- package/core/platform/MapUtilities.js.map +1 -1
- package/core/platform/ServerTiming.d.ts +2 -2
- package/core/platform/ServerTiming.js.map +1 -1
- package/core/platform/StringUtilities.js +1 -1
- package/core/platform/StringUtilities.js.map +1 -1
- package/core/platform/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/core/platform/platform-tsconfig.json +2 -1
- package/generated/protocol.d.ts +203 -73
- package/locales/af.json +86 -0
- package/locales/am.json +86 -0
- package/locales/ar.json +86 -0
- package/locales/as.json +86 -0
- package/locales/az.json +86 -0
- package/locales/be.json +86 -0
- package/locales/bg.json +86 -0
- package/locales/bn.json +86 -0
- package/locales/bs.json +86 -0
- package/locales/ca.json +86 -0
- package/locales/cs.json +86 -0
- package/locales/cy.json +86 -0
- package/locales/da.json +86 -0
- package/locales/de.json +86 -0
- package/locales/el.json +86 -0
- package/locales/en-GB.json +86 -0
- package/locales/en-US.json +86 -0
- package/locales/en-XL.json +86 -0
- package/locales/es-419.json +86 -0
- package/locales/es.json +86 -0
- package/locales/et.json +86 -0
- package/locales/eu.json +86 -0
- package/locales/fa.json +86 -0
- package/locales/fi.json +86 -0
- package/locales/fil.json +86 -0
- package/locales/fr-CA.json +86 -0
- package/locales/fr.json +86 -0
- package/locales/gl.json +86 -0
- package/locales/gu.json +86 -0
- package/locales/he.json +86 -0
- package/locales/hi.json +86 -0
- package/locales/hr.json +86 -0
- package/locales/hu.json +86 -0
- package/locales/hy.json +86 -0
- package/locales/id.json +86 -0
- package/locales/is.json +86 -0
- package/locales/it.json +86 -0
- package/locales/ja.json +86 -0
- package/locales/ka.json +86 -0
- package/locales/kk.json +86 -0
- package/locales/km.json +86 -0
- package/locales/kn.json +86 -0
- package/locales/ko.json +86 -0
- package/locales/ky.json +86 -0
- package/locales/lo.json +86 -0
- package/locales/lt.json +86 -0
- package/locales/lv.json +86 -0
- package/locales/mk.json +86 -0
- package/locales/ml.json +86 -0
- package/locales/mn.json +86 -0
- package/locales/mr.json +86 -0
- package/locales/ms.json +86 -0
- package/locales/my.json +86 -0
- package/locales/ne.json +86 -0
- package/locales/nl.json +86 -0
- package/locales/no.json +86 -0
- package/locales/or.json +86 -0
- package/locales/pa.json +86 -0
- package/locales/pl.json +86 -0
- package/locales/pt-PT.json +86 -0
- package/locales/pt.json +86 -0
- package/locales/ro.json +86 -0
- package/locales/ru.json +86 -0
- package/locales/si.json +86 -0
- package/locales/sk.json +86 -0
- package/locales/sl.json +86 -0
- package/locales/sq.json +86 -0
- package/locales/sr-Latn.json +86 -0
- package/locales/sr.json +86 -0
- package/locales/sv.json +86 -0
- package/locales/sw.json +86 -0
- package/locales/ta.json +86 -0
- package/locales/te.json +86 -0
- package/locales/th.json +86 -0
- package/locales/tr.json +86 -0
- package/locales/uk.json +86 -0
- package/locales/ur.json +86 -0
- package/locales/uz.json +86 -0
- package/locales/vi.json +86 -0
- package/locales/zh-HK.json +86 -0
- package/locales/zh-TW.json +86 -0
- package/locales/zh.json +86 -0
- package/locales/zu.json +86 -0
- package/models/cpu_profile/ProfileTreeModel.js +0 -2
- package/models/cpu_profile/ProfileTreeModel.js.map +1 -1
- package/models/cpu_profile/cpu_profile-tsconfig.json +2 -1
- package/models/cpu_profile/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/LanternComputationData.js +1 -1
- package/models/trace/LanternComputationData.js.map +1 -1
- package/models/trace/ModelImpl.d.ts +6 -6
- package/models/trace/ModelImpl.js +1 -0
- package/models/trace/ModelImpl.js.map +1 -1
- package/models/trace/Processor.d.ts +6 -0
- package/models/trace/Processor.js +90 -9
- package/models/trace/Processor.js.map +1 -1
- package/models/trace/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/extras/StackTraceForEvent.d.ts +12 -0
- package/models/trace/extras/StackTraceForEvent.js +163 -0
- package/models/trace/extras/StackTraceForEvent.js.map +1 -0
- package/models/trace/extras/ThirdParties.d.ts +7 -4
- package/models/trace/extras/ThirdParties.js +56 -65
- package/models/trace/extras/ThirdParties.js.map +1 -1
- package/models/trace/extras/TraceTree.js +8 -8
- package/models/trace/extras/TraceTree.js.map +1 -1
- package/models/trace/extras/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/extras/extras-tsconfig.json +3 -2
- package/models/trace/extras/extras.js.map +1 -1
- package/models/trace/handlers/AnimationFramesHandler.d.ts +11 -0
- package/models/trace/handlers/AnimationFramesHandler.js +102 -0
- package/models/trace/handlers/AnimationFramesHandler.js.map +1 -0
- package/models/trace/handlers/AsyncJSCallsHandler.d.ts +15 -0
- package/models/trace/handlers/AsyncJSCallsHandler.js +153 -0
- package/models/trace/handlers/AsyncJSCallsHandler.js.map +1 -0
- package/models/trace/handlers/DOMStatsHandler.d.ts +8 -0
- package/models/trace/handlers/DOMStatsHandler.js +22 -0
- package/models/trace/handlers/DOMStatsHandler.js.map +1 -0
- package/models/trace/handlers/ExtensionTraceDataHandler.d.ts +80 -2
- package/models/trace/handlers/ExtensionTraceDataHandler.js +163 -13
- package/models/trace/handlers/ExtensionTraceDataHandler.js.map +1 -1
- package/models/trace/handlers/FlowsHandler.js +47 -55
- package/models/trace/handlers/FlowsHandler.js.map +1 -1
- package/models/trace/handlers/InitiatorsHandler.d.ts +11 -0
- package/models/trace/handlers/InitiatorsHandler.js +33 -25
- package/models/trace/handlers/InitiatorsHandler.js.map +1 -1
- package/models/trace/handlers/LargestImagePaintHandler.d.ts +0 -2
- package/models/trace/handlers/LargestImagePaintHandler.js +27 -24
- package/models/trace/handlers/LargestImagePaintHandler.js.map +1 -1
- package/models/trace/handlers/LayoutShiftsHandler.d.ts +2 -2
- package/models/trace/handlers/LayoutShiftsHandler.js +3 -2
- package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
- package/models/trace/handlers/MetaHandler.d.ts +2 -2
- package/models/trace/handlers/MetaHandler.js +1 -1
- package/models/trace/handlers/MetaHandler.js.map +1 -1
- package/models/trace/handlers/ModelHandlers.d.ts +4 -1
- package/models/trace/handlers/ModelHandlers.js +4 -1
- package/models/trace/handlers/ModelHandlers.js.map +1 -1
- package/models/trace/handlers/NetworkRequestsHandler.d.ts +2 -0
- package/models/trace/handlers/NetworkRequestsHandler.js +21 -0
- package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
- package/models/trace/handlers/PageLoadMetricsHandler.d.ts +2 -2
- package/models/trace/handlers/PageLoadMetricsHandler.js +9 -9
- package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -1
- package/models/trace/handlers/RendererHandler.d.ts +4 -0
- package/models/trace/handlers/RendererHandler.js +33 -2
- package/models/trace/handlers/RendererHandler.js.map +1 -1
- package/models/trace/handlers/SamplesHandler.d.ts +2 -2
- package/models/trace/handlers/SamplesHandler.js +3 -3
- package/models/trace/handlers/SamplesHandler.js.map +1 -1
- package/models/trace/handlers/ServerTimingsHandler.js +2 -2
- package/models/trace/handlers/ServerTimingsHandler.js.map +1 -1
- package/models/trace/handlers/Threads.d.ts +1 -0
- package/models/trace/handlers/Threads.js +8 -0
- package/models/trace/handlers/Threads.js.map +1 -1
- package/models/trace/handlers/UserInteractionsHandler.js +5 -6
- package/models/trace/handlers/UserInteractionsHandler.js.map +1 -1
- package/models/trace/handlers/UserTimingsHandler.d.ts +1 -1
- package/models/trace/handlers/UserTimingsHandler.js +1 -1
- package/models/trace/handlers/UserTimingsHandler.js.map +1 -1
- package/models/trace/handlers/WarningsHandler.js +2 -2
- package/models/trace/handlers/WarningsHandler.js.map +1 -1
- package/models/trace/handlers/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/handlers/handlers-tsconfig.json +9 -1
- package/models/trace/handlers/handlers.d.ts +1 -0
- package/models/trace/handlers/handlers.js +1 -0
- package/models/trace/handlers/handlers.js.map +1 -1
- package/models/trace/handlers/helpers.d.ts +19 -0
- package/models/trace/handlers/helpers.js +123 -0
- package/models/trace/handlers/helpers.js.map +1 -0
- package/models/trace/helpers/SamplesIntegrator.js +2 -2
- package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
- package/models/trace/helpers/SyntheticEvents.js +1 -1
- package/models/trace/helpers/SyntheticEvents.js.map +1 -1
- package/models/trace/helpers/Timing.d.ts +5 -6
- package/models/trace/helpers/Timing.js +22 -31
- package/models/trace/helpers/Timing.js.map +1 -1
- package/models/trace/helpers/Trace.d.ts +24 -10
- package/models/trace/helpers/Trace.js +53 -6
- package/models/trace/helpers/Trace.js.map +1 -1
- package/models/trace/helpers/TreeHelpers.d.ts +0 -31
- package/models/trace/helpers/TreeHelpers.js +1 -142
- package/models/trace/helpers/TreeHelpers.js.map +1 -1
- package/models/trace/helpers/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/helpers/helpers-tsconfig.json +2 -1
- package/models/trace/insights/CLSCulprits.js +1 -2
- package/models/trace/insights/CLSCulprits.js.map +1 -1
- package/models/trace/insights/Common.d.ts +38 -1
- package/models/trace/insights/Common.js +123 -0
- package/models/trace/insights/Common.js.map +1 -1
- package/models/trace/insights/DOMSize.d.ts +9 -0
- package/models/trace/insights/DOMSize.js +102 -0
- package/models/trace/insights/DOMSize.js.map +1 -0
- package/models/trace/insights/DocumentLatency.js +1 -1
- package/models/trace/insights/DocumentLatency.js.map +1 -1
- package/models/trace/insights/FontDisplay.js +1 -1
- package/models/trace/insights/FontDisplay.js.map +1 -1
- package/models/trace/insights/ImageDelivery.d.ts +22 -4
- package/models/trace/insights/ImageDelivery.js +76 -6
- package/models/trace/insights/ImageDelivery.js.map +1 -1
- package/models/trace/insights/LCPDiscovery.js +2 -2
- package/models/trace/insights/LCPDiscovery.js.map +1 -1
- package/models/trace/insights/LCPPhases.js +7 -7
- package/models/trace/insights/LCPPhases.js.map +1 -1
- package/models/trace/insights/Models.d.ts +1 -0
- package/models/trace/insights/Models.js +1 -0
- package/models/trace/insights/Models.js.map +1 -1
- package/models/trace/insights/Statistics.d.ts +14 -0
- package/models/trace/insights/Statistics.js +86 -0
- package/models/trace/insights/Statistics.js.map +1 -0
- package/models/trace/insights/ThirdParties.d.ts +2 -2
- package/models/trace/insights/ThirdParties.js +5 -4
- package/models/trace/insights/ThirdParties.js.map +1 -1
- package/models/trace/insights/Viewport.js +2 -2
- package/models/trace/insights/Viewport.js.map +1 -1
- package/models/trace/insights/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/insights/insights-tsconfig.json +4 -1
- package/models/trace/insights/insights.d.ts +1 -0
- package/models/trace/insights/insights.js +1 -0
- package/models/trace/insights/insights.js.map +1 -1
- package/models/trace/insights/types.d.ts +4 -3
- package/models/trace/insights/types.js.map +1 -1
- package/models/trace/lantern/core/NetworkAnalyzer.d.ts +2 -2
- package/models/trace/lantern/core/NetworkAnalyzer.js +2 -3
- package/models/trace/lantern/core/NetworkAnalyzer.js.map +1 -1
- package/models/trace/lantern/core/core-tsconfig.json +2 -1
- package/models/trace/lantern/core/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/lantern/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/lantern/graph/PageDependencyGraph.js +0 -1
- package/models/trace/lantern/graph/PageDependencyGraph.js.map +1 -1
- package/models/trace/lantern/graph/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/lantern/graph/graph-tsconfig.json +2 -1
- package/models/trace/lantern/lantern-tsconfig.json +2 -1
- package/models/trace/lantern/metrics/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/lantern/metrics/metrics-tsconfig.json +2 -1
- package/models/trace/lantern/simulation/DNSCache.d.ts +2 -2
- package/models/trace/lantern/simulation/DNSCache.js.map +1 -1
- package/models/trace/lantern/simulation/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/lantern/simulation/simulation-tsconfig.json +2 -1
- package/models/trace/lantern/types/Lantern.d.ts +10 -10
- package/models/trace/lantern/types/Lantern.js.map +1 -1
- package/models/trace/lantern/types/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/lantern/types/types-tsconfig.json +2 -1
- package/models/trace/root-causes/LayoutShift.d.ts +6 -6
- package/models/trace/root-causes/LayoutShift.js +1 -1
- package/models/trace/root-causes/LayoutShift.js.map +1 -1
- package/models/trace/root-causes/RootCauses.d.ts +2 -2
- package/models/trace/root-causes/RootCauses.js.map +1 -1
- package/models/trace/root-causes/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/root-causes/root-causes-tsconfig.json +2 -1
- package/models/trace/trace-tsconfig.json +2 -1
- package/models/trace/types/Configuration.d.ts +2 -2
- package/models/trace/types/Configuration.js.map +1 -1
- package/models/trace/types/Extensions.d.ts +3 -3
- package/models/trace/types/Extensions.js.map +1 -1
- package/models/trace/types/File.d.ts +11 -11
- package/models/trace/types/File.js.map +1 -1
- package/models/trace/types/Timing.js.map +1 -1
- package/models/trace/types/TraceEvents.d.ts +107 -31
- package/models/trace/types/TraceEvents.js +34 -14
- package/models/trace/types/TraceEvents.js.map +1 -1
- package/models/trace/types/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -1
- package/models/trace/types/types-tsconfig.json +2 -1
- package/package.json +1 -1
- package/test/test-trace-engine.mjs +8 -7
|
@@ -24,6 +24,7 @@ export interface ParseOptions {
|
|
|
24
24
|
* @default false
|
|
25
25
|
*/
|
|
26
26
|
isCPUProfile?: boolean;
|
|
27
|
+
metadata?: Types.File.MetaData;
|
|
27
28
|
}
|
|
28
29
|
export declare class TraceProcessor extends EventTarget {
|
|
29
30
|
#private;
|
|
@@ -34,6 +35,11 @@ export declare class TraceProcessor extends EventTarget {
|
|
|
34
35
|
parse(traceEvents: readonly Types.Events.Event[], options: ParseOptions): Promise<void>;
|
|
35
36
|
get parsedTrace(): Handlers.Types.ParsedTrace | null;
|
|
36
37
|
get insights(): Insights.Types.TraceInsightSets | null;
|
|
38
|
+
/**
|
|
39
|
+
* Sort the insight models based on the impact of each insight's estimated savings, additionally weighted by the
|
|
40
|
+
* worst metrics according to field data (if present).
|
|
41
|
+
*/
|
|
42
|
+
sortInsightSet(insights: Insights.Types.TraceInsightSets, insightSet: Insights.Types.InsightSet, metadata: Types.File.MetaData | null): void;
|
|
37
43
|
}
|
|
38
44
|
/**
|
|
39
45
|
* Some Handlers need data provided by others. Dependencies of a handler handler are
|
|
@@ -120,7 +120,7 @@ export class TraceProcessor extends EventTarget {
|
|
|
120
120
|
this.#status = "PARSING" /* Status.PARSING */;
|
|
121
121
|
await this.#computeParsedTrace(traceEvents);
|
|
122
122
|
if (this.#data && !options.isCPUProfile) { // We do not calculate insights for CPU Profiles.
|
|
123
|
-
this.#computeInsights(this.#data, traceEvents);
|
|
123
|
+
this.#computeInsights(this.#data, traceEvents, options);
|
|
124
124
|
}
|
|
125
125
|
this.#status = "FINISHED_PARSING" /* Status.FINISHED_PARSING */;
|
|
126
126
|
}
|
|
@@ -266,7 +266,87 @@ export class TraceProcessor extends EventTarget {
|
|
|
266
266
|
};
|
|
267
267
|
return { graph, simulator, metrics };
|
|
268
268
|
}
|
|
269
|
-
|
|
269
|
+
/**
|
|
270
|
+
* Sort the insight models based on the impact of each insight's estimated savings, additionally weighted by the
|
|
271
|
+
* worst metrics according to field data (if present).
|
|
272
|
+
*/
|
|
273
|
+
sortInsightSet(insights, insightSet, metadata) {
|
|
274
|
+
// The initial order of the insights is alphabetical, based on `front_end/models/trace/insights/Models.ts`.
|
|
275
|
+
// The order here provides a baseline that groups insights in a more logical way.
|
|
276
|
+
const baselineOrder = {
|
|
277
|
+
InteractionToNextPaint: null,
|
|
278
|
+
LCPPhases: null,
|
|
279
|
+
LCPDiscovery: null,
|
|
280
|
+
CLSCulprits: null,
|
|
281
|
+
RenderBlocking: null,
|
|
282
|
+
ImageDelivery: null,
|
|
283
|
+
DocumentLatency: null,
|
|
284
|
+
FontDisplay: null,
|
|
285
|
+
Viewport: null,
|
|
286
|
+
DOMSize: null,
|
|
287
|
+
ThirdParties: null,
|
|
288
|
+
SlowCSSSelector: null,
|
|
289
|
+
};
|
|
290
|
+
// Determine the weights for each metric based on field data, utilizing the same scoring curve that Lighthouse uses.
|
|
291
|
+
const weights = Insights.Common.calculateMetricWeightsForSorting(insightSet, metadata);
|
|
292
|
+
// Normalize the estimated savings to a single number, weighted by its relative impact
|
|
293
|
+
// to the page experience based on the same scoring curve that Lighthouse uses.
|
|
294
|
+
const observedLcp = Insights.Common.getLCP(insights, insightSet.id)?.value;
|
|
295
|
+
const observedCls = Insights.Common.getCLS(insights, insightSet.id).value;
|
|
296
|
+
// INP is special - if users did not interact with the page, we'll have no INP, but we should still
|
|
297
|
+
// be able to prioritize insights based on this metric. When we observe no interaction, instead use
|
|
298
|
+
// a default value for the baseline INP.
|
|
299
|
+
const observedInp = Insights.Common.getINP(insights, insightSet.id)?.value ?? 200;
|
|
300
|
+
const observedLcpScore = observedLcp !== undefined ? Insights.Common.evaluateLCPMetricScore(observedLcp) : undefined;
|
|
301
|
+
const observedInpScore = Insights.Common.evaluateINPMetricScore(observedInp);
|
|
302
|
+
const observedClsScore = Insights.Common.evaluateCLSMetricScore(observedCls);
|
|
303
|
+
const insightToSortingRank = new Map();
|
|
304
|
+
for (const [name, model] of Object.entries(insightSet.model)) {
|
|
305
|
+
const lcp = model.metricSavings?.LCP ?? 0;
|
|
306
|
+
const inp = model.metricSavings?.INP ?? 0;
|
|
307
|
+
const cls = model.metricSavings?.CLS ?? 0;
|
|
308
|
+
const lcpPostSavings = observedLcp !== undefined ? Math.max(0, observedLcp - lcp) : undefined;
|
|
309
|
+
const inpPostSavings = Math.max(0, observedInp - inp);
|
|
310
|
+
const clsPostSavings = Math.max(0, observedCls - cls);
|
|
311
|
+
let score = 0;
|
|
312
|
+
if (weights.lcp && lcp && observedLcpScore !== undefined && lcpPostSavings !== undefined) {
|
|
313
|
+
score += weights.lcp * (Insights.Common.evaluateLCPMetricScore(lcpPostSavings) - observedLcpScore);
|
|
314
|
+
}
|
|
315
|
+
if (weights.inp && inp && observedInpScore !== undefined) {
|
|
316
|
+
score += weights.inp * (Insights.Common.evaluateINPMetricScore(inpPostSavings) - observedInpScore);
|
|
317
|
+
}
|
|
318
|
+
if (weights.cls && cls && observedClsScore !== undefined) {
|
|
319
|
+
score += weights.cls * (Insights.Common.evaluateCLSMetricScore(clsPostSavings) - observedClsScore);
|
|
320
|
+
}
|
|
321
|
+
insightToSortingRank.set(name, score);
|
|
322
|
+
}
|
|
323
|
+
// Now perform the actual sorting.
|
|
324
|
+
const baselineOrderKeys = Object.keys(baselineOrder);
|
|
325
|
+
const orderedKeys = Object.keys(insightSet.model);
|
|
326
|
+
orderedKeys.sort((a, b) => {
|
|
327
|
+
const a1 = baselineOrderKeys.indexOf(a);
|
|
328
|
+
const b1 = baselineOrderKeys.indexOf(b);
|
|
329
|
+
if (a1 >= 0 && b1 >= 0) {
|
|
330
|
+
return a1 - b1;
|
|
331
|
+
}
|
|
332
|
+
if (a1 >= 0) {
|
|
333
|
+
return -1;
|
|
334
|
+
}
|
|
335
|
+
if (b1 >= 0) {
|
|
336
|
+
return 1;
|
|
337
|
+
}
|
|
338
|
+
return 0;
|
|
339
|
+
});
|
|
340
|
+
orderedKeys.sort((a, b) => (insightToSortingRank.get(b) ?? 0) - (insightToSortingRank.get(a) ?? 0));
|
|
341
|
+
const newModel = {};
|
|
342
|
+
for (const key of orderedKeys) {
|
|
343
|
+
const model = insightSet.model[key];
|
|
344
|
+
// @ts-expect-error Maybe someday typescript will be powerful enough to handle this.
|
|
345
|
+
newModel[key] = model;
|
|
346
|
+
}
|
|
347
|
+
insightSet.model = newModel;
|
|
348
|
+
}
|
|
349
|
+
#computeInsightSet(insights, parsedTrace, insightRunners, context, options) {
|
|
270
350
|
const model = {};
|
|
271
351
|
for (const [name, insight] of Object.entries(insightRunners)) {
|
|
272
352
|
let insightResult;
|
|
@@ -297,7 +377,7 @@ export class TraceProcessor extends EventTarget {
|
|
|
297
377
|
// happen for real traces.
|
|
298
378
|
return;
|
|
299
379
|
}
|
|
300
|
-
const
|
|
380
|
+
const insightSet = {
|
|
301
381
|
id,
|
|
302
382
|
url,
|
|
303
383
|
navigation,
|
|
@@ -305,12 +385,13 @@ export class TraceProcessor extends EventTarget {
|
|
|
305
385
|
bounds: context.bounds,
|
|
306
386
|
model,
|
|
307
387
|
};
|
|
308
|
-
insights.set(
|
|
388
|
+
insights.set(insightSet.id, insightSet);
|
|
389
|
+
this.sortInsightSet(insights, insightSet, options.metadata ?? null);
|
|
309
390
|
}
|
|
310
391
|
/**
|
|
311
392
|
* Run all the insights and set the result to `#insights`.
|
|
312
393
|
*/
|
|
313
|
-
#computeInsights(parsedTrace, traceEvents) {
|
|
394
|
+
#computeInsights(parsedTrace, traceEvents, options) {
|
|
314
395
|
this.#insights = new Map();
|
|
315
396
|
const enabledInsightRunners = TraceProcessor.getEnabledInsightRunners(parsedTrace);
|
|
316
397
|
const navigations = parsedTrace.Meta.mainFrameNavigations.filter(navigation => navigation.args.frame && navigation.args.data?.navigationId);
|
|
@@ -320,13 +401,13 @@ export class TraceProcessor extends EventTarget {
|
|
|
320
401
|
if (navigations.length) {
|
|
321
402
|
const bounds = Helpers.Timing.traceWindowFromMicroSeconds(parsedTrace.Meta.traceBounds.min, navigations[0].ts);
|
|
322
403
|
// When using "Record and reload" option, it typically takes ~5ms. So use 50ms to be safe.
|
|
323
|
-
const threshold = Helpers.Timing.
|
|
404
|
+
const threshold = Helpers.Timing.milliToMicro(50);
|
|
324
405
|
if (bounds.range > threshold) {
|
|
325
406
|
const context = {
|
|
326
407
|
bounds,
|
|
327
408
|
frameId: parsedTrace.Meta.mainFrameId,
|
|
328
409
|
};
|
|
329
|
-
this.#
|
|
410
|
+
this.#computeInsightSet(this.#insights, parsedTrace, enabledInsightRunners, context, options);
|
|
330
411
|
}
|
|
331
412
|
// If threshold is not met, then the very beginning of the trace is ignored by the insights engine.
|
|
332
413
|
}
|
|
@@ -335,7 +416,7 @@ export class TraceProcessor extends EventTarget {
|
|
|
335
416
|
bounds: parsedTrace.Meta.traceBounds,
|
|
336
417
|
frameId: parsedTrace.Meta.mainFrameId,
|
|
337
418
|
};
|
|
338
|
-
this.#
|
|
419
|
+
this.#computeInsightSet(this.#insights, parsedTrace, enabledInsightRunners, context, options);
|
|
339
420
|
}
|
|
340
421
|
// Now run the insights for each navigation in isolation.
|
|
341
422
|
for (const [i, navigation] of navigations.entries()) {
|
|
@@ -381,7 +462,7 @@ export class TraceProcessor extends EventTarget {
|
|
|
381
462
|
navigationId,
|
|
382
463
|
lantern,
|
|
383
464
|
};
|
|
384
|
-
this.#
|
|
465
|
+
this.#computeInsightSet(this.#insights, parsedTrace, enabledInsightRunners, context, options);
|
|
385
466
|
}
|
|
386
467
|
}
|
|
387
468
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Processor.js","sourceRoot":"","sources":["../../../../../../front_end/models/trace/Processor.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAC7B,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,sBAAsB,MAAM,6BAA6B,CAAC;AAEtE,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAS1C,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAE7B;IADnB,MAAM,CAAU,SAAS,GAAG,oBAAoB,CAAC;IACjD,YAAmB,IAAuC,EAAE,OAAkB,EAAC,OAAO,EAAE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,OAAO,IAAI,CAAC;gBAC9B,CAAC;YACH,CAAC;YACD,SAAS,IAAI,WAAW,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,mDAAmD,SAAS,EAAE,CAAC,CAAC;QAClF,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzB,MAAM,OAAO,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;QAC3C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO;QACT,CAAC;QACD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;QAC9B,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC7B,CAAC;QACD,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC,CAAC;IAEF,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;QACrD,YAAY,CAAC,WAAyC,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,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.\nimport * as Handlers from './handlers/handlers.js';\nimport * as Helpers from './helpers/helpers.js';\nimport * as Insights from './insights/insights.js';\nimport * as Lantern from './lantern/lantern.js';\nimport * as LanternComputationData from './LanternComputationData.js';\nimport type * as Model from './ModelImpl.js';\nimport * as Types from './types/types.js';\n\nconst enum Status {\n IDLE = 'IDLE',\n PARSING = 'PARSING',\n FINISHED_PARSING = 'FINISHED_PARSING',\n ERRORED_WHILE_PARSING = 'ERRORED_WHILE_PARSING',\n}\n\nexport class TraceParseProgressEvent extends Event {\n static readonly eventName = 'traceparseprogress';\n constructor(public data: Model.TraceParseEventProgressData, init: EventInit = {bubbles: true}) {\n super(TraceParseProgressEvent.eventName, init);\n }\n}\n\n/**\n * Parsing a trace can take time. On large traces we see a breakdown of time like so:\n * - handleEvent() loop: ~20%\n * - finalize() loop: ~60%\n * - shallowClone calls: ~20%\n * The numbers below are set so we can report a progress percentage of [0...1]\n */\nconst enum ProgressPhase {\n HANDLE_EVENT = 0.2,\n FINALIZE = 0.8,\n CLONE = 1.0,\n}\nfunction calculateProgress(value: number, phase: ProgressPhase): number {\n // Finalize values should be [0.2...0.8]\n if (phase === ProgressPhase.FINALIZE) {\n return (value * (ProgressPhase.FINALIZE - ProgressPhase.HANDLE_EVENT)) + ProgressPhase.HANDLE_EVENT;\n }\n return value * phase;\n}\n\ndeclare global {\n interface HTMLElementEventMap {\n [TraceParseProgressEvent.eventName]: TraceParseProgressEvent;\n }\n}\n\nexport interface ParseOptions {\n /**\n * If the trace was just recorded on the current page, rather than an imported file.\n * TODO(paulirish): Maybe remove. This is currently unused by the Processor and Handlers\n * @default false\n */\n isFreshRecording?: boolean;\n /**\n * If the trace is a CPU Profile rather than a Chrome tracing trace.\n * @default false\n */\n isCPUProfile?: boolean;\n}\n\nexport class TraceProcessor extends EventTarget {\n // We force the Meta handler to be enabled, so the TraceHandlers type here is\n // the model handlers the user passes in and the Meta handler.\n readonly #traceHandlers: Partial<Handlers.Types.Handlers>;\n #status = Status.IDLE;\n #modelConfiguration = Types.Configuration.defaults();\n #data: Handlers.Types.ParsedTrace|null = null;\n #insights: Insights.Types.TraceInsightSets|null = null;\n\n static createWithAllHandlers(): TraceProcessor {\n return new TraceProcessor(Handlers.ModelHandlers, Types.Configuration.defaults());\n }\n\n static getEnabledInsightRunners(parsedTrace: Handlers.Types.ParsedTrace): Partial<Insights.Types.InsightModelsType> {\n const enabledInsights = {} as Insights.Types.InsightModelsType;\n for (const [name, insight] of Object.entries(Insights.Models)) {\n const deps = insight.deps();\n if (deps.some(dep => !parsedTrace[dep])) {\n continue;\n }\n Object.assign(enabledInsights, {[name]: insight});\n }\n return enabledInsights;\n }\n\n constructor(traceHandlers: Partial<Handlers.Types.Handlers>, modelConfiguration?: Types.Configuration.Configuration) {\n super();\n\n this.#verifyHandlers(traceHandlers);\n this.#traceHandlers = {\n Meta: Handlers.ModelHandlers.Meta,\n ...traceHandlers,\n };\n if (modelConfiguration) {\n this.#modelConfiguration = modelConfiguration;\n }\n this.#passConfigToHandlers();\n }\n\n #passConfigToHandlers(): void {\n for (const handler of Object.values(this.#traceHandlers)) {\n // Bit of an odd double check, but without this TypeScript refuses to let\n // you call the function as it thinks it might be undefined.\n if ('handleUserConfig' in handler && handler.handleUserConfig) {\n handler.handleUserConfig(this.#modelConfiguration);\n }\n }\n }\n\n /**\n * When the user passes in a set of handlers, we want to ensure that we have all\n * the required handlers. Handlers can depend on other handlers, so if the user\n * passes in FooHandler which depends on BarHandler, they must also pass in\n * BarHandler too. This method verifies that all dependencies are met, and\n * throws if not.\n **/\n #verifyHandlers(providedHandlers: Partial<Handlers.Types.Handlers>): void {\n // Tiny optimisation: if the amount of provided handlers matches the amount\n // of handlers in the Handlers.ModelHandlers object, that means that the\n // user has passed in every handler we have. So therefore they cannot have\n // missed any, and there is no need to iterate through the handlers and\n // check the dependencies.\n if (Object.keys(providedHandlers).length === Object.keys(Handlers.ModelHandlers).length) {\n return;\n }\n const requiredHandlerKeys: Set<Handlers.Types.HandlerName> = new Set();\n for (const [handlerName, handler] of Object.entries(providedHandlers)) {\n requiredHandlerKeys.add(handlerName as Handlers.Types.HandlerName);\n const deps = 'deps' in handler ? handler.deps() : [];\n for (const depName of deps) {\n requiredHandlerKeys.add(depName);\n }\n }\n\n const providedHandlerKeys = new Set(Object.keys(providedHandlers));\n // We always force the Meta handler to be enabled when creating the\n // Processor, so if it is missing from the set the user gave us that is OK,\n // as we will have enabled it anyway.\n requiredHandlerKeys.delete('Meta');\n\n for (const requiredKey of requiredHandlerKeys) {\n if (!providedHandlerKeys.has(requiredKey)) {\n throw new Error(`Required handler ${requiredKey} not provided.`);\n }\n }\n }\n\n reset(): void {\n if (this.#status === Status.PARSING) {\n throw new Error('Trace processor can\\'t reset while parsing.');\n }\n\n const handlers = Object.values(this.#traceHandlers);\n for (const handler of handlers) {\n handler.reset();\n }\n\n this.#data = null;\n this.#insights = null;\n this.#status = Status.IDLE;\n }\n\n async parse(traceEvents: readonly Types.Events.Event[], options: ParseOptions): Promise<void> {\n if (this.#status !== Status.IDLE) {\n throw new Error(`Trace processor can't start parsing when not idle. Current state: ${this.#status}`);\n }\n try {\n this.#status = Status.PARSING;\n await this.#computeParsedTrace(traceEvents);\n if (this.#data && !options.isCPUProfile) { // We do not calculate insights for CPU Profiles.\n this.#computeInsights(this.#data, traceEvents);\n }\n this.#status = Status.FINISHED_PARSING;\n } catch (e) {\n this.#status = Status.ERRORED_WHILE_PARSING;\n throw e;\n }\n }\n\n /**\n * Run all the handlers and set the result to `#data`.\n */\n async #computeParsedTrace(traceEvents: readonly Types.Events.Event[]): Promise<void> {\n /**\n * We want to yield regularly to maintain responsiveness. If we yield too often, we're wasting idle time.\n * We could do this by checking `performance.now()` regularly, but it's an expensive call in such a hot loop.\n * `eventsPerChunk` is an approximated proxy metric.\n * But how big a chunk? We're aiming for long tasks that are no smaller than 100ms and not bigger than 200ms.\n * It's CPU dependent, so it should be calibrated on oldish hardware.\n * Illustration of a previous change to `eventsPerChunk`: https://imgur.com/wzp8BnR\n */\n const eventsPerChunk = 50_000;\n // Convert to array so that we are able to iterate all handlers multiple times.\n const sortedHandlers = [...sortHandlers(this.#traceHandlers).values()];\n\n // Reset.\n for (const handler of sortedHandlers) {\n handler.reset();\n }\n\n // Handle each event.\n for (let i = 0; i < traceEvents.length; ++i) {\n // Every so often we take a break just to render.\n if (i % eventsPerChunk === 0 && i) {\n // Take the opportunity to provide status update events.\n const percent = calculateProgress(i / traceEvents.length, ProgressPhase.HANDLE_EVENT);\n this.dispatchEvent(new TraceParseProgressEvent({percent}));\n // TODO(paulirish): consider using `scheduler.yield()` or `scheduler.postTask(() => {}, {priority: 'user-blocking'})`\n await new Promise(resolve => setTimeout(resolve, 0));\n }\n const event = traceEvents[i];\n for (let j = 0; j < sortedHandlers.length; ++j) {\n sortedHandlers[j].handleEvent(event);\n }\n }\n\n // Finalize.\n for (const [i, handler] of sortedHandlers.entries()) {\n if (handler.finalize) {\n // Yield to the UI because finalize() calls can be expensive\n // TODO(jacktfranklin): consider using `scheduler.yield()` or `scheduler.postTask(() => {}, {priority: 'user-blocking'})`\n await new Promise(resolve => setTimeout(resolve, 0));\n await handler.finalize();\n }\n const percent = calculateProgress(i / sortedHandlers.length, ProgressPhase.FINALIZE);\n this.dispatchEvent(new TraceParseProgressEvent({percent}));\n }\n\n // Handlers that depend on other handlers do so via .data(), which used to always\n // return a shallow clone of its internal data structures. However, that pattern\n // easily results in egregious amounts of allocation. Now .data() does not do any\n // cloning, and it happens here instead so that users of the trace processor may\n // still assume that the parsed data is theirs.\n // See: crbug/41484172\n const shallowClone = (value: unknown, recurse = true): unknown => {\n if (value instanceof Map) {\n return new Map(value);\n }\n if (value instanceof Set) {\n return new Set(value);\n }\n if (Array.isArray(value)) {\n return [...value];\n }\n if (typeof value === 'object' && value && recurse) {\n const obj: Record<string, unknown> = {};\n for (const [key, v] of Object.entries(value)) {\n obj[key] = shallowClone(v, false);\n }\n return obj;\n }\n return value;\n };\n\n const parsedTrace = {};\n for (const [name, handler] of Object.entries(this.#traceHandlers)) {\n const data = shallowClone(handler.data());\n Object.assign(parsedTrace, {[name]: data});\n }\n this.dispatchEvent(new TraceParseProgressEvent({percent: ProgressPhase.CLONE}));\n\n this.#data = parsedTrace as Handlers.Types.ParsedTrace;\n }\n\n get parsedTrace(): Handlers.Types.ParsedTrace|null {\n if (this.#status !== Status.FINISHED_PARSING) {\n return null;\n }\n\n return this.#data;\n }\n\n get insights(): Insights.Types.TraceInsightSets|null {\n if (this.#status !== Status.FINISHED_PARSING) {\n return null;\n }\n\n return this.#insights;\n }\n\n #createLanternContext(\n parsedTrace: Handlers.Types.ParsedTrace, traceEvents: readonly Types.Events.Event[], frameId: string,\n navigationId: string): Insights.Types.LanternContext|undefined {\n // Check for required handlers.\n if (!parsedTrace.NetworkRequests || !parsedTrace.Workers || !parsedTrace.PageLoadMetrics) {\n return;\n }\n if (!parsedTrace.NetworkRequests.byTime.length) {\n throw new Lantern.Core.LanternError('No network requests found in trace');\n }\n\n const navStarts = parsedTrace.Meta.navigationsByFrameId.get(frameId);\n const navStartIndex = navStarts?.findIndex(n => n.args.data?.navigationId === navigationId);\n if (!navStarts || navStartIndex === undefined || navStartIndex === -1) {\n throw new Lantern.Core.LanternError('Could not find navigation start');\n }\n\n const startTime = navStarts[navStartIndex].ts;\n const endTime = navStartIndex + 1 < navStarts.length ? navStarts[navStartIndex + 1].ts : Number.POSITIVE_INFINITY;\n const boundedTraceEvents = traceEvents.filter(e => e.ts >= startTime && e.ts < endTime);\n\n // Lantern.Types.TraceEvent and Types.Events.Event represent the same\n // object - a trace event - but one is more flexible than the other. It should be safe to cast between them.\n const trace: Lantern.Types.Trace = {\n traceEvents: boundedTraceEvents as unknown as Lantern.Types.TraceEvent[],\n };\n\n const requests = LanternComputationData.createNetworkRequests(trace, parsedTrace, startTime, endTime);\n const graph = LanternComputationData.createGraph(requests, trace, parsedTrace);\n const processedNavigation = LanternComputationData.createProcessedNavigation(parsedTrace, frameId, navigationId);\n\n const networkAnalysis = Lantern.Core.NetworkAnalyzer.analyze(requests);\n if (!networkAnalysis) {\n return;\n }\n\n const simulator: Lantern.Simulation.Simulator<Types.Events.SyntheticNetworkRequest> =\n Lantern.Simulation.Simulator.createSimulator({\n // TODO(crbug.com/372674229): if devtools throttling was on, does this network analysis capture\n // that? Do we need to set 'devtools' throttlingMethod?\n networkAnalysis,\n throttlingMethod: 'provided',\n });\n\n const computeData = {graph, simulator, processedNavigation};\n const fcpResult = Lantern.Metrics.FirstContentfulPaint.compute(computeData);\n const lcpResult = Lantern.Metrics.LargestContentfulPaint.compute(computeData, {fcpResult});\n const interactiveResult = Lantern.Metrics.Interactive.compute(computeData, {lcpResult});\n const tbtResult = Lantern.Metrics.TotalBlockingTime.compute(computeData, {fcpResult, interactiveResult});\n const metrics = {\n firstContentfulPaint: fcpResult,\n interactive: interactiveResult,\n largestContentfulPaint: lcpResult,\n totalBlockingTime: tbtResult,\n };\n\n return {graph, simulator, metrics};\n }\n\n #computeInsightSets(\n insights: Insights.Types.TraceInsightSets, parsedTrace: Handlers.Types.ParsedTrace,\n insightRunners: Partial<typeof Insights.Models>, context: Insights.Types.InsightSetContext): void {\n const model = {} as Insights.Types.InsightSet['model'];\n\n for (const [name, insight] of Object.entries(insightRunners)) {\n let insightResult;\n try {\n insightResult = insight.generateInsight(parsedTrace, context);\n } catch (err) {\n insightResult = err;\n }\n Object.assign(model, {[name]: insightResult});\n }\n\n let id, urlString, navigation;\n if (context.navigation) {\n id = context.navigationId;\n urlString = context.navigation.args.data?.documentLoaderURL ?? parsedTrace.Meta.mainFrameURL;\n navigation = context.navigation;\n } else {\n id = Types.Events.NO_NAVIGATION;\n urlString = parsedTrace.Meta.mainFrameURL;\n }\n\n let url;\n try {\n url = new URL(urlString);\n } catch {\n // We're pretty sure this only happens for our test fixture: missing-url.json.gz. Shouldn't\n // happen for real traces.\n return;\n }\n\n const insightSets = {\n id,\n url,\n navigation,\n frameId: context.frameId,\n bounds: context.bounds,\n model,\n };\n insights.set(insightSets.id, insightSets);\n }\n\n /**\n * Run all the insights and set the result to `#insights`.\n */\n #computeInsights(parsedTrace: Handlers.Types.ParsedTrace, traceEvents: readonly Types.Events.Event[]): void {\n this.#insights = new Map();\n\n const enabledInsightRunners = TraceProcessor.getEnabledInsightRunners(parsedTrace);\n\n const navigations = parsedTrace.Meta.mainFrameNavigations.filter(\n navigation => navigation.args.frame && navigation.args.data?.navigationId);\n\n // Check if there is a meaningful chunk of work happening prior to the first navigation.\n // If so, we run the insights on that initial bounds.\n // Otherwise, there are no navigations and we do a no-navigation insights pass on the entire trace.\n if (navigations.length) {\n const bounds = Helpers.Timing.traceWindowFromMicroSeconds(parsedTrace.Meta.traceBounds.min, navigations[0].ts);\n // When using \"Record and reload\" option, it typically takes ~5ms. So use 50ms to be safe.\n const threshold = Helpers.Timing.millisecondsToMicroseconds(50 as Types.Timing.MilliSeconds);\n if (bounds.range > threshold) {\n const context: Insights.Types.InsightSetContext = {\n bounds,\n frameId: parsedTrace.Meta.mainFrameId,\n };\n this.#computeInsightSets(this.#insights, parsedTrace, enabledInsightRunners, context);\n }\n // If threshold is not met, then the very beginning of the trace is ignored by the insights engine.\n } else {\n const context: Insights.Types.InsightSetContext = {\n bounds: parsedTrace.Meta.traceBounds,\n frameId: parsedTrace.Meta.mainFrameId,\n };\n this.#computeInsightSets(this.#insights, parsedTrace, enabledInsightRunners, context);\n }\n\n // Now run the insights for each navigation in isolation.\n for (const [i, navigation] of navigations.entries()) {\n // The above filter guarantees these are present.\n const frameId = navigation.args.frame;\n const navigationId = navigation.args.data?.navigationId as string;\n\n // The lantern sub-context is optional on InsightSetContext, so not setting it is OK.\n // This is also a hedge against an error inside Lantern resulting in breaking the entire performance panel.\n // Additionally, many trace fixtures are too old to be processed by Lantern.\n let lantern;\n try {\n lantern = this.#createLanternContext(parsedTrace, traceEvents, frameId, navigationId);\n } catch (e) {\n // Don't allow an error in constructing the Lantern graphs to break the rest of the trace processor.\n // Log unexpected errors, but suppress anything that occurs from a trace being too old.\n // Otherwise tests using old fixtures become way too noisy.\n const expectedErrors = [\n 'mainDocumentRequest not found',\n 'missing metric scores for main frame',\n 'missing metric: FCP',\n 'missing metric: LCP',\n 'No network requests found in trace',\n 'Trace is too old',\n ];\n if (!(e instanceof Lantern.Core.LanternError)) {\n // If this wasn't a managed LanternError, the stack trace is likely needed for debugging.\n console.error(e);\n } else if (!expectedErrors.some(err => e.message === err)) {\n // To reduce noise from tests, only print errors that are not expected to occur because a trace is\n // too old (for which there is no single check).\n console.error(e);\n }\n }\n\n const min = navigation.ts;\n const max = i + 1 < navigations.length ? navigations[i + 1].ts : parsedTrace.Meta.traceBounds.max;\n const bounds = Helpers.Timing.traceWindowFromMicroSeconds(min, max);\n const context: Insights.Types.InsightSetContext = {\n bounds,\n frameId,\n navigation,\n navigationId,\n lantern,\n };\n\n this.#computeInsightSets(this.#insights, parsedTrace, enabledInsightRunners, context);\n }\n }\n}\n\n/**\n * Some Handlers need data provided by others. Dependencies of a handler handler are\n * declared in the `deps` field.\n * @returns A map from trace event handler name to trace event hander whose entries\n * iterate in such a way that each handler is visited after its dependencies.\n */\nexport function sortHandlers(traceHandlers: Partial<{[key in Handlers.Types.HandlerName]: Handlers.Types.Handler}>):\n Map<Handlers.Types.HandlerName, Handlers.Types.Handler> {\n const sortedMap = new Map<Handlers.Types.HandlerName, Handlers.Types.Handler>();\n const visited = new Set<Handlers.Types.HandlerName>();\n const visitHandler = (handlerName: Handlers.Types.HandlerName): void => {\n if (sortedMap.has(handlerName)) {\n return;\n }\n if (visited.has(handlerName)) {\n let stackPath = '';\n for (const handler of visited) {\n if (stackPath || handler === handlerName) {\n stackPath += `${handler}->`;\n }\n }\n stackPath += handlerName;\n throw new Error(`Found dependency cycle in trace event handlers: ${stackPath}`);\n }\n visited.add(handlerName);\n const handler = traceHandlers[handlerName];\n if (!handler) {\n return;\n }\n const deps = handler.deps?.();\n if (deps) {\n deps.forEach(visitHandler);\n }\n sortedMap.set(handlerName, handler);\n };\n\n for (const handlerName of Object.keys(traceHandlers)) {\n visitHandler(handlerName as Handlers.Types.HandlerName);\n }\n return sortedMap;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Processor.js","sourceRoot":"","sources":["../../../../../../front_end/models/trace/Processor.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAC7B,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,sBAAsB,MAAM,6BAA6B,CAAC;AAEtE,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AAa,CAAC,EAAE,CAAC;QACrD,YAAY,CAAC,WAAyC,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,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.\nimport * as Handlers from './handlers/handlers.js';\nimport * as Helpers from './helpers/helpers.js';\nimport * as Insights from './insights/insights.js';\nimport * as Lantern from './lantern/lantern.js';\nimport * as LanternComputationData from './LanternComputationData.js';\nimport type * as Model from './ModelImpl.js';\nimport * as Types from './types/types.js';\n\nconst enum Status {\n IDLE = 'IDLE',\n PARSING = 'PARSING',\n FINISHED_PARSING = 'FINISHED_PARSING',\n ERRORED_WHILE_PARSING = 'ERRORED_WHILE_PARSING',\n}\n\nexport class TraceParseProgressEvent extends Event {\n static readonly eventName = 'traceparseprogress';\n constructor(public data: Model.TraceParseEventProgressData, init: EventInit = {bubbles: true}) {\n super(TraceParseProgressEvent.eventName, init);\n }\n}\n\n/**\n * Parsing a trace can take time. On large traces we see a breakdown of time like so:\n * - handleEvent() loop: ~20%\n * - finalize() loop: ~60%\n * - shallowClone calls: ~20%\n * The numbers below are set so we can report a progress percentage of [0...1]\n */\nconst enum ProgressPhase {\n HANDLE_EVENT = 0.2,\n FINALIZE = 0.8,\n CLONE = 1.0,\n}\nfunction calculateProgress(value: number, phase: ProgressPhase): number {\n // Finalize values should be [0.2...0.8]\n if (phase === ProgressPhase.FINALIZE) {\n return (value * (ProgressPhase.FINALIZE - ProgressPhase.HANDLE_EVENT)) + ProgressPhase.HANDLE_EVENT;\n }\n return value * phase;\n}\n\ndeclare global {\n interface HTMLElementEventMap {\n [TraceParseProgressEvent.eventName]: TraceParseProgressEvent;\n }\n}\n\nexport interface ParseOptions {\n /**\n * If the trace was just recorded on the current page, rather than an imported file.\n * TODO(paulirish): Maybe remove. This is currently unused by the Processor and Handlers\n * @default false\n */\n isFreshRecording?: boolean;\n /**\n * If the trace is a CPU Profile rather than a Chrome tracing trace.\n * @default false\n */\n isCPUProfile?: boolean;\n metadata?: Types.File.MetaData;\n}\n\nexport class TraceProcessor extends EventTarget {\n // We force the Meta handler to be enabled, so the TraceHandlers type here is\n // the model handlers the user passes in and the Meta handler.\n readonly #traceHandlers: Partial<Handlers.Types.Handlers>;\n #status = Status.IDLE;\n #modelConfiguration = Types.Configuration.defaults();\n #data: Handlers.Types.ParsedTrace|null = null;\n #insights: Insights.Types.TraceInsightSets|null = null;\n\n static createWithAllHandlers(): TraceProcessor {\n return new TraceProcessor(Handlers.ModelHandlers, Types.Configuration.defaults());\n }\n\n static getEnabledInsightRunners(parsedTrace: Handlers.Types.ParsedTrace): Partial<Insights.Types.InsightModelsType> {\n const enabledInsights = {} as Insights.Types.InsightModelsType;\n for (const [name, insight] of Object.entries(Insights.Models)) {\n const deps = insight.deps();\n if (deps.some(dep => !parsedTrace[dep])) {\n continue;\n }\n Object.assign(enabledInsights, {[name]: insight});\n }\n return enabledInsights;\n }\n\n constructor(traceHandlers: Partial<Handlers.Types.Handlers>, modelConfiguration?: Types.Configuration.Configuration) {\n super();\n\n this.#verifyHandlers(traceHandlers);\n this.#traceHandlers = {\n Meta: Handlers.ModelHandlers.Meta,\n ...traceHandlers,\n };\n if (modelConfiguration) {\n this.#modelConfiguration = modelConfiguration;\n }\n this.#passConfigToHandlers();\n }\n\n #passConfigToHandlers(): void {\n for (const handler of Object.values(this.#traceHandlers)) {\n // Bit of an odd double check, but without this TypeScript refuses to let\n // you call the function as it thinks it might be undefined.\n if ('handleUserConfig' in handler && handler.handleUserConfig) {\n handler.handleUserConfig(this.#modelConfiguration);\n }\n }\n }\n\n /**\n * When the user passes in a set of handlers, we want to ensure that we have all\n * the required handlers. Handlers can depend on other handlers, so if the user\n * passes in FooHandler which depends on BarHandler, they must also pass in\n * BarHandler too. This method verifies that all dependencies are met, and\n * throws if not.\n **/\n #verifyHandlers(providedHandlers: Partial<Handlers.Types.Handlers>): void {\n // Tiny optimisation: if the amount of provided handlers matches the amount\n // of handlers in the Handlers.ModelHandlers object, that means that the\n // user has passed in every handler we have. So therefore they cannot have\n // missed any, and there is no need to iterate through the handlers and\n // check the dependencies.\n if (Object.keys(providedHandlers).length === Object.keys(Handlers.ModelHandlers).length) {\n return;\n }\n const requiredHandlerKeys: Set<Handlers.Types.HandlerName> = new Set();\n for (const [handlerName, handler] of Object.entries(providedHandlers)) {\n requiredHandlerKeys.add(handlerName as Handlers.Types.HandlerName);\n const deps = 'deps' in handler ? handler.deps() : [];\n for (const depName of deps) {\n requiredHandlerKeys.add(depName);\n }\n }\n\n const providedHandlerKeys = new Set(Object.keys(providedHandlers));\n // We always force the Meta handler to be enabled when creating the\n // Processor, so if it is missing from the set the user gave us that is OK,\n // as we will have enabled it anyway.\n requiredHandlerKeys.delete('Meta');\n\n for (const requiredKey of requiredHandlerKeys) {\n if (!providedHandlerKeys.has(requiredKey)) {\n throw new Error(`Required handler ${requiredKey} not provided.`);\n }\n }\n }\n\n reset(): void {\n if (this.#status === Status.PARSING) {\n throw new Error('Trace processor can\\'t reset while parsing.');\n }\n\n const handlers = Object.values(this.#traceHandlers);\n for (const handler of handlers) {\n handler.reset();\n }\n\n this.#data = null;\n this.#insights = null;\n this.#status = Status.IDLE;\n }\n\n async parse(traceEvents: readonly Types.Events.Event[], options: ParseOptions): Promise<void> {\n if (this.#status !== Status.IDLE) {\n throw new Error(`Trace processor can't start parsing when not idle. Current state: ${this.#status}`);\n }\n try {\n this.#status = Status.PARSING;\n await this.#computeParsedTrace(traceEvents);\n if (this.#data && !options.isCPUProfile) { // We do not calculate insights for CPU Profiles.\n this.#computeInsights(this.#data, traceEvents, options);\n }\n this.#status = Status.FINISHED_PARSING;\n } catch (e) {\n this.#status = Status.ERRORED_WHILE_PARSING;\n throw e;\n }\n }\n\n /**\n * Run all the handlers and set the result to `#data`.\n */\n async #computeParsedTrace(traceEvents: readonly Types.Events.Event[]): Promise<void> {\n /**\n * We want to yield regularly to maintain responsiveness. If we yield too often, we're wasting idle time.\n * We could do this by checking `performance.now()` regularly, but it's an expensive call in such a hot loop.\n * `eventsPerChunk` is an approximated proxy metric.\n * But how big a chunk? We're aiming for long tasks that are no smaller than 100ms and not bigger than 200ms.\n * It's CPU dependent, so it should be calibrated on oldish hardware.\n * Illustration of a previous change to `eventsPerChunk`: https://imgur.com/wzp8BnR\n */\n const eventsPerChunk = 50_000;\n // Convert to array so that we are able to iterate all handlers multiple times.\n const sortedHandlers = [...sortHandlers(this.#traceHandlers).values()];\n\n // Reset.\n for (const handler of sortedHandlers) {\n handler.reset();\n }\n\n // Handle each event.\n for (let i = 0; i < traceEvents.length; ++i) {\n // Every so often we take a break just to render.\n if (i % eventsPerChunk === 0 && i) {\n // Take the opportunity to provide status update events.\n const percent = calculateProgress(i / traceEvents.length, ProgressPhase.HANDLE_EVENT);\n this.dispatchEvent(new TraceParseProgressEvent({percent}));\n // TODO(paulirish): consider using `scheduler.yield()` or `scheduler.postTask(() => {}, {priority: 'user-blocking'})`\n await new Promise(resolve => setTimeout(resolve, 0));\n }\n const event = traceEvents[i];\n for (let j = 0; j < sortedHandlers.length; ++j) {\n sortedHandlers[j].handleEvent(event);\n }\n }\n\n // Finalize.\n for (const [i, handler] of sortedHandlers.entries()) {\n if (handler.finalize) {\n // Yield to the UI because finalize() calls can be expensive\n // TODO(jacktfranklin): consider using `scheduler.yield()` or `scheduler.postTask(() => {}, {priority: 'user-blocking'})`\n await new Promise(resolve => setTimeout(resolve, 0));\n await handler.finalize();\n }\n const percent = calculateProgress(i / sortedHandlers.length, ProgressPhase.FINALIZE);\n this.dispatchEvent(new TraceParseProgressEvent({percent}));\n }\n\n // Handlers that depend on other handlers do so via .data(), which used to always\n // return a shallow clone of its internal data structures. However, that pattern\n // easily results in egregious amounts of allocation. Now .data() does not do any\n // cloning, and it happens here instead so that users of the trace processor may\n // still assume that the parsed data is theirs.\n // See: crbug/41484172\n const shallowClone = (value: unknown, recurse = true): unknown => {\n if (value instanceof Map) {\n return new Map(value);\n }\n if (value instanceof Set) {\n return new Set(value);\n }\n if (Array.isArray(value)) {\n return [...value];\n }\n if (typeof value === 'object' && value && recurse) {\n const obj: Record<string, unknown> = {};\n for (const [key, v] of Object.entries(value)) {\n obj[key] = shallowClone(v, false);\n }\n return obj;\n }\n return value;\n };\n\n const parsedTrace = {};\n for (const [name, handler] of Object.entries(this.#traceHandlers)) {\n const data = shallowClone(handler.data());\n Object.assign(parsedTrace, {[name]: data});\n }\n this.dispatchEvent(new TraceParseProgressEvent({percent: ProgressPhase.CLONE}));\n\n this.#data = parsedTrace as Handlers.Types.ParsedTrace;\n }\n\n get parsedTrace(): Handlers.Types.ParsedTrace|null {\n if (this.#status !== Status.FINISHED_PARSING) {\n return null;\n }\n\n return this.#data;\n }\n\n get insights(): Insights.Types.TraceInsightSets|null {\n if (this.#status !== Status.FINISHED_PARSING) {\n return null;\n }\n\n return this.#insights;\n }\n\n #createLanternContext(\n parsedTrace: Handlers.Types.ParsedTrace, traceEvents: readonly Types.Events.Event[], frameId: string,\n navigationId: string): Insights.Types.LanternContext|undefined {\n // Check for required handlers.\n if (!parsedTrace.NetworkRequests || !parsedTrace.Workers || !parsedTrace.PageLoadMetrics) {\n return;\n }\n if (!parsedTrace.NetworkRequests.byTime.length) {\n throw new Lantern.Core.LanternError('No network requests found in trace');\n }\n\n const navStarts = parsedTrace.Meta.navigationsByFrameId.get(frameId);\n const navStartIndex = navStarts?.findIndex(n => n.args.data?.navigationId === navigationId);\n if (!navStarts || navStartIndex === undefined || navStartIndex === -1) {\n throw new Lantern.Core.LanternError('Could not find navigation start');\n }\n\n const startTime = navStarts[navStartIndex].ts;\n const endTime = navStartIndex + 1 < navStarts.length ? navStarts[navStartIndex + 1].ts : Number.POSITIVE_INFINITY;\n const boundedTraceEvents = traceEvents.filter(e => e.ts >= startTime && e.ts < endTime);\n\n // Lantern.Types.TraceEvent and Types.Events.Event represent the same\n // object - a trace event - but one is more flexible than the other. It should be safe to cast between them.\n const trace: Lantern.Types.Trace = {\n traceEvents: boundedTraceEvents as unknown as Lantern.Types.TraceEvent[],\n };\n\n const requests = LanternComputationData.createNetworkRequests(trace, parsedTrace, startTime, endTime);\n const graph = LanternComputationData.createGraph(requests, trace, parsedTrace);\n const processedNavigation = LanternComputationData.createProcessedNavigation(parsedTrace, frameId, navigationId);\n\n const networkAnalysis = Lantern.Core.NetworkAnalyzer.analyze(requests);\n if (!networkAnalysis) {\n return;\n }\n\n const simulator: Lantern.Simulation.Simulator<Types.Events.SyntheticNetworkRequest> =\n Lantern.Simulation.Simulator.createSimulator({\n // TODO(crbug.com/372674229): if devtools throttling was on, does this network analysis capture\n // that? Do we need to set 'devtools' throttlingMethod?\n networkAnalysis,\n throttlingMethod: 'provided',\n });\n\n const computeData = {graph, simulator, processedNavigation};\n const fcpResult = Lantern.Metrics.FirstContentfulPaint.compute(computeData);\n const lcpResult = Lantern.Metrics.LargestContentfulPaint.compute(computeData, {fcpResult});\n const interactiveResult = Lantern.Metrics.Interactive.compute(computeData, {lcpResult});\n const tbtResult = Lantern.Metrics.TotalBlockingTime.compute(computeData, {fcpResult, interactiveResult});\n const metrics = {\n firstContentfulPaint: fcpResult,\n interactive: interactiveResult,\n largestContentfulPaint: lcpResult,\n totalBlockingTime: tbtResult,\n };\n\n return {graph, simulator, metrics};\n }\n\n /**\n * Sort the insight models based on the impact of each insight's estimated savings, additionally weighted by the\n * worst metrics according to field data (if present).\n */\n sortInsightSet(\n insights: Insights.Types.TraceInsightSets, insightSet: Insights.Types.InsightSet,\n metadata: Types.File.MetaData|null): void {\n // The initial order of the insights is alphabetical, based on `front_end/models/trace/insights/Models.ts`.\n // The order here provides a baseline that groups insights in a more logical way.\n const baselineOrder: Record<keyof Insights.Types.InsightModels, null> = {\n InteractionToNextPaint: null,\n LCPPhases: null,\n LCPDiscovery: null,\n CLSCulprits: null,\n RenderBlocking: null,\n ImageDelivery: null,\n DocumentLatency: null,\n FontDisplay: null,\n Viewport: null,\n DOMSize: null,\n ThirdParties: null,\n SlowCSSSelector: null,\n };\n\n // Determine the weights for each metric based on field data, utilizing the same scoring curve that Lighthouse uses.\n const weights = Insights.Common.calculateMetricWeightsForSorting(insightSet, metadata);\n\n // Normalize the estimated savings to a single number, weighted by its relative impact\n // to the page experience based on the same scoring curve that Lighthouse uses.\n const observedLcp = Insights.Common.getLCP(insights, insightSet.id)?.value;\n const observedCls = Insights.Common.getCLS(insights, insightSet.id).value;\n\n // INP is special - if users did not interact with the page, we'll have no INP, but we should still\n // be able to prioritize insights based on this metric. When we observe no interaction, instead use\n // a default value for the baseline INP.\n const observedInp = Insights.Common.getINP(insights, insightSet.id)?.value ?? 200;\n\n const observedLcpScore =\n observedLcp !== undefined ? Insights.Common.evaluateLCPMetricScore(observedLcp) : undefined;\n const observedInpScore = Insights.Common.evaluateINPMetricScore(observedInp);\n const observedClsScore = Insights.Common.evaluateCLSMetricScore(observedCls);\n\n const insightToSortingRank = new Map<string, number>();\n for (const [name, model] of Object.entries(insightSet.model)) {\n const lcp = model.metricSavings?.LCP ?? 0;\n const inp = model.metricSavings?.INP ?? 0;\n const cls = model.metricSavings?.CLS ?? 0;\n\n const lcpPostSavings = observedLcp !== undefined ? Math.max(0, observedLcp - lcp) : undefined;\n const inpPostSavings = Math.max(0, observedInp - inp);\n const clsPostSavings = Math.max(0, observedCls - cls);\n\n let score = 0;\n if (weights.lcp && lcp && observedLcpScore !== undefined && lcpPostSavings !== undefined) {\n score += weights.lcp * (Insights.Common.evaluateLCPMetricScore(lcpPostSavings) - observedLcpScore);\n }\n if (weights.inp && inp && observedInpScore !== undefined) {\n score += weights.inp * (Insights.Common.evaluateINPMetricScore(inpPostSavings) - observedInpScore);\n }\n if (weights.cls && cls && observedClsScore !== undefined) {\n score += weights.cls * (Insights.Common.evaluateCLSMetricScore(clsPostSavings) - observedClsScore);\n }\n\n insightToSortingRank.set(name, score);\n }\n\n // Now perform the actual sorting.\n const baselineOrderKeys = Object.keys(baselineOrder);\n const orderedKeys = Object.keys(insightSet.model);\n orderedKeys.sort((a, b) => {\n const a1 = baselineOrderKeys.indexOf(a);\n const b1 = baselineOrderKeys.indexOf(b);\n if (a1 >= 0 && b1 >= 0) {\n return a1 - b1;\n }\n if (a1 >= 0) {\n return -1;\n }\n if (b1 >= 0) {\n return 1;\n }\n return 0;\n });\n orderedKeys.sort((a, b) => (insightToSortingRank.get(b) ?? 0) - (insightToSortingRank.get(a) ?? 0));\n\n const newModel = {} as Insights.Types.InsightModels;\n for (const key of orderedKeys as Array<keyof Insights.Types.InsightModels>) {\n const model = insightSet.model[key];\n // @ts-expect-error Maybe someday typescript will be powerful enough to handle this.\n newModel[key] = model;\n }\n insightSet.model = newModel;\n }\n\n #computeInsightSet(\n insights: Insights.Types.TraceInsightSets, parsedTrace: Handlers.Types.ParsedTrace,\n insightRunners: Partial<typeof Insights.Models>, context: Insights.Types.InsightSetContext,\n options: ParseOptions): void {\n const model = {} as Insights.Types.InsightSet['model'];\n\n for (const [name, insight] of Object.entries(insightRunners)) {\n let insightResult;\n try {\n insightResult = insight.generateInsight(parsedTrace, context);\n } catch (err) {\n insightResult = err;\n }\n Object.assign(model, {[name]: insightResult});\n }\n\n let id, urlString, navigation;\n if (context.navigation) {\n id = context.navigationId;\n urlString = context.navigation.args.data?.documentLoaderURL ?? parsedTrace.Meta.mainFrameURL;\n navigation = context.navigation;\n } else {\n id = Types.Events.NO_NAVIGATION;\n urlString = parsedTrace.Meta.mainFrameURL;\n }\n\n let url;\n try {\n url = new URL(urlString);\n } catch {\n // We're pretty sure this only happens for our test fixture: missing-url.json.gz. Shouldn't\n // happen for real traces.\n return;\n }\n\n const insightSet: Insights.Types.InsightSet = {\n id,\n url,\n navigation,\n frameId: context.frameId,\n bounds: context.bounds,\n model,\n };\n insights.set(insightSet.id, insightSet);\n this.sortInsightSet(insights, insightSet, options.metadata ?? null);\n }\n\n /**\n * Run all the insights and set the result to `#insights`.\n */\n #computeInsights(\n parsedTrace: Handlers.Types.ParsedTrace, traceEvents: readonly Types.Events.Event[],\n options: ParseOptions): void {\n this.#insights = new Map();\n\n const enabledInsightRunners = TraceProcessor.getEnabledInsightRunners(parsedTrace);\n\n const navigations = parsedTrace.Meta.mainFrameNavigations.filter(\n navigation => navigation.args.frame && navigation.args.data?.navigationId);\n\n // Check if there is a meaningful chunk of work happening prior to the first navigation.\n // If so, we run the insights on that initial bounds.\n // Otherwise, there are no navigations and we do a no-navigation insights pass on the entire trace.\n if (navigations.length) {\n const bounds = Helpers.Timing.traceWindowFromMicroSeconds(parsedTrace.Meta.traceBounds.min, navigations[0].ts);\n // When using \"Record and reload\" option, it typically takes ~5ms. So use 50ms to be safe.\n const threshold = Helpers.Timing.milliToMicro(50 as Types.Timing.MilliSeconds);\n if (bounds.range > threshold) {\n const context: Insights.Types.InsightSetContext = {\n bounds,\n frameId: parsedTrace.Meta.mainFrameId,\n };\n this.#computeInsightSet(this.#insights, parsedTrace, enabledInsightRunners, context, options);\n }\n // If threshold is not met, then the very beginning of the trace is ignored by the insights engine.\n } else {\n const context: Insights.Types.InsightSetContext = {\n bounds: parsedTrace.Meta.traceBounds,\n frameId: parsedTrace.Meta.mainFrameId,\n };\n this.#computeInsightSet(this.#insights, parsedTrace, enabledInsightRunners, context, options);\n }\n\n // Now run the insights for each navigation in isolation.\n for (const [i, navigation] of navigations.entries()) {\n // The above filter guarantees these are present.\n const frameId = navigation.args.frame;\n const navigationId = navigation.args.data?.navigationId as string;\n\n // The lantern sub-context is optional on InsightSetContext, so not setting it is OK.\n // This is also a hedge against an error inside Lantern resulting in breaking the entire performance panel.\n // Additionally, many trace fixtures are too old to be processed by Lantern.\n let lantern;\n try {\n lantern = this.#createLanternContext(parsedTrace, traceEvents, frameId, navigationId);\n } catch (e) {\n // Don't allow an error in constructing the Lantern graphs to break the rest of the trace processor.\n // Log unexpected errors, but suppress anything that occurs from a trace being too old.\n // Otherwise tests using old fixtures become way too noisy.\n const expectedErrors = [\n 'mainDocumentRequest not found',\n 'missing metric scores for main frame',\n 'missing metric: FCP',\n 'missing metric: LCP',\n 'No network requests found in trace',\n 'Trace is too old',\n ];\n if (!(e instanceof Lantern.Core.LanternError)) {\n // If this wasn't a managed LanternError, the stack trace is likely needed for debugging.\n console.error(e);\n } else if (!expectedErrors.some(err => e.message === err)) {\n // To reduce noise from tests, only print errors that are not expected to occur because a trace is\n // too old (for which there is no single check).\n console.error(e);\n }\n }\n\n const min = navigation.ts;\n const max = i + 1 < navigations.length ? navigations[i + 1].ts : parsedTrace.Meta.traceBounds.max;\n const bounds = Helpers.Timing.traceWindowFromMicroSeconds(min, max);\n const context: Insights.Types.InsightSetContext = {\n bounds,\n frameId,\n navigation,\n navigationId,\n lantern,\n };\n\n this.#computeInsightSet(this.#insights, parsedTrace, enabledInsightRunners, context, options);\n }\n }\n}\n\n/**\n * Some Handlers need data provided by others. Dependencies of a handler handler are\n * declared in the `deps` field.\n * @returns A map from trace event handler name to trace event hander whose entries\n * iterate in such a way that each handler is visited after its dependencies.\n */\nexport function sortHandlers(traceHandlers: Partial<{[key in Handlers.Types.HandlerName]: Handlers.Types.Handler}>):\n Map<Handlers.Types.HandlerName, Handlers.Types.Handler> {\n const sortedMap = new Map<Handlers.Types.HandlerName, Handlers.Types.Handler>();\n const visited = new Set<Handlers.Types.HandlerName>();\n const visitHandler = (handlerName: Handlers.Types.HandlerName): void => {\n if (sortedMap.has(handlerName)) {\n return;\n }\n if (visited.has(handlerName)) {\n let stackPath = '';\n for (const handler of visited) {\n if (stackPath || handler === handlerName) {\n stackPath += `${handler}->`;\n }\n }\n stackPath += handlerName;\n throw new Error(`Found dependency cycle in trace event handlers: ${stackPath}`);\n }\n visited.add(handlerName);\n const handler = traceHandlers[handlerName];\n if (!handler) {\n return;\n }\n const deps = handler.deps?.();\n if (deps) {\n deps.forEach(visitHandler);\n }\n sortedMap.set(handlerName, handler);\n };\n\n for (const handlerName of Object.keys(traceHandlers)) {\n visitHandler(handlerName as Handlers.Types.HandlerName);\n }\n return sortedMap;\n}\n"]}
|
|
@@ -32,7 +32,8 @@
|
|
|
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
|
-
"../../../../../../node_modules/@types/filesystem/index.d.ts"
|
|
35
|
+
"../../../../../../node_modules/@types/filesystem/index.d.ts",
|
|
36
|
+
"../../../../../../node_modules/@types/wicg-task-scheduling/index.d.ts"
|
|
36
37
|
],
|
|
37
38
|
"references": [
|
|
38
39
|
{
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type * as Protocol from '../../../generated/protocol.js';
|
|
2
|
+
import type * as Handlers from '../handlers/handlers.js';
|
|
3
|
+
import * as Types from '../types/types.js';
|
|
4
|
+
export declare const stackTraceForEventInTrace: Map<Readonly<Handlers.Types.EnabledHandlerDataWithMeta<typeof Handlers.ModelHandlers>>, Map<Types.Events.Event, Protocol.Runtime.StackTrace>>;
|
|
5
|
+
export declare function clearCacheForTrace(parsedTrace: Handlers.Types.ParsedTrace): void;
|
|
6
|
+
/**
|
|
7
|
+
* This util builds a stack trace that includes async calls for a given
|
|
8
|
+
* event. It leverages data we collect from sampling to deduce sync
|
|
9
|
+
* stacks and trace event instrumentation on the V8 debugger to stitch
|
|
10
|
+
* them together.
|
|
11
|
+
*/
|
|
12
|
+
export declare function get(event: Types.Events.Event, parsedTrace: Handlers.Types.ParsedTrace): Protocol.Runtime.StackTrace | null;
|
|
@@ -0,0 +1,163 @@
|
|
|
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 Platform from '../../../core/platform/platform.js';
|
|
5
|
+
import * as Helpers from '../helpers/helpers.js';
|
|
6
|
+
import * as Types from '../types/types.js';
|
|
7
|
+
export const stackTraceForEventInTrace = new Map();
|
|
8
|
+
export function clearCacheForTrace(parsedTrace) {
|
|
9
|
+
stackTraceForEventInTrace.delete(parsedTrace);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* This util builds a stack trace that includes async calls for a given
|
|
13
|
+
* event. It leverages data we collect from sampling to deduce sync
|
|
14
|
+
* stacks and trace event instrumentation on the V8 debugger to stitch
|
|
15
|
+
* them together.
|
|
16
|
+
*/
|
|
17
|
+
export function get(event, parsedTrace) {
|
|
18
|
+
let cacheForTrace = stackTraceForEventInTrace.get(parsedTrace);
|
|
19
|
+
if (!cacheForTrace) {
|
|
20
|
+
cacheForTrace = new Map();
|
|
21
|
+
stackTraceForEventInTrace.set(parsedTrace, cacheForTrace);
|
|
22
|
+
}
|
|
23
|
+
const resultFromCache = cacheForTrace.get(event);
|
|
24
|
+
if (resultFromCache) {
|
|
25
|
+
return resultFromCache;
|
|
26
|
+
}
|
|
27
|
+
let result = null;
|
|
28
|
+
if (Types.Events.isProfileCall(event)) {
|
|
29
|
+
result = getForProfileCall(event, parsedTrace);
|
|
30
|
+
}
|
|
31
|
+
else if (Types.Extensions.isSyntheticExtensionEntry(event)) {
|
|
32
|
+
result = getForExtensionEntry(event, parsedTrace);
|
|
33
|
+
}
|
|
34
|
+
if (result) {
|
|
35
|
+
cacheForTrace.set(event, result);
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
function getForProfileCall(event, parsedTrace) {
|
|
40
|
+
// When working with a CPU profile the renderer handler won't have
|
|
41
|
+
// entries in its tree.
|
|
42
|
+
const entryToNode = parsedTrace.Renderer.entryToNode.size > 0 ? parsedTrace.Renderer.entryToNode : parsedTrace.Samples.entryToNode;
|
|
43
|
+
const topStackTrace = { callFrames: [] };
|
|
44
|
+
let stackTrace = topStackTrace;
|
|
45
|
+
let currentEntry = event;
|
|
46
|
+
let node = entryToNode.get(event);
|
|
47
|
+
const traceCache = stackTraceForEventInTrace.get(parsedTrace) || new Map();
|
|
48
|
+
stackTraceForEventInTrace.set(parsedTrace, traceCache);
|
|
49
|
+
// Move up this node's ancestor tree appending frames to its
|
|
50
|
+
// stack trace.
|
|
51
|
+
while (node) {
|
|
52
|
+
if (!Types.Events.isProfileCall(node.entry)) {
|
|
53
|
+
node = node.parent;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
currentEntry = node.entry;
|
|
57
|
+
// First check if this entry was processed before.
|
|
58
|
+
const stackTraceFromCache = traceCache.get(node.entry);
|
|
59
|
+
if (stackTraceFromCache) {
|
|
60
|
+
stackTrace.callFrames.push(...stackTraceFromCache.callFrames.filter(callFrame => !isNativeJSFunction(callFrame)));
|
|
61
|
+
stackTrace.parent = stackTraceFromCache.parent;
|
|
62
|
+
// Only set the description to the cache value if we didn't
|
|
63
|
+
// compute it in the previous iteration, since the async stack
|
|
64
|
+
// trace descriptions / taskNames is only extracted when jumping
|
|
65
|
+
// to the async parent, and that might not have happened when
|
|
66
|
+
// the cached value was computed (e.g. the cached value
|
|
67
|
+
// computation started at some point inside the parent stack
|
|
68
|
+
// trace).
|
|
69
|
+
stackTrace.description = stackTrace.description || stackTraceFromCache.description;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
if (!isNativeJSFunction(currentEntry.callFrame)) {
|
|
73
|
+
stackTrace.callFrames.push(currentEntry.callFrame);
|
|
74
|
+
}
|
|
75
|
+
const maybeAsyncParentEvent = parsedTrace.AsyncJSCalls.asyncCallToScheduler.get(currentEntry);
|
|
76
|
+
const maybeAsyncParentNode = maybeAsyncParentEvent && entryToNode.get(maybeAsyncParentEvent.scheduler);
|
|
77
|
+
if (maybeAsyncParentNode) {
|
|
78
|
+
// The Protocol.Runtime.StackTrace type is recursive, so we
|
|
79
|
+
// move one level deeper in it as we walk up the ancestor tree.
|
|
80
|
+
stackTrace.parent = { callFrames: [] };
|
|
81
|
+
stackTrace = stackTrace.parent;
|
|
82
|
+
// Note: this description effectively corresponds to the name
|
|
83
|
+
// of the task that scheduled the stack trace we are jumping
|
|
84
|
+
// FROM, so it would make sense that it was set to that stack
|
|
85
|
+
// trace instead of the one we are jumping TO. However, the
|
|
86
|
+
// JS presentation utils we use to present async stack traces
|
|
87
|
+
// assume the description is added to the stack trace that
|
|
88
|
+
// scheduled the async task, so we build the data that way.
|
|
89
|
+
stackTrace.description = maybeAsyncParentEvent.taskName;
|
|
90
|
+
node = maybeAsyncParentNode;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
node = node.parent;
|
|
94
|
+
}
|
|
95
|
+
return topStackTrace;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Finds the JS call in which an extension entry was injected (the
|
|
99
|
+
* code location that called the extension API), and returns its stack
|
|
100
|
+
* trace.
|
|
101
|
+
*/
|
|
102
|
+
function getForExtensionEntry(event, parsedTrace) {
|
|
103
|
+
const eventCallPoint = Helpers.Trace.getZeroIndexedStackTraceForEvent(event)?.[0];
|
|
104
|
+
if (!eventCallPoint) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const eventCallTime = Types.Events.isPerformanceMeasureBegin(event.rawSourceEvent) ?
|
|
108
|
+
event.rawSourceEvent.args.callTime :
|
|
109
|
+
Types.Events.isPerformanceMark(event.rawSourceEvent) ?
|
|
110
|
+
event.rawSourceEvent.args.data?.callTime :
|
|
111
|
+
// event added with console.timeStamp: take the original event's
|
|
112
|
+
// ts.
|
|
113
|
+
event.rawSourceEvent.ts;
|
|
114
|
+
if (eventCallTime === undefined) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
const callsInThread = parsedTrace.Renderer.processes.get(event.pid)?.threads.get(event.tid)?.profileCalls;
|
|
118
|
+
if (!callsInThread) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const matchByName = callsInThread.filter(e => {
|
|
122
|
+
return e.callFrame.functionName === eventCallPoint.functionName;
|
|
123
|
+
});
|
|
124
|
+
const lastCallBeforeEventIndex = Platform.ArrayUtilities.nearestIndexFromEnd(matchByName, profileCall => profileCall.ts <= eventCallTime);
|
|
125
|
+
const firstCallAfterEventIndex = Platform.ArrayUtilities.nearestIndexFromBeginning(matchByName, profileCall => profileCall.ts >= eventCallTime);
|
|
126
|
+
const lastCallBeforeEvent = typeof lastCallBeforeEventIndex === 'number' && matchByName.at(lastCallBeforeEventIndex);
|
|
127
|
+
const firstCallAfterEvent = typeof firstCallAfterEventIndex === 'number' && matchByName.at(firstCallAfterEventIndex);
|
|
128
|
+
let closestMatchingProfileCall;
|
|
129
|
+
if (!lastCallBeforeEvent && !firstCallAfterEvent) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
if (!lastCallBeforeEvent) {
|
|
133
|
+
// Per the check above firstCallAfterEvent is guaranteed to exist
|
|
134
|
+
// but ts is unaware, so we cast the type.
|
|
135
|
+
closestMatchingProfileCall = firstCallAfterEvent;
|
|
136
|
+
}
|
|
137
|
+
else if (!firstCallAfterEvent) {
|
|
138
|
+
closestMatchingProfileCall = lastCallBeforeEvent;
|
|
139
|
+
}
|
|
140
|
+
else if (Helpers.Trace.eventContainsTimestamp(lastCallBeforeEvent, eventCallTime)) {
|
|
141
|
+
closestMatchingProfileCall = lastCallBeforeEvent;
|
|
142
|
+
} // pick the closest when the choice isn't clear.
|
|
143
|
+
else if (eventCallTime - lastCallBeforeEvent.ts < firstCallAfterEvent.ts - eventCallTime) {
|
|
144
|
+
closestMatchingProfileCall = lastCallBeforeEvent;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
closestMatchingProfileCall = firstCallAfterEvent;
|
|
148
|
+
}
|
|
149
|
+
return get(closestMatchingProfileCall, parsedTrace);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Determines if a function is a native JS API (like setTimeout,
|
|
153
|
+
* requestAnimationFrame, consoleTask.run. etc.). This is useful to
|
|
154
|
+
* discard stack frames corresponding to the JS scheduler function
|
|
155
|
+
* itself, since it's already being used as title of async stack traces
|
|
156
|
+
* taken from the async `taskName`. This is also consistent with the
|
|
157
|
+
* behaviour of the stack trace in the sources
|
|
158
|
+
* panel.
|
|
159
|
+
*/
|
|
160
|
+
function isNativeJSFunction({ columnNumber, lineNumber, url, scriptId }) {
|
|
161
|
+
return lineNumber === -1 && columnNumber === -1 && url === '' && scriptId === '0';
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=StackTraceForEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StackTraceForEvent.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/extras/StackTraceForEvent.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAG/D,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,MAAM,CAAC,MAAM,yBAAyB,GAClC,IAAI,GAAG,EAAoF,CAAC;AAEhG,MAAM,UAAU,kBAAkB,CAAC,WAAuC;IACxE,yBAAyB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAChD,CAAC;AACD;;;;;GAKG;AACH,MAAM,UAAU,GAAG,CAAC,KAAyB,EAAE,WAAuC;IAEpF,IAAI,aAAa,GAAG,yBAAyB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC/D,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QAC1B,yBAAyB,CAAC,GAAG,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,eAAe,GAAG,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,eAAe,EAAE,CAAC;QACpB,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,IAAI,MAAM,GAAqC,IAAI,CAAC;IACpD,IAAI,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACtC,MAAM,GA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ACtD,CAAC;AACD;;;;;;;;GAQG;AACH,SAAS,kBAAkB,CAAC,EAAC,YAAY,EAAE,UAAU,EAAE,GAAG,EAAE,QAAQ,EAA6B;IAC/F,OAAO,UAAU,KAAK,CAAC,CAAC,IAAI,YAAY,KAAK,CAAC,CAAC,IAAI,GAAG,KAAK,EAAE,IAAI,QAAQ,KAAK,GAAG,CAAC;AACpF,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 Platform from '../../../core/platform/platform.js';\nimport type * as Protocol from '../../../generated/protocol.js';\nimport type * as Handlers from '../handlers/handlers.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nexport const stackTraceForEventInTrace =\n new Map<Handlers.Types.ParsedTrace, Map<Types.Events.Event, Protocol.Runtime.StackTrace>>();\n\nexport function clearCacheForTrace(parsedTrace: Handlers.Types.ParsedTrace): void {\n stackTraceForEventInTrace.delete(parsedTrace);\n}\n/**\n * This util builds a stack trace that includes async calls for a given\n * event. It leverages data we collect from sampling to deduce sync\n * stacks and trace event instrumentation on the V8 debugger to stitch\n * them together.\n */\nexport function get(event: Types.Events.Event, parsedTrace: Handlers.Types.ParsedTrace): Protocol.Runtime.StackTrace|\n null {\n let cacheForTrace = stackTraceForEventInTrace.get(parsedTrace);\n if (!cacheForTrace) {\n cacheForTrace = new Map();\n stackTraceForEventInTrace.set(parsedTrace, cacheForTrace);\n }\n const resultFromCache = cacheForTrace.get(event);\n if (resultFromCache) {\n return resultFromCache;\n }\n let result: Protocol.Runtime.StackTrace|null = null;\n if (Types.Events.isProfileCall(event)) {\n result = getForProfileCall(event, parsedTrace);\n } else if (Types.Extensions.isSyntheticExtensionEntry(event)) {\n result = getForExtensionEntry(event, parsedTrace);\n }\n if (result) {\n cacheForTrace.set(event, result);\n }\n return result;\n}\n\nfunction getForProfileCall(\n event: Types.Events.SyntheticProfileCall, parsedTrace: Handlers.Types.ParsedTrace): Protocol.Runtime.StackTrace {\n // When working with a CPU profile the renderer handler won't have\n // entries in its tree.\n const entryToNode =\n parsedTrace.Renderer.entryToNode.size > 0 ? parsedTrace.Renderer.entryToNode : parsedTrace.Samples.entryToNode;\n const topStackTrace: Protocol.Runtime.StackTrace = {callFrames: []};\n let stackTrace: Protocol.Runtime.StackTrace = topStackTrace;\n let currentEntry = event;\n let node: Helpers.TreeHelpers.TraceEntryNode|null|undefined = entryToNode.get(event);\n const traceCache =\n stackTraceForEventInTrace.get(parsedTrace) || new Map<Types.Events.Event, Protocol.Runtime.StackTrace>();\n stackTraceForEventInTrace.set(parsedTrace, traceCache);\n // Move up this node's ancestor tree appending frames to its\n // stack trace.\n while (node) {\n if (!Types.Events.isProfileCall(node.entry)) {\n node = node.parent;\n continue;\n }\n\n currentEntry = node.entry;\n // First check if this entry was processed before.\n const stackTraceFromCache = traceCache.get(node.entry);\n if (stackTraceFromCache) {\n stackTrace.callFrames.push(...stackTraceFromCache.callFrames.filter(callFrame => !isNativeJSFunction(callFrame)));\n stackTrace.parent = stackTraceFromCache.parent;\n // Only set the description to the cache value if we didn't\n // compute it in the previous iteration, since the async stack\n // trace descriptions / taskNames is only extracted when jumping\n // to the async parent, and that might not have happened when\n // the cached value was computed (e.g. the cached value\n // computation started at some point inside the parent stack\n // trace).\n stackTrace.description = stackTrace.description || stackTraceFromCache.description;\n break;\n }\n\n if (!isNativeJSFunction(currentEntry.callFrame)) {\n stackTrace.callFrames.push(currentEntry.callFrame);\n }\n const maybeAsyncParentEvent = parsedTrace.AsyncJSCalls.asyncCallToScheduler.get(currentEntry);\n const maybeAsyncParentNode = maybeAsyncParentEvent && entryToNode.get(maybeAsyncParentEvent.scheduler);\n if (maybeAsyncParentNode) {\n // The Protocol.Runtime.StackTrace type is recursive, so we\n // move one level deeper in it as we walk up the ancestor tree.\n stackTrace.parent = {callFrames: []};\n stackTrace = stackTrace.parent;\n // Note: this description effectively corresponds to the name\n // of the task that scheduled the stack trace we are jumping\n // FROM, so it would make sense that it was set to that stack\n // trace instead of the one we are jumping TO. However, the\n // JS presentation utils we use to present async stack traces\n // assume the description is added to the stack trace that\n // scheduled the async task, so we build the data that way.\n stackTrace.description = maybeAsyncParentEvent.taskName;\n node = maybeAsyncParentNode;\n continue;\n }\n node = node.parent;\n }\n return topStackTrace;\n}\n\n/**\n * Finds the JS call in which an extension entry was injected (the\n * code location that called the extension API), and returns its stack\n * trace.\n */\nfunction getForExtensionEntry(event: Types.Extensions.SyntheticExtensionEntry, parsedTrace: Handlers.Types.ParsedTrace):\n Protocol.Runtime.StackTrace|null {\n const eventCallPoint = Helpers.Trace.getZeroIndexedStackTraceForEvent(event)?.[0];\n if (!eventCallPoint) {\n return null;\n }\n const eventCallTime = Types.Events.isPerformanceMeasureBegin(event.rawSourceEvent) ?\n event.rawSourceEvent.args.callTime :\n Types.Events.isPerformanceMark(event.rawSourceEvent) ?\n event.rawSourceEvent.args.data?.callTime :\n // event added with console.timeStamp: take the original event's\n // ts.\n event.rawSourceEvent.ts;\n if (eventCallTime === undefined) {\n return null;\n }\n const callsInThread = parsedTrace.Renderer.processes.get(event.pid)?.threads.get(event.tid)?.profileCalls;\n if (!callsInThread) {\n return null;\n }\n const matchByName = callsInThread.filter(e => {\n return e.callFrame.functionName === eventCallPoint.functionName;\n });\n\n const lastCallBeforeEventIndex =\n Platform.ArrayUtilities.nearestIndexFromEnd(matchByName, profileCall => profileCall.ts <= eventCallTime);\n const firstCallAfterEventIndex =\n Platform.ArrayUtilities.nearestIndexFromBeginning(matchByName, profileCall => profileCall.ts >= eventCallTime);\n const lastCallBeforeEvent = typeof lastCallBeforeEventIndex === 'number' && matchByName.at(lastCallBeforeEventIndex);\n const firstCallAfterEvent = typeof firstCallAfterEventIndex === 'number' && matchByName.at(firstCallAfterEventIndex);\n\n let closestMatchingProfileCall: Types.Events.SyntheticProfileCall;\n if (!lastCallBeforeEvent && !firstCallAfterEvent) {\n return null;\n }\n if (!lastCallBeforeEvent) {\n // Per the check above firstCallAfterEvent is guaranteed to exist\n // but ts is unaware, so we cast the type.\n closestMatchingProfileCall = firstCallAfterEvent as Types.Events.SyntheticProfileCall;\n } else if (!firstCallAfterEvent) {\n closestMatchingProfileCall = lastCallBeforeEvent;\n } else if (Helpers.Trace.eventContainsTimestamp(lastCallBeforeEvent, eventCallTime)) {\n closestMatchingProfileCall = lastCallBeforeEvent;\n } // pick the closest when the choice isn't clear.\n else if (eventCallTime - lastCallBeforeEvent.ts < firstCallAfterEvent.ts - eventCallTime) {\n closestMatchingProfileCall = lastCallBeforeEvent;\n } else {\n closestMatchingProfileCall = firstCallAfterEvent;\n }\n return get(closestMatchingProfileCall, parsedTrace);\n}\n/**\n * Determines if a function is a native JS API (like setTimeout,\n * requestAnimationFrame, consoleTask.run. etc.). This is useful to\n * discard stack frames corresponding to the JS scheduler function\n * itself, since it's already being used as title of async stack traces\n * taken from the async `taskName`. This is also consistent with the\n * behaviour of the stack trace in the sources\n * panel.\n */\nfunction isNativeJSFunction({columnNumber, lineNumber, url, scriptId}: Protocol.Runtime.CallFrame): boolean {\n return lineNumber === -1 && columnNumber === -1 && url === '' && scriptId === '0';\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ThirdPartyWeb from '../../../third_party/third-party-web/third-party-web.js';
|
|
2
|
-
import
|
|
2
|
+
import * as Handlers from '../handlers/handlers.js';
|
|
3
3
|
import * as Types from '../types/types.js';
|
|
4
4
|
export type Entity = typeof ThirdPartyWeb.ThirdPartyWeb.entities[number];
|
|
5
5
|
export interface Summary {
|
|
@@ -8,10 +8,9 @@ export interface Summary {
|
|
|
8
8
|
}
|
|
9
9
|
export interface SummaryMaps {
|
|
10
10
|
byEntity: Map<Entity, Summary>;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
byEvent: Map<Types.Events.Event, Summary>;
|
|
12
|
+
eventsByEntity: Map<Entity, Types.Events.Event[]>;
|
|
13
13
|
}
|
|
14
|
-
export declare function makeUpEntity(entityCache: Map<string, Entity>, url: string): Entity | undefined;
|
|
15
14
|
export declare function getEntitiesByRequest(requests: Types.Events.SyntheticNetworkRequest[]): {
|
|
16
15
|
entityByRequest: Map<Types.Events.SyntheticNetworkRequest, Entity>;
|
|
17
16
|
madeUpEntityCache: Map<string, Entity>;
|
|
@@ -21,3 +20,7 @@ export declare function getSummariesAndEntitiesForTraceBounds(parsedTrace: Handl
|
|
|
21
20
|
entityByRequest: Map<Types.Events.SyntheticNetworkRequest, Entity>;
|
|
22
21
|
madeUpEntityCache: Map<string, Entity>;
|
|
23
22
|
};
|
|
23
|
+
export declare function getSummariesAndEntitiesWithMapping(parsedTrace: Handlers.Types.ParsedTrace, traceBounds: Types.Timing.TraceWindowMicroSeconds, entityMapping: Handlers.Helpers.EntityMappings): {
|
|
24
|
+
summaries: SummaryMaps;
|
|
25
|
+
entityByEvent: Map<Types.Events.Event, Handlers.Helpers.Entity>;
|
|
26
|
+
};
|