@paulirish/trace_engine 0.0.31 → 0.0.33
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/README.md +6 -10
- package/analyze-trace.mjs +9 -10
- package/core/platform/ArrayUtilities.js +1 -0
- package/core/platform/ArrayUtilities.js.map +1 -1
- package/core/platform/DevToolsPath.d.ts +1 -1
- package/core/platform/DevToolsPath.js.map +1 -1
- package/core/platform/MimeType.js +4 -2
- package/core/platform/MimeType.js.map +1 -1
- package/core/platform/NumberUtilities.js +8 -0
- package/core/platform/NumberUtilities.js.map +1 -1
- package/core/platform/ServerTiming.d.ts +31 -0
- package/core/platform/ServerTiming.js +212 -0
- package/core/platform/ServerTiming.js.map +1 -0
- package/core/platform/Timing.d.ts +1 -1
- package/core/platform/Timing.js.map +1 -1
- package/core/platform/TypescriptUtilities.d.ts +3 -0
- package/core/platform/TypescriptUtilities.js.map +1 -1
- package/core/platform/UIString.d.ts +1 -1
- package/core/platform/UIString.js.map +1 -1
- package/core/platform/UserVisibleError.d.ts +1 -1
- package/core/platform/UserVisibleError.js.map +1 -1
- package/core/platform/platform-tsconfig.json +1 -1
- package/core/platform/platform.d.ts +2 -2
- package/core/platform/platform.js +2 -2
- package/core/platform/platform.js.map +1 -1
- package/generated/protocol.d.ts +258 -14
- package/models/trace/LanternComputationData.d.ts +4 -4
- package/models/trace/LanternComputationData.js +22 -23
- package/models/trace/LanternComputationData.js.map +1 -1
- package/models/trace/ModelImpl.d.ts +11 -12
- package/models/trace/ModelImpl.js +22 -33
- package/models/trace/ModelImpl.js.map +1 -1
- package/models/trace/Processor.d.ts +21 -12
- package/models/trace/Processor.js +148 -67
- package/models/trace/Processor.js.map +1 -1
- package/models/trace/TracingManager.js.map +1 -1
- package/models/trace/extras/FetchNodes.d.ts +8 -8
- package/models/trace/extras/FetchNodes.js +16 -11
- package/models/trace/extras/FetchNodes.js.map +1 -1
- package/models/trace/extras/FilmStrip.d.ts +2 -2
- package/models/trace/extras/FilmStrip.js +8 -8
- package/models/trace/extras/FilmStrip.js.map +1 -1
- package/models/trace/extras/MainThreadActivity.d.ts +1 -1
- package/models/trace/extras/MainThreadActivity.js +1 -1
- package/models/trace/extras/MainThreadActivity.js.map +1 -1
- package/models/trace/extras/Metadata.js +2 -2
- package/models/trace/extras/Metadata.js.map +1 -1
- package/models/trace/extras/URLForEntry.d.ts +9 -1
- package/models/trace/extras/URLForEntry.js +18 -10
- package/models/trace/extras/URLForEntry.js.map +1 -1
- package/models/trace/extras/extras.js +1 -1
- package/models/trace/handlers/AnimationHandler.d.ts +2 -2
- package/models/trace/handlers/AnimationHandler.js +1 -1
- package/models/trace/handlers/AnimationHandler.js.map +1 -1
- package/models/trace/handlers/AuctionWorkletsHandler.d.ts +2 -2
- package/models/trace/handlers/AuctionWorkletsHandler.js +11 -11
- package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -1
- package/models/trace/handlers/ExtensionTraceDataHandler.d.ts +7 -5
- package/models/trace/handlers/ExtensionTraceDataHandler.js +16 -10
- package/models/trace/handlers/ExtensionTraceDataHandler.js.map +1 -1
- package/models/trace/handlers/FramesHandler.d.ts +24 -19
- package/models/trace/handlers/FramesHandler.js +46 -25
- package/models/trace/handlers/FramesHandler.js.map +1 -1
- package/models/trace/handlers/GPUHandler.d.ts +4 -4
- package/models/trace/handlers/GPUHandler.js +3 -3
- package/models/trace/handlers/GPUHandler.js.map +1 -1
- package/models/trace/handlers/ImagePaintingHandler.d.ts +3 -3
- package/models/trace/handlers/ImagePaintingHandler.js +6 -8
- package/models/trace/handlers/ImagePaintingHandler.js.map +1 -1
- package/models/trace/handlers/InitiatorsHandler.d.ts +3 -3
- package/models/trace/handlers/InitiatorsHandler.js +14 -14
- package/models/trace/handlers/InitiatorsHandler.js.map +1 -1
- package/models/trace/handlers/InvalidationsHandler.d.ts +4 -2
- package/models/trace/handlers/InvalidationsHandler.js +29 -11
- package/models/trace/handlers/InvalidationsHandler.js.map +1 -1
- package/models/trace/handlers/LargestImagePaintHandler.d.ts +2 -2
- package/models/trace/handlers/LargestImagePaintHandler.js +1 -1
- package/models/trace/handlers/LargestImagePaintHandler.js.map +1 -1
- package/models/trace/handlers/LargestTextPaintHandler.d.ts +2 -2
- package/models/trace/handlers/LargestTextPaintHandler.js +1 -1
- package/models/trace/handlers/LargestTextPaintHandler.js.map +1 -1
- package/models/trace/handlers/LayerTreeHandler.d.ts +6 -6
- package/models/trace/handlers/LayerTreeHandler.js +6 -6
- package/models/trace/handlers/LayerTreeHandler.js.map +1 -1
- package/models/trace/handlers/LayoutShiftsHandler.d.ts +12 -20
- package/models/trace/handlers/LayoutShiftsHandler.js +73 -12
- package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
- package/models/trace/handlers/MemoryHandler.d.ts +2 -2
- package/models/trace/handlers/MemoryHandler.js +1 -1
- package/models/trace/handlers/MemoryHandler.js.map +1 -1
- package/models/trace/handlers/MetaHandler.d.ts +15 -14
- package/models/trace/handlers/MetaHandler.js +32 -30
- package/models/trace/handlers/MetaHandler.js.map +1 -1
- package/models/trace/handlers/ModelHandlers.d.ts +1 -1
- package/models/trace/handlers/ModelHandlers.js +1 -1
- package/models/trace/handlers/ModelHandlers.js.map +1 -1
- package/models/trace/handlers/NetworkRequestsHandler.d.ts +13 -12
- package/models/trace/handlers/NetworkRequestsHandler.js +68 -66
- package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
- package/models/trace/handlers/PageFramesHandler.d.ts +2 -2
- package/models/trace/handlers/PageFramesHandler.js +2 -2
- package/models/trace/handlers/PageFramesHandler.js.map +1 -1
- package/models/trace/handlers/PageLoadMetricsHandler.d.ts +7 -7
- package/models/trace/handlers/PageLoadMetricsHandler.js +21 -24
- package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -1
- package/models/trace/handlers/RendererHandler.d.ts +19 -19
- package/models/trace/handlers/RendererHandler.js +5 -5
- package/models/trace/handlers/RendererHandler.js.map +1 -1
- package/models/trace/handlers/SamplesHandler.d.ts +6 -6
- package/models/trace/handlers/SamplesHandler.js +4 -4
- package/models/trace/handlers/SamplesHandler.js.map +1 -1
- package/models/trace/handlers/ScreenshotsHandler.d.ts +6 -4
- package/models/trace/handlers/ScreenshotsHandler.js +11 -9
- package/models/trace/handlers/ScreenshotsHandler.js.map +1 -1
- package/models/trace/handlers/SelectorStatsHandler.d.ts +3 -3
- package/models/trace/handlers/SelectorStatsHandler.js +2 -2
- package/models/trace/handlers/SelectorStatsHandler.js.map +1 -1
- package/models/trace/handlers/ServerTimingsHandler.d.ts +10 -0
- package/models/trace/handlers/ServerTimingsHandler.js +118 -0
- package/models/trace/handlers/ServerTimingsHandler.js.map +1 -0
- package/models/trace/handlers/Threads.d.ts +7 -7
- package/models/trace/handlers/Threads.js +5 -5
- package/models/trace/handlers/Threads.js.map +1 -1
- package/models/trace/handlers/UserInteractionsHandler.d.ts +13 -11
- package/models/trace/handlers/UserInteractionsHandler.js +13 -7
- package/models/trace/handlers/UserInteractionsHandler.js.map +1 -1
- package/models/trace/handlers/UserTimingsHandler.d.ts +5 -5
- package/models/trace/handlers/UserTimingsHandler.js +52 -9
- package/models/trace/handlers/UserTimingsHandler.js.map +1 -1
- package/models/trace/handlers/WarningsHandler.d.ts +5 -5
- package/models/trace/handlers/WarningsHandler.js +4 -5
- package/models/trace/handlers/WarningsHandler.js.map +1 -1
- package/models/trace/handlers/WorkersHandler.d.ts +4 -4
- package/models/trace/handlers/WorkersHandler.js +1 -1
- package/models/trace/handlers/WorkersHandler.js.map +1 -1
- package/models/trace/handlers/handlers-tsconfig.json +1 -1
- package/models/trace/handlers/types.d.ts +7 -7
- package/models/trace/handlers/types.js.map +1 -1
- package/models/trace/helpers/Extensions.d.ts +5 -1
- package/models/trace/helpers/Extensions.js +5 -3
- package/models/trace/helpers/Extensions.js.map +1 -1
- package/models/trace/helpers/Network.d.ts +2 -2
- package/models/trace/helpers/Network.js +19 -2
- package/models/trace/helpers/Network.js.map +1 -1
- package/models/trace/helpers/SamplesIntegrator.d.ts +5 -5
- package/models/trace/helpers/SamplesIntegrator.js +10 -11
- package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
- package/models/trace/helpers/SyntheticEvents.d.ts +8 -14
- package/models/trace/helpers/SyntheticEvents.js +20 -31
- package/models/trace/helpers/SyntheticEvents.js.map +1 -1
- package/models/trace/helpers/Timing.d.ts +16 -5
- package/models/trace/helpers/Timing.js +33 -7
- package/models/trace/helpers/Timing.js.map +1 -1
- package/models/trace/helpers/Trace.d.ts +46 -33
- package/models/trace/helpers/Trace.js +53 -38
- package/models/trace/helpers/Trace.js.map +1 -1
- package/models/trace/helpers/TreeHelpers.d.ts +30 -8
- package/models/trace/helpers/TreeHelpers.js +91 -23
- package/models/trace/helpers/TreeHelpers.js.map +1 -1
- package/models/trace/insights/Common.d.ts +8 -2
- package/models/trace/insights/Common.js +33 -7
- package/models/trace/insights/Common.js.map +1 -1
- package/models/trace/insights/CumulativeLayoutShift.d.ts +34 -13
- package/models/trace/insights/CumulativeLayoutShift.js +151 -59
- package/models/trace/insights/CumulativeLayoutShift.js.map +1 -1
- package/models/trace/insights/DocumentLatency.d.ts +9 -4
- package/models/trace/insights/DocumentLatency.js +82 -7
- package/models/trace/insights/DocumentLatency.js.map +1 -1
- package/models/trace/insights/FontDisplay.d.ts +11 -0
- package/models/trace/insights/FontDisplay.js +44 -0
- package/models/trace/insights/FontDisplay.js.map +1 -0
- package/models/trace/insights/InsightRunners.d.ts +3 -0
- package/models/trace/insights/InsightRunners.js +3 -0
- package/models/trace/insights/InsightRunners.js.map +1 -1
- package/models/trace/insights/InteractionToNextPaint.d.ts +4 -5
- package/models/trace/insights/InteractionToNextPaint.js +5 -3
- package/models/trace/insights/InteractionToNextPaint.js.map +1 -1
- package/models/trace/insights/LargestContentfulPaint.d.ts +20 -7
- package/models/trace/insights/LargestContentfulPaint.js +57 -37
- package/models/trace/insights/LargestContentfulPaint.js.map +1 -1
- package/models/trace/insights/RenderBlocking.d.ts +3 -3
- package/models/trace/insights/RenderBlocking.js +29 -24
- package/models/trace/insights/RenderBlocking.js.map +1 -1
- package/models/trace/insights/SlowCSSSelector.d.ts +11 -0
- package/models/trace/insights/SlowCSSSelector.js +67 -0
- package/models/trace/insights/SlowCSSSelector.js.map +1 -0
- package/models/trace/insights/ThirdPartyWeb.d.ts +18 -0
- package/models/trace/insights/ThirdPartyWeb.js +174 -0
- package/models/trace/insights/ThirdPartyWeb.js.map +1 -0
- package/models/trace/insights/Viewport.d.ts +5 -2
- package/models/trace/insights/Viewport.js +14 -9
- package/models/trace/insights/Viewport.js.map +1 -1
- package/models/trace/insights/insights-tsconfig.json +9 -0
- 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 +43 -25
- package/models/trace/insights/types.js.map +1 -1
- package/models/trace/lantern/core/NetworkAnalyzer.d.ts +6 -6
- package/models/trace/lantern/core/NetworkAnalyzer.js +12 -12
- package/models/trace/lantern/core/NetworkAnalyzer.js.map +1 -1
- package/models/trace/lantern/graph/BaseNode.d.ts +4 -4
- package/models/trace/lantern/graph/BaseNode.js +21 -21
- package/models/trace/lantern/graph/BaseNode.js.map +1 -1
- package/models/trace/lantern/graph/CPUNode.d.ts +1 -1
- package/models/trace/lantern/graph/CPUNode.js +5 -5
- package/models/trace/lantern/graph/CPUNode.js.map +1 -1
- package/models/trace/lantern/graph/PageDependencyGraph.d.ts +4 -4
- package/models/trace/lantern/graph/PageDependencyGraph.js +5 -5
- package/models/trace/lantern/graph/PageDependencyGraph.js.map +1 -1
- package/models/trace/lantern/simulation/ConnectionPool.d.ts +7 -7
- package/models/trace/lantern/simulation/ConnectionPool.js +26 -26
- package/models/trace/lantern/simulation/ConnectionPool.js.map +1 -1
- package/models/trace/lantern/simulation/DNSCache.d.ts +3 -3
- package/models/trace/lantern/simulation/DNSCache.js +11 -11
- package/models/trace/lantern/simulation/DNSCache.js.map +1 -1
- package/models/trace/lantern/simulation/SimulationTimingMap.d.ts +1 -1
- package/models/trace/lantern/simulation/SimulationTimingMap.js +15 -15
- package/models/trace/lantern/simulation/SimulationTimingMap.js.map +1 -1
- package/models/trace/lantern/simulation/Simulator.d.ts +28 -28
- package/models/trace/lantern/simulation/Simulator.js +113 -113
- package/models/trace/lantern/simulation/Simulator.js.map +1 -1
- package/models/trace/lantern/simulation/TCPConnection.d.ts +9 -9
- package/models/trace/lantern/simulation/TCPConnection.js +36 -36
- package/models/trace/lantern/simulation/TCPConnection.js.map +1 -1
- package/models/trace/root-causes/LayoutShift.d.ts +13 -13
- package/models/trace/root-causes/LayoutShift.js +7 -25
- package/models/trace/root-causes/LayoutShift.js.map +1 -1
- package/models/trace/types/Configuration.d.ts +16 -0
- package/models/trace/types/Configuration.js +1 -0
- package/models/trace/types/Configuration.js.map +1 -1
- package/models/trace/types/Extensions.d.ts +9 -12
- package/models/trace/types/Extensions.js +2 -1
- package/models/trace/types/Extensions.js.map +1 -1
- package/models/trace/types/File.d.ts +68 -25
- package/models/trace/types/File.js +15 -3
- package/models/trace/types/File.js.map +1 -1
- package/models/trace/types/TraceEvents.d.ts +819 -730
- package/models/trace/types/TraceEvents.js +270 -280
- package/models/trace/types/TraceEvents.js.map +1 -1
- package/models/trace/types/types.d.ts +1 -1
- package/models/trace/types/types.js +1 -1
- package/models/trace/types/types.js.map +1 -1
- package/package.json +4 -2
- package/test/test-trace-engine.mjs +47 -2
- package/third_party/third-party-web/third-party-web.js +1 -0
- package/core/platform/PromiseUtilities.d.ts +0 -10
- package/core/platform/PromiseUtilities.js +0 -18
- package/core/platform/PromiseUtilities.js.map +0 -1
- package/core/platform/SetUtilities.d.ts +0 -2
- package/core/platform/SetUtilities.js +0 -23
- package/core/platform/SetUtilities.js.map +0 -1
- package/models/trace/EntriesFilter.d.ts +0 -72
- package/models/trace/EntriesFilter.js +0 -296
- package/models/trace/EntriesFilter.js.map +0 -1
- package/models/trace/LegacyTracingModel.js.map +0 -1
- package/models/trace/handlers/EnhancedTracesHandler.d.ts +0 -48
- package/models/trace/handlers/EnhancedTracesHandler.js +0 -165
- package/models/trace/handlers/EnhancedTracesHandler.js.map +0 -1
- package/models/trace/lantern/BaseNode.d.ts +0 -91
- package/models/trace/lantern/BaseNode.js +0 -268
- package/models/trace/lantern/BaseNode.js.map +0 -1
- package/models/trace/lantern/CPUNode.d.ts +0 -24
- package/models/trace/lantern/CPUNode.js +0 -64
- package/models/trace/lantern/CPUNode.js.map +0 -1
- package/models/trace/lantern/LanternError.d.ts +0 -3
- package/models/trace/lantern/LanternError.js +0 -7
- package/models/trace/lantern/LanternError.js.map +0 -1
- package/models/trace/lantern/MetricsModule.d.ts +0 -11
- package/models/trace/lantern/MetricsModule.js +0 -14
- package/models/trace/lantern/MetricsModule.js.map +0 -1
- package/models/trace/lantern/NetworkNode.d.ts +0 -22
- package/models/trace/lantern/NetworkNode.js +0 -83
- package/models/trace/lantern/NetworkNode.js.map +0 -1
- package/models/trace/lantern/PageDependencyGraph.d.ts +0 -43
- package/models/trace/lantern/PageDependencyGraph.js +0 -509
- package/models/trace/lantern/PageDependencyGraph.js.map +0 -1
- package/models/trace/lantern/SimulationModule.d.ts +0 -17
- package/models/trace/lantern/SimulationModule.js +0 -13
- package/models/trace/lantern/SimulationModule.js.map +0 -1
- package/models/trace/lantern/simulation/NetworkAnalyzer.d.ts +0 -112
- package/models/trace/lantern/simulation/NetworkAnalyzer.js +0 -486
- package/models/trace/lantern/simulation/NetworkAnalyzer.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAmC7B,MAAM,CAAN,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,iCAAe,CAAA;IACf,mCAAiB,CAAA;IACjB,uEAAuE;IACvE,6DAA2C,CAAA;IAC3C,yCAAuB,CAAA;AACzB,CAAC,EANW,cAAc,KAAd,cAAc,QAMzB","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 type * as Handlers from '../handlers/handlers.js';\nimport type * as Lantern from '../lantern/lantern.js';\nimport type * as Types from '../types/types.js';\n\nimport type * as InsightsRunners from './InsightRunners.js';\n\n/**\n * Context for the portion of the trace an insight should look at.\n */\nexport type InsightSetContext = InsightSetContextWithoutNavigation|InsightSetContextWithNavigation;\n\nexport interface InsightSetContextWithoutNavigation {\n bounds: Types.Timing.TraceWindowMicroSeconds;\n frameId: string;\n navigation?: never;\n}\n\nexport interface InsightSetContextWithNavigation {\n bounds: Types.Timing.TraceWindowMicroSeconds;\n frameId: string;\n navigation: Types.Events.NavigationStart;\n navigationId: string;\n lantern?: LanternContext;\n}\n\nexport interface LanternContext {\n graph: Lantern.Graph.Node<Types.Events.SyntheticNetworkRequest>;\n simulator: Lantern.Simulation.Simulator<Types.Events.SyntheticNetworkRequest>;\n metrics: Record<string, Lantern.Metrics.MetricResult>;\n}\n\nexport type InsightRunnersType = typeof InsightsRunners;\n\nexport enum InsightWarning {\n NO_FP = 'NO_FP',\n NO_LCP = 'NO_LCP',\n // No network request could be identified as the primary HTML document.\n NO_DOCUMENT_REQUEST = 'NO_DOCUMENT_REQUEST',\n NO_LAYOUT = 'NO_LAYOUT',\n}\n\nexport interface MetricSavings {\n /* eslint-disable @typescript-eslint/naming-convention */\n FCP?: Types.Timing.MilliSeconds;\n LCP?: Types.Timing.MilliSeconds;\n TBT?: Types.Timing.MilliSeconds;\n CLS?: number;\n INP?: Types.Timing.MilliSeconds;\n /* eslint-enable @typescript-eslint/naming-convention */\n}\n\nexport type InsightResult<R extends Record<string, unknown>> = R&{\n relatedEvents?: Types.Events.Event[],\n warnings?: InsightWarning[],\n metricSavings?: MetricSavings,\n};\n\n/**\n * Contains insights for a specific navigation. If a trace began after a navigation already started,\n * this could instead represent the duration from the beginning of the trace up to the first recorded\n * navigation (or the end of the trace).\n */\nexport type InsightSets = {\n /** If for a navigation, this is the navigationId. Else it is Trace.Types.Events.NO_NAVIGATION. */\n id: Types.Events.NavigationId,\n /** The URL to show in the accordion list. */\n url: URL,\n frameId: string,\n bounds: Types.Timing.TraceWindowMicroSeconds,\n data: InsightResults,\n navigation?: Types.Events.NavigationStart,\n};\n\n/**\n * Contains insights for a specific navigation.\n */\nexport type InsightResults = {\n [I in keyof InsightRunnersType]: ReturnType<InsightRunnersType[I]['generateInsight']>;\n};\n\n/**\n * Contains insights for the entire trace. Insights are mostly grouped by `navigationId`, with one exception:\n *\n * If the analyzed trace started after the navigation, and has meaningful work with that span, there is no\n * navigation to map it to. In this case `Types.Events.NO_NAVIGATION` is used for the key.\n */\nexport type TraceInsightSets = Map<Types.Events.NavigationId, InsightSets>;\n\n/**\n * Represents the narrow set of dependencies defined by an insight's `deps()` function. `Meta` is always included regardless of `deps()`.\n */\nexport type RequiredData<D extends() => Array<keyof typeof Handlers.ModelHandlers>> =\n Handlers.Types.EnabledHandlerDataWithMeta<Pick<typeof Handlers.ModelHandlers, ReturnType<D>[number]>>;\n"]}
|
|
@@ -34,7 +34,7 @@ declare class NetworkAnalyzer {
|
|
|
34
34
|
static groupByOrigin(records: Lantern.NetworkRequest[]): Map<string, Lantern.NetworkRequest[]>;
|
|
35
35
|
static getSummary(values: number[]): Summary;
|
|
36
36
|
static summarize(values: Map<string, number[]>): Map<string, Summary>;
|
|
37
|
-
static
|
|
37
|
+
static estimateValueByOrigin(requests: Lantern.NetworkRequest[], iteratee: (e: RequestInfo) => number | number[] | undefined): Map<string, number[]>;
|
|
38
38
|
/**
|
|
39
39
|
* Estimates the observed RTT to each origin based on how long the connection setup.
|
|
40
40
|
* For h1 and h2, this could includes two estimates - one for the TCP handshake, another for
|
|
@@ -43,31 +43,31 @@ declare class NetworkAnalyzer {
|
|
|
43
43
|
* single handshake.
|
|
44
44
|
* This is the most accurate and preferred method of measurement when the data is available.
|
|
45
45
|
*/
|
|
46
|
-
static
|
|
46
|
+
static estimateRTTViaConnectionTiming(info: RequestInfo): number[] | number | undefined;
|
|
47
47
|
/**
|
|
48
48
|
* Estimates the observed RTT to each origin based on how long a download took on a fresh connection.
|
|
49
49
|
* NOTE: this will tend to overestimate the actual RTT quite significantly as the download can be
|
|
50
50
|
* slow for other reasons as well such as bandwidth constraints.
|
|
51
51
|
*/
|
|
52
|
-
static
|
|
52
|
+
static estimateRTTViaDownloadTiming(info: RequestInfo): number | undefined;
|
|
53
53
|
/**
|
|
54
54
|
* Estimates the observed RTT to each origin based on how long it took until Chrome could
|
|
55
55
|
* start sending the actual request when a new connection was required.
|
|
56
56
|
* NOTE: this will tend to overestimate the actual RTT as the request can be delayed for other
|
|
57
57
|
* reasons as well such as more SSL handshakes if TLS False Start is not enabled.
|
|
58
58
|
*/
|
|
59
|
-
static
|
|
59
|
+
static estimateRTTViaSendStartTiming(info: RequestInfo): number | undefined;
|
|
60
60
|
/**
|
|
61
61
|
* Estimates the observed RTT to each origin based on how long it took until Chrome received the
|
|
62
62
|
* headers of the response (~TTFB).
|
|
63
63
|
* NOTE: this is the most inaccurate way to estimate the RTT, but in some environments it's all
|
|
64
64
|
* we have access to :(
|
|
65
65
|
*/
|
|
66
|
-
static
|
|
66
|
+
static estimateRTTViaHeadersEndTiming(info: RequestInfo): number | undefined;
|
|
67
67
|
/**
|
|
68
68
|
* Given the RTT to each origin, estimates the observed server response times.
|
|
69
69
|
*/
|
|
70
|
-
static
|
|
70
|
+
static estimateResponseTimeByOrigin(records: Lantern.NetworkRequest[], rttByOrigin: Map<string, number>): Map<string, number[]>;
|
|
71
71
|
static canTrustConnectionInformation(requests: Lantern.NetworkRequest[]): boolean;
|
|
72
72
|
/**
|
|
73
73
|
* Returns a map of requestId -> connectionReused, estimating the information if the information
|
|
@@ -93,7 +93,7 @@ class NetworkAnalyzer {
|
|
|
93
93
|
summaryByKey.set(NetworkAnalyzer.summary, NetworkAnalyzer.getSummary(allEstimates));
|
|
94
94
|
return summaryByKey;
|
|
95
95
|
}
|
|
96
|
-
static
|
|
96
|
+
static estimateValueByOrigin(requests, iteratee) {
|
|
97
97
|
const connectionWasReused = NetworkAnalyzer.estimateIfConnectionWasReused(requests);
|
|
98
98
|
const groupedByOrigin = NetworkAnalyzer.groupByOrigin(requests);
|
|
99
99
|
const estimates = new Map();
|
|
@@ -128,7 +128,7 @@ class NetworkAnalyzer {
|
|
|
128
128
|
* single handshake.
|
|
129
129
|
* This is the most accurate and preferred method of measurement when the data is available.
|
|
130
130
|
*/
|
|
131
|
-
static
|
|
131
|
+
static estimateRTTViaConnectionTiming(info) {
|
|
132
132
|
const { timing, connectionReused, request } = info;
|
|
133
133
|
if (connectionReused) {
|
|
134
134
|
return;
|
|
@@ -152,7 +152,7 @@ class NetworkAnalyzer {
|
|
|
152
152
|
* NOTE: this will tend to overestimate the actual RTT quite significantly as the download can be
|
|
153
153
|
* slow for other reasons as well such as bandwidth constraints.
|
|
154
154
|
*/
|
|
155
|
-
static
|
|
155
|
+
static estimateRTTViaDownloadTiming(info) {
|
|
156
156
|
const { timing, connectionReused, request } = info;
|
|
157
157
|
if (connectionReused) {
|
|
158
158
|
return;
|
|
@@ -181,7 +181,7 @@ class NetworkAnalyzer {
|
|
|
181
181
|
* NOTE: this will tend to overestimate the actual RTT as the request can be delayed for other
|
|
182
182
|
* reasons as well such as more SSL handshakes if TLS False Start is not enabled.
|
|
183
183
|
*/
|
|
184
|
-
static
|
|
184
|
+
static estimateRTTViaSendStartTiming(info) {
|
|
185
185
|
const { timing, connectionReused, request } = info;
|
|
186
186
|
if (connectionReused) {
|
|
187
187
|
return;
|
|
@@ -207,7 +207,7 @@ class NetworkAnalyzer {
|
|
|
207
207
|
* NOTE: this is the most inaccurate way to estimate the RTT, but in some environments it's all
|
|
208
208
|
* we have access to :(
|
|
209
209
|
*/
|
|
210
|
-
static
|
|
210
|
+
static estimateRTTViaHeadersEndTiming(info) {
|
|
211
211
|
const { timing, connectionReused, request } = info;
|
|
212
212
|
if (!Number.isFinite(timing.receiveHeadersEnd) || timing.receiveHeadersEnd < 0) {
|
|
213
213
|
return;
|
|
@@ -237,8 +237,8 @@ class NetworkAnalyzer {
|
|
|
237
237
|
/**
|
|
238
238
|
* Given the RTT to each origin, estimates the observed server response times.
|
|
239
239
|
*/
|
|
240
|
-
static
|
|
241
|
-
return NetworkAnalyzer.
|
|
240
|
+
static estimateResponseTimeByOrigin(records, rttByOrigin) {
|
|
241
|
+
return NetworkAnalyzer.estimateValueByOrigin(records, ({ request, timing }) => {
|
|
242
242
|
if (request.serverResponseTime !== undefined) {
|
|
243
243
|
return request.serverResponseTime;
|
|
244
244
|
}
|
|
@@ -334,7 +334,7 @@ class NetworkAnalyzer {
|
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
if (!forceCoarseEstimates) {
|
|
337
|
-
collectEstimates(this.
|
|
337
|
+
collectEstimates(this.estimateRTTViaConnectionTiming);
|
|
338
338
|
}
|
|
339
339
|
// Connection timing can be missing for a few reasons:
|
|
340
340
|
// - Origin was preconnected, which we don't have instrumentation for.
|
|
@@ -343,13 +343,13 @@ class NetworkAnalyzer {
|
|
|
343
343
|
// - Not provided in LR netstack.
|
|
344
344
|
if (!originEstimates.length) {
|
|
345
345
|
if (useDownloadEstimates) {
|
|
346
|
-
collectEstimates(this.
|
|
346
|
+
collectEstimates(this.estimateRTTViaDownloadTiming, coarseEstimateMultiplier);
|
|
347
347
|
}
|
|
348
348
|
if (useSendStartEstimates) {
|
|
349
|
-
collectEstimates(this.
|
|
349
|
+
collectEstimates(this.estimateRTTViaSendStartTiming, coarseEstimateMultiplier);
|
|
350
350
|
}
|
|
351
351
|
if (useHeadersEndEstimates) {
|
|
352
|
-
collectEstimates(this.
|
|
352
|
+
collectEstimates(this.estimateRTTViaHeadersEndTiming, coarseEstimateMultiplier);
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
355
|
if (originEstimates.length) {
|
|
@@ -374,7 +374,7 @@ class NetworkAnalyzer {
|
|
|
374
374
|
rttByOrigin.set(origin, summary.min);
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
|
-
const estimatesByOrigin = NetworkAnalyzer.
|
|
377
|
+
const estimatesByOrigin = NetworkAnalyzer.estimateResponseTimeByOrigin(records, rttByOrigin);
|
|
378
378
|
return NetworkAnalyzer.summarize(estimatesByOrigin);
|
|
379
379
|
}
|
|
380
380
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkAnalyzer.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/core/NetworkAnalyzer.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAI7B,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAE/C,MAAM,QAAQ;IACZ;;;;OAIG;IACH,MAAM,CAAC,wBAAwB,CAAC,GAAW;QACzC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YACzC,OAAO,GAAG,CAAC;QACb,CAAC;QACD,2EAA2E;QAC3E,+EAA+E;QAC/E,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,GAAG,CAAC,OAAO,CAAC,sBAAsB,EAAE,WAAW,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,0BAA0B,CAAC,IAAY,EAAE,IAAY;QAC1D,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,GAAG,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A+B,CAAC,OAAO,CAAC;SAC5D,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAmC,OAAiB,EAAE,WAAmB;QAChG,2GAA2G;QAC3G,OAAO,OAAO,CAAC,IAAI,CACf,OAAO,CAAC,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,0BAA0B,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAClH,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,sBAAsB,CAAmC,OAAiB,EAAE,WAAmB;QACpG,2GAA2G;QAC3G,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,CACnC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,YAAY,KAAK,UAAU;YAC1C,gGAAgG;YAChG,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,0BAA0B,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAC3G,CAAC;QACF,OAAO,gBAAgB,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,gBAAgB,CAAmC,OAAU;QAClE,OAAO,OAAO,CAAC,mBAAmB,EAAE,CAAC;YACnC,OAAO,GAAG,OAAO,CAAC,mBAAwB,CAAC;QAC7C,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAED,OAAO,EAAC,eAAe,EAAC,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 type * as Lantern from '../types/types.js';\n\nimport {LanternError} from './LanternError.js';\n\nclass UrlUtils {\n /**\n * There is fancy URL rewriting logic for the chrome://settings page that we need to work around.\n * Why? Special handling was added by Chrome team to allow a pushState transition between chrome:// pages.\n * As a result, the network URL (chrome://chrome/settings/) doesn't match the final document URL (chrome://settings/).\n */\n static rewriteChromeInternalUrl(url: string): string {\n if (!url || !url.startsWith('chrome://')) {\n return url;\n }\n // Chrome adds a trailing slash to `chrome://` URLs, but the spec does not.\n // https://github.com/GoogleChrome/lighthouse/pull/3941#discussion_r154026009\n if (url.endsWith('/')) {\n url = url.replace(/\\/$/, '');\n }\n return url.replace(/^chrome:\\/\\/chrome\\//, 'chrome://');\n }\n\n /**\n * Determine if url1 equals url2, ignoring URL fragments.\n */\n static equalWithExcludedFragments(url1: string, url2: string): boolean {\n [url1, url2] = [url1, url2].map(this.rewriteChromeInternalUrl);\n try {\n const urla = new URL(url1);\n urla.hash = '';\n\n const urlb = new URL(url2);\n urlb.hash = '';\n\n return urla.href === urlb.href;\n } catch (e) {\n return false;\n }\n }\n}\n\ninterface Summary {\n min: number;\n max: number;\n avg: number;\n median: number;\n}\n\ninterface RTTEstimateOptions {\n /**\n * TCP connection handshake information will be used when available, but in\n * some circumstances this data can be unreliable. This flag exposes an\n * option to ignore the handshake data and use the coarse download/TTFB timing data.\n */\n forceCoarseEstimates?: boolean;\n /**\n * Coarse estimates include lots of extra time and noise multiply by some factor\n * to deflate the estimates a bit.\n */\n coarseEstimateMultiplier?: number;\n /** Useful for testing to isolate the different methods of estimation. */\n useDownloadEstimates?: boolean;\n /** Useful for testing to isolate the different methods of estimation. */\n useSendStartEstimates?: boolean;\n /** Useful for testing to isolate the different methods of estimation. */\n useHeadersEndEstimates?: boolean;\n}\n\ntype RequestInfo = {\n request: Lantern.NetworkRequest,\n timing: Lantern.ResourceTiming,\n connectionReused?: boolean,\n};\n\nconst INITIAL_CWD = 14 * 1024;\n\n// Assume that 40% of TTFB was server response time by default for static assets\nconst DEFAULT_SERVER_RESPONSE_PERCENTAGE = 0.4;\n\n/**\n * For certain resource types, server response time takes up a greater percentage of TTFB (dynamic\n * assets like HTML documents, XHR/API calls, etc)\n */\nconst SERVER_RESPONSE_PERCENTAGE_OF_TTFB: Partial<Record<Lantern.ResourceType, number>> = {\n Document: 0.9,\n XHR: 0.9,\n Fetch: 0.9,\n};\n\nclass NetworkAnalyzer {\n static get summary(): string {\n return '__SUMMARY__';\n }\n\n static groupByOrigin(records: Lantern.NetworkRequest[]): Map<string, Lantern.NetworkRequest[]> {\n const grouped = new Map();\n records.forEach(item => {\n const key = item.parsedURL.securityOrigin;\n const group = grouped.get(key) || [];\n group.push(item);\n grouped.set(key, group);\n });\n return grouped;\n }\n\n static getSummary(values: number[]): Summary {\n values.sort((a, b) => a - b);\n\n let median;\n if (values.length === 0) {\n median = values[0];\n } else if (values.length % 2 === 0) {\n const a = values[Math.floor((values.length - 1) / 2)];\n const b = values[Math.floor((values.length - 1) / 2) + 1];\n median = (a + b) / 2;\n } else {\n median = values[Math.floor((values.length - 1) / 2)];\n }\n\n return {\n min: values[0],\n max: values[values.length - 1],\n avg: values.reduce((a, b) => a + b, 0) / values.length,\n median,\n };\n }\n\n static summarize(values: Map<string, number[]>): Map<string, Summary> {\n const summaryByKey = new Map();\n const allEstimates = [];\n for (const [key, estimates] of values) {\n summaryByKey.set(key, NetworkAnalyzer.getSummary(estimates));\n allEstimates.push(...estimates);\n }\n\n summaryByKey.set(NetworkAnalyzer.summary, NetworkAnalyzer.getSummary(allEstimates));\n return summaryByKey;\n }\n\n static _estimateValueByOrigin(\n requests: Lantern.NetworkRequest[],\n iteratee: (e: RequestInfo) => number | number[] | undefined): Map<string, number[]> {\n const connectionWasReused = NetworkAnalyzer.estimateIfConnectionWasReused(requests);\n const groupedByOrigin = NetworkAnalyzer.groupByOrigin(requests);\n\n const estimates = new Map();\n for (const [origin, originRequests] of groupedByOrigin.entries()) {\n let originEstimates: number[] = [];\n\n for (const request of originRequests) {\n const timing = request.timing;\n if (!timing) {\n continue;\n }\n\n const value = iteratee({\n request,\n timing,\n connectionReused: connectionWasReused.get(request.requestId),\n });\n if (typeof value !== 'undefined') {\n originEstimates = originEstimates.concat(value);\n }\n }\n\n if (!originEstimates.length) {\n continue;\n }\n estimates.set(origin, originEstimates);\n }\n\n return estimates;\n }\n\n /**\n * Estimates the observed RTT to each origin based on how long the connection setup.\n * For h1 and h2, this could includes two estimates - one for the TCP handshake, another for\n * SSL negotiation.\n * For h3, we get only one estimate since QUIC establishes a secure connection in a\n * single handshake.\n * This is the most accurate and preferred method of measurement when the data is available.\n */\n static _estimateRTTViaConnectionTiming(info: RequestInfo): number[]|number|undefined {\n const {timing, connectionReused, request} = info;\n if (connectionReused) {\n return;\n }\n\n const {connectStart, sslStart, sslEnd, connectEnd} = timing;\n if (connectEnd >= 0 && connectStart >= 0 && request.protocol.startsWith('h3')) {\n // These values are equal to sslStart and sslEnd for h3.\n return connectEnd - connectStart;\n }\n if (sslStart >= 0 && sslEnd >= 0 && sslStart !== connectStart) {\n // SSL can also be more than 1 RT but assume False Start was used.\n return [connectEnd - sslStart, sslStart - connectStart];\n }\n if (connectStart >= 0 && connectEnd >= 0) {\n return connectEnd - connectStart;\n }\n\n return;\n }\n\n /**\n * Estimates the observed RTT to each origin based on how long a download took on a fresh connection.\n * NOTE: this will tend to overestimate the actual RTT quite significantly as the download can be\n * slow for other reasons as well such as bandwidth constraints.\n */\n static _estimateRTTViaDownloadTiming(info: RequestInfo): number|undefined {\n const {timing, connectionReused, request} = info;\n if (connectionReused) {\n return;\n }\n\n // Only look at downloads that went past the initial congestion window\n if (request.transferSize <= INITIAL_CWD) {\n return;\n }\n if (!Number.isFinite(timing.receiveHeadersEnd) || timing.receiveHeadersEnd < 0) {\n return;\n }\n\n // Compute the amount of time downloading everything after the first congestion window took\n const totalTime = request.networkEndTime - request.networkRequestTime;\n const downloadTimeAfterFirstByte = totalTime - timing.receiveHeadersEnd;\n const numberOfRoundTrips = Math.log2(request.transferSize / INITIAL_CWD);\n\n // Ignore requests that required a high number of round trips since bandwidth starts to play\n // a larger role than latency\n if (numberOfRoundTrips > 5) {\n return;\n }\n\n return downloadTimeAfterFirstByte / numberOfRoundTrips;\n }\n\n /**\n * Estimates the observed RTT to each origin based on how long it took until Chrome could\n * start sending the actual request when a new connection was required.\n * NOTE: this will tend to overestimate the actual RTT as the request can be delayed for other\n * reasons as well such as more SSL handshakes if TLS False Start is not enabled.\n */\n static _estimateRTTViaSendStartTiming(info: RequestInfo): number|undefined {\n const {timing, connectionReused, request} = info;\n if (connectionReused) {\n return;\n }\n\n if (!Number.isFinite(timing.sendStart) || timing.sendStart < 0) {\n return;\n }\n\n // Assume everything before sendStart was just DNS + (SSL)? + TCP handshake\n // 1 RT for DNS, 1 RT (maybe) for SSL, 1 RT for TCP\n let roundTrips = 1;\n // TCP\n if (!request.protocol.startsWith('h3')) {\n roundTrips += 1;\n }\n if (request.parsedURL.scheme === 'https') {\n roundTrips += 1;\n }\n return timing.sendStart / roundTrips;\n }\n\n /**\n * Estimates the observed RTT to each origin based on how long it took until Chrome received the\n * headers of the response (~TTFB).\n * NOTE: this is the most inaccurate way to estimate the RTT, but in some environments it's all\n * we have access to :(\n */\n static _estimateRTTViaHeadersEndTiming(info: RequestInfo): number|undefined {\n const {timing, connectionReused, request} = info;\n if (!Number.isFinite(timing.receiveHeadersEnd) || timing.receiveHeadersEnd < 0) {\n return;\n }\n if (!request.resourceType) {\n return;\n }\n\n const serverResponseTimePercentage =\n SERVER_RESPONSE_PERCENTAGE_OF_TTFB[request.resourceType] || DEFAULT_SERVER_RESPONSE_PERCENTAGE;\n const estimatedServerResponseTime = timing.receiveHeadersEnd * serverResponseTimePercentage;\n\n // When connection was reused...\n // TTFB = 1 RT for request + server response time\n let roundTrips = 1;\n\n // When connection was fresh...\n // TTFB = DNS + (SSL)? + TCP handshake + 1 RT for request + server response time\n if (!connectionReused) {\n roundTrips += 1; // DNS\n if (!request.protocol.startsWith('h3')) {\n roundTrips += 1; // TCP\n }\n if (request.parsedURL.scheme === 'https') {\n roundTrips += 1; // SSL\n }\n }\n\n // subtract out our estimated server response time\n return Math.max((timing.receiveHeadersEnd - estimatedServerResponseTime) / roundTrips, 3);\n }\n\n /**\n * Given the RTT to each origin, estimates the observed server response times.\n */\n static _estimateResponseTimeByOrigin(records: Lantern.NetworkRequest[], rttByOrigin: Map<string, number>):\n Map<string, number[]> {\n return NetworkAnalyzer._estimateValueByOrigin(records, ({request, timing}) => {\n if (request.serverResponseTime !== undefined) {\n return request.serverResponseTime;\n }\n\n if (!Number.isFinite(timing.receiveHeadersEnd) || timing.receiveHeadersEnd < 0) {\n return;\n }\n if (!Number.isFinite(timing.sendEnd) || timing.sendEnd < 0) {\n return;\n }\n\n const ttfb = timing.receiveHeadersEnd - timing.sendEnd;\n const origin = request.parsedURL.securityOrigin;\n const rtt = rttByOrigin.get(origin) || rttByOrigin.get(NetworkAnalyzer.summary) || 0;\n return Math.max(ttfb - rtt, 0);\n });\n }\n\n static canTrustConnectionInformation(requests: Lantern.NetworkRequest[]): boolean {\n const connectionIdWasStarted = new Map();\n for (const request of requests) {\n const started = connectionIdWasStarted.get(request.connectionId) || !request.connectionReused;\n connectionIdWasStarted.set(request.connectionId, started);\n }\n\n // We probably can't trust the network information if all the connection IDs were the same\n if (connectionIdWasStarted.size <= 1) {\n return false;\n }\n // Or if there were connections that were always reused (a connection had to have started at some point)\n return Array.from(connectionIdWasStarted.values()).every(started => started);\n }\n\n /**\n * Returns a map of requestId -> connectionReused, estimating the information if the information\n * available in the records themselves appears untrustworthy.\n */\n static estimateIfConnectionWasReused(records: Lantern.NetworkRequest[], options?: {forceCoarseEstimates: boolean}):\n Map<string, boolean> {\n const {forceCoarseEstimates = false} = options || {};\n\n // Check if we can trust the connection information coming from the protocol\n if (!forceCoarseEstimates && NetworkAnalyzer.canTrustConnectionInformation(records)) {\n return new Map(records.map(request => [request.requestId, Boolean(request.connectionReused)]));\n }\n\n // Otherwise we're on our own, a request may not have needed a fresh connection if...\n // - It was not the first request to the domain\n // - It was H2\n // - It was after the first request to the domain ended\n const connectionWasReused = new Map();\n const groupedByOrigin = NetworkAnalyzer.groupByOrigin(records);\n for (const originRecords of groupedByOrigin.values()) {\n const earliestReusePossible =\n originRecords.map(request => request.networkEndTime).reduce((a, b) => Math.min(a, b), Infinity);\n\n for (const request of originRecords) {\n connectionWasReused.set(\n request.requestId,\n request.networkRequestTime >= earliestReusePossible || request.protocol === 'h2',\n );\n }\n\n const firstRecord = originRecords.reduce((a, b) => {\n return a.networkRequestTime > b.networkRequestTime ? b : a;\n });\n connectionWasReused.set(firstRecord.requestId, false);\n }\n\n return connectionWasReused;\n }\n\n /**\n * Estimates the RTT to each origin by examining observed network timing information.\n * Attempts to use the most accurate information first and falls back to coarser estimates when it\n * is unavailable.\n */\n static estimateRTTByOrigin(records: Lantern.NetworkRequest[], options?: RTTEstimateOptions): Map<string, Summary> {\n const {\n forceCoarseEstimates = false,\n // coarse estimates include lots of extra time and noise\n // multiply by some factor to deflate the estimates a bit.\n coarseEstimateMultiplier = 0.3,\n useDownloadEstimates = true,\n useSendStartEstimates = true,\n useHeadersEndEstimates = true,\n } = options || {};\n\n const connectionWasReused = NetworkAnalyzer.estimateIfConnectionWasReused(records);\n const groupedByOrigin = NetworkAnalyzer.groupByOrigin(records);\n\n const estimatesByOrigin = new Map();\n for (const [origin, originRequests] of groupedByOrigin.entries()) {\n const originEstimates: number[] = [];\n\n // eslint-disable-next-line no-inner-declarations\n function collectEstimates(estimator: (e: RequestInfo) => number[] | number | undefined, multiplier = 1): void {\n for (const request of originRequests) {\n const timing = request.timing;\n if (!timing) {\n continue;\n }\n\n const estimates = estimator({\n request,\n timing,\n connectionReused: connectionWasReused.get(request.requestId),\n });\n if (estimates === undefined) {\n continue;\n }\n\n if (!Array.isArray(estimates)) {\n originEstimates.push(estimates * multiplier);\n } else {\n originEstimates.push(...estimates.map(e => e * multiplier));\n }\n }\n }\n\n if (!forceCoarseEstimates) {\n collectEstimates(this._estimateRTTViaConnectionTiming);\n }\n\n // Connection timing can be missing for a few reasons:\n // - Origin was preconnected, which we don't have instrumentation for.\n // - Trace began recording after a connection has already been established (for example, in timespan mode)\n // - Perhaps Chrome established a connection already in the background (service worker? Just guessing here)\n // - Not provided in LR netstack.\n if (!originEstimates.length) {\n if (useDownloadEstimates) {\n collectEstimates(this._estimateRTTViaDownloadTiming, coarseEstimateMultiplier);\n }\n if (useSendStartEstimates) {\n collectEstimates(this._estimateRTTViaSendStartTiming, coarseEstimateMultiplier);\n }\n if (useHeadersEndEstimates) {\n collectEstimates(this._estimateRTTViaHeadersEndTiming, coarseEstimateMultiplier);\n }\n }\n\n if (originEstimates.length) {\n estimatesByOrigin.set(origin, originEstimates);\n }\n }\n\n if (!estimatesByOrigin.size) {\n throw new LanternError('No timing information available');\n }\n return NetworkAnalyzer.summarize(estimatesByOrigin);\n }\n\n /**\n * Estimates the server response time of each origin. RTT times can be passed in or will be\n * estimated automatically if not provided.\n */\n static estimateServerResponseTimeByOrigin(records: Lantern.NetworkRequest[], options?: RTTEstimateOptions&{\n rttByOrigin?: Map<string, number>,\n }): Map<string, Summary> {\n let rttByOrigin = (options || {}).rttByOrigin;\n if (!rttByOrigin) {\n rttByOrigin = new Map();\n\n const rttSummaryByOrigin = NetworkAnalyzer.estimateRTTByOrigin(records, options);\n for (const [origin, summary] of rttSummaryByOrigin.entries()) {\n rttByOrigin.set(origin, summary.min);\n }\n }\n\n const estimatesByOrigin = NetworkAnalyzer._estimateResponseTimeByOrigin(records, rttByOrigin);\n return NetworkAnalyzer.summarize(estimatesByOrigin);\n }\n\n /**\n * Computes the average throughput for the given requests in bits/second.\n * Excludes data URI, failed or otherwise incomplete, and cached requests.\n * Returns Infinity if there were no analyzable network requests.\n */\n static estimateThroughput(records: Lantern.NetworkRequest[]): number {\n let totalBytes = 0;\n\n // We will measure throughput by summing the total bytes downloaded by the total time spent\n // downloading those bytes. We slice up all the network requests into start/end boundaries, so\n // it's easier to deal with the gaps in downloading.\n const timeBoundaries = records\n .reduce(\n (boundaries, request) => {\n const scheme = request.parsedURL?.scheme;\n // Requests whose bodies didn't come over the network or didn't completely finish will mess\n // with the computation, just skip over them.\n if (scheme === 'data' || request.failed || !request.finished ||\n request.statusCode > 300 || !request.transferSize) {\n return boundaries;\n }\n\n // If we've made it this far, all the times we need should be valid (i.e. not undefined/-1).\n totalBytes += request.transferSize;\n boundaries.push({time: request.responseHeadersEndTime / 1000, isStart: true});\n boundaries.push({time: request.networkEndTime / 1000, isStart: false});\n return boundaries;\n },\n [] as Array<{time: number, isStart: boolean}>)\n .sort((a, b) => a.time - b.time);\n\n if (!timeBoundaries.length) {\n return Infinity;\n }\n\n let inflight = 0;\n let currentStart = 0;\n let totalDuration = 0;\n\n timeBoundaries.forEach(boundary => {\n if (boundary.isStart) {\n if (inflight === 0) {\n // We just ended a quiet period, keep track of when the download period started\n currentStart = boundary.time;\n }\n inflight++;\n } else {\n inflight--;\n if (inflight === 0) {\n // We just entered a quiet period, update our duration with the time we spent downloading\n totalDuration += boundary.time - currentStart;\n }\n }\n });\n\n return totalBytes * 8 / totalDuration;\n }\n\n static computeRTTAndServerResponseTime(records: Lantern.NetworkRequest[]):\n {rtt: number, additionalRttByOrigin: Map<string, number>, serverResponseTimeByOrigin: Map<string, number>} {\n // First pass compute the estimated observed RTT to each origin's servers.\n const rttByOrigin = new Map<string, number>();\n for (const [origin, summary] of NetworkAnalyzer.estimateRTTByOrigin(records).entries()) {\n rttByOrigin.set(origin, summary.min);\n }\n\n // We'll use the minimum RTT as the assumed connection latency since we care about how much addt'l\n // latency each origin introduces as Lantern will be simulating with its own connection latency.\n const minimumRtt = Math.min(...Array.from(rttByOrigin.values()));\n // We'll use the observed RTT information to help estimate the server response time\n const responseTimeSummaries = NetworkAnalyzer.estimateServerResponseTimeByOrigin(records, {\n rttByOrigin,\n });\n\n const additionalRttByOrigin = new Map<string, number>();\n const serverResponseTimeByOrigin = new Map<string, number>();\n for (const [origin, summary] of responseTimeSummaries.entries()) {\n // Not all origins have usable timing data, we'll default to using no additional latency.\n const rttForOrigin = rttByOrigin.get(origin) || minimumRtt;\n additionalRttByOrigin.set(origin, rttForOrigin - minimumRtt);\n serverResponseTimeByOrigin.set(origin, summary.median);\n }\n\n return {\n rtt: minimumRtt,\n additionalRttByOrigin,\n serverResponseTimeByOrigin,\n };\n }\n\n static analyze(records: Lantern.NetworkRequest[]): Lantern.Simulation.Settings['networkAnalysis'] {\n const throughput = NetworkAnalyzer.estimateThroughput(records);\n return {\n throughput,\n ...NetworkAnalyzer.computeRTTAndServerResponseTime(records),\n };\n }\n\n static findResourceForUrl<T extends Lantern.NetworkRequest>(records: Array<T>, resourceUrl: string): T|undefined {\n // equalWithExcludedFragments is expensive, so check that the resourceUrl starts with the request url first\n return records.find(\n request => resourceUrl.startsWith(request.url) && UrlUtils.equalWithExcludedFragments(request.url, resourceUrl),\n );\n }\n\n static findLastDocumentForUrl<T extends Lantern.NetworkRequest>(records: Array<T>, resourceUrl: string): T|undefined {\n // equalWithExcludedFragments is expensive, so check that the resourceUrl starts with the request url first\n const matchingRequests = records.filter(\n request => request.resourceType === 'Document' &&\n // Note: `request.url` should never have a fragment, else this optimization gives wrong results.\n resourceUrl.startsWith(request.url) && UrlUtils.equalWithExcludedFragments(request.url, resourceUrl),\n );\n return matchingRequests[matchingRequests.length - 1];\n }\n\n /**\n * Resolves redirect chain given a main document.\n * See: {@link NetworkAnalyzer.findLastDocumentForUrl} for how to retrieve main document.\n */\n static resolveRedirects<T extends Lantern.NetworkRequest>(request: T): T {\n while (request.redirectDestination) {\n request = request.redirectDestination as T;\n }\n return request;\n }\n}\n\nexport {NetworkAnalyzer};\n"]}
|
|
1
|
+
{"version":3,"file":"NetworkAnalyzer.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/core/NetworkAnalyzer.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAI7B,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAE/C,MAAM,QAAQ;IACZ;;;;OAIG;IACH,MAAM,CAAC,wBAAwB,CAAC,GAAW;QACzC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,C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OAAO,CAAC,mBAAmB,EAAE,CAAC;YACnC,OAAO,GAAG,OAAO,CAAC,mBAAwB,CAAC;QAC7C,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAED,OAAO,EAAC,eAAe,EAAC,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 type * as Lantern from '../types/types.js';\n\nimport {LanternError} from './LanternError.js';\n\nclass UrlUtils {\n /**\n * There is fancy URL rewriting logic for the chrome://settings page that we need to work around.\n * Why? Special handling was added by Chrome team to allow a pushState transition between chrome:// pages.\n * As a result, the network URL (chrome://chrome/settings/) doesn't match the final document URL (chrome://settings/).\n */\n static rewriteChromeInternalUrl(url: string): string {\n if (!url || !url.startsWith('chrome://')) {\n return url;\n }\n // Chrome adds a trailing slash to `chrome://` URLs, but the spec does not.\n // https://github.com/GoogleChrome/lighthouse/pull/3941#discussion_r154026009\n if (url.endsWith('/')) {\n url = url.replace(/\\/$/, '');\n }\n return url.replace(/^chrome:\\/\\/chrome\\//, 'chrome://');\n }\n\n /**\n * Determine if url1 equals url2, ignoring URL fragments.\n */\n static equalWithExcludedFragments(url1: string, url2: string): boolean {\n [url1, url2] = [url1, url2].map(this.rewriteChromeInternalUrl);\n try {\n const urla = new URL(url1);\n urla.hash = '';\n\n const urlb = new URL(url2);\n urlb.hash = '';\n\n return urla.href === urlb.href;\n } catch (e) {\n return false;\n }\n }\n}\n\ninterface Summary {\n min: number;\n max: number;\n avg: number;\n median: number;\n}\n\ninterface RTTEstimateOptions {\n /**\n * TCP connection handshake information will be used when available, but in\n * some circumstances this data can be unreliable. This flag exposes an\n * option to ignore the handshake data and use the coarse download/TTFB timing data.\n */\n forceCoarseEstimates?: boolean;\n /**\n * Coarse estimates include lots of extra time and noise multiply by some factor\n * to deflate the estimates a bit.\n */\n coarseEstimateMultiplier?: number;\n /** Useful for testing to isolate the different methods of estimation. */\n useDownloadEstimates?: boolean;\n /** Useful for testing to isolate the different methods of estimation. */\n useSendStartEstimates?: boolean;\n /** Useful for testing to isolate the different methods of estimation. */\n useHeadersEndEstimates?: boolean;\n}\n\ntype RequestInfo = {\n request: Lantern.NetworkRequest,\n timing: Lantern.ResourceTiming,\n connectionReused?: boolean,\n};\n\nconst INITIAL_CWD = 14 * 1024;\n\n// Assume that 40% of TTFB was server response time by default for static assets\nconst DEFAULT_SERVER_RESPONSE_PERCENTAGE = 0.4;\n\n/**\n * For certain resource types, server response time takes up a greater percentage of TTFB (dynamic\n * assets like HTML documents, XHR/API calls, etc)\n */\nconst SERVER_RESPONSE_PERCENTAGE_OF_TTFB: Partial<Record<Lantern.ResourceType, number>> = {\n Document: 0.9,\n XHR: 0.9,\n Fetch: 0.9,\n};\n\nclass NetworkAnalyzer {\n static get summary(): string {\n return '__SUMMARY__';\n }\n\n static groupByOrigin(records: Lantern.NetworkRequest[]): Map<string, Lantern.NetworkRequest[]> {\n const grouped = new Map();\n records.forEach(item => {\n const key = item.parsedURL.securityOrigin;\n const group = grouped.get(key) || [];\n group.push(item);\n grouped.set(key, group);\n });\n return grouped;\n }\n\n static getSummary(values: number[]): Summary {\n values.sort((a, b) => a - b);\n\n let median;\n if (values.length === 0) {\n median = values[0];\n } else if (values.length % 2 === 0) {\n const a = values[Math.floor((values.length - 1) / 2)];\n const b = values[Math.floor((values.length - 1) / 2) + 1];\n median = (a + b) / 2;\n } else {\n median = values[Math.floor((values.length - 1) / 2)];\n }\n\n return {\n min: values[0],\n max: values[values.length - 1],\n avg: values.reduce((a, b) => a + b, 0) / values.length,\n median,\n };\n }\n\n static summarize(values: Map<string, number[]>): Map<string, Summary> {\n const summaryByKey = new Map();\n const allEstimates = [];\n for (const [key, estimates] of values) {\n summaryByKey.set(key, NetworkAnalyzer.getSummary(estimates));\n allEstimates.push(...estimates);\n }\n\n summaryByKey.set(NetworkAnalyzer.summary, NetworkAnalyzer.getSummary(allEstimates));\n return summaryByKey;\n }\n\n static estimateValueByOrigin(\n requests: Lantern.NetworkRequest[],\n iteratee: (e: RequestInfo) => number | number[] | undefined): Map<string, number[]> {\n const connectionWasReused = NetworkAnalyzer.estimateIfConnectionWasReused(requests);\n const groupedByOrigin = NetworkAnalyzer.groupByOrigin(requests);\n\n const estimates = new Map();\n for (const [origin, originRequests] of groupedByOrigin.entries()) {\n let originEstimates: number[] = [];\n\n for (const request of originRequests) {\n const timing = request.timing;\n if (!timing) {\n continue;\n }\n\n const value = iteratee({\n request,\n timing,\n connectionReused: connectionWasReused.get(request.requestId),\n });\n if (typeof value !== 'undefined') {\n originEstimates = originEstimates.concat(value);\n }\n }\n\n if (!originEstimates.length) {\n continue;\n }\n estimates.set(origin, originEstimates);\n }\n\n return estimates;\n }\n\n /**\n * Estimates the observed RTT to each origin based on how long the connection setup.\n * For h1 and h2, this could includes two estimates - one for the TCP handshake, another for\n * SSL negotiation.\n * For h3, we get only one estimate since QUIC establishes a secure connection in a\n * single handshake.\n * This is the most accurate and preferred method of measurement when the data is available.\n */\n static estimateRTTViaConnectionTiming(info: RequestInfo): number[]|number|undefined {\n const {timing, connectionReused, request} = info;\n if (connectionReused) {\n return;\n }\n\n const {connectStart, sslStart, sslEnd, connectEnd} = timing;\n if (connectEnd >= 0 && connectStart >= 0 && request.protocol.startsWith('h3')) {\n // These values are equal to sslStart and sslEnd for h3.\n return connectEnd - connectStart;\n }\n if (sslStart >= 0 && sslEnd >= 0 && sslStart !== connectStart) {\n // SSL can also be more than 1 RT but assume False Start was used.\n return [connectEnd - sslStart, sslStart - connectStart];\n }\n if (connectStart >= 0 && connectEnd >= 0) {\n return connectEnd - connectStart;\n }\n\n return;\n }\n\n /**\n * Estimates the observed RTT to each origin based on how long a download took on a fresh connection.\n * NOTE: this will tend to overestimate the actual RTT quite significantly as the download can be\n * slow for other reasons as well such as bandwidth constraints.\n */\n static estimateRTTViaDownloadTiming(info: RequestInfo): number|undefined {\n const {timing, connectionReused, request} = info;\n if (connectionReused) {\n return;\n }\n\n // Only look at downloads that went past the initial congestion window\n if (request.transferSize <= INITIAL_CWD) {\n return;\n }\n if (!Number.isFinite(timing.receiveHeadersEnd) || timing.receiveHeadersEnd < 0) {\n return;\n }\n\n // Compute the amount of time downloading everything after the first congestion window took\n const totalTime = request.networkEndTime - request.networkRequestTime;\n const downloadTimeAfterFirstByte = totalTime - timing.receiveHeadersEnd;\n const numberOfRoundTrips = Math.log2(request.transferSize / INITIAL_CWD);\n\n // Ignore requests that required a high number of round trips since bandwidth starts to play\n // a larger role than latency\n if (numberOfRoundTrips > 5) {\n return;\n }\n\n return downloadTimeAfterFirstByte / numberOfRoundTrips;\n }\n\n /**\n * Estimates the observed RTT to each origin based on how long it took until Chrome could\n * start sending the actual request when a new connection was required.\n * NOTE: this will tend to overestimate the actual RTT as the request can be delayed for other\n * reasons as well such as more SSL handshakes if TLS False Start is not enabled.\n */\n static estimateRTTViaSendStartTiming(info: RequestInfo): number|undefined {\n const {timing, connectionReused, request} = info;\n if (connectionReused) {\n return;\n }\n\n if (!Number.isFinite(timing.sendStart) || timing.sendStart < 0) {\n return;\n }\n\n // Assume everything before sendStart was just DNS + (SSL)? + TCP handshake\n // 1 RT for DNS, 1 RT (maybe) for SSL, 1 RT for TCP\n let roundTrips = 1;\n // TCP\n if (!request.protocol.startsWith('h3')) {\n roundTrips += 1;\n }\n if (request.parsedURL.scheme === 'https') {\n roundTrips += 1;\n }\n return timing.sendStart / roundTrips;\n }\n\n /**\n * Estimates the observed RTT to each origin based on how long it took until Chrome received the\n * headers of the response (~TTFB).\n * NOTE: this is the most inaccurate way to estimate the RTT, but in some environments it's all\n * we have access to :(\n */\n static estimateRTTViaHeadersEndTiming(info: RequestInfo): number|undefined {\n const {timing, connectionReused, request} = info;\n if (!Number.isFinite(timing.receiveHeadersEnd) || timing.receiveHeadersEnd < 0) {\n return;\n }\n if (!request.resourceType) {\n return;\n }\n\n const serverResponseTimePercentage =\n SERVER_RESPONSE_PERCENTAGE_OF_TTFB[request.resourceType] || DEFAULT_SERVER_RESPONSE_PERCENTAGE;\n const estimatedServerResponseTime = timing.receiveHeadersEnd * serverResponseTimePercentage;\n\n // When connection was reused...\n // TTFB = 1 RT for request + server response time\n let roundTrips = 1;\n\n // When connection was fresh...\n // TTFB = DNS + (SSL)? + TCP handshake + 1 RT for request + server response time\n if (!connectionReused) {\n roundTrips += 1; // DNS\n if (!request.protocol.startsWith('h3')) {\n roundTrips += 1; // TCP\n }\n if (request.parsedURL.scheme === 'https') {\n roundTrips += 1; // SSL\n }\n }\n\n // subtract out our estimated server response time\n return Math.max((timing.receiveHeadersEnd - estimatedServerResponseTime) / roundTrips, 3);\n }\n\n /**\n * Given the RTT to each origin, estimates the observed server response times.\n */\n static estimateResponseTimeByOrigin(records: Lantern.NetworkRequest[], rttByOrigin: Map<string, number>):\n Map<string, number[]> {\n return NetworkAnalyzer.estimateValueByOrigin(records, ({request, timing}) => {\n if (request.serverResponseTime !== undefined) {\n return request.serverResponseTime;\n }\n\n if (!Number.isFinite(timing.receiveHeadersEnd) || timing.receiveHeadersEnd < 0) {\n return;\n }\n if (!Number.isFinite(timing.sendEnd) || timing.sendEnd < 0) {\n return;\n }\n\n const ttfb = timing.receiveHeadersEnd - timing.sendEnd;\n const origin = request.parsedURL.securityOrigin;\n const rtt = rttByOrigin.get(origin) || rttByOrigin.get(NetworkAnalyzer.summary) || 0;\n return Math.max(ttfb - rtt, 0);\n });\n }\n\n static canTrustConnectionInformation(requests: Lantern.NetworkRequest[]): boolean {\n const connectionIdWasStarted = new Map();\n for (const request of requests) {\n const started = connectionIdWasStarted.get(request.connectionId) || !request.connectionReused;\n connectionIdWasStarted.set(request.connectionId, started);\n }\n\n // We probably can't trust the network information if all the connection IDs were the same\n if (connectionIdWasStarted.size <= 1) {\n return false;\n }\n // Or if there were connections that were always reused (a connection had to have started at some point)\n return Array.from(connectionIdWasStarted.values()).every(started => started);\n }\n\n /**\n * Returns a map of requestId -> connectionReused, estimating the information if the information\n * available in the records themselves appears untrustworthy.\n */\n static estimateIfConnectionWasReused(records: Lantern.NetworkRequest[], options?: {forceCoarseEstimates: boolean}):\n Map<string, boolean> {\n const {forceCoarseEstimates = false} = options || {};\n\n // Check if we can trust the connection information coming from the protocol\n if (!forceCoarseEstimates && NetworkAnalyzer.canTrustConnectionInformation(records)) {\n return new Map(records.map(request => [request.requestId, Boolean(request.connectionReused)]));\n }\n\n // Otherwise we're on our own, a request may not have needed a fresh connection if...\n // - It was not the first request to the domain\n // - It was H2\n // - It was after the first request to the domain ended\n const connectionWasReused = new Map();\n const groupedByOrigin = NetworkAnalyzer.groupByOrigin(records);\n for (const originRecords of groupedByOrigin.values()) {\n const earliestReusePossible =\n originRecords.map(request => request.networkEndTime).reduce((a, b) => Math.min(a, b), Infinity);\n\n for (const request of originRecords) {\n connectionWasReused.set(\n request.requestId,\n request.networkRequestTime >= earliestReusePossible || request.protocol === 'h2',\n );\n }\n\n const firstRecord = originRecords.reduce((a, b) => {\n return a.networkRequestTime > b.networkRequestTime ? b : a;\n });\n connectionWasReused.set(firstRecord.requestId, false);\n }\n\n return connectionWasReused;\n }\n\n /**\n * Estimates the RTT to each origin by examining observed network timing information.\n * Attempts to use the most accurate information first and falls back to coarser estimates when it\n * is unavailable.\n */\n static estimateRTTByOrigin(records: Lantern.NetworkRequest[], options?: RTTEstimateOptions): Map<string, Summary> {\n const {\n forceCoarseEstimates = false,\n // coarse estimates include lots of extra time and noise\n // multiply by some factor to deflate the estimates a bit.\n coarseEstimateMultiplier = 0.3,\n useDownloadEstimates = true,\n useSendStartEstimates = true,\n useHeadersEndEstimates = true,\n } = options || {};\n\n const connectionWasReused = NetworkAnalyzer.estimateIfConnectionWasReused(records);\n const groupedByOrigin = NetworkAnalyzer.groupByOrigin(records);\n\n const estimatesByOrigin = new Map();\n for (const [origin, originRequests] of groupedByOrigin.entries()) {\n const originEstimates: number[] = [];\n\n // eslint-disable-next-line no-inner-declarations\n function collectEstimates(estimator: (e: RequestInfo) => number[] | number | undefined, multiplier = 1): void {\n for (const request of originRequests) {\n const timing = request.timing;\n if (!timing) {\n continue;\n }\n\n const estimates = estimator({\n request,\n timing,\n connectionReused: connectionWasReused.get(request.requestId),\n });\n if (estimates === undefined) {\n continue;\n }\n\n if (!Array.isArray(estimates)) {\n originEstimates.push(estimates * multiplier);\n } else {\n originEstimates.push(...estimates.map(e => e * multiplier));\n }\n }\n }\n\n if (!forceCoarseEstimates) {\n collectEstimates(this.estimateRTTViaConnectionTiming);\n }\n\n // Connection timing can be missing for a few reasons:\n // - Origin was preconnected, which we don't have instrumentation for.\n // - Trace began recording after a connection has already been established (for example, in timespan mode)\n // - Perhaps Chrome established a connection already in the background (service worker? Just guessing here)\n // - Not provided in LR netstack.\n if (!originEstimates.length) {\n if (useDownloadEstimates) {\n collectEstimates(this.estimateRTTViaDownloadTiming, coarseEstimateMultiplier);\n }\n if (useSendStartEstimates) {\n collectEstimates(this.estimateRTTViaSendStartTiming, coarseEstimateMultiplier);\n }\n if (useHeadersEndEstimates) {\n collectEstimates(this.estimateRTTViaHeadersEndTiming, coarseEstimateMultiplier);\n }\n }\n\n if (originEstimates.length) {\n estimatesByOrigin.set(origin, originEstimates);\n }\n }\n\n if (!estimatesByOrigin.size) {\n throw new LanternError('No timing information available');\n }\n return NetworkAnalyzer.summarize(estimatesByOrigin);\n }\n\n /**\n * Estimates the server response time of each origin. RTT times can be passed in or will be\n * estimated automatically if not provided.\n */\n static estimateServerResponseTimeByOrigin(records: Lantern.NetworkRequest[], options?: RTTEstimateOptions&{\n rttByOrigin?: Map<string, number>,\n }): Map<string, Summary> {\n let rttByOrigin = (options || {}).rttByOrigin;\n if (!rttByOrigin) {\n rttByOrigin = new Map();\n\n const rttSummaryByOrigin = NetworkAnalyzer.estimateRTTByOrigin(records, options);\n for (const [origin, summary] of rttSummaryByOrigin.entries()) {\n rttByOrigin.set(origin, summary.min);\n }\n }\n\n const estimatesByOrigin = NetworkAnalyzer.estimateResponseTimeByOrigin(records, rttByOrigin);\n return NetworkAnalyzer.summarize(estimatesByOrigin);\n }\n\n /**\n * Computes the average throughput for the given requests in bits/second.\n * Excludes data URI, failed or otherwise incomplete, and cached requests.\n * Returns Infinity if there were no analyzable network requests.\n */\n static estimateThroughput(records: Lantern.NetworkRequest[]): number {\n let totalBytes = 0;\n\n // We will measure throughput by summing the total bytes downloaded by the total time spent\n // downloading those bytes. We slice up all the network requests into start/end boundaries, so\n // it's easier to deal with the gaps in downloading.\n const timeBoundaries = records\n .reduce(\n (boundaries, request) => {\n const scheme = request.parsedURL?.scheme;\n // Requests whose bodies didn't come over the network or didn't completely finish will mess\n // with the computation, just skip over them.\n if (scheme === 'data' || request.failed || !request.finished ||\n request.statusCode > 300 || !request.transferSize) {\n return boundaries;\n }\n\n // If we've made it this far, all the times we need should be valid (i.e. not undefined/-1).\n totalBytes += request.transferSize;\n boundaries.push({time: request.responseHeadersEndTime / 1000, isStart: true});\n boundaries.push({time: request.networkEndTime / 1000, isStart: false});\n return boundaries;\n },\n [] as Array<{time: number, isStart: boolean}>)\n .sort((a, b) => a.time - b.time);\n\n if (!timeBoundaries.length) {\n return Infinity;\n }\n\n let inflight = 0;\n let currentStart = 0;\n let totalDuration = 0;\n\n timeBoundaries.forEach(boundary => {\n if (boundary.isStart) {\n if (inflight === 0) {\n // We just ended a quiet period, keep track of when the download period started\n currentStart = boundary.time;\n }\n inflight++;\n } else {\n inflight--;\n if (inflight === 0) {\n // We just entered a quiet period, update our duration with the time we spent downloading\n totalDuration += boundary.time - currentStart;\n }\n }\n });\n\n return totalBytes * 8 / totalDuration;\n }\n\n static computeRTTAndServerResponseTime(records: Lantern.NetworkRequest[]):\n {rtt: number, additionalRttByOrigin: Map<string, number>, serverResponseTimeByOrigin: Map<string, number>} {\n // First pass compute the estimated observed RTT to each origin's servers.\n const rttByOrigin = new Map<string, number>();\n for (const [origin, summary] of NetworkAnalyzer.estimateRTTByOrigin(records).entries()) {\n rttByOrigin.set(origin, summary.min);\n }\n\n // We'll use the minimum RTT as the assumed connection latency since we care about how much addt'l\n // latency each origin introduces as Lantern will be simulating with its own connection latency.\n const minimumRtt = Math.min(...Array.from(rttByOrigin.values()));\n // We'll use the observed RTT information to help estimate the server response time\n const responseTimeSummaries = NetworkAnalyzer.estimateServerResponseTimeByOrigin(records, {\n rttByOrigin,\n });\n\n const additionalRttByOrigin = new Map<string, number>();\n const serverResponseTimeByOrigin = new Map<string, number>();\n for (const [origin, summary] of responseTimeSummaries.entries()) {\n // Not all origins have usable timing data, we'll default to using no additional latency.\n const rttForOrigin = rttByOrigin.get(origin) || minimumRtt;\n additionalRttByOrigin.set(origin, rttForOrigin - minimumRtt);\n serverResponseTimeByOrigin.set(origin, summary.median);\n }\n\n return {\n rtt: minimumRtt,\n additionalRttByOrigin,\n serverResponseTimeByOrigin,\n };\n }\n\n static analyze(records: Lantern.NetworkRequest[]): Lantern.Simulation.Settings['networkAnalysis'] {\n const throughput = NetworkAnalyzer.estimateThroughput(records);\n return {\n throughput,\n ...NetworkAnalyzer.computeRTTAndServerResponseTime(records),\n };\n }\n\n static findResourceForUrl<T extends Lantern.NetworkRequest>(records: Array<T>, resourceUrl: string): T|undefined {\n // equalWithExcludedFragments is expensive, so check that the resourceUrl starts with the request url first\n return records.find(\n request => resourceUrl.startsWith(request.url) && UrlUtils.equalWithExcludedFragments(request.url, resourceUrl),\n );\n }\n\n static findLastDocumentForUrl<T extends Lantern.NetworkRequest>(records: Array<T>, resourceUrl: string): T|undefined {\n // equalWithExcludedFragments is expensive, so check that the resourceUrl starts with the request url first\n const matchingRequests = records.filter(\n request => request.resourceType === 'Document' &&\n // Note: `request.url` should never have a fragment, else this optimization gives wrong results.\n resourceUrl.startsWith(request.url) && UrlUtils.equalWithExcludedFragments(request.url, resourceUrl),\n );\n return matchingRequests[matchingRequests.length - 1];\n }\n\n /**\n * Resolves redirect chain given a main document.\n * See: {@link NetworkAnalyzer.findLastDocumentForUrl} for how to retrieve main document.\n */\n static resolveRedirects<T extends Lantern.NetworkRequest>(request: T): T {\n while (request.redirectDestination) {\n request = request.redirectDestination as T;\n }\n return request;\n }\n}\n\nexport {NetworkAnalyzer};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as Lantern from '../types/types.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { CPUNode } from './CPUNode.js';
|
|
3
|
+
import type { NetworkNode } from './NetworkNode.js';
|
|
4
4
|
/**
|
|
5
5
|
* A union of all types derived from BaseNode, allowing type check discrimination
|
|
6
6
|
* based on `node.type`. If a new node type is created, it should be added here.
|
|
@@ -25,8 +25,8 @@ declare class BaseNode<T = Lantern.AnyNetworkObject> {
|
|
|
25
25
|
};
|
|
26
26
|
_id: string;
|
|
27
27
|
_isMainDocument: boolean;
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
dependents: Node[];
|
|
29
|
+
dependencies: Node[];
|
|
30
30
|
constructor(id: string);
|
|
31
31
|
get id(): string;
|
|
32
32
|
get type(): 'network' | 'cpu';
|
|
@@ -21,13 +21,13 @@ class BaseNode {
|
|
|
21
21
|
};
|
|
22
22
|
_id;
|
|
23
23
|
_isMainDocument;
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
dependents;
|
|
25
|
+
dependencies;
|
|
26
26
|
constructor(id) {
|
|
27
27
|
this._id = id;
|
|
28
28
|
this._isMainDocument = false;
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
29
|
+
this.dependents = [];
|
|
30
|
+
this.dependencies = [];
|
|
31
31
|
}
|
|
32
32
|
get id() {
|
|
33
33
|
return this._id;
|
|
@@ -54,21 +54,21 @@ class BaseNode {
|
|
|
54
54
|
return this._isMainDocument;
|
|
55
55
|
}
|
|
56
56
|
getDependents() {
|
|
57
|
-
return this.
|
|
57
|
+
return this.dependents.slice();
|
|
58
58
|
}
|
|
59
59
|
getNumberOfDependents() {
|
|
60
|
-
return this.
|
|
60
|
+
return this.dependents.length;
|
|
61
61
|
}
|
|
62
62
|
getDependencies() {
|
|
63
|
-
return this.
|
|
63
|
+
return this.dependencies.slice();
|
|
64
64
|
}
|
|
65
65
|
getNumberOfDependencies() {
|
|
66
|
-
return this.
|
|
66
|
+
return this.dependencies.length;
|
|
67
67
|
}
|
|
68
68
|
getRootNode() {
|
|
69
69
|
let rootNode = this;
|
|
70
|
-
while (rootNode.
|
|
71
|
-
rootNode = rootNode.
|
|
70
|
+
while (rootNode.dependencies.length) {
|
|
71
|
+
rootNode = rootNode.dependencies[0];
|
|
72
72
|
}
|
|
73
73
|
return rootNode;
|
|
74
74
|
}
|
|
@@ -80,25 +80,25 @@ class BaseNode {
|
|
|
80
80
|
if (node === this) {
|
|
81
81
|
throw new Core.LanternError('Cannot add dependency on itself');
|
|
82
82
|
}
|
|
83
|
-
if (this.
|
|
83
|
+
if (this.dependencies.includes(node)) {
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
|
-
node.
|
|
87
|
-
this.
|
|
86
|
+
node.dependents.push(this);
|
|
87
|
+
this.dependencies.push(node);
|
|
88
88
|
}
|
|
89
89
|
removeDependent(node) {
|
|
90
90
|
node.removeDependency(this);
|
|
91
91
|
}
|
|
92
92
|
removeDependency(node) {
|
|
93
|
-
if (!this.
|
|
93
|
+
if (!this.dependencies.includes(node)) {
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
|
-
const thisIndex = node.
|
|
97
|
-
node.
|
|
98
|
-
this.
|
|
96
|
+
const thisIndex = node.dependents.indexOf(this);
|
|
97
|
+
node.dependents.splice(thisIndex, 1);
|
|
98
|
+
this.dependencies.splice(this.dependencies.indexOf(node), 1);
|
|
99
99
|
}
|
|
100
100
|
removeAllDependencies() {
|
|
101
|
-
for (const node of this.
|
|
101
|
+
for (const node of this.dependencies.slice()) {
|
|
102
102
|
this.removeDependency(node);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -158,7 +158,7 @@ class BaseNode {
|
|
|
158
158
|
// Node included, so walk back up dependencies, cloning nodes from here back to the root.
|
|
159
159
|
node.traverse(node => idsToIncludedClones.set(node.id, node.cloneWithoutRelationships()),
|
|
160
160
|
// Dependencies already cloned have already cloned ancestors, so no need to visit again.
|
|
161
|
-
node => node.
|
|
161
|
+
node => node.dependencies.filter(parent => !idsToIncludedClones.has(parent.id)));
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
// Copy dependencies between nodes.
|
|
@@ -167,7 +167,7 @@ class BaseNode {
|
|
|
167
167
|
if (!clonedNode) {
|
|
168
168
|
return;
|
|
169
169
|
}
|
|
170
|
-
for (const dependency of originalNode.
|
|
170
|
+
for (const dependency of originalNode.dependencies) {
|
|
171
171
|
const clonedDependency = idsToIncludedClones.get(dependency.id);
|
|
172
172
|
if (!clonedDependency) {
|
|
173
173
|
throw new Core.LanternError('Dependency somehow not cloned');
|
|
@@ -254,7 +254,7 @@ class BaseNode {
|
|
|
254
254
|
visited.add(currentNode);
|
|
255
255
|
currentPath.push(currentNode);
|
|
256
256
|
// Add all of its dependents to our toVisit stack
|
|
257
|
-
const nodesToExplore = direction === 'dependents' ? currentNode.
|
|
257
|
+
const nodesToExplore = direction === 'dependents' ? currentNode.dependents : currentNode.dependencies;
|
|
258
258
|
for (const nextNode of nodesToExplore) {
|
|
259
259
|
if (toVisit.includes(nextNode)) {
|
|
260
260
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseNode.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/graph/BaseNode.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAYxC;;;;;;;;;;;GAWG;AAEH,MAAM,QAAQ;IACZ,MAAM,CAAC,KAAK,GAAG;QACb,OAAO,EAAE,SAAS;QAClB,GAAG,EAAE,KAAK;KACF,CAAC;IAEX,GAAG,CAAS;IACZ,eAAe,CAAU;IACzB,WAAW,CAAS;IACpB,aAAa,CAAS;IAEtB,YAAY,EAAU;QACpB,IAAI,CAAC,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C;IAED,WAAW,CAAC,IAAU;QACpB,OAAO,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;IAC1C,CAAC;;AAGH,OAAO,EAAC,QAAQ,EAAC,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 Core from '../core/core.js';\nimport type * as Lantern from '../types/types.js';\n\nimport {type CPUNode} from './CPUNode.js';\nimport {type NetworkNode} from './NetworkNode.js';\n\n/**\n * A union of all types derived from BaseNode, allowing type check discrimination\n * based on `node.type`. If a new node type is created, it should be added here.\n */\nexport type Node<T = Lantern.AnyNetworkObject> = CPUNode<T>|NetworkNode<T>;\n\n/**\n * @fileoverview This class encapsulates logic for handling resources and tasks used to model the\n * execution dependency graph of the page. A node has a unique identifier and can depend on other\n * nodes/be depended on. The construction of the graph maintains some important invariants that are\n * inherent to the model:\n *\n * 1. The graph is a DAG, there are no cycles.\n * 2. There is always a root node upon which all other nodes eventually depend.\n *\n * This allows particular optimizations in this class so that we do no need to check for cycles as\n * these methods are called and we can always start traversal at the root node.\n */\n\nclass BaseNode<T = Lantern.AnyNetworkObject> {\n static types = {\n NETWORK: 'network',\n CPU: 'cpu',\n } as const;\n\n _id: string;\n _isMainDocument: boolean;\n _dependents: Node[];\n _dependencies: Node[];\n\n constructor(id: string) {\n this._id = id;\n this._isMainDocument = false;\n this._dependents = [];\n this._dependencies = [];\n }\n\n get id(): string {\n return this._id;\n }\n\n get type(): 'network'|'cpu' {\n throw new Core.LanternError('Unimplemented');\n }\n\n /**\n * In microseconds\n */\n get startTime(): number {\n throw new Core.LanternError('Unimplemented');\n }\n\n /**\n * In microseconds\n */\n get endTime(): number {\n throw new Core.LanternError('Unimplemented');\n }\n\n setIsMainDocument(value: boolean): void {\n this._isMainDocument = value;\n }\n\n isMainDocument(): boolean {\n return this._isMainDocument;\n }\n\n getDependents(): Node[] {\n return this._dependents.slice();\n }\n\n getNumberOfDependents(): number {\n return this._dependents.length;\n }\n\n getDependencies(): Node[] {\n return this._dependencies.slice();\n }\n\n getNumberOfDependencies(): number {\n return this._dependencies.length;\n }\n\n getRootNode(): Node<T> {\n let rootNode = this as BaseNode as Node;\n while (rootNode._dependencies.length) {\n rootNode = rootNode._dependencies[0];\n }\n\n return rootNode;\n }\n\n addDependent(node: Node): void {\n node.addDependency(this as BaseNode as Node);\n }\n\n addDependency(node: Node): void {\n // @ts-expect-error - in checkJs, ts doesn't know that CPUNode and NetworkNode *are* BaseNodes.\n if (node === this) {\n throw new Core.LanternError('Cannot add dependency on itself');\n }\n\n if (this._dependencies.includes(node)) {\n return;\n }\n\n node._dependents.push(this as BaseNode as Node);\n this._dependencies.push(node);\n }\n\n removeDependent(node: Node): void {\n node.removeDependency(this as BaseNode as Node);\n }\n\n removeDependency(node: Node): void {\n if (!this._dependencies.includes(node)) {\n return;\n }\n\n const thisIndex = node._dependents.indexOf(this as BaseNode as Node);\n node._dependents.splice(thisIndex, 1);\n this._dependencies.splice(this._dependencies.indexOf(node), 1);\n }\n\n removeAllDependencies(): void {\n for (const node of this._dependencies.slice()) {\n this.removeDependency(node);\n }\n }\n\n /**\n * Computes whether the given node is anywhere in the dependency graph of this node.\n * While this method can prevent cycles, it walks the graph and should be used sparingly.\n * Nodes are always considered dependent on themselves for the purposes of cycle detection.\n */\n isDependentOn(node: BaseNode<T>): boolean {\n let isDependentOnNode = false;\n this.traverse(\n currentNode => {\n if (isDependentOnNode) {\n return;\n }\n isDependentOnNode = currentNode === node;\n },\n currentNode => {\n // If we've already found the dependency, don't traverse further.\n if (isDependentOnNode) {\n return [];\n }\n // Otherwise, traverse the dependencies.\n return currentNode.getDependencies();\n });\n\n return isDependentOnNode;\n }\n\n /**\n * Clones the node's information without adding any dependencies/dependents.\n */\n cloneWithoutRelationships(): Node<T> {\n const node = new BaseNode(this.id) as Node<T>;\n node.setIsMainDocument(this._isMainDocument);\n return node;\n }\n\n /**\n * Clones the entire graph connected to this node filtered by the optional predicate. If a node is\n * included by the predicate, all nodes along the paths between the node and the root will be included. If the\n * node this was called on is not included in the resulting filtered graph, the method will throw.\n *\n * This does not clone NetworkNode's `record` or `rawRecord` fields. It may be reasonable to clone the former,\n * to assist in graph construction, but the latter should never be cloned as one contraint of Lantern is that\n * the underlying data records are accessible for plain object reference equality checks.\n */\n cloneWithRelationships(predicate?: (arg0: Node) => boolean): Node {\n const rootNode = this.getRootNode();\n\n const idsToIncludedClones = new Map<string, Node>();\n\n // Walk down dependents.\n rootNode.traverse(node => {\n if (idsToIncludedClones.has(node.id)) {\n return;\n }\n\n if (predicate === undefined) {\n // No condition for entry, so clone every node.\n idsToIncludedClones.set(node.id, node.cloneWithoutRelationships());\n return;\n }\n\n if (predicate(node)) {\n // Node included, so walk back up dependencies, cloning nodes from here back to the root.\n node.traverse(\n node => idsToIncludedClones.set(node.id, node.cloneWithoutRelationships()),\n // Dependencies already cloned have already cloned ancestors, so no need to visit again.\n node => node._dependencies.filter(parent => !idsToIncludedClones.has(parent.id)),\n );\n }\n });\n\n // Copy dependencies between nodes.\n rootNode.traverse(originalNode => {\n const clonedNode = idsToIncludedClones.get(originalNode.id);\n if (!clonedNode) {\n return;\n }\n\n for (const dependency of originalNode._dependencies) {\n const clonedDependency = idsToIncludedClones.get(dependency.id);\n if (!clonedDependency) {\n throw new Core.LanternError('Dependency somehow not cloned');\n }\n clonedNode.addDependency(clonedDependency);\n }\n });\n\n const clonedThisNode = idsToIncludedClones.get(this.id);\n if (!clonedThisNode) {\n throw new Core.LanternError('Cloned graph missing node');\n }\n return clonedThisNode;\n }\n\n /**\n * Traverses all connected nodes in BFS order, calling `callback` exactly once\n * on each. `traversalPath` is the shortest (though not necessarily unique)\n * path from `node` to the root of the iteration.\n *\n * The `getNextNodes` function takes a visited node and returns which nodes to\n * visit next. It defaults to returning the node's dependents.\n */\n traverse(callback: (node: Node<T>, traversalPath: Node<T>[]) => void, getNextNodes?: (arg0: Node<T>) => Node<T>[]):\n void {\n for (const {node, traversalPath} of this.traverseGenerator(getNextNodes)) {\n callback(node, traversalPath);\n }\n }\n\n /**\n * @see BaseNode.traverse\n */\n // clang-format off\n *traverseGenerator(getNextNodes?: (arg0: Node) => Node[]):\n Generator<{node: Node, traversalPath: Node[]}, void, unknown> {\n // clang-format on\n if (!getNextNodes) {\n getNextNodes = node => node.getDependents();\n }\n\n // @ts-expect-error - only traverses graphs of Node, so force tsc to treat `this` as one\n const queue: Node[][] = [[this]];\n const visited = new Set([this.id]);\n\n while (queue.length) {\n // @ts-expect-error - queue has length so it's guaranteed to have an item\n const traversalPath: Node[] = queue.shift();\n const node = traversalPath[0];\n yield {node, traversalPath};\n\n for (const nextNode of getNextNodes(node)) {\n if (visited.has(nextNode.id)) {\n continue;\n }\n visited.add(nextNode.id);\n\n queue.push([nextNode, ...traversalPath]);\n }\n }\n }\n\n /**\n * Returns whether the given node has a cycle in its dependent graph by performing a DFS.\n */\n static hasCycle(node: Node, direction: 'dependents'|'dependencies'|'both' = 'both'): boolean {\n // Checking 'both' is the default entrypoint to recursively check both directions\n if (direction === 'both') {\n return BaseNode.hasCycle(node, 'dependents') || BaseNode.hasCycle(node, 'dependencies');\n }\n\n const visited = new Set();\n const currentPath: BaseNode[] = [];\n const toVisit = [node];\n const depthAdded = new Map([[node, 0]]);\n\n // Keep going while we have nodes to visit in the stack\n while (toVisit.length) {\n // Get the last node in the stack (DFS uses stack, not queue)\n // @ts-expect-error - toVisit has length so it's guaranteed to have an item\n const currentNode: BaseNode = toVisit.pop();\n\n // We've hit a cycle if the node we're visiting is in our current dependency path\n if (currentPath.includes(currentNode)) {\n return true;\n }\n // If we've already visited the node, no need to revisit it\n if (visited.has(currentNode)) {\n continue;\n }\n\n // Since we're visiting this node, clear out any nodes in our path that we had to backtrack\n // @ts-expect-error\n while (currentPath.length > depthAdded.get(currentNode)) {\n currentPath.pop();\n }\n\n // Update our data structures to reflect that we're adding this node to our path\n visited.add(currentNode);\n currentPath.push(currentNode);\n\n // Add all of its dependents to our toVisit stack\n const nodesToExplore = direction === 'dependents' ? currentNode._dependents : currentNode._dependencies;\n for (const nextNode of nodesToExplore) {\n if (toVisit.includes(nextNode)) {\n continue;\n }\n toVisit.push(nextNode);\n depthAdded.set(nextNode, currentPath.length);\n }\n }\n\n return false;\n }\n\n canDependOn(node: Node): boolean {\n return node.startTime <= this.startTime;\n }\n}\n\nexport {BaseNode};\n"]}
|
|
1
|
+
{"version":3,"file":"BaseNode.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/graph/BaseNode.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAYxC;;;;;;;;;;;GAWG;AAEH,MAAM,QAAQ;IACZ,MAAM,CAAC,KAAK,GAAG;QACb,OAAO,EAAE,SAAS;QAClB,GAAG,EAAE,KAAK;KACF,CAAC;IAEX,GAAG,CAAS;IACZ,eAAe,CAAU;IACzB,UAAU,CAAS;IACnB,YAAY,CAAS;IAErB,YAAY,EAAU;QACpB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IACzB,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,IAAI,IAAI;QACN,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACX,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED,iBAAiB,CAAC,KAA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,OAAO,WAAW,CAAC,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;gBACxD,WAAW,CAAC,GAAG,EAAE,CAAC;YACpB,CAAC;YAED,gFAAgF;YAChF,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YACzB,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAE9B,iDAAiD;YACjD,MAAM,cAAc,GAAG,SAAS,KAAK,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,YAAY,CAAC;YACtG,KAAK,MAAM,QAAQ,IAAI,cAAc,EAAE,CAAC;gBACtC,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC/B,SAAS;gBACX,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACvB,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,WAAW,CAAC,IAAU;QACpB,OAAO,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;IAC1C,CAAC;;AAGH,OAAO,EAAC,QAAQ,EAAC,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 Core from '../core/core.js';\nimport type * as Lantern from '../types/types.js';\n\nimport type {CPUNode} from './CPUNode.js';\nimport type {NetworkNode} from './NetworkNode.js';\n\n/**\n * A union of all types derived from BaseNode, allowing type check discrimination\n * based on `node.type`. If a new node type is created, it should be added here.\n */\nexport type Node<T = Lantern.AnyNetworkObject> = CPUNode<T>|NetworkNode<T>;\n\n/**\n * @fileoverview This class encapsulates logic for handling resources and tasks used to model the\n * execution dependency graph of the page. A node has a unique identifier and can depend on other\n * nodes/be depended on. The construction of the graph maintains some important invariants that are\n * inherent to the model:\n *\n * 1. The graph is a DAG, there are no cycles.\n * 2. There is always a root node upon which all other nodes eventually depend.\n *\n * This allows particular optimizations in this class so that we do no need to check for cycles as\n * these methods are called and we can always start traversal at the root node.\n */\n\nclass BaseNode<T = Lantern.AnyNetworkObject> {\n static types = {\n NETWORK: 'network',\n CPU: 'cpu',\n } as const;\n\n _id: string;\n _isMainDocument: boolean;\n dependents: Node[];\n dependencies: Node[];\n\n constructor(id: string) {\n this._id = id;\n this._isMainDocument = false;\n this.dependents = [];\n this.dependencies = [];\n }\n\n get id(): string {\n return this._id;\n }\n\n get type(): 'network'|'cpu' {\n throw new Core.LanternError('Unimplemented');\n }\n\n /**\n * In microseconds\n */\n get startTime(): number {\n throw new Core.LanternError('Unimplemented');\n }\n\n /**\n * In microseconds\n */\n get endTime(): number {\n throw new Core.LanternError('Unimplemented');\n }\n\n setIsMainDocument(value: boolean): void {\n this._isMainDocument = value;\n }\n\n isMainDocument(): boolean {\n return this._isMainDocument;\n }\n\n getDependents(): Node[] {\n return this.dependents.slice();\n }\n\n getNumberOfDependents(): number {\n return this.dependents.length;\n }\n\n getDependencies(): Node[] {\n return this.dependencies.slice();\n }\n\n getNumberOfDependencies(): number {\n return this.dependencies.length;\n }\n\n getRootNode(): Node<T> {\n let rootNode = this as BaseNode as Node;\n while (rootNode.dependencies.length) {\n rootNode = rootNode.dependencies[0];\n }\n\n return rootNode;\n }\n\n addDependent(node: Node): void {\n node.addDependency(this as BaseNode as Node);\n }\n\n addDependency(node: Node): void {\n // @ts-expect-error - in checkJs, ts doesn't know that CPUNode and NetworkNode *are* BaseNodes.\n if (node === this) {\n throw new Core.LanternError('Cannot add dependency on itself');\n }\n\n if (this.dependencies.includes(node)) {\n return;\n }\n\n node.dependents.push(this as BaseNode as Node);\n this.dependencies.push(node);\n }\n\n removeDependent(node: Node): void {\n node.removeDependency(this as BaseNode as Node);\n }\n\n removeDependency(node: Node): void {\n if (!this.dependencies.includes(node)) {\n return;\n }\n\n const thisIndex = node.dependents.indexOf(this as BaseNode as Node);\n node.dependents.splice(thisIndex, 1);\n this.dependencies.splice(this.dependencies.indexOf(node), 1);\n }\n\n removeAllDependencies(): void {\n for (const node of this.dependencies.slice()) {\n this.removeDependency(node);\n }\n }\n\n /**\n * Computes whether the given node is anywhere in the dependency graph of this node.\n * While this method can prevent cycles, it walks the graph and should be used sparingly.\n * Nodes are always considered dependent on themselves for the purposes of cycle detection.\n */\n isDependentOn(node: BaseNode<T>): boolean {\n let isDependentOnNode = false;\n this.traverse(\n currentNode => {\n if (isDependentOnNode) {\n return;\n }\n isDependentOnNode = currentNode === node;\n },\n currentNode => {\n // If we've already found the dependency, don't traverse further.\n if (isDependentOnNode) {\n return [];\n }\n // Otherwise, traverse the dependencies.\n return currentNode.getDependencies();\n });\n\n return isDependentOnNode;\n }\n\n /**\n * Clones the node's information without adding any dependencies/dependents.\n */\n cloneWithoutRelationships(): Node<T> {\n const node = new BaseNode(this.id) as Node<T>;\n node.setIsMainDocument(this._isMainDocument);\n return node;\n }\n\n /**\n * Clones the entire graph connected to this node filtered by the optional predicate. If a node is\n * included by the predicate, all nodes along the paths between the node and the root will be included. If the\n * node this was called on is not included in the resulting filtered graph, the method will throw.\n *\n * This does not clone NetworkNode's `record` or `rawRecord` fields. It may be reasonable to clone the former,\n * to assist in graph construction, but the latter should never be cloned as one contraint of Lantern is that\n * the underlying data records are accessible for plain object reference equality checks.\n */\n cloneWithRelationships(predicate?: (arg0: Node) => boolean): Node {\n const rootNode = this.getRootNode();\n\n const idsToIncludedClones = new Map<string, Node>();\n\n // Walk down dependents.\n rootNode.traverse(node => {\n if (idsToIncludedClones.has(node.id)) {\n return;\n }\n\n if (predicate === undefined) {\n // No condition for entry, so clone every node.\n idsToIncludedClones.set(node.id, node.cloneWithoutRelationships());\n return;\n }\n\n if (predicate(node)) {\n // Node included, so walk back up dependencies, cloning nodes from here back to the root.\n node.traverse(\n node => idsToIncludedClones.set(node.id, node.cloneWithoutRelationships()),\n // Dependencies already cloned have already cloned ancestors, so no need to visit again.\n node => node.dependencies.filter(parent => !idsToIncludedClones.has(parent.id)),\n );\n }\n });\n\n // Copy dependencies between nodes.\n rootNode.traverse(originalNode => {\n const clonedNode = idsToIncludedClones.get(originalNode.id);\n if (!clonedNode) {\n return;\n }\n\n for (const dependency of originalNode.dependencies) {\n const clonedDependency = idsToIncludedClones.get(dependency.id);\n if (!clonedDependency) {\n throw new Core.LanternError('Dependency somehow not cloned');\n }\n clonedNode.addDependency(clonedDependency);\n }\n });\n\n const clonedThisNode = idsToIncludedClones.get(this.id);\n if (!clonedThisNode) {\n throw new Core.LanternError('Cloned graph missing node');\n }\n return clonedThisNode;\n }\n\n /**\n * Traverses all connected nodes in BFS order, calling `callback` exactly once\n * on each. `traversalPath` is the shortest (though not necessarily unique)\n * path from `node` to the root of the iteration.\n *\n * The `getNextNodes` function takes a visited node and returns which nodes to\n * visit next. It defaults to returning the node's dependents.\n */\n traverse(callback: (node: Node<T>, traversalPath: Node<T>[]) => void, getNextNodes?: (arg0: Node<T>) => Node<T>[]):\n void {\n for (const {node, traversalPath} of this.traverseGenerator(getNextNodes)) {\n callback(node, traversalPath);\n }\n }\n\n /**\n * @see BaseNode.traverse\n */\n // clang-format off\n *traverseGenerator(getNextNodes?: (arg0: Node) => Node[]):\n Generator<{node: Node, traversalPath: Node[]}, void, unknown> {\n // clang-format on\n if (!getNextNodes) {\n getNextNodes = node => node.getDependents();\n }\n\n // @ts-expect-error - only traverses graphs of Node, so force tsc to treat `this` as one\n const queue: Node[][] = [[this]];\n const visited = new Set([this.id]);\n\n while (queue.length) {\n // @ts-expect-error - queue has length so it's guaranteed to have an item\n const traversalPath: Node[] = queue.shift();\n const node = traversalPath[0];\n yield {node, traversalPath};\n\n for (const nextNode of getNextNodes(node)) {\n if (visited.has(nextNode.id)) {\n continue;\n }\n visited.add(nextNode.id);\n\n queue.push([nextNode, ...traversalPath]);\n }\n }\n }\n\n /**\n * Returns whether the given node has a cycle in its dependent graph by performing a DFS.\n */\n static hasCycle(node: Node, direction: 'dependents'|'dependencies'|'both' = 'both'): boolean {\n // Checking 'both' is the default entrypoint to recursively check both directions\n if (direction === 'both') {\n return BaseNode.hasCycle(node, 'dependents') || BaseNode.hasCycle(node, 'dependencies');\n }\n\n const visited = new Set();\n const currentPath: BaseNode[] = [];\n const toVisit = [node];\n const depthAdded = new Map([[node, 0]]);\n\n // Keep going while we have nodes to visit in the stack\n while (toVisit.length) {\n // Get the last node in the stack (DFS uses stack, not queue)\n // @ts-expect-error - toVisit has length so it's guaranteed to have an item\n const currentNode: BaseNode = toVisit.pop();\n\n // We've hit a cycle if the node we're visiting is in our current dependency path\n if (currentPath.includes(currentNode)) {\n return true;\n }\n // If we've already visited the node, no need to revisit it\n if (visited.has(currentNode)) {\n continue;\n }\n\n // Since we're visiting this node, clear out any nodes in our path that we had to backtrack\n // @ts-expect-error\n while (currentPath.length > depthAdded.get(currentNode)) {\n currentPath.pop();\n }\n\n // Update our data structures to reflect that we're adding this node to our path\n visited.add(currentNode);\n currentPath.push(currentNode);\n\n // Add all of its dependents to our toVisit stack\n const nodesToExplore = direction === 'dependents' ? currentNode.dependents : currentNode.dependencies;\n for (const nextNode of nodesToExplore) {\n if (toVisit.includes(nextNode)) {\n continue;\n }\n toVisit.push(nextNode);\n depthAdded.set(nextNode, currentPath.length);\n }\n }\n\n return false;\n }\n\n canDependOn(node: Node): boolean {\n return node.startTime <= this.startTime;\n }\n}\n\nexport {BaseNode};\n"]}
|
|
@@ -3,7 +3,7 @@ import type * as Lantern from '../types/types.js';
|
|
|
3
3
|
declare class CPUNode<T = Lantern.AnyNetworkObject> extends BaseNode<T> {
|
|
4
4
|
_event: Lantern.TraceEvent;
|
|
5
5
|
_childEvents: Lantern.TraceEvent[];
|
|
6
|
-
|
|
6
|
+
correctedEndTs: number | undefined;
|
|
7
7
|
constructor(parentEvent: Lantern.TraceEvent, childEvents?: Lantern.TraceEvent[], correctedEndTs?: number);
|
|
8
8
|
get type(): 'cpu';
|
|
9
9
|
get startTime(): number;
|
|
@@ -5,13 +5,13 @@ import { BaseNode } from './BaseNode.js';
|
|
|
5
5
|
class CPUNode extends BaseNode {
|
|
6
6
|
_event;
|
|
7
7
|
_childEvents;
|
|
8
|
-
|
|
8
|
+
correctedEndTs;
|
|
9
9
|
constructor(parentEvent, childEvents = [], correctedEndTs) {
|
|
10
10
|
const nodeId = `${parentEvent.tid}.${parentEvent.ts}`;
|
|
11
11
|
super(nodeId);
|
|
12
12
|
this._event = parentEvent;
|
|
13
13
|
this._childEvents = childEvents;
|
|
14
|
-
this.
|
|
14
|
+
this.correctedEndTs = correctedEndTs;
|
|
15
15
|
}
|
|
16
16
|
get type() {
|
|
17
17
|
return BaseNode.types.CPU;
|
|
@@ -20,8 +20,8 @@ class CPUNode extends BaseNode {
|
|
|
20
20
|
return this._event.ts;
|
|
21
21
|
}
|
|
22
22
|
get endTime() {
|
|
23
|
-
if (this.
|
|
24
|
-
return this.
|
|
23
|
+
if (this.correctedEndTs) {
|
|
24
|
+
return this.correctedEndTs;
|
|
25
25
|
}
|
|
26
26
|
return this._event.ts + this._event.dur;
|
|
27
27
|
}
|
|
@@ -57,7 +57,7 @@ class CPUNode extends BaseNode {
|
|
|
57
57
|
return urls;
|
|
58
58
|
}
|
|
59
59
|
cloneWithoutRelationships() {
|
|
60
|
-
return new CPUNode(this._event, this._childEvents, this.
|
|
60
|
+
return new CPUNode(this._event, this._childEvents, this.correctedEndTs);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
export { CPUNode };
|