@paulirish/trace_engine 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/README.md +2 -17
  2. package/core/platform/ArrayUtilities.js.map +1 -1
  3. package/core/platform/DOMUtilities.js.map +1 -1
  4. package/core/platform/MapUtilities.d.ts +1 -0
  5. package/core/platform/MapUtilities.js +3 -0
  6. package/core/platform/MapUtilities.js.map +1 -1
  7. package/core/platform/MimeType.js +1 -0
  8. package/core/platform/MimeType.js.map +1 -1
  9. package/core/platform/NumberUtilities.js.map +1 -1
  10. package/core/platform/SetUtilities.js.map +1 -1
  11. package/core/platform/StringUtilities.js +3 -3
  12. package/core/platform/StringUtilities.js.map +1 -1
  13. package/core/platform/TypedArrayUtilities.d.ts +26 -0
  14. package/core/platform/TypedArrayUtilities.js +111 -0
  15. package/core/platform/TypedArrayUtilities.js.map +1 -0
  16. package/core/platform/TypescriptUtilities.js.map +1 -1
  17. package/core/platform/UserVisibleError.js.map +1 -1
  18. package/core/platform/platform-tsconfig.json +1 -0
  19. package/core/platform/platform.d.ts +2 -1
  20. package/core/platform/platform.js +2 -1
  21. package/core/platform/platform.js.map +1 -1
  22. package/generated/protocol.d.ts +163 -35
  23. package/models/cpu_profile/CPUProfileDataModel.js.map +1 -1
  24. package/models/cpu_profile/ProfileTreeModel.js.map +1 -1
  25. package/models/trace/EntriesFilter.d.ts +7 -1
  26. package/models/trace/EntriesFilter.js +13 -2
  27. package/models/trace/EntriesFilter.js.map +1 -1
  28. package/models/trace/LegacyTracingModel.js.map +1 -1
  29. package/models/trace/ModelImpl.js.map +1 -1
  30. package/models/trace/Processor.js +45 -33
  31. package/models/trace/Processor.js.map +1 -1
  32. package/models/trace/TracingManager.js.map +1 -1
  33. package/models/trace/extras/FetchNodes.d.ts +1 -1
  34. package/models/trace/extras/FetchNodes.js +1 -2
  35. package/models/trace/extras/FetchNodes.js.map +1 -1
  36. package/models/trace/extras/FilmStrip.js.map +1 -1
  37. package/models/trace/extras/MainThreadActivity.js.map +1 -1
  38. package/models/trace/extras/Metadata.d.ts +2 -2
  39. package/models/trace/extras/Metadata.js +10 -2
  40. package/models/trace/extras/Metadata.js.map +1 -1
  41. package/models/trace/handlers/AnimationHandler.js +1 -1
  42. package/models/trace/handlers/AnimationHandler.js.map +1 -1
  43. package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -1
  44. package/models/trace/handlers/ExtensionTraceDataHandler.d.ts +13 -0
  45. package/models/trace/handlers/ExtensionTraceDataHandler.js +93 -0
  46. package/models/trace/handlers/ExtensionTraceDataHandler.js.map +1 -0
  47. package/models/trace/handlers/FramesHandler.js.map +1 -1
  48. package/models/trace/handlers/GPUHandler.js +1 -1
  49. package/models/trace/handlers/GPUHandler.js.map +1 -1
  50. package/models/trace/handlers/InitiatorsHandler.js +32 -3
  51. package/models/trace/handlers/InitiatorsHandler.js.map +1 -1
  52. package/models/trace/handlers/InvalidationsHandler.js +10 -1
  53. package/models/trace/handlers/InvalidationsHandler.js.map +1 -1
  54. package/models/trace/handlers/LargestImagePaintHandler.js +1 -1
  55. package/models/trace/handlers/LargestImagePaintHandler.js.map +1 -1
  56. package/models/trace/handlers/LargestTextPaintHandler.js +1 -1
  57. package/models/trace/handlers/LargestTextPaintHandler.js.map +1 -1
  58. package/models/trace/handlers/LayerTreeHandler.js +3 -3
  59. package/models/trace/handlers/LayerTreeHandler.js.map +1 -1
  60. package/models/trace/handlers/LayoutShiftsHandler.d.ts +5 -5
  61. package/models/trace/handlers/LayoutShiftsHandler.js +6 -5
  62. package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
  63. package/models/trace/handlers/MemoryHandler.js +1 -1
  64. package/models/trace/handlers/MemoryHandler.js.map +1 -1
  65. package/models/trace/handlers/MetaHandler.js +12 -10
  66. package/models/trace/handlers/MetaHandler.js.map +1 -1
  67. package/models/trace/handlers/ModelHandlers.d.ts +1 -0
  68. package/models/trace/handlers/ModelHandlers.js +1 -0
  69. package/models/trace/handlers/ModelHandlers.js.map +1 -1
  70. package/models/trace/handlers/NetworkRequestsHandler.js +2 -2
  71. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
  72. package/models/trace/handlers/PageLoadMetricsHandler.d.ts +11 -7
  73. package/models/trace/handlers/PageLoadMetricsHandler.js +11 -35
  74. package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -1
  75. package/models/trace/handlers/RendererHandler.js.map +1 -1
  76. package/models/trace/handlers/SamplesHandler.js +2 -2
  77. package/models/trace/handlers/SamplesHandler.js.map +1 -1
  78. package/models/trace/handlers/ScreenshotsHandler.js +2 -1
  79. package/models/trace/handlers/ScreenshotsHandler.js.map +1 -1
  80. package/models/trace/handlers/Threads.js.map +1 -1
  81. package/models/trace/handlers/UserInteractionsHandler.d.ts +2 -0
  82. package/models/trace/handlers/UserInteractionsHandler.js +21 -11
  83. package/models/trace/handlers/UserInteractionsHandler.js.map +1 -1
  84. package/models/trace/handlers/UserTimingsHandler.js +1 -0
  85. package/models/trace/handlers/UserTimingsHandler.js.map +1 -1
  86. package/models/trace/handlers/WarningsHandler.js +2 -2
  87. package/models/trace/handlers/WarningsHandler.js.map +1 -1
  88. package/models/trace/handlers/WorkersHandler.js +3 -3
  89. package/models/trace/handlers/WorkersHandler.js.map +1 -1
  90. package/models/trace/handlers/handlers-tsconfig.json +1 -0
  91. package/models/trace/handlers/types.js.map +1 -1
  92. package/models/trace/helpers/Extensions.d.ts +2 -0
  93. package/models/trace/helpers/Extensions.js +22 -0
  94. package/models/trace/helpers/Extensions.js.map +1 -0
  95. package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
  96. package/models/trace/helpers/Timing.js.map +1 -1
  97. package/models/trace/helpers/Trace.d.ts +4 -3
  98. package/models/trace/helpers/Trace.js +17 -3
  99. package/models/trace/helpers/Trace.js.map +1 -1
  100. package/models/trace/helpers/TreeHelpers.js.map +1 -1
  101. package/models/trace/helpers/helpers-tsconfig.json +1 -0
  102. package/models/trace/helpers/helpers.d.ts +1 -0
  103. package/models/trace/helpers/helpers.js +1 -0
  104. package/models/trace/helpers/helpers.js.map +1 -1
  105. package/models/trace/insights/InsightRunners.d.ts +2 -0
  106. package/models/trace/insights/InsightRunners.js +2 -0
  107. package/models/trace/insights/InsightRunners.js.map +1 -1
  108. package/models/trace/insights/InteractionToNextPaint.d.ts +9 -0
  109. package/models/trace/insights/InteractionToNextPaint.js +35 -0
  110. package/models/trace/insights/InteractionToNextPaint.js.map +1 -0
  111. package/models/trace/insights/LargestContentfulPaint.d.ts +31 -0
  112. package/models/trace/insights/LargestContentfulPaint.js +104 -0
  113. package/models/trace/insights/LargestContentfulPaint.js.map +1 -0
  114. package/models/trace/insights/RenderBlocking.js.map +1 -1
  115. package/models/trace/insights/insights-tsconfig.json +2 -0
  116. package/models/trace/insights/types.d.ts +3 -1
  117. package/models/trace/insights/types.js +3 -0
  118. package/models/trace/insights/types.js.map +1 -1
  119. package/models/trace/root-causes/LayoutShift.d.ts +9 -3
  120. package/models/trace/root-causes/LayoutShift.js +35 -15
  121. package/models/trace/root-causes/LayoutShift.js.map +1 -1
  122. package/models/trace/root-causes/RootCauses.d.ts +2 -1
  123. package/models/trace/root-causes/RootCauses.js +1 -0
  124. package/models/trace/root-causes/RootCauses.js.map +1 -1
  125. package/models/trace/types/Configuration.js +10 -2
  126. package/models/trace/types/Configuration.js.map +1 -1
  127. package/models/trace/types/Extensions.d.ts +62 -0
  128. package/models/trace/types/Extensions.js +38 -0
  129. package/models/trace/types/Extensions.js.map +1 -0
  130. package/models/trace/types/File.d.ts +13 -0
  131. package/models/trace/types/File.js.map +1 -1
  132. package/models/trace/types/TraceEvents.d.ts +55 -14
  133. package/models/trace/types/TraceEvents.js +37 -9
  134. package/models/trace/types/TraceEvents.js.map +1 -1
  135. package/models/trace/types/types-tsconfig.json +1 -0
  136. package/models/trace/types/types.d.ts +1 -0
  137. package/models/trace/types/types.js +1 -0
  138. package/models/trace/types/types.js.map +1 -1
  139. package/package.json +1 -1
  140. package/core/platform/array-utilities.d.ts +0 -66
  141. package/core/platform/array-utilities.js +0 -199
  142. package/core/platform/array-utilities.js.map +0 -1
  143. package/core/platform/date-utilities.d.ts +0 -2
  144. package/core/platform/date-utilities.js +0 -14
  145. package/core/platform/date-utilities.js.map +0 -1
  146. package/core/platform/dcheck-tsconfig.json +0 -8
  147. package/core/platform/dcheck.d.ts +0 -4
  148. package/core/platform/dcheck.js +0 -5
  149. package/core/platform/dom-utilities.d.ts +0 -8
  150. package/core/platform/dom-utilities.js +0 -109
  151. package/core/platform/dom-utilities.js.map +0 -1
  152. package/core/platform/keyboard-utilities.d.ts +0 -17
  153. package/core/platform/keyboard-utilities.js +0 -22
  154. package/core/platform/keyboard-utilities.js.map +0 -1
  155. package/core/platform/map-utilities.d.ts +0 -18
  156. package/core/platform/map-utilities.js +0 -76
  157. package/core/platform/map-utilities.js.map +0 -1
  158. package/core/platform/number-utilities.d.ts +0 -15
  159. package/core/platform/number-utilities.js +0 -82
  160. package/core/platform/number-utilities.js.map +0 -1
  161. package/core/platform/promise-utilities.d.ts +0 -10
  162. package/core/platform/promise-utilities.js +0 -18
  163. package/core/platform/promise-utilities.js.map +0 -1
  164. package/core/platform/set-utilities.d.ts +0 -2
  165. package/core/platform/set-utilities.js +0 -23
  166. package/core/platform/set-utilities.js.map +0 -1
  167. package/core/platform/string-utilities.d.ts +0 -71
  168. package/core/platform/string-utilities.js +0 -513
  169. package/core/platform/string-utilities.js.map +0 -1
  170. package/core/platform/typescript-utilities.d.ts +0 -56
  171. package/core/platform/typescript-utilities.js +0 -25
  172. package/core/platform/typescript-utilities.js.map +0 -1
  173. /package/core/platform/{brand.d.ts → Brand.d.ts} +0 -0
  174. /package/core/platform/{brand.js → Brand.js} +0 -0
  175. /package/core/platform/{brand.js.map → Brand.js.map} +0 -0
@@ -174,8 +174,10 @@ export function handleEvent(event) {
174
174
  if (frame.parent) {
175
175
  continue;
176
176
  }
177
- mainFrameId = frame.frame;
178
- mainFrameURL = frame.url;
177
+ if (frame.url) {
178
+ mainFrameId = frame.frame;
179
+ mainFrameURL = frame.url;
180
+ }
179
181
  topLevelRendererIds.add(frame.processId);
180
182
  }
181
183
  return;
@@ -319,19 +321,19 @@ export function data() {
319
321
  traceBounds: { ...traceBounds },
320
322
  browserProcessId,
321
323
  browserThreadId,
322
- processNames: new Map(processNames),
324
+ processNames,
323
325
  gpuProcessId,
324
326
  gpuThreadId: gpuThreadId === Types.TraceEvents.ThreadID(-1) ? undefined : gpuThreadId,
325
327
  viewportRect: viewportRect || undefined,
326
328
  mainFrameId,
327
329
  mainFrameURL,
328
- navigationsByFrameId: new Map(navigationsByFrameId),
329
- navigationsByNavigationId: new Map(navigationsByNavigationId),
330
- threadsInProcess: new Map(threadsInProcess),
331
- rendererProcessesByFrame: new Map(rendererProcessesByFrameId),
332
- topLevelRendererIds: new Set(topLevelRendererIds),
333
- frameByProcessId: new Map(framesByProcessId),
334
- mainFrameNavigations: [...mainFrameNavigations],
330
+ navigationsByFrameId,
331
+ navigationsByNavigationId,
332
+ threadsInProcess,
333
+ rendererProcessesByFrame: rendererProcessesByFrameId,
334
+ topLevelRendererIds,
335
+ frameByProcessId: framesByProcessId,
336
+ mainFrameNavigations,
335
337
  traceIsGeneric,
336
338
  };
337
339
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MetaHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/MetaHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAC/D,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAI3C,qFAAqF;AACrF,MAAM,0BAA0B,GAAqB,IAAI,GAAG,EAAE,CAAC;AAE/D,4EAA4E;AAC5E,0DAA0D;AAC1D,IAAI,WAAW,GAAW,EAAE,CA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,CAAC;QAC5C,oBAAoB,EAAE,CAAC,GAAG,oBAAoB,CAAC;QAC/C,cAAc;KACf,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2022 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {HandlerState} from './types.js';\n\n// We track the renderer processes we see in each frame on the way through the trace.\nconst rendererProcessesByFrameId: FrameProcessData = new Map();\n\n// We will often want to key data by Frame IDs, and commonly we'll care most\n// about the main frame's ID, so we store and expose that.\nlet mainFrameId: string = '';\nlet mainFrameURL: string = '';\n\nconst framesByProcessId = new Map<Types.TraceEvents.ProcessID, Map<string, Types.TraceEvents.TraceFrame>>();\n\n// We will often want to key data by the browser process, GPU process and top\n// level renderer IDs, so keep a track on those.\nlet browserProcessId: Types.TraceEvents.ProcessID = Types.TraceEvents.ProcessID(-1);\nlet browserThreadId: Types.TraceEvents.ThreadID = Types.TraceEvents.ThreadID(-1);\nlet gpuProcessId: Types.TraceEvents.ProcessID = Types.TraceEvents.ProcessID(-1);\nlet gpuThreadId: Types.TraceEvents.ThreadID = Types.TraceEvents.ThreadID(-1);\nlet viewportRect: DOMRect|null = null;\n\nconst processNames: Map<Types.TraceEvents.ProcessID, Types.TraceEvents.TraceEventProcessName> = new Map();\n\nconst topLevelRendererIds = new Set<Types.TraceEvents.ProcessID>();\nconst traceBounds: Types.Timing.TraceWindowMicroSeconds = {\n min: Types.Timing.MicroSeconds(Number.POSITIVE_INFINITY),\n max: Types.Timing.MicroSeconds(Number.NEGATIVE_INFINITY),\n range: Types.Timing.MicroSeconds(Number.POSITIVE_INFINITY),\n};\n\n/**\n * These represent the user navigating. Values such as First Contentful Paint,\n * etc, are relative to the navigation.\n *\n * We store navigation events both by the frame and navigation ID. This means\n * when we need to look them up, we can use whichever ID we have.\n *\n * Note that these Maps will have the same values in them; these are just keyed\n * differently to make look-ups easier.\n *\n * We also additionally maintain an array of only navigations that occured on\n * the main frame. In many places in the UI we only care about highlighting\n * main frame navigations, so calculating this list here is better than\n * filtering either of the below maps over and over again at the UI layer.\n */\nconst navigationsByFrameId = new Map<string, Types.TraceEvents.TraceEventNavigationStart[]>();\nconst navigationsByNavigationId = new Map<string, Types.TraceEvents.TraceEventNavigationStart>();\nconst mainFrameNavigations: Types.TraceEvents.TraceEventNavigationStart[] = [];\n\n// Represents all the threads in the trace, organized by process. This is mostly for internal\n// bookkeeping so that during the finalize pass we can obtain the main and browser thread IDs.\nconst threadsInProcess =\n new Map<Types.TraceEvents.ProcessID, Map<Types.TraceEvents.ThreadID, Types.TraceEvents.TraceEventThreadName>>();\n\nlet traceStartedTimeFromTracingStartedEvent = Types.Timing.MicroSeconds(-1);\nconst eventPhasesOfInterestForTraceBounds = new Set([\n Types.TraceEvents.Phase.BEGIN,\n Types.TraceEvents.Phase.END,\n Types.TraceEvents.Phase.COMPLETE,\n Types.TraceEvents.Phase.INSTANT,\n]);\n\nlet handlerState = HandlerState.UNINITIALIZED;\n// Tracks if the trace is a generic trace, which here means that it did not come from athe DevTools Performance Panel recording.\n// We assume a trace is generic, and mark it as not generic if we see any of:\n// - TracingStartedInPage\n// - TracingStartedInBrowser\n// - TracingSessionIdForWorker\n// These are all events which indicate this is a Chrome browser trace.\nlet traceIsGeneric = true;\nconst CHROME_WEB_TRACE_EVENTS = new Set([\n Types.TraceEvents.KnownEventName.TracingStartedInPage,\n Types.TraceEvents.KnownEventName.TracingSessionIdForWorker,\n Types.TraceEvents.KnownEventName.TracingStartedInBrowser,\n\n]);\n\nexport function reset(): void {\n navigationsByFrameId.clear();\n navigationsByNavigationId.clear();\n processNames.clear();\n mainFrameNavigations.length = 0;\n\n browserProcessId = Types.TraceEvents.ProcessID(-1);\n browserThreadId = Types.TraceEvents.ThreadID(-1);\n gpuProcessId = Types.TraceEvents.ProcessID(-1);\n gpuThreadId = Types.TraceEvents.ThreadID(-1);\n viewportRect = null;\n topLevelRendererIds.clear();\n threadsInProcess.clear();\n rendererProcessesByFrameId.clear();\n framesByProcessId.clear();\n\n traceBounds.min = Types.Timing.MicroSeconds(Number.POSITIVE_INFINITY);\n traceBounds.max = Types.Timing.MicroSeconds(Number.NEGATIVE_INFINITY);\n traceBounds.range = Types.Timing.MicroSeconds(Number.POSITIVE_INFINITY);\n traceStartedTimeFromTracingStartedEvent = Types.Timing.MicroSeconds(-1);\n\n traceIsGeneric = true;\n\n handlerState = HandlerState.UNINITIALIZED;\n}\n\nexport function initialize(): void {\n if (handlerState !== HandlerState.UNINITIALIZED) {\n throw new Error('Meta Handler was not reset');\n }\n\n handlerState = HandlerState.INITIALIZED;\n}\n\nfunction updateRendererProcessByFrame(\n event: Types.TraceEvents.TraceEventData, frame: Types.TraceEvents.TraceFrame): void {\n const framesInProcessById = Platform.MapUtilities.getWithDefault(framesByProcessId, frame.processId, () => new Map());\n framesInProcessById.set(frame.frame, frame);\n\n const rendererProcessInFrame = Platform.MapUtilities.getWithDefault(\n rendererProcessesByFrameId, frame.frame,\n () => new Map<\n Types.TraceEvents.ProcessID,\n {frame: Types.TraceEvents.TraceFrame, window: Types.Timing.TraceWindowMicroSeconds}[]>());\n const rendererProcessInfo = Platform.MapUtilities.getWithDefault(rendererProcessInFrame, frame.processId, () => {\n return [];\n });\n const lastProcessData = rendererProcessInfo.at(-1);\n\n // Only store a new entry if the URL changed, otherwise it's just\n // redundant information.\n if (lastProcessData && lastProcessData.frame.url === frame.url) {\n return;\n }\n // For now we store the time of the event as the min. In the finalize we step\n // through each of these windows and update their max and range values.\n rendererProcessInfo.push({\n frame,\n window: {\n min: event.ts,\n max: Types.Timing.MicroSeconds(0),\n range: Types.Timing.MicroSeconds(0),\n },\n });\n}\n\nexport function handleEvent(event: Types.TraceEvents.TraceEventData): void {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Meta Handler is not initialized');\n }\n\n if (traceIsGeneric && CHROME_WEB_TRACE_EVENTS.has(event.name as Types.TraceEvents.KnownEventName)) {\n traceIsGeneric = false;\n }\n\n if (Types.TraceEvents.isProcessName(event)) {\n processNames.set(event.pid, event);\n }\n\n // If there is a timestamp (which meta events do not have), and the event does\n // not end with ::UMA then it, and the event is in the set of valid phases,\n // then it should be included for the purposes of calculating the trace bounds.\n // The UMA events in particular seem to be reported on page unloading, which\n // often extends the bounds of the trace unhelpfully.\n if (event.ts !== 0 && !event.name.endsWith('::UMA') && eventPhasesOfInterestForTraceBounds.has(event.ph)) {\n traceBounds.min = Types.Timing.MicroSeconds(Math.min(event.ts, traceBounds.min));\n const eventDuration = event.dur || Types.Timing.MicroSeconds(0);\n traceBounds.max = Types.Timing.MicroSeconds(Math.max(event.ts + eventDuration, traceBounds.max));\n }\n\n if (Types.TraceEvents.isProcessName(event) &&\n (event.args.name === 'Browser' || event.args.name === 'HeadlessBrowser')) {\n browserProcessId = event.pid;\n return;\n }\n\n if (Types.TraceEvents.isProcessName(event) && (event.args.name === 'Gpu' || event.args.name === 'GPU Process')) {\n gpuProcessId = event.pid;\n return;\n }\n\n if (Types.TraceEvents.isThreadName(event) && event.args.name === 'CrGpuMain') {\n gpuThreadId = event.tid;\n return;\n }\n\n if (Types.TraceEvents.isThreadName(event) && event.args.name === 'CrBrowserMain') {\n browserThreadId = event.tid;\n }\n\n if (Types.TraceEvents.isTraceEventMainFrameViewport(event) && viewportRect === null) {\n const rectAsArray = event.args.data.viewport_rect;\n const viewportX = rectAsArray[0];\n const viewportY = rectAsArray[1];\n const viewportWidth = rectAsArray[2];\n const viewportHeight = rectAsArray[5];\n viewportRect = new DOMRect(viewportX, viewportY, viewportWidth, viewportHeight);\n }\n\n // The TracingStartedInBrowser event includes the data on which frames are\n // in scope at the start of the trace. We use this to identify the frame with\n // no parent, i.e. the top level frame.\n if (Types.TraceEvents.isTraceEventTracingStartedInBrowser(event)) {\n traceStartedTimeFromTracingStartedEvent = event.ts;\n\n if (!event.args.data) {\n throw new Error('No frames found in trace data');\n }\n\n for (const frame of (event.args.data.frames ?? [])) {\n updateRendererProcessByFrame(event, frame);\n\n if (frame.parent) {\n continue;\n }\n\n mainFrameId = frame.frame;\n mainFrameURL = frame.url;\n topLevelRendererIds.add(frame.processId);\n }\n return;\n }\n\n // FrameCommittedInBrowser events tell us information about each frame\n // and we use these to track how long each individual renderer is active\n // for. We track all renderers here (top level and those in frames), but\n // for convenience we also populate a set of top level renderer IDs.\n if (Types.TraceEvents.isTraceEventFrameCommittedInBrowser(event)) {\n const frame = event.args.data;\n if (!frame) {\n return;\n }\n\n updateRendererProcessByFrame(event, frame);\n\n if (frame.parent) {\n return;\n }\n\n topLevelRendererIds.add(frame.processId);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventCommitLoad(event)) {\n const frameData = event.args.data;\n if (!frameData) {\n return;\n }\n\n const {frame, name, url} = frameData;\n updateRendererProcessByFrame(event, {processId: event.pid, frame, name, url});\n return;\n }\n\n // Track all threads based on the process & thread IDs.\n if (Types.TraceEvents.isThreadName(event)) {\n const threads = Platform.MapUtilities.getWithDefault(threadsInProcess, event.pid, () => new Map());\n threads.set(event.tid, event);\n return;\n }\n\n // Track all navigation events. Note that there can be navigation start events\n // but where the documentLoaderURL is empty. As far as the trace rendering is\n // concerned, these events are noise so we filter them out here.\n // (The filtering of empty URLs is done in the\n // isTraceEventNavigationStartWithURL check)\n if (Types.TraceEvents.isTraceEventNavigationStartWithURL(event) && event.args.data) {\n const navigationId = event.args.data.navigationId;\n if (navigationsByNavigationId.has(navigationId)) {\n // We have only ever seen this situation once, in crbug.com/1503982, where the user ran:\n // window.location.href = 'javascript:console.log(\"foo\")'\n // In this situation two identical navigationStart events are emitted with the same data, URL and ID.\n // So, in this situation we drop/ignore any subsequent navigations if we have already seen that ID.\n return;\n }\n navigationsByNavigationId.set(navigationId, event);\n\n const frameId = event.args.frame;\n const existingFrameNavigations = navigationsByFrameId.get(frameId) || [];\n existingFrameNavigations.push(event);\n navigationsByFrameId.set(frameId, existingFrameNavigations);\n if (frameId === mainFrameId) {\n mainFrameNavigations.push(event);\n }\n return;\n }\n}\n\nexport async function finalize(): Promise<void> {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Handler is not initialized');\n }\n\n // We try to set the minimum time by finding the event with the smallest\n // timestamp. However, if we also got a timestamp from the\n // TracingStartedInBrowser event, we should always use that.\n // But in some traces (for example, CPU profiles) we do not get that event,\n // hence why we need to check we got a timestamp from it before setting it.\n if (traceStartedTimeFromTracingStartedEvent >= 0) {\n traceBounds.min = traceStartedTimeFromTracingStartedEvent;\n }\n traceBounds.range = Types.Timing.MicroSeconds(traceBounds.max - traceBounds.min);\n\n // If we go from foo.com to example.com we will get a new renderer, and\n // therefore the \"top level renderer\" will have a different PID as it has\n // changed. Here we step through each renderer process and updated its window\n // bounds, such that we end up with the time ranges in the trace for when\n // each particular renderer started and stopped being the main renderer\n // process.\n for (const [, processWindows] of rendererProcessesByFrameId) {\n const processWindowValues = [...processWindows.values()].flat();\n for (let i = 0; i < processWindowValues.length; i++) {\n const currentWindow = processWindowValues[i];\n const nextWindow = processWindowValues[i + 1];\n\n // For the last window we set its max to be positive infinity.\n // TODO: Move the trace bounds handler into meta so we can clamp first and last windows.\n if (!nextWindow) {\n currentWindow.window.max = Types.Timing.MicroSeconds(traceBounds.max);\n currentWindow.window.range = Types.Timing.MicroSeconds(traceBounds.max - currentWindow.window.min);\n } else {\n currentWindow.window.max = Types.Timing.MicroSeconds(nextWindow.window.min - 1);\n currentWindow.window.range = Types.Timing.MicroSeconds(currentWindow.window.max - currentWindow.window.min);\n }\n }\n }\n\n // Frame ids which we didn't register using either the TracingStartedInBrowser or\n // the FrameCommittedInBrowser events are considered noise, so we filter them out, as well\n // as the navigations that belong to such frames.\n for (const [frameId, navigations] of navigationsByFrameId) {\n // The frames in the rendererProcessesByFrameId map come only from the\n // TracingStartedInBrowser and FrameCommittedInBrowser events, so we can use it as point\n // of comparison to determine if a frameId should be discarded.\n if (rendererProcessesByFrameId.has(frameId)) {\n continue;\n }\n navigationsByFrameId.delete(frameId);\n for (const navigation of navigations) {\n if (!navigation.args.data) {\n continue;\n }\n navigationsByNavigationId.delete(navigation.args.data.navigationId);\n }\n }\n\n // Sometimes in traces the TracingStartedInBrowser event can give us an\n // incorrect initial URL for the main frame's URL - about:blank or the URL of\n // the previous page. This doesn't matter too much except we often use this\n // URL as the visual name of the trace shown to the user (e.g. in the history\n // dropdown). We can be more accurate by finding the first main frame\n // navigaton, and using its URL, if we have it.\n // However, to avoid doing this in a case where the first navigation is far\n // into the trace's lifecycle, we only do this in situations where the first\n // navigation happened very soon (0.5 seconds) after the trace started\n // recording.\n const firstMainFrameNav = mainFrameNavigations.at(0);\n const firstNavTimeThreshold = Helpers.Timing.secondsToMicroseconds(Types.Timing.Seconds(0.5));\n if (firstMainFrameNav) {\n const navigationIsWithinThreshold = firstMainFrameNav.ts - traceBounds.min < firstNavTimeThreshold;\n if (firstMainFrameNav.args.data?.isOutermostMainFrame && firstMainFrameNav.args.data?.documentLoaderURL &&\n navigationIsWithinThreshold) {\n mainFrameURL = firstMainFrameNav.args.data.documentLoaderURL;\n }\n }\n\n handlerState = HandlerState.FINALIZED;\n}\n\nexport type MetaHandlerData = {\n traceIsGeneric: boolean,\n traceBounds: Types.Timing.TraceWindowMicroSeconds,\n browserProcessId: Types.TraceEvents.ProcessID,\n processNames: Map<Types.TraceEvents.ProcessID, Types.TraceEvents.TraceEventProcessName>,\n browserThreadId: Types.TraceEvents.ThreadID,\n gpuProcessId: Types.TraceEvents.ProcessID,\n gpuThreadId?: Types.TraceEvents.ThreadID,\n viewportRect?: DOMRect,\n navigationsByFrameId: Map<string, Types.TraceEvents.TraceEventNavigationStart[]>,\n navigationsByNavigationId: Map<string, Types.TraceEvents.TraceEventNavigationStart>,\n threadsInProcess:\n Map<Types.TraceEvents.ProcessID,\n Map<Types.TraceEvents.ThreadID, Types.TraceEvents.TraceEventThreadName>>,\n mainFrameId: string,\n mainFrameURL: string,\n /**\n * A frame can have multiple renderer processes, at the same time,\n * a renderer process can have multiple URLs. This map tracks the\n * processes active on a given frame, with the time window in which\n * they were active. Because a renderer process might have multiple\n * URLs, each process in each frame has an array of windows, with an\n * entry for each URL it had.\n */\n rendererProcessesByFrame: FrameProcessData,\n topLevelRendererIds: Set<Types.TraceEvents.ProcessID>,\n frameByProcessId: Map<Types.TraceEvents.ProcessID, Map<string, Types.TraceEvents.TraceFrame>>,\n mainFrameNavigations: Types.TraceEvents.TraceEventNavigationStart[],\n};\n\n// Each frame has a single render process at a given time but it can have\n// multiple render processes during a trace, for example if a navigation\n// occurred in the frame. This map tracks the process that was active for\n// each frame at each point in time. Also, because a process can be\n// assigned to multiple URLs, there is a window for each URL a process\n// was assigned.\n//\n// Note that different sites always end up in different render\n// processes, however two different URLs can point to the same site.\n// For example: https://google.com and https://maps.google.com point to\n// the same site.\n// Read more about this in\n// https://developer.chrome.com/articles/renderingng-architecture/#threads\n// and https://web.dev/same-site-same-origin/\nexport type FrameProcessData =\n Map<string,\n Map<Types.TraceEvents.ProcessID,\n {frame: Types.TraceEvents.TraceFrame, window: Types.Timing.TraceWindowMicroSeconds}[]>>;\n\nexport function data(): MetaHandlerData {\n if (handlerState !== HandlerState.FINALIZED) {\n throw new Error('Meta Handler is not finalized');\n }\n\n return {\n traceBounds: {...traceBounds},\n browserProcessId,\n browserThreadId,\n processNames: new Map(processNames),\n gpuProcessId,\n gpuThreadId: gpuThreadId === Types.TraceEvents.ThreadID(-1) ? undefined : gpuThreadId,\n viewportRect: viewportRect || undefined,\n mainFrameId,\n mainFrameURL,\n navigationsByFrameId: new Map(navigationsByFrameId),\n navigationsByNavigationId: new Map(navigationsByNavigationId),\n threadsInProcess: new Map(threadsInProcess),\n rendererProcessesByFrame: new Map(rendererProcessesByFrameId),\n topLevelRendererIds: new Set(topLevelRendererIds),\n frameByProcessId: new Map(framesByProcessId),\n mainFrameNavigations: [...mainFrameNavigations],\n traceIsGeneric,\n };\n}\n"]}
1
+ {"version":3,"file":"Met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,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,YAAY,iCAAyB,CAAC;AACxC,CAAC;AAmDD,MAAM,UAAU,IAAI;IAClB,IAAI,YAAY,mCAA2B,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IAED,OAAO;QACL,WAAW,EAAE,EAAC,GAAG,WAAW,EAAC;QAC7B,gBAAgB;QAChB,eAAe;QACf,YAAY;QACZ,YAAY;QACZ,WAAW,EAAE,WAAW,KAAK,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW;QACrF,YAAY,EAAE,YAAY,IAAI,SAAS;QACvC,WAAW;QACX,YAAY;QACZ,oBAAoB;QACpB,yBAAyB;QACzB,gBAAgB;QAChB,wBAAwB,EAAE,0BAA0B;QACpD,mBAAmB;QACnB,gBAAgB,EAAE,iBAAiB;QACnC,oBAAoB;QACpB,cAAc;KACf,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2022 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {HandlerState} from './types.js';\n\n// We track the renderer processes we see in each frame on the way through the trace.\nconst rendererProcessesByFrameId: FrameProcessData = new Map();\n\n// We will often want to key data by Frame IDs, and commonly we'll care most\n// about the main frame's ID, so we store and expose that.\nlet mainFrameId: string = '';\nlet mainFrameURL: string = '';\n\nconst framesByProcessId = new Map<Types.TraceEvents.ProcessID, Map<string, Types.TraceEvents.TraceFrame>>();\n\n// We will often want to key data by the browser process, GPU process and top\n// level renderer IDs, so keep a track on those.\nlet browserProcessId: Types.TraceEvents.ProcessID = Types.TraceEvents.ProcessID(-1);\nlet browserThreadId: Types.TraceEvents.ThreadID = Types.TraceEvents.ThreadID(-1);\nlet gpuProcessId: Types.TraceEvents.ProcessID = Types.TraceEvents.ProcessID(-1);\nlet gpuThreadId: Types.TraceEvents.ThreadID = Types.TraceEvents.ThreadID(-1);\nlet viewportRect: DOMRect|null = null;\n\nconst processNames: Map<Types.TraceEvents.ProcessID, Types.TraceEvents.TraceEventProcessName> = new Map();\n\nconst topLevelRendererIds = new Set<Types.TraceEvents.ProcessID>();\nconst traceBounds: Types.Timing.TraceWindowMicroSeconds = {\n min: Types.Timing.MicroSeconds(Number.POSITIVE_INFINITY),\n max: Types.Timing.MicroSeconds(Number.NEGATIVE_INFINITY),\n range: Types.Timing.MicroSeconds(Number.POSITIVE_INFINITY),\n};\n\n/**\n * These represent the user navigating. Values such as First Contentful Paint,\n * etc, are relative to the navigation.\n *\n * We store navigation events both by the frame and navigation ID. This means\n * when we need to look them up, we can use whichever ID we have.\n *\n * Note that these Maps will have the same values in them; these are just keyed\n * differently to make look-ups easier.\n *\n * We also additionally maintain an array of only navigations that occured on\n * the main frame. In many places in the UI we only care about highlighting\n * main frame navigations, so calculating this list here is better than\n * filtering either of the below maps over and over again at the UI layer.\n */\nconst navigationsByFrameId = new Map<string, Types.TraceEvents.TraceEventNavigationStart[]>();\nconst navigationsByNavigationId = new Map<string, Types.TraceEvents.TraceEventNavigationStart>();\nconst mainFrameNavigations: Types.TraceEvents.TraceEventNavigationStart[] = [];\n\n// Represents all the threads in the trace, organized by process. This is mostly for internal\n// bookkeeping so that during the finalize pass we can obtain the main and browser thread IDs.\nconst threadsInProcess =\n new Map<Types.TraceEvents.ProcessID, Map<Types.TraceEvents.ThreadID, Types.TraceEvents.TraceEventThreadName>>();\n\nlet traceStartedTimeFromTracingStartedEvent = Types.Timing.MicroSeconds(-1);\nconst eventPhasesOfInterestForTraceBounds = new Set([\n Types.TraceEvents.Phase.BEGIN,\n Types.TraceEvents.Phase.END,\n Types.TraceEvents.Phase.COMPLETE,\n Types.TraceEvents.Phase.INSTANT,\n]);\n\nlet handlerState = HandlerState.UNINITIALIZED;\n// Tracks if the trace is a generic trace, which here means that it did not come from athe DevTools Performance Panel recording.\n// We assume a trace is generic, and mark it as not generic if we see any of:\n// - TracingStartedInPage\n// - TracingStartedInBrowser\n// - TracingSessionIdForWorker\n// These are all events which indicate this is a Chrome browser trace.\nlet traceIsGeneric = true;\nconst CHROME_WEB_TRACE_EVENTS = new Set([\n Types.TraceEvents.KnownEventName.TracingStartedInPage,\n Types.TraceEvents.KnownEventName.TracingSessionIdForWorker,\n Types.TraceEvents.KnownEventName.TracingStartedInBrowser,\n\n]);\n\nexport function reset(): void {\n navigationsByFrameId.clear();\n navigationsByNavigationId.clear();\n processNames.clear();\n mainFrameNavigations.length = 0;\n\n browserProcessId = Types.TraceEvents.ProcessID(-1);\n browserThreadId = Types.TraceEvents.ThreadID(-1);\n gpuProcessId = Types.TraceEvents.ProcessID(-1);\n gpuThreadId = Types.TraceEvents.ThreadID(-1);\n viewportRect = null;\n topLevelRendererIds.clear();\n threadsInProcess.clear();\n rendererProcessesByFrameId.clear();\n framesByProcessId.clear();\n\n traceBounds.min = Types.Timing.MicroSeconds(Number.POSITIVE_INFINITY);\n traceBounds.max = Types.Timing.MicroSeconds(Number.NEGATIVE_INFINITY);\n traceBounds.range = Types.Timing.MicroSeconds(Number.POSITIVE_INFINITY);\n traceStartedTimeFromTracingStartedEvent = Types.Timing.MicroSeconds(-1);\n\n traceIsGeneric = true;\n\n handlerState = HandlerState.UNINITIALIZED;\n}\n\nexport function initialize(): void {\n if (handlerState !== HandlerState.UNINITIALIZED) {\n throw new Error('Meta Handler was not reset');\n }\n\n handlerState = HandlerState.INITIALIZED;\n}\n\nfunction updateRendererProcessByFrame(\n event: Types.TraceEvents.TraceEventData, frame: Types.TraceEvents.TraceFrame): void {\n const framesInProcessById = Platform.MapUtilities.getWithDefault(framesByProcessId, frame.processId, () => new Map());\n framesInProcessById.set(frame.frame, frame);\n\n const rendererProcessInFrame = Platform.MapUtilities.getWithDefault(\n rendererProcessesByFrameId, frame.frame,\n () => new Map<\n Types.TraceEvents.ProcessID,\n {frame: Types.TraceEvents.TraceFrame, window: Types.Timing.TraceWindowMicroSeconds}[]>());\n const rendererProcessInfo = Platform.MapUtilities.getWithDefault(rendererProcessInFrame, frame.processId, () => {\n return [];\n });\n const lastProcessData = rendererProcessInfo.at(-1);\n\n // Only store a new entry if the URL changed, otherwise it's just\n // redundant information.\n if (lastProcessData && lastProcessData.frame.url === frame.url) {\n return;\n }\n // For now we store the time of the event as the min. In the finalize we step\n // through each of these windows and update their max and range values.\n rendererProcessInfo.push({\n frame,\n window: {\n min: event.ts,\n max: Types.Timing.MicroSeconds(0),\n range: Types.Timing.MicroSeconds(0),\n },\n });\n}\n\nexport function handleEvent(event: Types.TraceEvents.TraceEventData): void {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Meta Handler is not initialized');\n }\n\n if (traceIsGeneric && CHROME_WEB_TRACE_EVENTS.has(event.name as Types.TraceEvents.KnownEventName)) {\n traceIsGeneric = false;\n }\n\n if (Types.TraceEvents.isProcessName(event)) {\n processNames.set(event.pid, event);\n }\n\n // If there is a timestamp (which meta events do not have), and the event does\n // not end with ::UMA then it, and the event is in the set of valid phases,\n // then it should be included for the purposes of calculating the trace bounds.\n // The UMA events in particular seem to be reported on page unloading, which\n // often extends the bounds of the trace unhelpfully.\n if (event.ts !== 0 && !event.name.endsWith('::UMA') && eventPhasesOfInterestForTraceBounds.has(event.ph)) {\n traceBounds.min = Types.Timing.MicroSeconds(Math.min(event.ts, traceBounds.min));\n const eventDuration = event.dur || Types.Timing.MicroSeconds(0);\n traceBounds.max = Types.Timing.MicroSeconds(Math.max(event.ts + eventDuration, traceBounds.max));\n }\n\n if (Types.TraceEvents.isProcessName(event) &&\n (event.args.name === 'Browser' || event.args.name === 'HeadlessBrowser')) {\n browserProcessId = event.pid;\n return;\n }\n\n if (Types.TraceEvents.isProcessName(event) && (event.args.name === 'Gpu' || event.args.name === 'GPU Process')) {\n gpuProcessId = event.pid;\n return;\n }\n\n if (Types.TraceEvents.isThreadName(event) && event.args.name === 'CrGpuMain') {\n gpuThreadId = event.tid;\n return;\n }\n\n if (Types.TraceEvents.isThreadName(event) && event.args.name === 'CrBrowserMain') {\n browserThreadId = event.tid;\n }\n\n if (Types.TraceEvents.isTraceEventMainFrameViewport(event) && viewportRect === null) {\n const rectAsArray = event.args.data.viewport_rect;\n const viewportX = rectAsArray[0];\n const viewportY = rectAsArray[1];\n const viewportWidth = rectAsArray[2];\n const viewportHeight = rectAsArray[5];\n viewportRect = new DOMRect(viewportX, viewportY, viewportWidth, viewportHeight);\n }\n\n // The TracingStartedInBrowser event includes the data on which frames are\n // in scope at the start of the trace. We use this to identify the frame with\n // no parent, i.e. the top level frame.\n if (Types.TraceEvents.isTraceEventTracingStartedInBrowser(event)) {\n traceStartedTimeFromTracingStartedEvent = event.ts;\n\n if (!event.args.data) {\n throw new Error('No frames found in trace data');\n }\n\n for (const frame of (event.args.data.frames ?? [])) {\n updateRendererProcessByFrame(event, frame);\n\n if (frame.parent) {\n continue;\n }\n\n if (frame.url) {\n mainFrameId = frame.frame;\n mainFrameURL = frame.url;\n }\n topLevelRendererIds.add(frame.processId);\n }\n return;\n }\n\n // FrameCommittedInBrowser events tell us information about each frame\n // and we use these to track how long each individual renderer is active\n // for. We track all renderers here (top level and those in frames), but\n // for convenience we also populate a set of top level renderer IDs.\n if (Types.TraceEvents.isTraceEventFrameCommittedInBrowser(event)) {\n const frame = event.args.data;\n if (!frame) {\n return;\n }\n\n updateRendererProcessByFrame(event, frame);\n\n if (frame.parent) {\n return;\n }\n\n topLevelRendererIds.add(frame.processId);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventCommitLoad(event)) {\n const frameData = event.args.data;\n if (!frameData) {\n return;\n }\n\n const {frame, name, url} = frameData;\n updateRendererProcessByFrame(event, {processId: event.pid, frame, name, url});\n return;\n }\n\n // Track all threads based on the process & thread IDs.\n if (Types.TraceEvents.isThreadName(event)) {\n const threads = Platform.MapUtilities.getWithDefault(threadsInProcess, event.pid, () => new Map());\n threads.set(event.tid, event);\n return;\n }\n\n // Track all navigation events. Note that there can be navigation start events\n // but where the documentLoaderURL is empty. As far as the trace rendering is\n // concerned, these events are noise so we filter them out here.\n // (The filtering of empty URLs is done in the\n // isTraceEventNavigationStartWithURL check)\n if (Types.TraceEvents.isTraceEventNavigationStartWithURL(event) && event.args.data) {\n const navigationId = event.args.data.navigationId;\n if (navigationsByNavigationId.has(navigationId)) {\n // We have only ever seen this situation once, in crbug.com/1503982, where the user ran:\n // window.location.href = 'javascript:console.log(\"foo\")'\n // In this situation two identical navigationStart events are emitted with the same data, URL and ID.\n // So, in this situation we drop/ignore any subsequent navigations if we have already seen that ID.\n return;\n }\n navigationsByNavigationId.set(navigationId, event);\n\n const frameId = event.args.frame;\n const existingFrameNavigations = navigationsByFrameId.get(frameId) || [];\n existingFrameNavigations.push(event);\n navigationsByFrameId.set(frameId, existingFrameNavigations);\n if (frameId === mainFrameId) {\n mainFrameNavigations.push(event);\n }\n return;\n }\n}\n\nexport async function finalize(): Promise<void> {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Handler is not initialized');\n }\n\n // We try to set the minimum time by finding the event with the smallest\n // timestamp. However, if we also got a timestamp from the\n // TracingStartedInBrowser event, we should always use that.\n // But in some traces (for example, CPU profiles) we do not get that event,\n // hence why we need to check we got a timestamp from it before setting it.\n if (traceStartedTimeFromTracingStartedEvent >= 0) {\n traceBounds.min = traceStartedTimeFromTracingStartedEvent;\n }\n traceBounds.range = Types.Timing.MicroSeconds(traceBounds.max - traceBounds.min);\n\n // If we go from foo.com to example.com we will get a new renderer, and\n // therefore the \"top level renderer\" will have a different PID as it has\n // changed. Here we step through each renderer process and updated its window\n // bounds, such that we end up with the time ranges in the trace for when\n // each particular renderer started and stopped being the main renderer\n // process.\n for (const [, processWindows] of rendererProcessesByFrameId) {\n const processWindowValues = [...processWindows.values()].flat();\n for (let i = 0; i < processWindowValues.length; i++) {\n const currentWindow = processWindowValues[i];\n const nextWindow = processWindowValues[i + 1];\n\n // For the last window we set its max to be positive infinity.\n // TODO: Move the trace bounds handler into meta so we can clamp first and last windows.\n if (!nextWindow) {\n currentWindow.window.max = Types.Timing.MicroSeconds(traceBounds.max);\n currentWindow.window.range = Types.Timing.MicroSeconds(traceBounds.max - currentWindow.window.min);\n } else {\n currentWindow.window.max = Types.Timing.MicroSeconds(nextWindow.window.min - 1);\n currentWindow.window.range = Types.Timing.MicroSeconds(currentWindow.window.max - currentWindow.window.min);\n }\n }\n }\n\n // Frame ids which we didn't register using either the TracingStartedInBrowser or\n // the FrameCommittedInBrowser events are considered noise, so we filter them out, as well\n // as the navigations that belong to such frames.\n for (const [frameId, navigations] of navigationsByFrameId) {\n // The frames in the rendererProcessesByFrameId map come only from the\n // TracingStartedInBrowser and FrameCommittedInBrowser events, so we can use it as point\n // of comparison to determine if a frameId should be discarded.\n if (rendererProcessesByFrameId.has(frameId)) {\n continue;\n }\n navigationsByFrameId.delete(frameId);\n for (const navigation of navigations) {\n if (!navigation.args.data) {\n continue;\n }\n navigationsByNavigationId.delete(navigation.args.data.navigationId);\n }\n }\n\n // Sometimes in traces the TracingStartedInBrowser event can give us an\n // incorrect initial URL for the main frame's URL - about:blank or the URL of\n // the previous page. This doesn't matter too much except we often use this\n // URL as the visual name of the trace shown to the user (e.g. in the history\n // dropdown). We can be more accurate by finding the first main frame\n // navigaton, and using its URL, if we have it.\n // However, to avoid doing this in a case where the first navigation is far\n // into the trace's lifecycle, we only do this in situations where the first\n // navigation happened very soon (0.5 seconds) after the trace started\n // recording.\n const firstMainFrameNav = mainFrameNavigations.at(0);\n const firstNavTimeThreshold = Helpers.Timing.secondsToMicroseconds(Types.Timing.Seconds(0.5));\n if (firstMainFrameNav) {\n const navigationIsWithinThreshold = firstMainFrameNav.ts - traceBounds.min < firstNavTimeThreshold;\n if (firstMainFrameNav.args.data?.isOutermostMainFrame && firstMainFrameNav.args.data?.documentLoaderURL &&\n navigationIsWithinThreshold) {\n mainFrameURL = firstMainFrameNav.args.data.documentLoaderURL;\n }\n }\n\n handlerState = HandlerState.FINALIZED;\n}\n\nexport type MetaHandlerData = {\n traceIsGeneric: boolean,\n traceBounds: Types.Timing.TraceWindowMicroSeconds,\n browserProcessId: Types.TraceEvents.ProcessID,\n processNames: Map<Types.TraceEvents.ProcessID, Types.TraceEvents.TraceEventProcessName>,\n browserThreadId: Types.TraceEvents.ThreadID,\n gpuProcessId: Types.TraceEvents.ProcessID,\n gpuThreadId?: Types.TraceEvents.ThreadID,\n viewportRect?: DOMRect,\n navigationsByFrameId: Map<string, Types.TraceEvents.TraceEventNavigationStart[]>,\n navigationsByNavigationId: Map<string, Types.TraceEvents.TraceEventNavigationStart>,\n threadsInProcess:\n Map<Types.TraceEvents.ProcessID,\n Map<Types.TraceEvents.ThreadID, Types.TraceEvents.TraceEventThreadName>>,\n mainFrameId: string,\n mainFrameURL: string,\n /**\n * A frame can have multiple renderer processes, at the same time,\n * a renderer process can have multiple URLs. This map tracks the\n * processes active on a given frame, with the time window in which\n * they were active. Because a renderer process might have multiple\n * URLs, each process in each frame has an array of windows, with an\n * entry for each URL it had.\n */\n rendererProcessesByFrame: FrameProcessData,\n topLevelRendererIds: Set<Types.TraceEvents.ProcessID>,\n frameByProcessId: Map<Types.TraceEvents.ProcessID, Map<string, Types.TraceEvents.TraceFrame>>,\n mainFrameNavigations: Types.TraceEvents.TraceEventNavigationStart[],\n};\n\n// Each frame has a single render process at a given time but it can have\n// multiple render processes during a trace, for example if a navigation\n// occurred in the frame. This map tracks the process that was active for\n// each frame at each point in time. Also, because a process can be\n// assigned to multiple URLs, there is a window for each URL a process\n// was assigned.\n//\n// Note that different sites always end up in different render\n// processes, however two different URLs can point to the same site.\n// For example: https://google.com and https://maps.google.com point to\n// the same site.\n// Read more about this in\n// https://developer.chrome.com/articles/renderingng-architecture/#threads\n// and https://web.dev/same-site-same-origin/\nexport type FrameProcessData =\n Map<string,\n Map<Types.TraceEvents.ProcessID,\n {frame: Types.TraceEvents.TraceFrame, window: Types.Timing.TraceWindowMicroSeconds}[]>>;\n\nexport function data(): MetaHandlerData {\n if (handlerState !== HandlerState.FINALIZED) {\n throw new Error('Meta Handler is not finalized');\n }\n\n return {\n traceBounds: {...traceBounds},\n browserProcessId,\n browserThreadId,\n processNames,\n gpuProcessId,\n gpuThreadId: gpuThreadId === Types.TraceEvents.ThreadID(-1) ? undefined : gpuThreadId,\n viewportRect: viewportRect || undefined,\n mainFrameId,\n mainFrameURL,\n navigationsByFrameId,\n navigationsByNavigationId,\n threadsInProcess,\n rendererProcessesByFrame: rendererProcessesByFrameId,\n topLevelRendererIds,\n frameByProcessId: framesByProcessId,\n mainFrameNavigations,\n traceIsGeneric,\n };\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  export * as Animations from './AnimationHandler.js';
2
2
  export * as AuctionWorklets from './AuctionWorkletsHandler.js';
3
+ export * as ExtensionTraceData from './ExtensionTraceDataHandler.js';
3
4
  export * as Frames from './FramesHandler.js';
4
5
  export * as GPU from './GPUHandler.js';
5
6
  export * as Initiators from './InitiatorsHandler.js';
@@ -3,6 +3,7 @@
3
3
  // found in the LICENSE file.
4
4
  export * as Animations from './AnimationHandler.js';
5
5
  export * as AuctionWorklets from './AuctionWorkletsHandler.js';
6
+ export * as ExtensionTraceData from './ExtensionTraceDataHandler.js';
6
7
  export * as Frames from './FramesHandler.js';
7
8
  export * as GPU from './GPUHandler.js';
8
9
  export * as Initiators from './InitiatorsHandler.js';
@@ -1 +1 @@
1
- {"version":3,"file":"ModelHandlers.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/ModelHandlers.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAC;AAC7C,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,aAAa,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,iBAAiB,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAC;AAC7C,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AACjD,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAC;AAC/C,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AACjD,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAC","sourcesContent":["// Copyright 2022 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\nexport * as Animations from './AnimationHandler.js';\nexport * as AuctionWorklets from './AuctionWorkletsHandler.js';\nexport * as Frames from './FramesHandler.js';\nexport * as GPU from './GPUHandler.js';\nexport * as Initiators from './InitiatorsHandler.js';\nexport * as Invalidations from './InvalidationsHandler.js';\nexport * as LargestImagePaint from './LargestImagePaintHandler.js';\nexport * as LargestTextPaint from './LargestTextPaintHandler.js';\nexport * as LayerTree from './LayerTreeHandler.js';\nexport * as LayoutShifts from './LayoutShiftsHandler.js';\nexport * as Memory from './MemoryHandler.js';\nexport * as Meta from './MetaHandler.js';\nexport * as NetworkRequests from './NetworkRequestsHandler.js';\nexport * as PageLoadMetrics from './PageLoadMetricsHandler.js';\nexport * as Renderer from './RendererHandler.js';\nexport * as Samples from './SamplesHandler.js';\nexport * as Screenshots from './ScreenshotsHandler.js';\nexport * as UserInteractions from './UserInteractionsHandler.js';\nexport * as UserTimings from './UserTimingsHandler.js';\nexport * as Warnings from './WarningsHandler.js';\nexport * as Workers from './WorkersHandler.js';\n"]}
1
+ {"version":3,"file":"ModelHandlers.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/ModelHandlers.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAC;AAC7C,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,aAAa,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,iBAAiB,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAC;AAC7C,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AACjD,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAC;AAC/C,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AACjD,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAC","sourcesContent":["// Copyright 2022 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\nexport * as Animations from './AnimationHandler.js';\nexport * as AuctionWorklets from './AuctionWorkletsHandler.js';\nexport * as ExtensionTraceData from './ExtensionTraceDataHandler.js';\nexport * as Frames from './FramesHandler.js';\nexport * as GPU from './GPUHandler.js';\nexport * as Initiators from './InitiatorsHandler.js';\nexport * as Invalidations from './InvalidationsHandler.js';\nexport * as LargestImagePaint from './LargestImagePaintHandler.js';\nexport * as LargestTextPaint from './LargestTextPaintHandler.js';\nexport * as LayerTree from './LayerTreeHandler.js';\nexport * as LayoutShifts from './LayoutShiftsHandler.js';\nexport * as Memory from './MemoryHandler.js';\nexport * as Meta from './MetaHandler.js';\nexport * as NetworkRequests from './NetworkRequestsHandler.js';\nexport * as PageLoadMetrics from './PageLoadMetricsHandler.js';\nexport * as Renderer from './RendererHandler.js';\nexport * as Samples from './SamplesHandler.js';\nexport * as Screenshots from './ScreenshotsHandler.js';\nexport * as UserInteractions from './UserInteractionsHandler.js';\nexport * as UserTimings from './UserTimingsHandler.js';\nexport * as Warnings from './WarningsHandler.js';\nexport * as Workers from './WorkersHandler.js';\n"]}
@@ -356,8 +356,8 @@ export function data() {
356
356
  throw new Error('Network Request handler is not finalized');
357
357
  }
358
358
  return {
359
- byOrigin: new Map(requestsByOrigin),
360
- byTime: [...requestsByTime],
359
+ byOrigin: requestsByOrigin,
360
+ byTime: requestsByTime,
361
361
  };
362
362
  }
363
363
  export function deps() {
@@ -1 +1 @@
1
- {"version":3,"file":"NetworkRequests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,CAAC,SAAS,CAAC;YACzC,GAAG,EAAE,gBAAgB,CAAC,GAAG;YACzB,GAAG,EAAE,gBAAgB,CAAC,GAAG;SAC1B,CAAC;QAEF,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,GAAG,EAAE;YACjF,OAAO;gBACL,cAAc,EAAE,EAAE;gBAClB,iBAAiB,EAAE,EAAE;gBACrB,GAAG,EAAE,EAAE;aACR,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,mEAAmE;QACnE,uEAAuE;QACvE,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,KAAK,cAAc,EAAE;YAC5D,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SAC/C;aAAM;YACL,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SAC5C;QAED,uEAAuE;QACvE,gEAAgE;QAChE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAChC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;KACnC;IAED,YAAY,iCAAyB,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,IAAI,YAAY,mCAA2B,EAAE;QAC3C,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;KAC7D;IAED,OAAO;QACL,QAAQ,EAAE,IAAI,GAAG,CAAC,gBAAgB,CAAC;QACnC,MAAM,EAAE,CAAC,GAAG,cAAc,CAAC;KAC5B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,CAAC,CAAC;AAClB,CAAC","sourcesContent":["// Copyright 2022 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\nimport {type TraceEventHandlerName, HandlerState} from './types.js';\n\nimport {data as metaHandlerData} from './MetaHandler.js';\nimport * as Helpers from '../helpers/helpers.js';\n\nimport * as Types from '../types/types.js';\n\nconst MILLISECONDS_TO_MICROSECONDS = 1000;\nconst SECONDS_TO_MICROSECONDS = 1000000;\n\n// Network requests from traces are actually formed of 5 trace records.\n// This handler tracks all trace records based on the request ID, and\n// then creates a new synthetic trace event for those network requests.\n//\n// This interface, then, defines the shape of the object we intend to\n// keep for each request in the trace. In the finalize we will convert\n// these 5 types of trace records to a synthetic complete event that\n// represents a composite of these trace records.\ninterface TraceEventsForNetworkRequest {\n changePriority?: Types.TraceEvents.TraceEventResourceChangePriority;\n willSendRequests?: Types.TraceEvents.TraceEventResourceWillSendRequest[];\n sendRequests?: Types.TraceEvents.TraceEventResourceSendRequest[];\n receiveResponse?: Types.TraceEvents.TraceEventResourceReceiveResponse;\n resourceFinish?: Types.TraceEvents.TraceEventResourceFinish;\n receivedData?: Types.TraceEvents.TraceEventResourceReceivedData[];\n resourceMarkAsCached?: Types.TraceEvents.TraceEventResourceMarkAsCached;\n}\n\ninterface NetworkRequestData {\n byOrigin: Map<string, {\n renderBlocking: Types.TraceEvents.SyntheticNetworkRequest[],\n nonRenderBlocking: Types.TraceEvents.SyntheticNetworkRequest[],\n all: Types.TraceEvents.SyntheticNetworkRequest[],\n }>;\n byTime: Types.TraceEvents.SyntheticNetworkRequest[];\n}\n\nconst requestMap = new Map<string, TraceEventsForNetworkRequest>();\nconst requestsByOrigin = new Map<string, {\n renderBlocking: Types.TraceEvents.SyntheticNetworkRequest[],\n nonRenderBlocking: Types.TraceEvents.SyntheticNetworkRequest[],\n all: Types.TraceEvents.SyntheticNetworkRequest[],\n}>();\nconst requestsByTime: Types.TraceEvents.SyntheticNetworkRequest[] = [];\n\nfunction storeTraceEventWithRequestId<K extends keyof TraceEventsForNetworkRequest>(\n requestId: string, key: K, value: TraceEventsForNetworkRequest[K]): void {\n if (!requestMap.has(requestId)) {\n requestMap.set(requestId, {});\n }\n\n const traceEvents = requestMap.get(requestId);\n if (!traceEvents) {\n throw new Error(`Unable to locate trace events for request ID ${requestId}`);\n }\n\n if (Array.isArray(traceEvents[key])) {\n const target = traceEvents[key] as Types.TraceEvents.TraceEventData[];\n const values = value as Types.TraceEvents.TraceEventData[];\n target.push(...values);\n } else {\n traceEvents[key] = value;\n }\n}\n\nfunction firstPositiveValueInList(entries: number[]): number {\n for (const entry of entries) {\n if (entry > 0) {\n return entry;\n }\n }\n\n // In the event we don't find a positive value, we return 0 so as to\n // be a mathematical noop. It's typically not correct to return – say –\n // a -1 here because it would affect the calculation of stats below.\n return 0;\n}\n\nlet handlerState = HandlerState.UNINITIALIZED;\n\nexport function reset(): void {\n requestsByOrigin.clear();\n requestMap.clear();\n requestsByTime.length = 0;\n\n handlerState = HandlerState.UNINITIALIZED;\n}\n\nexport function initialize(): void {\n handlerState = HandlerState.INITIALIZED;\n}\n\nexport function handleEvent(event: Types.TraceEvents.TraceEventData): void {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Network Request handler is not initialized');\n }\n\n if (Types.TraceEvents.isTraceEventResourceChangePriority(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'changePriority', event);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventResourceWillSendRequest(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'willSendRequests', [event]);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventResourceSendRequest(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'sendRequests', [event]);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventResourceReceiveResponse(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'receiveResponse', event);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventResourceReceivedData(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'receivedData', [event]);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventResourceFinish(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'resourceFinish', event);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventResourceMarkAsCached(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'resourceMarkAsCached', event);\n return;\n }\n}\n\nexport async function finalize(): Promise<void> {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Network Request handler is not initialized');\n }\n\n const {rendererProcessesByFrame} = metaHandlerData();\n for (const [requestId, request] of requestMap.entries()) {\n // If we have an incomplete set of events here, we choose to drop the network\n // request rather than attempt to synthesize the missing data.\n if (!request.sendRequests || !request.receiveResponse) {\n continue;\n }\n\n // In the data we may get multiple willSendRequests and sendRequests, which\n // will indicate that there are redirects for a given (sub)resource. In the\n // case of a navigation, e.g., example.com/ we will get willSendRequests,\n // and we should use these to calculate time spent in redirects.\n // In the case of sub-resources, however, e.g., example.com/foo.js we will\n // *only* get sendRequests, and we use these instead of willSendRequests\n // to detect the time in redirects. We always use the sendRequest for the\n // url, priority etc since it contains those values, but we use the\n // willSendRequest (if it exists) to calculate the timestamp and durations\n // of redirects.\n const redirects: Types.TraceEvents.SyntheticNetworkRedirect[] = [];\n for (let i = 0; i < request.sendRequests.length - 1; i++) {\n const sendRequest = request.sendRequests[i];\n const nextSendRequest = request.sendRequests[i + 1];\n\n // Use the willSendRequests as the source for redirects if possible.\n // We default to those of the sendRequests, however, since willSendRequest\n // is not guaranteed to be present in the data for every request.\n let ts = sendRequest.ts;\n let dur = Types.Timing.MicroSeconds(nextSendRequest.ts - sendRequest.ts);\n if (request.willSendRequests && request.willSendRequests[i] && request.willSendRequests[i + 1]) {\n const willSendRequest = request.willSendRequests[i];\n const nextWillSendRequest = request.willSendRequests[i + 1];\n ts = willSendRequest.ts;\n dur = Types.Timing.MicroSeconds(nextWillSendRequest.ts - willSendRequest.ts);\n }\n\n redirects.push({\n url: sendRequest.args.data.url,\n priority: sendRequest.args.data.priority,\n requestMethod: sendRequest.args.data.requestMethod,\n ts,\n dur,\n });\n }\n\n // If a ResourceFinish event with an encoded data length is received,\n // then the resource was not cached; it was fetched before it was\n // requested, e.g. because it was pushed in this navigation.\n const isPushedResource = request.resourceFinish?.args.data.encodedDataLength !== 0;\n // This works around crbug.com/998397, which reports pushed resources, and resources served by a service worker as disk cached.\n const isDiskCached = request.receiveResponse.args.data.fromCache &&\n !request.receiveResponse.args.data.fromServiceWorker && !isPushedResource;\n // If the request contains a resourceMarkAsCached event, it was served from memory cache.\n const isMemoryCached = request.resourceMarkAsCached !== undefined;\n\n // The timing data returned is from the original (uncached) request, which\n // means that if we leave the above network record data as-is when the\n // request came from either the disk cache or memory cache, our calculations\n // will be incorrect.\n //\n // Here we add a flag so when we calculate the timestamps of the various\n // events, we can overwrite them.\n // These timestamps may not be perfect (indeed they don't always match\n // the Network CDP domain exactly, which is likely an artifact of the way\n // the data is routed on the backend), but they're the closest we have.\n const isCached = isMemoryCached || isDiskCached;\n\n const timing = request.receiveResponse.args.data.timing;\n // If a non-cached request has no |timing| indicates data URLs, we ignore it.\n if (!timing && !isCached) {\n continue;\n }\n\n const firstSendRequest = request.sendRequests[0];\n const finalSendRequest = request.sendRequests[request.sendRequests.length - 1];\n\n const initialPriority = finalSendRequest.args.data.priority;\n let finalPriority = initialPriority;\n if (request.changePriority) {\n finalPriority = request.changePriority.args.data.priority;\n }\n\n // Start time\n // =======================\n // The time where the request started, which is either the first willSendRequest\n // event if there is one, or, if there is not, the sendRequest.\n const startTime = (request.willSendRequests && request.willSendRequests.length) ?\n Types.Timing.MicroSeconds(request.willSendRequests[0].ts) :\n Types.Timing.MicroSeconds(firstSendRequest.ts);\n\n // End redirect time\n // =======================\n // It's possible that when we start requesting data we will receive redirections.\n // Here we note the time of the *last* willSendRequest / sendRequest event,\n // which is used later on in the calculations for time queueing etc.\n const endRedirectTime = (request.willSendRequests && request.willSendRequests.length) ?\n Types.Timing.MicroSeconds(request.willSendRequests[request.willSendRequests.length - 1].ts) :\n Types.Timing.MicroSeconds(finalSendRequest.ts);\n\n // Finish time and end time\n // =======================\n // The finish time and the end time are subtly different.\n // - Finish time: records the point at which the network stack stopped receiving the data\n // - End time: the timestamp of the finish event itself (if one exists)\n //\n // The end time, then, will be slightly after the finish time.\n const endTime = request.resourceFinish ? request.resourceFinish.ts : endRedirectTime;\n const finishTime = request.resourceFinish?.args.data.finishTime ?\n Types.Timing.MicroSeconds(request.resourceFinish.args.data.finishTime * SECONDS_TO_MICROSECONDS) :\n Types.Timing.MicroSeconds(endTime);\n\n // Network duration\n // =======================\n // Time spent on the network.\n const networkDuration = isCached ? Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((finishTime || endRedirectTime) - endRedirectTime);\n\n // Processing duration\n // =======================\n // Time spent from start to end.\n const processingDuration = Types.Timing.MicroSeconds(endTime - (finishTime || endTime));\n\n // Redirection duration\n // =======================\n // Time between the first willSendRequest / sendRequest and last. This we place in *front* of the\n // queueing, since the queueing time that we know about from the trace data is only the last request,\n // i.e., the one that occurs after all the redirects.\n const redirectionDuration = Types.Timing.MicroSeconds(endRedirectTime - startTime);\n\n // Queueing\n // =======================\n // The amount of time queueing is the time between the request's start time to the requestTime\n // arg recorded in the receiveResponse event. In the cases where the recorded start time is larger\n // that the requestTime we set queueing time to zero.\n const queueing = isCached ?\n Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds(Platform.NumberUtilities.clamp(\n (timing.requestTime * SECONDS_TO_MICROSECONDS - endRedirectTime), 0, Number.MAX_VALUE));\n\n // Stalled\n // =======================\n // If the request is cached, the amount of time stalled is the time between the start time and\n // receiving a response.\n // Otherwise it is whichever positive number comes first from the following timing info:\n // DNS start, Connection start, Send Start, or the time duration between our start time and\n // receiving a response.\n const stalled = isCached ? Types.Timing.MicroSeconds(request.receiveResponse.ts - startTime) :\n Types.Timing.MicroSeconds(firstPositiveValueInList([\n timing.dnsStart * MILLISECONDS_TO_MICROSECONDS,\n timing.connectStart * MILLISECONDS_TO_MICROSECONDS,\n timing.sendStart * MILLISECONDS_TO_MICROSECONDS,\n (request.receiveResponse.ts - endRedirectTime),\n ]));\n\n // Sending HTTP request\n // =======================\n // Time when the HTTP request is sent.\n const sendStartTime = isCached ?\n startTime :\n Types.Timing.MicroSeconds(\n timing.requestTime * SECONDS_TO_MICROSECONDS + timing.sendStart * MILLISECONDS_TO_MICROSECONDS);\n\n // Waiting\n // =======================\n // Time from when the send finished going to when the headers were received.\n const waiting = isCached ?\n Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((timing.receiveHeadersEnd - timing.sendEnd) * MILLISECONDS_TO_MICROSECONDS);\n\n // Download\n // =======================\n // Time from receipt of headers to the finish time.\n const downloadStart = isCached ?\n startTime :\n Types.Timing.MicroSeconds(\n timing.requestTime * SECONDS_TO_MICROSECONDS + timing.receiveHeadersEnd * MILLISECONDS_TO_MICROSECONDS);\n const download = isCached ? Types.Timing.MicroSeconds(endTime - request.receiveResponse.ts) :\n Types.Timing.MicroSeconds(((finishTime || downloadStart) - downloadStart));\n\n const totalTime = Types.Timing.MicroSeconds(networkDuration + processingDuration);\n\n // Collect a few values from the timing info.\n // If the Network request is cached, we zero out them.\n const dnsLookup = isCached ?\n Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((timing.dnsEnd - timing.dnsStart) * MILLISECONDS_TO_MICROSECONDS);\n const ssl = isCached ? Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((timing.sslEnd - timing.sslStart) * MILLISECONDS_TO_MICROSECONDS);\n const proxyNegotiation = isCached ?\n Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((timing.proxyEnd - timing.proxyStart) * MILLISECONDS_TO_MICROSECONDS);\n const requestSent = isCached ?\n Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((timing.sendEnd - timing.sendStart) * MILLISECONDS_TO_MICROSECONDS);\n const initialConnection = isCached ?\n Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((timing.connectEnd - timing.connectStart) * MILLISECONDS_TO_MICROSECONDS);\n\n // Finally get some of the general data from the trace events.\n const {frame, url, renderBlocking} = finalSendRequest.args.data;\n const {encodedDataLength, decodedBodyLength} =\n request.resourceFinish ? request.resourceFinish.args.data : {encodedDataLength: 0, decodedBodyLength: 0};\n const {host, protocol, pathname, search} = new URL(url);\n const isHttps = protocol === 'https:';\n const requestingFrameUrl =\n Helpers.Trace.activeURLForFrameAtTime(frame, finalSendRequest.ts, rendererProcessesByFrame) || '';\n\n // Construct a synthetic trace event for this network request.\n const networkEvent: Types.TraceEvents.SyntheticNetworkRequest = {\n args: {\n data: {\n // All data we create from trace events should be added to |syntheticData|.\n syntheticData: {\n dnsLookup,\n download,\n downloadStart,\n finishTime,\n initialConnection,\n isDiskCached,\n isHttps,\n isMemoryCached,\n isPushedResource,\n networkDuration,\n processingDuration,\n proxyNegotiation,\n queueing,\n redirectionDuration,\n requestSent,\n sendStartTime,\n ssl,\n stalled,\n totalTime,\n waiting,\n },\n // All fields below are from TraceEventsForNetworkRequest.\n decodedBodyLength,\n encodedDataLength,\n frame,\n fromServiceWorker: request.receiveResponse.args.data.fromServiceWorker,\n isLinkPreload: request.receiveResponse.args.data.isLinkPreload || false,\n host,\n mimeType: request.receiveResponse.args.data.mimeType,\n pathname,\n priority: finalPriority,\n initialPriority,\n protocol,\n redirects,\n // In the event the property isn't set, assume non-blocking.\n renderBlocking: renderBlocking ? renderBlocking : 'non_blocking',\n requestId,\n requestingFrameUrl,\n requestMethod: finalSendRequest.args.data.requestMethod,\n resourceType: finalSendRequest.args.data.resourceType,\n search,\n statusCode: request.receiveResponse.args.data.statusCode,\n responseHeaders: request.receiveResponse.args.data.headers || [],\n fetchPriorityHint: finalSendRequest.args.data.fetchPriorityHint,\n initiator: finalSendRequest.args.data.initiator,\n stackTrace: finalSendRequest.args.data.stackTrace,\n timing,\n url,\n },\n },\n cat: 'loading',\n name: 'SyntheticNetworkRequest',\n ph: Types.TraceEvents.Phase.COMPLETE,\n dur: Types.Timing.MicroSeconds(endTime - startTime),\n tdur: Types.Timing.MicroSeconds(endTime - startTime),\n ts: Types.Timing.MicroSeconds(startTime),\n tts: Types.Timing.MicroSeconds(startTime),\n pid: finalSendRequest.pid,\n tid: finalSendRequest.tid,\n };\n\n const requests = Platform.MapUtilities.getWithDefault(requestsByOrigin, host, () => {\n return {\n renderBlocking: [],\n nonRenderBlocking: [],\n all: [],\n };\n });\n\n // For ease of rendering we sometimes want to differentiate between\n // render-blocking and non-render-blocking, so we divide the data here.\n if (networkEvent.args.data.renderBlocking === 'non_blocking') {\n requests.nonRenderBlocking.push(networkEvent);\n } else {\n requests.renderBlocking.push(networkEvent);\n }\n\n // However, there are also times where we just want to loop through all\n // the captured requests, so here we store all of them together.\n requests.all.push(networkEvent);\n requestsByTime.push(networkEvent);\n }\n\n handlerState = HandlerState.FINALIZED;\n}\n\nexport function data(): NetworkRequestData {\n if (handlerState !== HandlerState.FINALIZED) {\n throw new Error('Network Request handler is not finalized');\n }\n\n return {\n byOrigin: new Map(requestsByOrigin),\n byTime: [...requestsByTime],\n };\n}\n\nexport function deps(): TraceEventHandlerName[] {\n return ['Meta'];\n}\n"]}
1
+ {"version":3,"file":"NetworkRequestsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/NetworkRequestsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAG/D,OAAO,EAAC,IAAI,IAAI,eAAe,EAAC,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,MAAM,4BAA4B,GAAG,IAAI,CAAC;AAC1C,MAAM,uBAAuB,GAAG,OAAO,CAAC;AA6BxC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAwC,CAAC;AACnE,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAI5B,CAAC;AACL,MAAM,cAAc,GAAgD,EAAE,CAAC;AAEvE,SAAS,4BAA4B,CACjC,SAA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QAEH,mEAAmE;QACnE,uEAAuE;QACvE,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,KAAK,cAAc,EAAE,CAAC;YAC7D,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAChD,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC7C,CAAC;QAED,uEAAuE;QACvE,gEAAgE;QAChE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAChC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACpC,CAAC;IAED,YAAY,iCAAyB,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,IAAI,YAAY,mCAA2B,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,gBAAgB;QAC1B,MAAM,EAAE,cAAc;KACvB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,CAAC,CAAC;AAClB,CAAC","sourcesContent":["// Copyright 2022 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\nimport {type TraceEventHandlerName, HandlerState} from './types.js';\n\nimport {data as metaHandlerData} from './MetaHandler.js';\nimport * as Helpers from '../helpers/helpers.js';\n\nimport * as Types from '../types/types.js';\n\nconst MILLISECONDS_TO_MICROSECONDS = 1000;\nconst SECONDS_TO_MICROSECONDS = 1000000;\n\n// Network requests from traces are actually formed of 5 trace records.\n// This handler tracks all trace records based on the request ID, and\n// then creates a new synthetic trace event for those network requests.\n//\n// This interface, then, defines the shape of the object we intend to\n// keep for each request in the trace. In the finalize we will convert\n// these 5 types of trace records to a synthetic complete event that\n// represents a composite of these trace records.\ninterface TraceEventsForNetworkRequest {\n changePriority?: Types.TraceEvents.TraceEventResourceChangePriority;\n willSendRequests?: Types.TraceEvents.TraceEventResourceWillSendRequest[];\n sendRequests?: Types.TraceEvents.TraceEventResourceSendRequest[];\n receiveResponse?: Types.TraceEvents.TraceEventResourceReceiveResponse;\n resourceFinish?: Types.TraceEvents.TraceEventResourceFinish;\n receivedData?: Types.TraceEvents.TraceEventResourceReceivedData[];\n resourceMarkAsCached?: Types.TraceEvents.TraceEventResourceMarkAsCached;\n}\n\ninterface NetworkRequestData {\n byOrigin: Map<string, {\n renderBlocking: Types.TraceEvents.SyntheticNetworkRequest[],\n nonRenderBlocking: Types.TraceEvents.SyntheticNetworkRequest[],\n all: Types.TraceEvents.SyntheticNetworkRequest[],\n }>;\n byTime: Types.TraceEvents.SyntheticNetworkRequest[];\n}\n\nconst requestMap = new Map<string, TraceEventsForNetworkRequest>();\nconst requestsByOrigin = new Map<string, {\n renderBlocking: Types.TraceEvents.SyntheticNetworkRequest[],\n nonRenderBlocking: Types.TraceEvents.SyntheticNetworkRequest[],\n all: Types.TraceEvents.SyntheticNetworkRequest[],\n}>();\nconst requestsByTime: Types.TraceEvents.SyntheticNetworkRequest[] = [];\n\nfunction storeTraceEventWithRequestId<K extends keyof TraceEventsForNetworkRequest>(\n requestId: string, key: K, value: TraceEventsForNetworkRequest[K]): void {\n if (!requestMap.has(requestId)) {\n requestMap.set(requestId, {});\n }\n\n const traceEvents = requestMap.get(requestId);\n if (!traceEvents) {\n throw new Error(`Unable to locate trace events for request ID ${requestId}`);\n }\n\n if (Array.isArray(traceEvents[key])) {\n const target = traceEvents[key] as Types.TraceEvents.TraceEventData[];\n const values = value as Types.TraceEvents.TraceEventData[];\n target.push(...values);\n } else {\n traceEvents[key] = value;\n }\n}\n\nfunction firstPositiveValueInList(entries: number[]): number {\n for (const entry of entries) {\n if (entry > 0) {\n return entry;\n }\n }\n\n // In the event we don't find a positive value, we return 0 so as to\n // be a mathematical noop. It's typically not correct to return – say –\n // a -1 here because it would affect the calculation of stats below.\n return 0;\n}\n\nlet handlerState = HandlerState.UNINITIALIZED;\n\nexport function reset(): void {\n requestsByOrigin.clear();\n requestMap.clear();\n requestsByTime.length = 0;\n\n handlerState = HandlerState.UNINITIALIZED;\n}\n\nexport function initialize(): void {\n handlerState = HandlerState.INITIALIZED;\n}\n\nexport function handleEvent(event: Types.TraceEvents.TraceEventData): void {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Network Request handler is not initialized');\n }\n\n if (Types.TraceEvents.isTraceEventResourceChangePriority(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'changePriority', event);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventResourceWillSendRequest(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'willSendRequests', [event]);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventResourceSendRequest(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'sendRequests', [event]);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventResourceReceiveResponse(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'receiveResponse', event);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventResourceReceivedData(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'receivedData', [event]);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventResourceFinish(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'resourceFinish', event);\n return;\n }\n\n if (Types.TraceEvents.isTraceEventResourceMarkAsCached(event)) {\n storeTraceEventWithRequestId(event.args.data.requestId, 'resourceMarkAsCached', event);\n return;\n }\n}\n\nexport async function finalize(): Promise<void> {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Network Request handler is not initialized');\n }\n\n const {rendererProcessesByFrame} = metaHandlerData();\n for (const [requestId, request] of requestMap.entries()) {\n // If we have an incomplete set of events here, we choose to drop the network\n // request rather than attempt to synthesize the missing data.\n if (!request.sendRequests || !request.receiveResponse) {\n continue;\n }\n\n // In the data we may get multiple willSendRequests and sendRequests, which\n // will indicate that there are redirects for a given (sub)resource. In the\n // case of a navigation, e.g., example.com/ we will get willSendRequests,\n // and we should use these to calculate time spent in redirects.\n // In the case of sub-resources, however, e.g., example.com/foo.js we will\n // *only* get sendRequests, and we use these instead of willSendRequests\n // to detect the time in redirects. We always use the sendRequest for the\n // url, priority etc since it contains those values, but we use the\n // willSendRequest (if it exists) to calculate the timestamp and durations\n // of redirects.\n const redirects: Types.TraceEvents.SyntheticNetworkRedirect[] = [];\n for (let i = 0; i < request.sendRequests.length - 1; i++) {\n const sendRequest = request.sendRequests[i];\n const nextSendRequest = request.sendRequests[i + 1];\n\n // Use the willSendRequests as the source for redirects if possible.\n // We default to those of the sendRequests, however, since willSendRequest\n // is not guaranteed to be present in the data for every request.\n let ts = sendRequest.ts;\n let dur = Types.Timing.MicroSeconds(nextSendRequest.ts - sendRequest.ts);\n if (request.willSendRequests && request.willSendRequests[i] && request.willSendRequests[i + 1]) {\n const willSendRequest = request.willSendRequests[i];\n const nextWillSendRequest = request.willSendRequests[i + 1];\n ts = willSendRequest.ts;\n dur = Types.Timing.MicroSeconds(nextWillSendRequest.ts - willSendRequest.ts);\n }\n\n redirects.push({\n url: sendRequest.args.data.url,\n priority: sendRequest.args.data.priority,\n requestMethod: sendRequest.args.data.requestMethod,\n ts,\n dur,\n });\n }\n\n // If a ResourceFinish event with an encoded data length is received,\n // then the resource was not cached; it was fetched before it was\n // requested, e.g. because it was pushed in this navigation.\n const isPushedResource = request.resourceFinish?.args.data.encodedDataLength !== 0;\n // This works around crbug.com/998397, which reports pushed resources, and resources served by a service worker as disk cached.\n const isDiskCached = request.receiveResponse.args.data.fromCache &&\n !request.receiveResponse.args.data.fromServiceWorker && !isPushedResource;\n // If the request contains a resourceMarkAsCached event, it was served from memory cache.\n const isMemoryCached = request.resourceMarkAsCached !== undefined;\n\n // The timing data returned is from the original (uncached) request, which\n // means that if we leave the above network record data as-is when the\n // request came from either the disk cache or memory cache, our calculations\n // will be incorrect.\n //\n // Here we add a flag so when we calculate the timestamps of the various\n // events, we can overwrite them.\n // These timestamps may not be perfect (indeed they don't always match\n // the Network CDP domain exactly, which is likely an artifact of the way\n // the data is routed on the backend), but they're the closest we have.\n const isCached = isMemoryCached || isDiskCached;\n\n const timing = request.receiveResponse.args.data.timing;\n // If a non-cached request has no |timing| indicates data URLs, we ignore it.\n if (!timing && !isCached) {\n continue;\n }\n\n const firstSendRequest = request.sendRequests[0];\n const finalSendRequest = request.sendRequests[request.sendRequests.length - 1];\n\n const initialPriority = finalSendRequest.args.data.priority;\n let finalPriority = initialPriority;\n if (request.changePriority) {\n finalPriority = request.changePriority.args.data.priority;\n }\n\n // Start time\n // =======================\n // The time where the request started, which is either the first willSendRequest\n // event if there is one, or, if there is not, the sendRequest.\n const startTime = (request.willSendRequests && request.willSendRequests.length) ?\n Types.Timing.MicroSeconds(request.willSendRequests[0].ts) :\n Types.Timing.MicroSeconds(firstSendRequest.ts);\n\n // End redirect time\n // =======================\n // It's possible that when we start requesting data we will receive redirections.\n // Here we note the time of the *last* willSendRequest / sendRequest event,\n // which is used later on in the calculations for time queueing etc.\n const endRedirectTime = (request.willSendRequests && request.willSendRequests.length) ?\n Types.Timing.MicroSeconds(request.willSendRequests[request.willSendRequests.length - 1].ts) :\n Types.Timing.MicroSeconds(finalSendRequest.ts);\n\n // Finish time and end time\n // =======================\n // The finish time and the end time are subtly different.\n // - Finish time: records the point at which the network stack stopped receiving the data\n // - End time: the timestamp of the finish event itself (if one exists)\n //\n // The end time, then, will be slightly after the finish time.\n const endTime = request.resourceFinish ? request.resourceFinish.ts : endRedirectTime;\n const finishTime = request.resourceFinish?.args.data.finishTime ?\n Types.Timing.MicroSeconds(request.resourceFinish.args.data.finishTime * SECONDS_TO_MICROSECONDS) :\n Types.Timing.MicroSeconds(endTime);\n\n // Network duration\n // =======================\n // Time spent on the network.\n const networkDuration = isCached ? Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((finishTime || endRedirectTime) - endRedirectTime);\n\n // Processing duration\n // =======================\n // Time spent from start to end.\n const processingDuration = Types.Timing.MicroSeconds(endTime - (finishTime || endTime));\n\n // Redirection duration\n // =======================\n // Time between the first willSendRequest / sendRequest and last. This we place in *front* of the\n // queueing, since the queueing time that we know about from the trace data is only the last request,\n // i.e., the one that occurs after all the redirects.\n const redirectionDuration = Types.Timing.MicroSeconds(endRedirectTime - startTime);\n\n // Queueing\n // =======================\n // The amount of time queueing is the time between the request's start time to the requestTime\n // arg recorded in the receiveResponse event. In the cases where the recorded start time is larger\n // that the requestTime we set queueing time to zero.\n const queueing = isCached ?\n Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds(Platform.NumberUtilities.clamp(\n (timing.requestTime * SECONDS_TO_MICROSECONDS - endRedirectTime), 0, Number.MAX_VALUE));\n\n // Stalled\n // =======================\n // If the request is cached, the amount of time stalled is the time between the start time and\n // receiving a response.\n // Otherwise it is whichever positive number comes first from the following timing info:\n // DNS start, Connection start, Send Start, or the time duration between our start time and\n // receiving a response.\n const stalled = isCached ? Types.Timing.MicroSeconds(request.receiveResponse.ts - startTime) :\n Types.Timing.MicroSeconds(firstPositiveValueInList([\n timing.dnsStart * MILLISECONDS_TO_MICROSECONDS,\n timing.connectStart * MILLISECONDS_TO_MICROSECONDS,\n timing.sendStart * MILLISECONDS_TO_MICROSECONDS,\n (request.receiveResponse.ts - endRedirectTime),\n ]));\n\n // Sending HTTP request\n // =======================\n // Time when the HTTP request is sent.\n const sendStartTime = isCached ?\n startTime :\n Types.Timing.MicroSeconds(\n timing.requestTime * SECONDS_TO_MICROSECONDS + timing.sendStart * MILLISECONDS_TO_MICROSECONDS);\n\n // Waiting\n // =======================\n // Time from when the send finished going to when the headers were received.\n const waiting = isCached ?\n Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((timing.receiveHeadersEnd - timing.sendEnd) * MILLISECONDS_TO_MICROSECONDS);\n\n // Download\n // =======================\n // Time from receipt of headers to the finish time.\n const downloadStart = isCached ?\n startTime :\n Types.Timing.MicroSeconds(\n timing.requestTime * SECONDS_TO_MICROSECONDS + timing.receiveHeadersEnd * MILLISECONDS_TO_MICROSECONDS);\n const download = isCached ? Types.Timing.MicroSeconds(endTime - request.receiveResponse.ts) :\n Types.Timing.MicroSeconds(((finishTime || downloadStart) - downloadStart));\n\n const totalTime = Types.Timing.MicroSeconds(networkDuration + processingDuration);\n\n // Collect a few values from the timing info.\n // If the Network request is cached, we zero out them.\n const dnsLookup = isCached ?\n Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((timing.dnsEnd - timing.dnsStart) * MILLISECONDS_TO_MICROSECONDS);\n const ssl = isCached ? Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((timing.sslEnd - timing.sslStart) * MILLISECONDS_TO_MICROSECONDS);\n const proxyNegotiation = isCached ?\n Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((timing.proxyEnd - timing.proxyStart) * MILLISECONDS_TO_MICROSECONDS);\n const requestSent = isCached ?\n Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((timing.sendEnd - timing.sendStart) * MILLISECONDS_TO_MICROSECONDS);\n const initialConnection = isCached ?\n Types.Timing.MicroSeconds(0) :\n Types.Timing.MicroSeconds((timing.connectEnd - timing.connectStart) * MILLISECONDS_TO_MICROSECONDS);\n\n // Finally get some of the general data from the trace events.\n const {frame, url, renderBlocking} = finalSendRequest.args.data;\n const {encodedDataLength, decodedBodyLength} =\n request.resourceFinish ? request.resourceFinish.args.data : {encodedDataLength: 0, decodedBodyLength: 0};\n const {host, protocol, pathname, search} = new URL(url);\n const isHttps = protocol === 'https:';\n const requestingFrameUrl =\n Helpers.Trace.activeURLForFrameAtTime(frame, finalSendRequest.ts, rendererProcessesByFrame) || '';\n\n // Construct a synthetic trace event for this network request.\n const networkEvent: Types.TraceEvents.SyntheticNetworkRequest = {\n args: {\n data: {\n // All data we create from trace events should be added to |syntheticData|.\n syntheticData: {\n dnsLookup,\n download,\n downloadStart,\n finishTime,\n initialConnection,\n isDiskCached,\n isHttps,\n isMemoryCached,\n isPushedResource,\n networkDuration,\n processingDuration,\n proxyNegotiation,\n queueing,\n redirectionDuration,\n requestSent,\n sendStartTime,\n ssl,\n stalled,\n totalTime,\n waiting,\n },\n // All fields below are from TraceEventsForNetworkRequest.\n decodedBodyLength,\n encodedDataLength,\n frame,\n fromServiceWorker: request.receiveResponse.args.data.fromServiceWorker,\n isLinkPreload: request.receiveResponse.args.data.isLinkPreload || false,\n host,\n mimeType: request.receiveResponse.args.data.mimeType,\n pathname,\n priority: finalPriority,\n initialPriority,\n protocol,\n redirects,\n // In the event the property isn't set, assume non-blocking.\n renderBlocking: renderBlocking ? renderBlocking : 'non_blocking',\n requestId,\n requestingFrameUrl,\n requestMethod: finalSendRequest.args.data.requestMethod,\n resourceType: finalSendRequest.args.data.resourceType,\n search,\n statusCode: request.receiveResponse.args.data.statusCode,\n responseHeaders: request.receiveResponse.args.data.headers || [],\n fetchPriorityHint: finalSendRequest.args.data.fetchPriorityHint,\n initiator: finalSendRequest.args.data.initiator,\n stackTrace: finalSendRequest.args.data.stackTrace,\n timing,\n url,\n },\n },\n cat: 'loading',\n name: 'SyntheticNetworkRequest',\n ph: Types.TraceEvents.Phase.COMPLETE,\n dur: Types.Timing.MicroSeconds(endTime - startTime),\n tdur: Types.Timing.MicroSeconds(endTime - startTime),\n ts: Types.Timing.MicroSeconds(startTime),\n tts: Types.Timing.MicroSeconds(startTime),\n pid: finalSendRequest.pid,\n tid: finalSendRequest.tid,\n };\n\n const requests = Platform.MapUtilities.getWithDefault(requestsByOrigin, host, () => {\n return {\n renderBlocking: [],\n nonRenderBlocking: [],\n all: [],\n };\n });\n\n // For ease of rendering we sometimes want to differentiate between\n // render-blocking and non-render-blocking, so we divide the data here.\n if (networkEvent.args.data.renderBlocking === 'non_blocking') {\n requests.nonRenderBlocking.push(networkEvent);\n } else {\n requests.renderBlocking.push(networkEvent);\n }\n\n // However, there are also times where we just want to loop through all\n // the captured requests, so here we store all of them together.\n requests.all.push(networkEvent);\n requestsByTime.push(networkEvent);\n }\n\n handlerState = HandlerState.FINALIZED;\n}\n\nexport function data(): NetworkRequestData {\n if (handlerState !== HandlerState.FINALIZED) {\n throw new Error('Network Request handler is not finalized');\n }\n\n return {\n byOrigin: requestsByOrigin,\n byTime: requestsByTime,\n };\n}\n\nexport function deps(): TraceEventHandlerName[] {\n return ['Meta'];\n}\n"]}
@@ -1,12 +1,6 @@
1
1
  import { type TraceEventHandlerName } from './types.js';
2
2
  import * as Types from '../types/types.js';
3
3
  export declare function reset(): void;
4
- export declare const MarkerName: readonly ["MarkDOMContent", "MarkLoad", "firstPaint", "firstContentfulPaint", "largestContentfulPaint::Candidate"];
5
- interface MakerEvent extends Types.TraceEvents.TraceEventData {
6
- name: typeof MarkerName[number];
7
- }
8
- export declare function isTraceEventMarkerEvent(event: Types.TraceEvents.TraceEventData): event is MakerEvent;
9
- export declare function eventIsPageLoadEvent(event: Types.TraceEvents.TraceEventData): event is Types.TraceEvents.PageLoadEvent;
10
4
  export declare function handleEvent(event: Types.TraceEvents.TraceEventData): void;
11
5
  export declare function getFrameIdForPageLoadEvent(event: Types.TraceEvents.PageLoadEvent): string;
12
6
  /**
@@ -35,7 +29,17 @@ export declare function scoreClassificationForDOMContentLoaded(_dclTimeInMicrose
35
29
  export declare function scoreClassificationForTotalBlockingTime(tbtTimeInMicroseconds: Types.Timing.MicroSeconds): ScoreClassification;
36
30
  export declare function finalize(): Promise<void>;
37
31
  export type PageLoadMetricsData = {
32
+ /**
33
+ * This represents the metric scores for all navigations, for all frames in a trace.
34
+ * Given a frame id, the map points to another map from navigation id to metric scores.
35
+ * The metric scores include the event related to the metric as well as the data regarding
36
+ * the score itself.
37
+ */
38
38
  metricScoresByFrameId: Map<string, Map<string, Map<MetricName, MetricScore>>>;
39
+ /**
40
+ * Page load events with no associated duration that happened in the
41
+ * main frame.
42
+ */
39
43
  allMarkerEvents: Types.TraceEvents.PageLoadEvent[];
40
44
  };
41
45
  export declare function data(): PageLoadMetricsData;
@@ -63,5 +67,5 @@ export interface MetricScore {
63
67
  event?: Types.TraceEvents.PageLoadEvent;
64
68
  navigation?: Types.TraceEvents.TraceEventNavigationStart;
65
69
  estimated?: boolean;
70
+ timing: Types.Timing.MicroSeconds;
66
71
  }
67
- export {};
@@ -43,27 +43,8 @@ let pageLoadEventsArray = [];
43
43
  // entire trace this set will contain all the LCP events that were used - e.g.
44
44
  // the candidates that were the actual LCP events.
45
45
  const selectedLCPCandidateEvents = new Set();
46
- export const MarkerName = ['MarkDOMContent', 'MarkLoad', 'firstPaint', 'firstContentfulPaint', 'largestContentfulPaint::Candidate'];
47
- const markerTypeGuards = [
48
- Types.TraceEvents.isTraceEventMarkDOMContent,
49
- Types.TraceEvents.isTraceEventMarkLoad,
50
- Types.TraceEvents.isTraceEventFirstPaint,
51
- Types.TraceEvents.isTraceEventFirstContentfulPaint,
52
- Types.TraceEvents.isTraceEventLargestContentfulPaintCandidate,
53
- Types.TraceEvents.isTraceEventNavigationStart,
54
- ];
55
- export function isTraceEventMarkerEvent(event) {
56
- return markerTypeGuards.some(fn => fn(event));
57
- }
58
- const pageLoadEventTypeGuards = [
59
- ...markerTypeGuards,
60
- Types.TraceEvents.isTraceEventInteractiveTime,
61
- ];
62
- export function eventIsPageLoadEvent(event) {
63
- return pageLoadEventTypeGuards.some(fn => fn(event));
64
- }
65
46
  export function handleEvent(event) {
66
- if (!eventIsPageLoadEvent(event)) {
47
+ if (!Types.TraceEvents.eventIsPageLoadEvent(event)) {
67
48
  return;
68
49
  }
69
50
  pageLoadEventsArray.push(event);
@@ -99,7 +80,7 @@ function storePageLoadMetricAgainstNavigationId(navigation, event) {
99
80
  maximumFractionDigits: 2,
100
81
  });
101
82
  const classification = scoreClassificationForFirstContentfulPaint(fcpTime);
102
- const metricScore = { event, score, metricName: "FCP" /* MetricName.FCP */, classification, navigation };
83
+ const metricScore = { event, score, metricName: "FCP" /* MetricName.FCP */, classification, navigation, timing: fcpTime };
103
84
  storeMetricScore(frameId, navigationId, metricScore);
104
85
  return;
105
86
  }
@@ -110,7 +91,7 @@ function storePageLoadMetricAgainstNavigationId(navigation, event) {
110
91
  maximumFractionDigits: 2,
111
92
  });
112
93
  const classification = "unclassified" /* ScoreClassification.UNCLASSIFIED */;
113
- const metricScore = { event, score, metricName: "FP" /* MetricName.FP */, classification, navigation };
94
+ const metricScore = { event, score, metricName: "FP" /* MetricName.FP */, classification, navigation, timing: paintTime };
114
95
  storeMetricScore(frameId, navigationId, metricScore);
115
96
  return;
116
97
  }
@@ -126,6 +107,7 @@ function storePageLoadMetricAgainstNavigationId(navigation, event) {
126
107
  metricName: "DCL" /* MetricName.DCL */,
127
108
  classification: scoreClassificationForDOMContentLoaded(dclTime),
128
109
  navigation,
110
+ timing: dclTime,
129
111
  };
130
112
  storeMetricScore(frameId, navigationId, metricScore);
131
113
  return;
@@ -142,6 +124,7 @@ function storePageLoadMetricAgainstNavigationId(navigation, event) {
142
124
  metricName: "TTI" /* MetricName.TTI */,
143
125
  classification: scoreClassificationForTimeToInteractive(ttiValue),
144
126
  navigation,
127
+ timing: ttiValue,
145
128
  };
146
129
  storeMetricScore(frameId, navigationId, tti);
147
130
  const tbtValue = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(event.args.args.total_blocking_time_ms));
@@ -155,6 +138,7 @@ function storePageLoadMetricAgainstNavigationId(navigation, event) {
155
138
  metricName: "TBT" /* MetricName.TBT */,
156
139
  classification: scoreClassificationForTotalBlockingTime(tbtValue),
157
140
  navigation,
141
+ timing: tbtValue,
158
142
  };
159
143
  storeMetricScore(frameId, navigationId, tbt);
160
144
  return;
@@ -171,6 +155,7 @@ function storePageLoadMetricAgainstNavigationId(navigation, event) {
171
155
  metricName: "L" /* MetricName.L */,
172
156
  classification: "unclassified" /* ScoreClassification.UNCLASSIFIED */,
173
157
  navigation,
158
+ timing: loadTime,
174
159
  };
175
160
  storeMetricScore(frameId, navigationId, metricScore);
176
161
  return;
@@ -191,6 +176,7 @@ function storePageLoadMetricAgainstNavigationId(navigation, event) {
191
176
  metricName: "LCP" /* MetricName.LCP */,
192
177
  classification: scoreClassificationForLargestContentfulPaint(lcpTime),
193
178
  navigation,
179
+ timing: lcpTime,
194
180
  };
195
181
  const metricsByNavigation = Platform.MapUtilities.getWithDefault(metricScoresByFrameId, frameId, () => new Map());
196
182
  const metrics = Platform.MapUtilities.getWithDefault(metricsByNavigation, navigationId, () => new Map());
@@ -380,25 +366,15 @@ export async function finalize() {
380
366
  const mainFrame = metaHandlerData().mainFrameId;
381
367
  // Filter out LCP candidates to use only definitive LCP values
382
368
  const allEventsButLCP = pageLoadEventsArray.filter(event => !Types.TraceEvents.isTraceEventLargestContentfulPaintCandidate(event));
383
- const markerEvents = [...allFinalLCPEvents, ...allEventsButLCP].filter(isTraceEventMarkerEvent);
369
+ const markerEvents = [...allFinalLCPEvents, ...allEventsButLCP].filter(Types.TraceEvents.isTraceEventMarkerEvent);
384
370
  // Filter by main frame and sort.
385
371
  allMarkerEvents =
386
372
  markerEvents.filter(event => getFrameIdForPageLoadEvent(event) === mainFrame).sort((a, b) => a.ts - b.ts);
387
373
  }
388
374
  export function data() {
389
375
  return {
390
- /**
391
- * This represents the metric scores for all navigations, for all frames in a trace.
392
- * Given a frame id, the map points to another map from navigation id to metric scores.
393
- * The metric scores include the event related to the metric as well as the data regarding
394
- * the score itself.
395
- */
396
- metricScoresByFrameId: new Map(metricScoresByFrameId),
397
- /**
398
- * Page load events with no associated duration that happened in the
399
- * main frame.
400
- */
401
- allMarkerEvents: [...allMarkerEvents],
376
+ metricScoresByFrameId,
377
+ allMarkerEvents,
402
378
  };
403
379
  }
404
380
  export function deps() {