@paulirish/trace_engine 0.0.41 → 0.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
  2. package/generated/protocol.d.ts +79 -3
  3. package/locales/en-US.json +222 -0
  4. package/locales/en-XL.json +222 -0
  5. package/models/cpu_profile/CPUProfileDataModel.d.ts +7 -0
  6. package/models/cpu_profile/CPUProfileDataModel.js +7 -0
  7. package/models/cpu_profile/CPUProfileDataModel.js.map +1 -1
  8. package/models/cpu_profile/ProfileTreeModel.d.ts +1 -1
  9. package/models/cpu_profile/ProfileTreeModel.js.map +1 -1
  10. package/models/trace/LanternComputationData.d.ts +1 -1
  11. package/models/trace/LanternComputationData.js +7 -5
  12. package/models/trace/LanternComputationData.js.map +1 -1
  13. package/models/trace/Processor.d.ts +2 -16
  14. package/models/trace/Processor.js +6 -4
  15. package/models/trace/Processor.js.map +1 -1
  16. package/models/trace/extras/FilmStrip.d.ts +5 -5
  17. package/models/trace/extras/FilmStrip.js +2 -1
  18. package/models/trace/extras/FilmStrip.js.map +1 -1
  19. package/models/trace/extras/MainThreadActivity.d.ts +1 -1
  20. package/models/trace/extras/MainThreadActivity.js +3 -3
  21. package/models/trace/extras/MainThreadActivity.js.map +1 -1
  22. package/models/trace/extras/ThirdParties.d.ts +14 -13
  23. package/models/trace/extras/ThirdParties.js +51 -61
  24. package/models/trace/extras/ThirdParties.js.map +1 -1
  25. package/models/trace/extras/TimelineJSProfile.d.ts +1 -1
  26. package/models/trace/extras/TimelineJSProfile.js +9 -4
  27. package/models/trace/extras/TimelineJSProfile.js.map +1 -1
  28. package/models/trace/extras/TraceTree.d.ts +6 -6
  29. package/models/trace/extras/TraceTree.js +4 -1
  30. package/models/trace/extras/TraceTree.js.map +1 -1
  31. package/models/trace/handlers/AnimationFramesHandler.js +1 -1
  32. package/models/trace/handlers/AnimationFramesHandler.js.map +1 -1
  33. package/models/trace/handlers/ExtensionTraceDataHandler.js +8 -2
  34. package/models/trace/handlers/ExtensionTraceDataHandler.js.map +1 -1
  35. package/models/trace/handlers/FlowsHandler.js.map +1 -1
  36. package/models/trace/handlers/FramesHandler.d.ts +12 -12
  37. package/models/trace/handlers/FramesHandler.js +3 -3
  38. package/models/trace/handlers/FramesHandler.js.map +1 -1
  39. package/models/trace/handlers/LayoutShiftsHandler.d.ts +2 -2
  40. package/models/trace/handlers/LayoutShiftsHandler.js +25 -16
  41. package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
  42. package/models/trace/handlers/MetaHandler.d.ts +2 -2
  43. package/models/trace/handlers/MetaHandler.js +18 -18
  44. package/models/trace/handlers/MetaHandler.js.map +1 -1
  45. package/models/trace/handlers/NetworkRequestsHandler.js +37 -38
  46. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
  47. package/models/trace/handlers/PageLoadMetricsHandler.d.ts +6 -6
  48. package/models/trace/handlers/PageLoadMetricsHandler.js +9 -9
  49. package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -1
  50. package/models/trace/handlers/RendererHandler.js +3 -3
  51. package/models/trace/handlers/RendererHandler.js.map +1 -1
  52. package/models/trace/handlers/SamplesHandler.d.ts +1 -1
  53. package/models/trace/handlers/SamplesHandler.js +50 -42
  54. package/models/trace/handlers/SamplesHandler.js.map +1 -1
  55. package/models/trace/handlers/ScreenshotsHandler.d.ts +6 -3
  56. package/models/trace/handlers/ScreenshotsHandler.js +21 -7
  57. package/models/trace/handlers/ScreenshotsHandler.js.map +1 -1
  58. package/models/trace/handlers/ServerTimingsHandler.js +4 -4
  59. package/models/trace/handlers/ServerTimingsHandler.js.map +1 -1
  60. package/models/trace/handlers/Threads.js +3 -4
  61. package/models/trace/handlers/Threads.js.map +1 -1
  62. package/models/trace/handlers/UserInteractionsHandler.d.ts +2 -2
  63. package/models/trace/handlers/UserInteractionsHandler.js +12 -12
  64. package/models/trace/handlers/UserInteractionsHandler.js.map +1 -1
  65. package/models/trace/handlers/WarningsHandler.d.ts +2 -2
  66. package/models/trace/handlers/WarningsHandler.js +2 -2
  67. package/models/trace/handlers/WarningsHandler.js.map +1 -1
  68. package/models/trace/handlers/helpers.d.ts +3 -3
  69. package/models/trace/handlers/helpers.js +16 -19
  70. package/models/trace/handlers/helpers.js.map +1 -1
  71. package/models/trace/handlers/types.d.ts +1 -1
  72. package/models/trace/handlers/types.js.map +1 -1
  73. package/models/trace/helpers/SamplesIntegrator.js +52 -13
  74. package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
  75. package/models/trace/helpers/Timing.d.ts +23 -23
  76. package/models/trace/helpers/Timing.js +11 -11
  77. package/models/trace/helpers/Timing.js.map +1 -1
  78. package/models/trace/helpers/Trace.d.ts +14 -13
  79. package/models/trace/helpers/Trace.js +10 -4
  80. package/models/trace/helpers/Trace.js.map +1 -1
  81. package/models/trace/helpers/TreeHelpers.d.ts +2 -2
  82. package/models/trace/helpers/TreeHelpers.js +4 -4
  83. package/models/trace/helpers/TreeHelpers.js.map +1 -1
  84. package/models/trace/insights/CLSCulprits.d.ts +44 -1
  85. package/models/trace/insights/CLSCulprits.js +44 -2
  86. package/models/trace/insights/CLSCulprits.js.map +1 -1
  87. package/models/trace/insights/Common.d.ts +11 -7
  88. package/models/trace/insights/Common.js +85 -26
  89. package/models/trace/insights/Common.js.map +1 -1
  90. package/models/trace/insights/DOMSize.d.ts +26 -1
  91. package/models/trace/insights/DOMSize.js +44 -7
  92. package/models/trace/insights/DOMSize.js.map +1 -1
  93. package/models/trace/insights/DocumentLatency.d.ts +50 -3
  94. package/models/trace/insights/DocumentLatency.js +51 -4
  95. package/models/trace/insights/DocumentLatency.js.map +1 -1
  96. package/models/trace/insights/FontDisplay.d.ts +8 -2
  97. package/models/trace/insights/FontDisplay.js +10 -4
  98. package/models/trace/insights/FontDisplay.js.map +1 -1
  99. package/models/trace/insights/ForcedReflow.d.ts +30 -0
  100. package/models/trace/insights/ForcedReflow.js +181 -0
  101. package/models/trace/insights/ForcedReflow.js.map +1 -0
  102. package/models/trace/insights/ImageDelivery.d.ts +15 -1
  103. package/models/trace/insights/ImageDelivery.js +21 -1
  104. package/models/trace/insights/ImageDelivery.js.map +1 -1
  105. package/models/trace/insights/InteractionToNextPaint.d.ts +26 -1
  106. package/models/trace/insights/InteractionToNextPaint.js +27 -1
  107. package/models/trace/insights/InteractionToNextPaint.js.map +1 -1
  108. package/models/trace/insights/LCPDiscovery.d.ts +38 -2
  109. package/models/trace/insights/LCPDiscovery.js +38 -2
  110. package/models/trace/insights/LCPDiscovery.js.map +1 -1
  111. package/models/trace/insights/LCPPhases.d.ts +36 -7
  112. package/models/trace/insights/LCPPhases.js +37 -8
  113. package/models/trace/insights/LCPPhases.js.map +1 -1
  114. package/models/trace/insights/LongCriticalNetworkTree.d.ts +22 -0
  115. package/models/trace/insights/LongCriticalNetworkTree.js +40 -0
  116. package/models/trace/insights/LongCriticalNetworkTree.js.map +1 -0
  117. package/models/trace/insights/Models.d.ts +2 -0
  118. package/models/trace/insights/Models.js +2 -0
  119. package/models/trace/insights/Models.js.map +1 -1
  120. package/models/trace/insights/RenderBlocking.d.ts +14 -1
  121. package/models/trace/insights/RenderBlocking.js +14 -1
  122. package/models/trace/insights/RenderBlocking.js.map +1 -1
  123. package/models/trace/insights/SlowCSSSelector.d.ts +27 -2
  124. package/models/trace/insights/SlowCSSSelector.js +27 -2
  125. package/models/trace/insights/SlowCSSSelector.js.map +1 -1
  126. package/models/trace/insights/ThirdParties.d.ts +13 -4
  127. package/models/trace/insights/ThirdParties.js +21 -12
  128. package/models/trace/insights/ThirdParties.js.map +1 -1
  129. package/models/trace/insights/Viewport.d.ts +2 -1
  130. package/models/trace/insights/Viewport.js +2 -1
  131. package/models/trace/insights/Viewport.js.map +1 -1
  132. package/models/trace/insights/insights-tsconfig.json +2 -0
  133. package/models/trace/insights/types.d.ts +23 -8
  134. package/models/trace/insights/types.js.map +1 -1
  135. package/models/trace/lantern/graph/CPUNode.d.ts +1 -1
  136. package/models/trace/lantern/graph/CPUNode.js.map +1 -1
  137. package/models/trace/lantern/graph/NetworkNode.d.ts +1 -1
  138. package/models/trace/lantern/graph/NetworkNode.js.map +1 -1
  139. package/models/trace/types/Configuration.d.ts +15 -0
  140. package/models/trace/types/Configuration.js.map +1 -1
  141. package/models/trace/types/File.d.ts +4 -4
  142. package/models/trace/types/File.js.map +1 -1
  143. package/models/trace/types/Timing.d.ts +7 -13
  144. package/models/trace/types/Timing.js +5 -2
  145. package/models/trace/types/Timing.js.map +1 -1
  146. package/models/trace/types/TraceEvents.d.ts +143 -108
  147. package/models/trace/types/TraceEvents.js +9 -7
  148. package/models/trace/types/TraceEvents.js.map +1 -1
  149. package/package.json +1 -1
  150. package/test/test-trace-engine.mjs +18 -14
@@ -1 +1 @@
1
- {"version":3,"file":"Threads.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/Threads.ts"],"names":[],"mappings":"AAgCA,SAAS,8BAA8B,CACnC,GAA2B,EAAE,MAA+B,EAC5D,mBAAwC;IAC1C,IAAI,UAAU,iCAAmB,CAAC;IAClC,IAAI,MAAM,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;QACrC,UAAU,6CAAyB,CAAC;IACtC,CAAC;SAAM,IAAI,MAAM,CAAC,IAAI,KAAK,wBAAwB,EAAE,CAAC;QACpD,UAAU,mCAAoB,CAAC;IACjC,CAAC;SAAM,IAAI,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,sBAAsB,CAAC,EAAE,CAAC;QAC3D,UAAU,2CAAwB,CAAC;IACrC,CAAC;SAAM,IAAI,mBAAmB,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QACjD,UAAU,qDAA6B,CAAC;IAC1C,CAAC;SAAM,IAAI,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACjD,oEAAoE;QACpE,UAAU,6CAAyB,CAAC;IACtC,C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;IAC3E,2EAA2E;IAC3E,0EAA0E;IAC1E,gCAAgC;IAChC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC;IACjG,IAAI,mBAAmB,CAAC,MAAM,EAAE,CAAC;QAC/B,mBAAmB,CAAC,GAAG,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;QAC1D,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,IAAI,WAAW,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;QAC/C,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC;YACnE,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;gBACpC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;oBACxB,kEAAkE;oBAClE,6DAA6D;oBAC7D,qBAAqB;oBACrB,SAAS;gBACX,CAAC;gBAED,YAAY,CAAC,IAAI,CAAC;oBAChB,GAAG;oBACH,GAAG;oBACH,0CAA0C;oBAC1C,IAAI,EAAE,IAAI;oBACV,OAAO,EAAE,MAAM,CAAC,YAAY;oBAC5B,0DAA0D;oBAC1D,oBAAoB,EAAE,KAAK;oBAC3B,IAAI,EAAE,MAAM,CAAC,WAAW;oBACxB,IAAI,4CAAwB;oBAC5B,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,WAAW;iBAC7C,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IACnD,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["// Copyright 2023 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n//\nimport type * as Helpers from '../helpers/helpers.js';\nimport type * as Types from '../types/types.js';\n\nimport type {AuctionWorkletsData} from './AuctionWorkletsHandler.js';\nimport type * as Renderer from './RendererHandler.js';\nimport type {ParsedTrace} from './types.js';\n\nexport interface ThreadData {\n pid: Types.Events.ProcessID;\n tid: Types.Events.ThreadID;\n entries: readonly Types.Events.Event[];\n processIsOnMainFrame: boolean;\n tree: Helpers.TreeHelpers.TraceEntryTree;\n type: ThreadType;\n name: string|null;\n entryToNode: Map<Types.Events.Event, Helpers.TreeHelpers.TraceEntryNode>;\n}\n\nexport const enum ThreadType {\n MAIN_THREAD = 'MAIN_THREAD',\n WORKER = 'WORKER',\n RASTERIZER = 'RASTERIZER',\n AUCTION_WORKLET = 'AUCTION_WORKLET',\n OTHER = 'OTHER',\n CPU_PROFILE = 'CPU_PROFILE',\n THREAD_POOL = 'THREAD_POOL',\n}\n\nfunction getThreadTypeForRendererThread(\n pid: Types.Events.ProcessID, thread: Renderer.RendererThread,\n auctionWorkletsData: AuctionWorkletsData): ThreadType {\n let threadType = ThreadType.OTHER;\n if (thread.name === 'CrRendererMain') {\n threadType = ThreadType.MAIN_THREAD;\n } else if (thread.name === 'DedicatedWorker thread') {\n threadType = ThreadType.WORKER;\n } else if (thread.name?.startsWith('CompositorTileWorker')) {\n threadType = ThreadType.RASTERIZER;\n } else if (auctionWorkletsData.worklets.has(pid)) {\n threadType = ThreadType.AUCTION_WORKLET;\n } else if (thread.name?.startsWith('ThreadPool')) {\n // TODO(paulirish): perhaps exclude ThreadPoolServiceThread entirely\n threadType = ThreadType.THREAD_POOL;\n }\n return threadType;\n}\n\nexport function threadsInRenderer(\n rendererData: Renderer.RendererHandlerData, auctionWorkletsData: AuctionWorkletsData): readonly ThreadData[] {\n const foundThreads: ThreadData[] = [];\n // If we have Renderer threads, we prefer to use those. In the event that a\n // trace is a CPU Profile trace, we will never have Renderer threads, so we\n // know if there are no Renderer threads that we can fallback to using the\n // data from the SamplesHandler.\n if (rendererData.processes.size) {\n for (const [pid, process] of rendererData.processes) {\n for (const [tid, thread] of process.threads) {\n if (!thread.tree) {\n // Drop threads where we could not create the tree; this indicates\n // unexpected data and we won't be able to support all the UI\n // filtering we need.\n continue;\n }\n const threadType = getThreadTypeForRendererThread(pid, thread, auctionWorkletsData);\n foundThreads.push({\n name: thread.name,\n pid,\n tid,\n processIsOnMainFrame: process.isOnMainFrame,\n entries: thread.entries,\n tree: thread.tree,\n type: threadType,\n entryToNode: rendererData.entryToNode,\n });\n }\n }\n }\n return foundThreads;\n}\n\nconst threadsInTraceCache = new WeakMap<ParsedTrace, readonly ThreadData[]>();\n\n/**\n * Given trace parsed data, this helper will return a high level array of\n * ThreadData. This is useful because it allows you to get a list of threads\n * regardless of if the trace is a CPU Profile or a Tracing profile. Thus you\n * can use this helper to iterate over threads in confidence that it will work\n * for both trace types.\n * The resulting data is cached per-trace, so you can safely call this multiple times.\n */\nexport function threadsInTrace(parsedTrace: ParsedTrace): readonly ThreadData[] {\n const cached = threadsInTraceCache.get(parsedTrace);\n if (cached) {\n return cached;\n }\n\n // If we have Renderer threads, we prefer to use those. In the event that a\n // trace is a CPU Profile trace, we will never have Renderer threads, so we\n // know if there are no Renderer threads that we can fallback to using the\n // data from the SamplesHandler.\n const threadsFromRenderer = threadsInRenderer(parsedTrace.Renderer, parsedTrace.AuctionWorklets);\n if (threadsFromRenderer.length) {\n threadsInTraceCache.set(parsedTrace, threadsFromRenderer);\n return threadsFromRenderer;\n }\n\n const foundThreads: ThreadData[] = [];\n if (parsedTrace.Samples.profilesInProcess.size) {\n for (const [pid, process] of parsedTrace.Samples.profilesInProcess) {\n for (const [tid, thread] of process) {\n if (!thread.profileTree) {\n // Drop threads where we could not create the tree; this indicates\n // unexpected data and we won't be able to support all the UI\n // filtering we need.\n continue;\n }\n\n foundThreads.push({\n pid,\n tid,\n // CPU Profile threads do not have a name.\n name: null,\n entries: thread.profileCalls,\n // There is no concept of a \"Main Frame\" in a CPU profile.\n processIsOnMainFrame: false,\n tree: thread.profileTree,\n type: ThreadType.CPU_PROFILE,\n entryToNode: parsedTrace.Samples.entryToNode,\n });\n }\n }\n }\n\n threadsInTraceCache.set(parsedTrace, foundThreads);\n return foundThreads;\n}\n"]}
1
+ {"version":3,"file":"Threads.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/Threads.ts"],"names":[],"mappings":"AAgCA,SAAS,8BAA8B,CACnC,GAA2B,EAAE,MAA+B,EAC5D,mBAAwC;IAC1C,IAAI,UAAU,iCAAmB,CAAC;IAClC,IAAI,MAAM,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;QACrC,UAAU,6CAAyB,CAAC;IACtC,CAAC;SAAM,IAAI,MAAM,CAAC,IAAI,KAAK,wBAAwB,EAAE,CAAC;QACpD,UAAU,mCAAoB,CAAC;IACjC,CAAC;SAAM,IAAI,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,sBAAsB,CAAC,EAAE,CAAC;QAC3D,UAAU,2CAAwB,CAAC;IACrC,CAAC;SAAM,IAAI,mBAAmB,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QACjD,UAAU,qDAA6B,CAAC;IAC1C,CAAC;SAAM,IAAI,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACjD,oEAAoE;QACpE,UAAU,6CAAyB,CAAC;IACtC,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC7B,YAA0C,EAAE,mBAAwC;IACtF,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,2EAA2E;IAC3E,2EAA2E;IAC3E,0EAA0E;IAC1E,gCAAgC;IAChC,IAAI,YAAY,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QAChC,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,YAAY,CAAC,SAAS,EAAE,CAAC;YACpD,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,C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AE,CAAC;QAC/C,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC;YACnE,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;gBACpC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;oBACxB,kEAAkE;oBAClE,6DAA6D;oBAC7D,qBAAqB;oBACrB,SAAS;gBACX,CAAC;gBAED,YAAY,CAAC,IAAI,CAAC;oBAChB,GAAG;oBACH,GAAG;oBACH,0CAA0C;oBAC1C,IAAI,EAAE,IAAI;oBACV,OAAO,EAAE,MAAM,CAAC,YAAY;oBAC5B,0DAA0D;oBAC1D,oBAAoB,EAAE,KAAK;oBAC3B,IAAI,EAAE,MAAM,CAAC,WAAW;oBACxB,IAAI,4CAAwB;oBAC5B,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,WAAW;iBAC7C,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IACnD,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["// Copyright 2023 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n//\nimport type * as Helpers from '../helpers/helpers.js';\nimport type * as Types from '../types/types.js';\n\nimport type {AuctionWorkletsData} from './AuctionWorkletsHandler.js';\nimport type * as Renderer from './RendererHandler.js';\nimport type {ParsedTrace} from './types.js';\n\nexport interface ThreadData {\n pid: Types.Events.ProcessID;\n tid: Types.Events.ThreadID;\n entries: readonly Types.Events.Event[];\n processIsOnMainFrame: boolean;\n tree: Helpers.TreeHelpers.TraceEntryTree;\n type: ThreadType;\n name: string|null;\n entryToNode: Map<Types.Events.Event, Helpers.TreeHelpers.TraceEntryNode>;\n}\n\nexport const enum ThreadType {\n MAIN_THREAD = 'MAIN_THREAD',\n WORKER = 'WORKER',\n RASTERIZER = 'RASTERIZER',\n AUCTION_WORKLET = 'AUCTION_WORKLET',\n OTHER = 'OTHER',\n CPU_PROFILE = 'CPU_PROFILE',\n THREAD_POOL = 'THREAD_POOL',\n}\n\nfunction getThreadTypeForRendererThread(\n pid: Types.Events.ProcessID, thread: Renderer.RendererThread,\n auctionWorkletsData: AuctionWorkletsData): ThreadType {\n let threadType = ThreadType.OTHER;\n if (thread.name === 'CrRendererMain') {\n threadType = ThreadType.MAIN_THREAD;\n } else if (thread.name === 'DedicatedWorker thread') {\n threadType = ThreadType.WORKER;\n } else if (thread.name?.startsWith('CompositorTileWorker')) {\n threadType = ThreadType.RASTERIZER;\n } else if (auctionWorkletsData.worklets.has(pid)) {\n threadType = ThreadType.AUCTION_WORKLET;\n } else if (thread.name?.startsWith('ThreadPool')) {\n // TODO(paulirish): perhaps exclude ThreadPoolServiceThread entirely\n threadType = ThreadType.THREAD_POOL;\n }\n return threadType;\n}\n\nexport function threadsInRenderer(\n rendererData: Renderer.RendererHandlerData, auctionWorkletsData: AuctionWorkletsData): readonly ThreadData[] {\n const foundThreads: ThreadData[] = [];\n // If we have Renderer threads, we prefer to use those. In the event that a\n // trace is a CPU Profile trace, we will never have Renderer threads, so we\n // know if there are no Renderer threads that we can fallback to using the\n // data from the SamplesHandler.\n if (rendererData.processes.size) {\n for (const [pid, process] of rendererData.processes) {\n for (const [tid, thread] of process.threads) {\n if (!thread.tree) {\n // Drop threads where we could not create the tree; this indicates\n // unexpected data and we won't be able to support all the UI\n // filtering we need.\n continue;\n }\n const threadType = getThreadTypeForRendererThread(pid, thread, auctionWorkletsData);\n foundThreads.push({\n name: thread.name,\n pid,\n tid,\n processIsOnMainFrame: process.isOnMainFrame,\n entries: thread.entries,\n tree: thread.tree,\n type: threadType,\n entryToNode: rendererData.entryToNode,\n });\n }\n }\n }\n return foundThreads;\n}\n\nconst threadsInTraceCache = new WeakMap<ParsedTrace, readonly ThreadData[]>();\n\n/**\n * Given trace parsed data, this helper will return a high level array of\n * ThreadData. This is useful because it allows you to get a list of threads\n * regardless of if the trace is a CPU Profile or a Tracing profile. Thus you\n * can use this helper to iterate over threads in confidence that it will work\n * for both trace types.\n * The resulting data is cached per-trace, so you can safely call this multiple times.\n */\nexport function threadsInTrace(parsedTrace: ParsedTrace): readonly ThreadData[] {\n const cached = threadsInTraceCache.get(parsedTrace);\n if (cached) {\n return cached;\n }\n\n // If we have Renderer threads, we prefer to use those.\n const threadsFromRenderer = threadsInRenderer(parsedTrace.Renderer, parsedTrace.AuctionWorklets);\n if (threadsFromRenderer.length) {\n threadsInTraceCache.set(parsedTrace, threadsFromRenderer);\n return threadsFromRenderer;\n }\n\n // If it's a CPU Profile trace, there will be no Renderer threads.\n // We can fallback to using the data from the SamplesHandler.\n const foundThreads: ThreadData[] = [];\n if (parsedTrace.Samples.profilesInProcess.size) {\n for (const [pid, process] of parsedTrace.Samples.profilesInProcess) {\n for (const [tid, thread] of process) {\n if (!thread.profileTree) {\n // Drop threads where we could not create the tree; this indicates\n // unexpected data and we won't be able to support all the UI\n // filtering we need.\n continue;\n }\n\n foundThreads.push({\n pid,\n tid,\n // CPU Profile threads do not have a name.\n name: null,\n entries: thread.profileCalls,\n // There is no concept of a \"Main Frame\" in a CPU profile.\n processIsOnMainFrame: false,\n tree: thread.profileTree,\n type: ThreadType.CPU_PROFILE,\n entryToNode: parsedTrace.Samples.entryToNode,\n });\n }\n }\n }\n\n threadsInTraceCache.set(parsedTrace, foundThreads);\n return foundThreads;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import * as Types from '../types/types.js';
2
2
  import { ScoreClassification } from './PageLoadMetricsHandler.js';
3
3
  import type { HandlerName } from './types.js';
4
- export declare const LONG_INTERACTION_THRESHOLD: Types.Timing.MicroSeconds;
4
+ export declare const LONG_INTERACTION_THRESHOLD: Types.Timing.Micro;
5
5
  export interface UserInteractionsData {
6
6
  /** All the user events we found in the trace */
7
7
  allEvents: readonly Types.Events.EventTimingBeginOrEnd[];
@@ -66,4 +66,4 @@ export declare function deps(): HandlerName[];
66
66
  * Classifications sourced from
67
67
  * https://web.dev/articles/inp#good-score
68
68
  */
69
- export declare function scoreClassificationForInteractionToNextPaint(timing: Types.Timing.MicroSeconds): ScoreClassification;
69
+ export declare function scoreClassificationForInteractionToNextPaint(timing: Types.Timing.Micro): ScoreClassification;
@@ -13,9 +13,9 @@ import { data as metaHandlerData } from './MetaHandler.js';
13
13
  const allEvents = [];
14
14
  const beginCommitCompositorFrameEvents = [];
15
15
  const parseMetaViewportEvents = [];
16
- export const LONG_INTERACTION_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.MilliSeconds(200));
16
+ export const LONG_INTERACTION_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.Milli(200));
17
17
  const INP_GOOD_TIMING = LONG_INTERACTION_THRESHOLD;
18
- const INP_MEDIUM_TIMING = Helpers.Timing.milliToMicro(Types.Timing.MilliSeconds(500));
18
+ const INP_MEDIUM_TIMING = Helpers.Timing.milliToMicro(Types.Timing.Milli(500));
19
19
  let longestInteractionEvent = null;
20
20
  const interactionEvents = [];
21
21
  const interactionEventsWithNoNesting = [];
@@ -132,7 +132,7 @@ export function removeNestedInteractions(interactions) {
132
132
  function storeEventIfEarliestForCategoryAndEndTime(interaction) {
133
133
  const category = categoryOfInteraction(interaction);
134
134
  const earliestEventForEndTime = earliestEventForEndTimePerCategory[category];
135
- const endTime = Types.Timing.MicroSeconds(interaction.ts + interaction.dur);
135
+ const endTime = Types.Timing.Micro(interaction.ts + interaction.dur);
136
136
  const earliestCurrentEvent = earliestEventForEndTime.get(endTime);
137
137
  if (!earliestCurrentEvent) {
138
138
  earliestEventForEndTime.set(endTime, interaction);
@@ -190,9 +190,9 @@ export function removeNestedInteractions(interactions) {
190
190
  function writeSyntheticTimespans(event) {
191
191
  const startEvent = event.args.data.beginEvent;
192
192
  const endEvent = event.args.data.endEvent;
193
- event.inputDelay = Types.Timing.MicroSeconds(event.processingStart - startEvent.ts);
194
- event.mainThreadHandling = Types.Timing.MicroSeconds(event.processingEnd - event.processingStart);
195
- event.presentationDelay = Types.Timing.MicroSeconds(endEvent.ts - event.processingEnd);
193
+ event.inputDelay = Types.Timing.Micro(event.processingStart - startEvent.ts);
194
+ event.mainThreadHandling = Types.Timing.Micro(event.processingEnd - event.processingStart);
195
+ event.presentationDelay = Types.Timing.Micro(endEvent.ts - event.processingEnd);
196
196
  }
197
197
  export async function finalize() {
198
198
  const { navigationsByFrameId } = metaHandlerData();
@@ -219,9 +219,9 @@ export async function finalize() {
219
219
  // will give us a processingStart and processingEnd time in microseconds
220
220
  // that is relative to event.ts, and can be used when drawing boxes.
221
221
  // There is some inaccuracy here as we are converting milliseconds to microseconds, but it is good enough until the backend emits more accurate numbers.
222
- const processingStartRelativeToTraceTime = Types.Timing.MicroSeconds(Helpers.Timing.milliToMicro(processingStart) - Helpers.Timing.milliToMicro(timeStamp) +
222
+ const processingStartRelativeToTraceTime = Types.Timing.Micro(Helpers.Timing.milliToMicro(processingStart) - Helpers.Timing.milliToMicro(timeStamp) +
223
223
  interactionStartEvent.ts);
224
- const processingEndRelativeToTraceTime = Types.Timing.MicroSeconds((Helpers.Timing.milliToMicro(processingEnd) - Helpers.Timing.milliToMicro(timeStamp)) +
224
+ const processingEndRelativeToTraceTime = Types.Timing.Micro((Helpers.Timing.milliToMicro(processingEnd) - Helpers.Timing.milliToMicro(timeStamp)) +
225
225
  interactionStartEvent.ts);
226
226
  // Ultimate frameId fallback only needed for TSC, see comments in the type.
227
227
  const frameId = interactionStartEvent.args.frame ?? interactionStartEvent.args.data.frame ?? '';
@@ -238,9 +238,9 @@ export async function finalize() {
238
238
  processingStart: processingStartRelativeToTraceTime,
239
239
  processingEnd: processingEndRelativeToTraceTime,
240
240
  // These will be set in writeSyntheticTimespans()
241
- inputDelay: Types.Timing.MicroSeconds(-1),
242
- mainThreadHandling: Types.Timing.MicroSeconds(-1),
243
- presentationDelay: Types.Timing.MicroSeconds(-1),
241
+ inputDelay: Types.Timing.Micro(-1),
242
+ mainThreadHandling: Types.Timing.Micro(-1),
243
+ presentationDelay: Types.Timing.Micro(-1),
244
244
  args: {
245
245
  data: {
246
246
  beginEvent: interactionStartEvent,
@@ -250,7 +250,7 @@ export async function finalize() {
250
250
  },
251
251
  },
252
252
  ts: interactionStartEvent.ts,
253
- dur: Types.Timing.MicroSeconds(endEvent.ts - interactionStartEvent.ts),
253
+ dur: Types.Timing.Micro(endEvent.ts - interactionStartEvent.ts),
254
254
  type: interactionStartEvent.args.data.type,
255
255
  interactionId: interactionStartEvent.args.data.interactionId,
256
256
  });
@@ -1 +1 @@
1
- {"version":3,"file":"UserInteractionsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/UserInteractionsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,IAAI,IAAI,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAIzD,2EAA2E;AAC3E,sEAAsE;AACtE,wEAAwE;AACxE,2DAA2D;AAE3D,yEAAyE;AACzE,0EAA0E;AAC1E,MAAM,SAAS,GAAyC,EAAE,CAAC;AAE3D,MAAM,gCAAgC,GAA8C,EAAE,CAAC;AACvF,MAAM,uBAAuB,GAAqC,EAAE,CAAC;AAErE,MAAM,CAAC,MAAM,0BAA0B,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;AAEtG,MAAM,eAAe,GAAG,0BAA0B,CAAC;AACnD,MAAM,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;AAkCtF,IAAI,uBAAuB,GAA+C,I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AAC,MAAiC;IAC5F,IAAI,MAAM,IAAI,eAAe,EAAE,CAAC;QAC9B,6CAAgC;IAClC,CAAC;IAED,IAAI,MAAM,IAAI,iBAAiB,EAAE,CAAC;QAChC,yCAA8B;IAChC,CAAC;IAED,2CAA+B;AACjC,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 Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {data as metaHandlerData} from './MetaHandler.js';\nimport {ScoreClassification} from './PageLoadMetricsHandler.js';\nimport type {HandlerName} from './types.js';\n\n// This handler serves two purposes. It generates a list of events that are\n// used to show user clicks in the timeline. It is also used to gather\n// EventTimings into Interactions, which we use to show interactions and\n// highlight long interactions to the user, along with INP.\n\n// We don't need to know which process / thread these events occurred in,\n// because they are effectively global, so we just track all that we find.\nconst allEvents: Types.Events.EventTimingBeginOrEnd[] = [];\n\nconst beginCommitCompositorFrameEvents: Types.Events.BeginCommitCompositorFrame[] = [];\nconst parseMetaViewportEvents: Types.Events.ParseMetaViewport[] = [];\n\nexport const LONG_INTERACTION_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.MilliSeconds(200));\n\nconst INP_GOOD_TIMING = LONG_INTERACTION_THRESHOLD;\nconst INP_MEDIUM_TIMING = Helpers.Timing.milliToMicro(Types.Timing.MilliSeconds(500));\n\nexport interface UserInteractionsData {\n /** All the user events we found in the trace */\n allEvents: readonly Types.Events.EventTimingBeginOrEnd[];\n /** All the BeginCommitCompositorFrame events we found in the trace */\n beginCommitCompositorFrameEvents: readonly Types.Events.BeginCommitCompositorFrame[];\n /** All the ParseMetaViewport events we found in the trace */\n parseMetaViewportEvents: readonly Types.Events.ParseMetaViewport[];\n /** All the interaction events we found in the trace that had an\n * interactionId and a duration > 0\n **/\n interactionEvents: readonly Types.Events.SyntheticInteractionPair[];\n /** If the user rapidly generates interaction events (think typing into a\n * text box), in the UI we only really want to show the user the longest\n * interaction in that set.\n * For example picture interactions like this:\n * ===[interaction A]==========\n * =[interaction B]======\n * =[interaction C]=\n *\n * These events all end at the same time, and so in this instance we only want\n * to show the first interaction A on the timeline, as that is the longest one\n * and the one the developer should be focusing on. So this array of events is\n * all the interaction events filtered down, removing any nested interactions\n * entirely.\n **/\n interactionEventsWithNoNesting: readonly Types.Events.SyntheticInteractionPair[];\n // The longest duration interaction event. Can be null if the trace has no interaction events.\n longestInteractionEvent: Readonly<Types.Events.SyntheticInteractionPair>|null;\n // All interactions that went over the interaction threshold (200ms, see https://web.dev/inp/)\n interactionsOverThreshold: Readonly<Set<Types.Events.SyntheticInteractionPair>>;\n}\n\nlet longestInteractionEvent: Types.Events.SyntheticInteractionPair|null = null;\n\nconst interactionEvents: Types.Events.SyntheticInteractionPair[] = [];\nconst interactionEventsWithNoNesting: Types.Events.SyntheticInteractionPair[] = [];\nconst eventTimingEndEventsById = new Map<string, Types.Events.EventTimingEnd>();\nconst eventTimingStartEventsForInteractions: Types.Events.EventTimingBegin[] = [];\n\nexport function reset(): void {\n allEvents.length = 0;\n beginCommitCompositorFrameEvents.length = 0;\n parseMetaViewportEvents.length = 0;\n interactionEvents.length = 0;\n eventTimingStartEventsForInteractions.length = 0;\n eventTimingEndEventsById.clear();\n interactionEventsWithNoNesting.length = 0;\n longestInteractionEvent = null;\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (Types.Events.isBeginCommitCompositorFrame(event)) {\n beginCommitCompositorFrameEvents.push(event);\n return;\n }\n\n if (Types.Events.isParseMetaViewport(event)) {\n parseMetaViewportEvents.push(event);\n return;\n }\n\n if (!Types.Events.isEventTiming(event)) {\n return;\n }\n\n if (Types.Events.isEventTimingEnd(event)) {\n // Store the end event; for each start event that is an interaction, we need the matching end event to calculate the duration correctly.\n eventTimingEndEventsById.set(event.id, event);\n }\n\n allEvents.push(event);\n\n // From this point on we want to find events that represent interactions.\n // These events are always start events - those are the ones that contain all\n // the metadata about the interaction.\n if (!event.args.data || !Types.Events.isEventTimingStart(event)) {\n return;\n }\n const {duration, interactionId} = event.args.data;\n // We exclude events for the sake of interactions if:\n // 1. They have no duration.\n // 2. They have no interactionId\n // 3. They have an interactionId of 0: this indicates that it's not an\n // interaction that we care about because it hasn't had its own interactionId\n // set (0 is the default on the backend).\n // See: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/responsiveness_metrics.cc;l=133;drc=40c209a9c365ebb9f16fb99dfe78c7fe768b9594\n\n if (duration < 1 || interactionId === undefined || interactionId === 0) {\n return;\n }\n\n // Store the start event. In the finalize() function we will pair this with\n // its end event and create the synthetic interaction event.\n eventTimingStartEventsForInteractions.push(event);\n}\n\n/**\n * See https://web.dev/better-responsiveness-metric/#interaction-types for the\n * table that defines these sets.\n **/\nconst pointerEventTypes = new Set([\n 'pointerdown',\n 'touchstart',\n 'pointerup',\n 'touchend',\n 'mousedown',\n 'mouseup',\n 'click',\n]);\n\nconst keyboardEventTypes = new Set([\n 'keydown',\n 'keypress',\n 'keyup',\n]);\n\nexport type InteractionCategory = 'KEYBOARD'|'POINTER'|'OTHER';\nexport function categoryOfInteraction(interaction: Types.Events.SyntheticInteractionPair): InteractionCategory {\n if (pointerEventTypes.has(interaction.type)) {\n return 'POINTER';\n }\n if (keyboardEventTypes.has(interaction.type)) {\n return 'KEYBOARD';\n }\n\n return 'OTHER';\n}\n\n/**\n * We define a set of interactions as nested where:\n * 1. Their end times align.\n * 2. The longest interaction's start time is earlier than all other\n * interactions with the same end time.\n * 3. The interactions are of the same category [each interaction is either\n * categorised as keyboard, or pointer.]\n *\n * =============A=[pointerup]=\n * ====B=[pointerdown]=\n * ===C=[pointerdown]==\n * ===D=[pointerup]===\n *\n * In this example, B, C and D are all nested and therefore should not be\n * returned from this function.\n *\n * However, in this example we would only consider B nested (under A) and D\n * nested (under C). A and C both stay because they are of different types.\n * ========A=[keydown]====\n * =======B=[keyup]=====\n * ====C=[pointerdown]=\n * =D=[pointerup]=\n **/\nexport function removeNestedInteractions(interactions: readonly Types.Events.SyntheticInteractionPair[]):\n readonly Types.Events.SyntheticInteractionPair[] {\n /**\n * Because we nest events only that are in the same category, we store the\n * longest event for a given end time by category.\n **/\n const earliestEventForEndTimePerCategory:\n Record<InteractionCategory, Map<Types.Timing.MicroSeconds, Types.Events.SyntheticInteractionPair>> = {\n POINTER: new Map(),\n KEYBOARD: new Map(),\n OTHER: new Map(),\n };\n\n function storeEventIfEarliestForCategoryAndEndTime(interaction: Types.Events.SyntheticInteractionPair): void {\n const category = categoryOfInteraction(interaction);\n const earliestEventForEndTime = earliestEventForEndTimePerCategory[category];\n const endTime = Types.Timing.MicroSeconds(interaction.ts + interaction.dur);\n\n const earliestCurrentEvent = earliestEventForEndTime.get(endTime);\n if (!earliestCurrentEvent) {\n earliestEventForEndTime.set(endTime, interaction);\n return;\n }\n if (interaction.ts < earliestCurrentEvent.ts) {\n earliestEventForEndTime.set(endTime, interaction);\n } else if (\n interaction.ts === earliestCurrentEvent.ts &&\n interaction.interactionId === earliestCurrentEvent.interactionId) {\n // We have seen in traces that the same interaction can have multiple\n // events (e.g. a 'click' and a 'pointerdown'). Often only one of these\n // events will have an event handler bound to it which caused delay on\n // the main thread, and the others will not. This leads to a situation\n // where if we pick one of the events that had no event handler, its\n // processing duration (processingEnd - processingStart) will be 0, but if we\n // had picked the event that had the slow event handler, we would show\n // correctly the main thread delay due to the event handler.\n // So, if we find events with the same interactionId and the same\n // begin/end times, we pick the one with the largest (processingEnd -\n // processingStart) time in order to make sure we find the event with the\n // worst main thread delay, as that is the one the user should care\n // about.\n const currentProcessingDuration = earliestCurrentEvent.processingEnd - earliestCurrentEvent.processingStart;\n const newProcessingDuration = interaction.processingEnd - interaction.processingStart;\n\n // Use the new interaction if it has a longer processing duration than the existing one.\n if (newProcessingDuration > currentProcessingDuration) {\n earliestEventForEndTime.set(endTime, interaction);\n }\n }\n\n // Maximize the processing duration based on the \"children\" interactions.\n // We pick the earliest start processing duration, and the latest end\n // processing duration to avoid under-reporting.\n if (interaction.processingStart < earliestCurrentEvent.processingStart) {\n earliestCurrentEvent.processingStart = interaction.processingStart;\n writeSyntheticTimespans(earliestCurrentEvent);\n }\n if (interaction.processingEnd > earliestCurrentEvent.processingEnd) {\n earliestCurrentEvent.processingEnd = interaction.processingEnd;\n writeSyntheticTimespans(earliestCurrentEvent);\n }\n }\n\n for (const interaction of interactions) {\n storeEventIfEarliestForCategoryAndEndTime(interaction);\n }\n\n // Combine all the events that we have kept from all the per-category event\n // maps back into an array and sort them by timestamp.\n const keptEvents = Object.values(earliestEventForEndTimePerCategory)\n .flatMap(eventsByEndTime => Array.from(eventsByEndTime.values()));\n keptEvents.sort((eventA, eventB) => {\n return eventA.ts - eventB.ts;\n });\n return keptEvents;\n}\n\nfunction writeSyntheticTimespans(event: Types.Events.SyntheticInteractionPair): void {\n const startEvent = event.args.data.beginEvent;\n const endEvent = event.args.data.endEvent;\n\n event.inputDelay = Types.Timing.MicroSeconds(event.processingStart - startEvent.ts);\n event.mainThreadHandling = Types.Timing.MicroSeconds(event.processingEnd - event.processingStart);\n event.presentationDelay = Types.Timing.MicroSeconds(endEvent.ts - event.processingEnd);\n}\n\nexport async function finalize(): Promise<void> {\n const {navigationsByFrameId} = metaHandlerData();\n\n // For each interaction start event, find the async end event by the ID, and then create the Synthetic Interaction event.\n for (const interactionStartEvent of eventTimingStartEventsForInteractions) {\n const endEvent = eventTimingEndEventsById.get(interactionStartEvent.id);\n if (!endEvent) {\n // If we cannot find an end event, bail and drop this event.\n continue;\n }\n const {type, interactionId, timeStamp, processingStart, processingEnd} = interactionStartEvent.args.data;\n if (!type || !interactionId || !timeStamp || !processingStart || !processingEnd) {\n // A valid interaction event that we care about has to have a type (e.g. pointerdown, keyup).\n // We also need to ensure it has an interactionId and various timings. There are edge cases where these aren't included in the trace event.\n continue;\n }\n\n // In the future we will add microsecond timestamps to the trace events…\n // (See https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/window_performance.cc;l=900-901;drc=b503c262e425eae59ced4a80d59d176ed07152c7 )\n // …but until then we can use the millisecond precision values that are in\n // the trace event. To adjust them to be relative to the event.ts and the\n // trace timestamps, for both processingStart and processingEnd we subtract\n // the event timestamp (NOT event.ts, but the timeStamp millisecond value\n // emitted in args.data), and then add that value to the event.ts. This\n // will give us a processingStart and processingEnd time in microseconds\n // that is relative to event.ts, and can be used when drawing boxes.\n // There is some inaccuracy here as we are converting milliseconds to microseconds, but it is good enough until the backend emits more accurate numbers.\n const processingStartRelativeToTraceTime = Types.Timing.MicroSeconds(\n Helpers.Timing.milliToMicro(processingStart) - Helpers.Timing.milliToMicro(timeStamp) +\n interactionStartEvent.ts,\n );\n\n const processingEndRelativeToTraceTime = Types.Timing.MicroSeconds(\n (Helpers.Timing.milliToMicro(processingEnd) - Helpers.Timing.milliToMicro(timeStamp)) +\n interactionStartEvent.ts);\n\n // Ultimate frameId fallback only needed for TSC, see comments in the type.\n const frameId = interactionStartEvent.args.frame ?? interactionStartEvent.args.data.frame ?? '';\n const navigation = Helpers.Trace.getNavigationForTraceEvent(interactionStartEvent, frameId, navigationsByFrameId);\n const navigationId = navigation?.args.data?.navigationId;\n const interactionEvent =\n Helpers.SyntheticEvents.SyntheticEventsManager.registerSyntheticEvent<Types.Events.SyntheticInteractionPair>({\n // Use the start event to define the common fields.\n rawSourceEvent: interactionStartEvent,\n cat: interactionStartEvent.cat,\n name: interactionStartEvent.name,\n pid: interactionStartEvent.pid,\n tid: interactionStartEvent.tid,\n ph: interactionStartEvent.ph,\n processingStart: processingStartRelativeToTraceTime,\n processingEnd: processingEndRelativeToTraceTime,\n // These will be set in writeSyntheticTimespans()\n inputDelay: Types.Timing.MicroSeconds(-1),\n mainThreadHandling: Types.Timing.MicroSeconds(-1),\n presentationDelay: Types.Timing.MicroSeconds(-1),\n args: {\n data: {\n beginEvent: interactionStartEvent,\n endEvent,\n frame: frameId,\n navigationId,\n },\n },\n ts: interactionStartEvent.ts,\n dur: Types.Timing.MicroSeconds(endEvent.ts - interactionStartEvent.ts),\n type: interactionStartEvent.args.data.type,\n interactionId: interactionStartEvent.args.data.interactionId,\n });\n writeSyntheticTimespans(interactionEvent);\n\n interactionEvents.push(interactionEvent);\n }\n\n interactionEventsWithNoNesting.push(...removeNestedInteractions(interactionEvents));\n\n // Pick the longest interactions from the set that were not nested, as we\n // know those are the set of the largest interactions.\n for (const interactionEvent of interactionEventsWithNoNesting) {\n if (!longestInteractionEvent || longestInteractionEvent.dur < interactionEvent.dur) {\n longestInteractionEvent = interactionEvent;\n }\n }\n}\n\nexport function data(): UserInteractionsData {\n return {\n allEvents,\n beginCommitCompositorFrameEvents,\n parseMetaViewportEvents,\n interactionEvents,\n interactionEventsWithNoNesting,\n longestInteractionEvent,\n interactionsOverThreshold: new Set(interactionEvents.filter(event => {\n return event.dur > LONG_INTERACTION_THRESHOLD;\n })),\n };\n}\n\nexport function deps(): HandlerName[] {\n return ['Meta'];\n}\n\n/**\n * Classifications sourced from\n * https://web.dev/articles/inp#good-score\n */\nexport function scoreClassificationForInteractionToNextPaint(timing: Types.Timing.MicroSeconds): ScoreClassification {\n if (timing <= INP_GOOD_TIMING) {\n return ScoreClassification.GOOD;\n }\n\n if (timing <= INP_MEDIUM_TIMING) {\n return ScoreClassification.OK;\n }\n\n return ScoreClassification.BAD;\n}\n"]}
1
+ {"version":3,"file":"UserInteractionsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/UserInteractionsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,IAAI,IAAI,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAIzD,2EAA2E;AAC3E,sEAAsE;AACtE,wEAAwE;AACxE,2DAA2D;AAE3D,yEAAyE;AACzE,0EAA0E;AAC1E,MAA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7C,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,SAAS;QACT,gCAAgC;QAChC,uBAAuB;QACvB,iBAAiB;QACjB,8BAA8B;QAC9B,uBAAuB;QACvB,yBAAyB,EAAE,IAAI,GAAG,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YAClE,OAAO,KAAK,CAAC,GAAG,GAAG,0BAA0B,CAAC;QAChD,CAAC,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,CAAC,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,4CAA4C,CAAC,MAA0B;IACrF,IAAI,MAAM,IAAI,eAAe,EAAE,CAAC;QAC9B,6CAAgC;IAClC,CAAC;IAED,IAAI,MAAM,IAAI,iBAAiB,EAAE,CAAC;QAChC,yCAA8B;IAChC,CAAC;IAED,2CAA+B;AACjC,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 Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {data as metaHandlerData} from './MetaHandler.js';\nimport {ScoreClassification} from './PageLoadMetricsHandler.js';\nimport type {HandlerName} from './types.js';\n\n// This handler serves two purposes. It generates a list of events that are\n// used to show user clicks in the timeline. It is also used to gather\n// EventTimings into Interactions, which we use to show interactions and\n// highlight long interactions to the user, along with INP.\n\n// We don't need to know which process / thread these events occurred in,\n// because they are effectively global, so we just track all that we find.\nconst allEvents: Types.Events.EventTimingBeginOrEnd[] = [];\n\nconst beginCommitCompositorFrameEvents: Types.Events.BeginCommitCompositorFrame[] = [];\nconst parseMetaViewportEvents: Types.Events.ParseMetaViewport[] = [];\n\nexport const LONG_INTERACTION_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.Milli(200));\n\nconst INP_GOOD_TIMING = LONG_INTERACTION_THRESHOLD;\nconst INP_MEDIUM_TIMING = Helpers.Timing.milliToMicro(Types.Timing.Milli(500));\n\nexport interface UserInteractionsData {\n /** All the user events we found in the trace */\n allEvents: readonly Types.Events.EventTimingBeginOrEnd[];\n /** All the BeginCommitCompositorFrame events we found in the trace */\n beginCommitCompositorFrameEvents: readonly Types.Events.BeginCommitCompositorFrame[];\n /** All the ParseMetaViewport events we found in the trace */\n parseMetaViewportEvents: readonly Types.Events.ParseMetaViewport[];\n /** All the interaction events we found in the trace that had an\n * interactionId and a duration > 0\n **/\n interactionEvents: readonly Types.Events.SyntheticInteractionPair[];\n /** If the user rapidly generates interaction events (think typing into a\n * text box), in the UI we only really want to show the user the longest\n * interaction in that set.\n * For example picture interactions like this:\n * ===[interaction A]==========\n * =[interaction B]======\n * =[interaction C]=\n *\n * These events all end at the same time, and so in this instance we only want\n * to show the first interaction A on the timeline, as that is the longest one\n * and the one the developer should be focusing on. So this array of events is\n * all the interaction events filtered down, removing any nested interactions\n * entirely.\n **/\n interactionEventsWithNoNesting: readonly Types.Events.SyntheticInteractionPair[];\n // The longest duration interaction event. Can be null if the trace has no interaction events.\n longestInteractionEvent: Readonly<Types.Events.SyntheticInteractionPair>|null;\n // All interactions that went over the interaction threshold (200ms, see https://web.dev/inp/)\n interactionsOverThreshold: Readonly<Set<Types.Events.SyntheticInteractionPair>>;\n}\n\nlet longestInteractionEvent: Types.Events.SyntheticInteractionPair|null = null;\n\nconst interactionEvents: Types.Events.SyntheticInteractionPair[] = [];\nconst interactionEventsWithNoNesting: Types.Events.SyntheticInteractionPair[] = [];\nconst eventTimingEndEventsById = new Map<string, Types.Events.EventTimingEnd>();\nconst eventTimingStartEventsForInteractions: Types.Events.EventTimingBegin[] = [];\n\nexport function reset(): void {\n allEvents.length = 0;\n beginCommitCompositorFrameEvents.length = 0;\n parseMetaViewportEvents.length = 0;\n interactionEvents.length = 0;\n eventTimingStartEventsForInteractions.length = 0;\n eventTimingEndEventsById.clear();\n interactionEventsWithNoNesting.length = 0;\n longestInteractionEvent = null;\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (Types.Events.isBeginCommitCompositorFrame(event)) {\n beginCommitCompositorFrameEvents.push(event);\n return;\n }\n\n if (Types.Events.isParseMetaViewport(event)) {\n parseMetaViewportEvents.push(event);\n return;\n }\n\n if (!Types.Events.isEventTiming(event)) {\n return;\n }\n\n if (Types.Events.isEventTimingEnd(event)) {\n // Store the end event; for each start event that is an interaction, we need the matching end event to calculate the duration correctly.\n eventTimingEndEventsById.set(event.id, event);\n }\n\n allEvents.push(event);\n\n // From this point on we want to find events that represent interactions.\n // These events are always start events - those are the ones that contain all\n // the metadata about the interaction.\n if (!event.args.data || !Types.Events.isEventTimingStart(event)) {\n return;\n }\n const {duration, interactionId} = event.args.data;\n // We exclude events for the sake of interactions if:\n // 1. They have no duration.\n // 2. They have no interactionId\n // 3. They have an interactionId of 0: this indicates that it's not an\n // interaction that we care about because it hasn't had its own interactionId\n // set (0 is the default on the backend).\n // See: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/responsiveness_metrics.cc;l=133;drc=40c209a9c365ebb9f16fb99dfe78c7fe768b9594\n\n if (duration < 1 || interactionId === undefined || interactionId === 0) {\n return;\n }\n\n // Store the start event. In the finalize() function we will pair this with\n // its end event and create the synthetic interaction event.\n eventTimingStartEventsForInteractions.push(event);\n}\n\n/**\n * See https://web.dev/better-responsiveness-metric/#interaction-types for the\n * table that defines these sets.\n **/\nconst pointerEventTypes = new Set([\n 'pointerdown',\n 'touchstart',\n 'pointerup',\n 'touchend',\n 'mousedown',\n 'mouseup',\n 'click',\n]);\n\nconst keyboardEventTypes = new Set([\n 'keydown',\n 'keypress',\n 'keyup',\n]);\n\nexport type InteractionCategory = 'KEYBOARD'|'POINTER'|'OTHER';\nexport function categoryOfInteraction(interaction: Types.Events.SyntheticInteractionPair): InteractionCategory {\n if (pointerEventTypes.has(interaction.type)) {\n return 'POINTER';\n }\n if (keyboardEventTypes.has(interaction.type)) {\n return 'KEYBOARD';\n }\n\n return 'OTHER';\n}\n\n/**\n * We define a set of interactions as nested where:\n * 1. Their end times align.\n * 2. The longest interaction's start time is earlier than all other\n * interactions with the same end time.\n * 3. The interactions are of the same category [each interaction is either\n * categorised as keyboard, or pointer.]\n *\n * =============A=[pointerup]=\n * ====B=[pointerdown]=\n * ===C=[pointerdown]==\n * ===D=[pointerup]===\n *\n * In this example, B, C and D are all nested and therefore should not be\n * returned from this function.\n *\n * However, in this example we would only consider B nested (under A) and D\n * nested (under C). A and C both stay because they are of different types.\n * ========A=[keydown]====\n * =======B=[keyup]=====\n * ====C=[pointerdown]=\n * =D=[pointerup]=\n **/\nexport function removeNestedInteractions(interactions: readonly Types.Events.SyntheticInteractionPair[]):\n readonly Types.Events.SyntheticInteractionPair[] {\n /**\n * Because we nest events only that are in the same category, we store the\n * longest event for a given end time by category.\n **/\n const earliestEventForEndTimePerCategory:\n Record<InteractionCategory, Map<Types.Timing.Micro, Types.Events.SyntheticInteractionPair>> = {\n POINTER: new Map(),\n KEYBOARD: new Map(),\n OTHER: new Map(),\n };\n\n function storeEventIfEarliestForCategoryAndEndTime(interaction: Types.Events.SyntheticInteractionPair): void {\n const category = categoryOfInteraction(interaction);\n const earliestEventForEndTime = earliestEventForEndTimePerCategory[category];\n const endTime = Types.Timing.Micro(interaction.ts + interaction.dur);\n\n const earliestCurrentEvent = earliestEventForEndTime.get(endTime);\n if (!earliestCurrentEvent) {\n earliestEventForEndTime.set(endTime, interaction);\n return;\n }\n if (interaction.ts < earliestCurrentEvent.ts) {\n earliestEventForEndTime.set(endTime, interaction);\n } else if (\n interaction.ts === earliestCurrentEvent.ts &&\n interaction.interactionId === earliestCurrentEvent.interactionId) {\n // We have seen in traces that the same interaction can have multiple\n // events (e.g. a 'click' and a 'pointerdown'). Often only one of these\n // events will have an event handler bound to it which caused delay on\n // the main thread, and the others will not. This leads to a situation\n // where if we pick one of the events that had no event handler, its\n // processing duration (processingEnd - processingStart) will be 0, but if we\n // had picked the event that had the slow event handler, we would show\n // correctly the main thread delay due to the event handler.\n // So, if we find events with the same interactionId and the same\n // begin/end times, we pick the one with the largest (processingEnd -\n // processingStart) time in order to make sure we find the event with the\n // worst main thread delay, as that is the one the user should care\n // about.\n const currentProcessingDuration = earliestCurrentEvent.processingEnd - earliestCurrentEvent.processingStart;\n const newProcessingDuration = interaction.processingEnd - interaction.processingStart;\n\n // Use the new interaction if it has a longer processing duration than the existing one.\n if (newProcessingDuration > currentProcessingDuration) {\n earliestEventForEndTime.set(endTime, interaction);\n }\n }\n\n // Maximize the processing duration based on the \"children\" interactions.\n // We pick the earliest start processing duration, and the latest end\n // processing duration to avoid under-reporting.\n if (interaction.processingStart < earliestCurrentEvent.processingStart) {\n earliestCurrentEvent.processingStart = interaction.processingStart;\n writeSyntheticTimespans(earliestCurrentEvent);\n }\n if (interaction.processingEnd > earliestCurrentEvent.processingEnd) {\n earliestCurrentEvent.processingEnd = interaction.processingEnd;\n writeSyntheticTimespans(earliestCurrentEvent);\n }\n }\n\n for (const interaction of interactions) {\n storeEventIfEarliestForCategoryAndEndTime(interaction);\n }\n\n // Combine all the events that we have kept from all the per-category event\n // maps back into an array and sort them by timestamp.\n const keptEvents = Object.values(earliestEventForEndTimePerCategory)\n .flatMap(eventsByEndTime => Array.from(eventsByEndTime.values()));\n keptEvents.sort((eventA, eventB) => {\n return eventA.ts - eventB.ts;\n });\n return keptEvents;\n}\n\nfunction writeSyntheticTimespans(event: Types.Events.SyntheticInteractionPair): void {\n const startEvent = event.args.data.beginEvent;\n const endEvent = event.args.data.endEvent;\n\n event.inputDelay = Types.Timing.Micro(event.processingStart - startEvent.ts);\n event.mainThreadHandling = Types.Timing.Micro(event.processingEnd - event.processingStart);\n event.presentationDelay = Types.Timing.Micro(endEvent.ts - event.processingEnd);\n}\n\nexport async function finalize(): Promise<void> {\n const {navigationsByFrameId} = metaHandlerData();\n\n // For each interaction start event, find the async end event by the ID, and then create the Synthetic Interaction event.\n for (const interactionStartEvent of eventTimingStartEventsForInteractions) {\n const endEvent = eventTimingEndEventsById.get(interactionStartEvent.id);\n if (!endEvent) {\n // If we cannot find an end event, bail and drop this event.\n continue;\n }\n const {type, interactionId, timeStamp, processingStart, processingEnd} = interactionStartEvent.args.data;\n if (!type || !interactionId || !timeStamp || !processingStart || !processingEnd) {\n // A valid interaction event that we care about has to have a type (e.g. pointerdown, keyup).\n // We also need to ensure it has an interactionId and various timings. There are edge cases where these aren't included in the trace event.\n continue;\n }\n\n // In the future we will add microsecond timestamps to the trace events…\n // (See https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/window_performance.cc;l=900-901;drc=b503c262e425eae59ced4a80d59d176ed07152c7 )\n // …but until then we can use the millisecond precision values that are in\n // the trace event. To adjust them to be relative to the event.ts and the\n // trace timestamps, for both processingStart and processingEnd we subtract\n // the event timestamp (NOT event.ts, but the timeStamp millisecond value\n // emitted in args.data), and then add that value to the event.ts. This\n // will give us a processingStart and processingEnd time in microseconds\n // that is relative to event.ts, and can be used when drawing boxes.\n // There is some inaccuracy here as we are converting milliseconds to microseconds, but it is good enough until the backend emits more accurate numbers.\n const processingStartRelativeToTraceTime = Types.Timing.Micro(\n Helpers.Timing.milliToMicro(processingStart) - Helpers.Timing.milliToMicro(timeStamp) +\n interactionStartEvent.ts,\n );\n\n const processingEndRelativeToTraceTime = Types.Timing.Micro(\n (Helpers.Timing.milliToMicro(processingEnd) - Helpers.Timing.milliToMicro(timeStamp)) +\n interactionStartEvent.ts);\n\n // Ultimate frameId fallback only needed for TSC, see comments in the type.\n const frameId = interactionStartEvent.args.frame ?? interactionStartEvent.args.data.frame ?? '';\n const navigation = Helpers.Trace.getNavigationForTraceEvent(interactionStartEvent, frameId, navigationsByFrameId);\n const navigationId = navigation?.args.data?.navigationId;\n const interactionEvent =\n Helpers.SyntheticEvents.SyntheticEventsManager.registerSyntheticEvent<Types.Events.SyntheticInteractionPair>({\n // Use the start event to define the common fields.\n rawSourceEvent: interactionStartEvent,\n cat: interactionStartEvent.cat,\n name: interactionStartEvent.name,\n pid: interactionStartEvent.pid,\n tid: interactionStartEvent.tid,\n ph: interactionStartEvent.ph,\n processingStart: processingStartRelativeToTraceTime,\n processingEnd: processingEndRelativeToTraceTime,\n // These will be set in writeSyntheticTimespans()\n inputDelay: Types.Timing.Micro(-1),\n mainThreadHandling: Types.Timing.Micro(-1),\n presentationDelay: Types.Timing.Micro(-1),\n args: {\n data: {\n beginEvent: interactionStartEvent,\n endEvent,\n frame: frameId,\n navigationId,\n },\n },\n ts: interactionStartEvent.ts,\n dur: Types.Timing.Micro(endEvent.ts - interactionStartEvent.ts),\n type: interactionStartEvent.args.data.type,\n interactionId: interactionStartEvent.args.data.interactionId,\n });\n writeSyntheticTimespans(interactionEvent);\n\n interactionEvents.push(interactionEvent);\n }\n\n interactionEventsWithNoNesting.push(...removeNestedInteractions(interactionEvents));\n\n // Pick the longest interactions from the set that were not nested, as we\n // know those are the set of the largest interactions.\n for (const interactionEvent of interactionEventsWithNoNesting) {\n if (!longestInteractionEvent || longestInteractionEvent.dur < interactionEvent.dur) {\n longestInteractionEvent = interactionEvent;\n }\n }\n}\n\nexport function data(): UserInteractionsData {\n return {\n allEvents,\n beginCommitCompositorFrameEvents,\n parseMetaViewportEvents,\n interactionEvents,\n interactionEventsWithNoNesting,\n longestInteractionEvent,\n interactionsOverThreshold: new Set(interactionEvents.filter(event => {\n return event.dur > LONG_INTERACTION_THRESHOLD;\n })),\n };\n}\n\nexport function deps(): HandlerName[] {\n return ['Meta'];\n}\n\n/**\n * Classifications sourced from\n * https://web.dev/articles/inp#good-score\n */\nexport function scoreClassificationForInteractionToNextPaint(timing: Types.Timing.Micro): ScoreClassification {\n if (timing <= INP_GOOD_TIMING) {\n return ScoreClassification.GOOD;\n }\n\n if (timing <= INP_MEDIUM_TIMING) {\n return ScoreClassification.OK;\n }\n\n return ScoreClassification.BAD;\n}\n"]}
@@ -5,8 +5,8 @@ export interface WarningsData {
5
5
  perWarning: Map<Warning, Types.Events.Event[]>;
6
6
  }
7
7
  export type Warning = 'LONG_TASK' | 'IDLE_CALLBACK_OVER_TIME' | 'FORCED_REFLOW' | 'LONG_INTERACTION';
8
- export declare const FORCED_REFLOW_THRESHOLD: Types.Timing.MicroSeconds;
9
- export declare const LONG_MAIN_THREAD_TASK_THRESHOLD: Types.Timing.MicroSeconds;
8
+ export declare const FORCED_REFLOW_THRESHOLD: Types.Timing.Micro;
9
+ export declare const LONG_MAIN_THREAD_TASK_THRESHOLD: Types.Timing.Micro;
10
10
  export declare function reset(): void;
11
11
  export declare function handleEvent(event: Types.Events.Event): void;
12
12
  export declare function deps(): HandlerName[];
@@ -21,8 +21,8 @@ const jsInvokeStack = [];
21
21
  * Tracks reflow events in a task.
22
22
  */
23
23
  const taskReflowEvents = [];
24
- export const FORCED_REFLOW_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.MilliSeconds(30));
25
- export const LONG_MAIN_THREAD_TASK_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.MilliSeconds(50));
24
+ export const FORCED_REFLOW_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.Milli(30));
25
+ export const LONG_MAIN_THREAD_TASK_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.Milli(50));
26
26
  export function reset() {
27
27
  warningsPerEvent.clear();
28
28
  eventsPerWarning.clear();
@@ -1 +1 @@
1
- {"version":3,"file":"WarningsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/WarningsHandler.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;AAG3C,OAAO,EAAC,IAAI,IAAI,2BAA2B,EAAC,MAAM,8BAA8B,CAAC;AAYjF,MAAM,gB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C7D,MAAM,gBAAgB,GAAG,2BAA2B,EAAE,CAAC,yBAAyB,CAAC;IACjF,KAAK,MAAM,WAAW,IAAI,gBAAgB,EAAE,CAAC;QAC3C,YAAY,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,QAAQ,EAAE,gBAAgB;QAC1B,UAAU,EAAE,gBAAgB;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2023 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport type {HandlerName} from './types.js';\nimport {data as userInteractionsHandlerData} from './UserInteractionsHandler.js';\n\nexport interface WarningsData {\n // Tracks warnings keyed by the event.\n perEvent: Map<Types.Events.Event, Warning[]>;\n // The same data in reverse: for each type of warning, track the events.\n // Useful if we need to enumerate events by type of issue\n perWarning: Map<Warning, Types.Events.Event[]>;\n}\n\nexport type Warning = 'LONG_TASK'|'IDLE_CALLBACK_OVER_TIME'|'FORCED_REFLOW'|'LONG_INTERACTION';\n\nconst warningsPerEvent: WarningsData['perEvent'] = new Map();\nconst eventsPerWarning: WarningsData['perWarning'] = new Map();\n\n/**\n * Tracks the stack formed by nested trace events up to a given point\n */\nconst allEventsStack: Types.Events.Event[] = [];\n/**\n * Tracks the stack formed by JS invocation trace events up to a given point.\n * F.e. FunctionCall, EvaluateScript, V8Execute.\n * Not to be confused with ProfileCalls.\n */\nconst jsInvokeStack: Types.Events.Event[] = [];\n/**\n * Tracks reflow events in a task.\n */\nconst taskReflowEvents: Types.Events.Event[] = [];\n\nexport const FORCED_REFLOW_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.MilliSeconds(30));\n\nexport const LONG_MAIN_THREAD_TASK_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.MilliSeconds(50));\n\nexport function reset(): void {\n warningsPerEvent.clear();\n eventsPerWarning.clear();\n allEventsStack.length = 0;\n jsInvokeStack.length = 0;\n taskReflowEvents.length = 0;\n}\n\nfunction storeWarning(event: Types.Events.Event, warning: Warning): void {\n const existingWarnings = Platform.MapUtilities.getWithDefault(warningsPerEvent, event, () => []);\n existingWarnings.push(warning);\n warningsPerEvent.set(event, existingWarnings);\n\n const existingEvents = Platform.MapUtilities.getWithDefault(eventsPerWarning, warning, () => []);\n existingEvents.push(event);\n eventsPerWarning.set(warning, existingEvents);\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n processForcedReflowWarning(event);\n if (event.name === Types.Events.Name.RUN_TASK) {\n const {duration} = Helpers.Timing.eventTimingsMicroSeconds(event);\n if (duration > LONG_MAIN_THREAD_TASK_THRESHOLD) {\n storeWarning(event, 'LONG_TASK');\n }\n return;\n }\n\n if (Types.Events.isFireIdleCallback(event)) {\n const {duration} = Helpers.Timing.eventTimingsMilliSeconds(event);\n if (duration > event.args.data.allottedMilliseconds) {\n storeWarning(event, 'IDLE_CALLBACK_OVER_TIME');\n }\n return;\n }\n}\n\n/**\n * Reflows* are added a warning to if:\n * 1. They are forced/sync, meaning they are invoked by JS and finish\n * during the Script execution.\n * 2. Their duration exceeds a threshold.\n * - *Reflow: The style recalculation and layout steps in a render task.\n */\nfunction processForcedReflowWarning(event: Types.Events.Event): void {\n // Update the event and the JS invocation stacks.\n accomodateEventInStack(event, allEventsStack);\n accomodateEventInStack(event, jsInvokeStack, /* pushEventToStack */ Types.Events.isJSInvocationEvent(event));\n if (jsInvokeStack.length) {\n // Current event falls inside a JS call.\n if (event.name === Types.Events.Name.LAYOUT || event.name === Types.Events.Name.UPDATE_LAYOUT_TREE) {\n // A forced reflow happened. However we need to check if\n // the threshold is surpassed to add a warning. Accumulate the\n // event to check for this after the current Task is over.\n taskReflowEvents.push(event);\n return;\n }\n }\n if (allEventsStack.length === 1) {\n // We hit a new task. Check if the forced reflows in the previous\n // task exceeded the threshold and add a warning if so.\n const totalTime = taskReflowEvents.reduce((time, event) => time + (event.dur || 0), 0);\n if (totalTime >= FORCED_REFLOW_THRESHOLD) {\n taskReflowEvents.forEach(reflowEvent => storeWarning(reflowEvent, 'FORCED_REFLOW'));\n }\n taskReflowEvents.length = 0;\n }\n}\n\n/**\n * Updates a given trace event stack given a new event.\n */\nfunction accomodateEventInStack(event: Types.Events.Event, stack: Types.Events.Event[], pushEventToStack = true): void {\n let nextItem = stack.at(-1);\n while (nextItem && event.ts > nextItem.ts + (nextItem.dur || 0)) {\n stack.pop();\n nextItem = stack.at(-1);\n }\n if (!pushEventToStack) {\n return;\n }\n stack.push(event);\n}\n\nexport function deps(): HandlerName[] {\n return ['UserInteractions'];\n}\n\nexport async function finalize(): Promise<void> {\n // These events do exist on the UserInteractionsHandler, but we also put\n // them into the WarningsHandler so that the warnings handler can be the\n // source of truth and the way to look up all warnings for a given event.\n // Otherwise, we would have to look up warnings across multiple handlers for\n // a given event, which will start to get messy very quickly.\n const longInteractions = userInteractionsHandlerData().interactionsOverThreshold;\n for (const interaction of longInteractions) {\n storeWarning(interaction, 'LONG_INTERACTION');\n }\n}\n\nexport function data(): WarningsData {\n return {\n perEvent: warningsPerEvent,\n perWarning: eventsPerWarning,\n };\n}\n"]}
1
+ {"version":3,"file":"WarningsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/WarningsHandler.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;AAG3C,OAAO,EAAC,IAAI,IAAI,2BAA2B,EAAC,MAAM,8BAA8B,CAAC;AAYjF,MAAM,gBAAgB,GAA6B,IAAI,GAAG,EAAE,CAAC;AAC7D,MAAM,gBAAgB,GAA+B,IAAI,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,MAAM,WAAW,IAAI,gBAAgB,EAAE,CAAC;QAC3C,YAAY,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,QAAQ,EAAE,gBAAgB;QAC1B,UAAU,EAAE,gBAAgB;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2023 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport type {HandlerName} from './types.js';\nimport {data as userInteractionsHandlerData} from './UserInteractionsHandler.js';\n\nexport interface WarningsData {\n // Tracks warnings keyed by the event.\n perEvent: Map<Types.Events.Event, Warning[]>;\n // The same data in reverse: for each type of warning, track the events.\n // Useful if we need to enumerate events by type of issue\n perWarning: Map<Warning, Types.Events.Event[]>;\n}\n\nexport type Warning = 'LONG_TASK'|'IDLE_CALLBACK_OVER_TIME'|'FORCED_REFLOW'|'LONG_INTERACTION';\n\nconst warningsPerEvent: WarningsData['perEvent'] = new Map();\nconst eventsPerWarning: WarningsData['perWarning'] = new Map();\n\n/**\n * Tracks the stack formed by nested trace events up to a given point\n */\nconst allEventsStack: Types.Events.Event[] = [];\n/**\n * Tracks the stack formed by JS invocation trace events up to a given point.\n * F.e. FunctionCall, EvaluateScript, V8Execute.\n * Not to be confused with ProfileCalls.\n */\nconst jsInvokeStack: Types.Events.Event[] = [];\n/**\n * Tracks reflow events in a task.\n */\nconst taskReflowEvents: Types.Events.Event[] = [];\n\nexport const FORCED_REFLOW_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.Milli(30));\n\nexport const LONG_MAIN_THREAD_TASK_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.Milli(50));\n\nexport function reset(): void {\n warningsPerEvent.clear();\n eventsPerWarning.clear();\n allEventsStack.length = 0;\n jsInvokeStack.length = 0;\n taskReflowEvents.length = 0;\n}\n\nfunction storeWarning(event: Types.Events.Event, warning: Warning): void {\n const existingWarnings = Platform.MapUtilities.getWithDefault(warningsPerEvent, event, () => []);\n existingWarnings.push(warning);\n warningsPerEvent.set(event, existingWarnings);\n\n const existingEvents = Platform.MapUtilities.getWithDefault(eventsPerWarning, warning, () => []);\n existingEvents.push(event);\n eventsPerWarning.set(warning, existingEvents);\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n processForcedReflowWarning(event);\n if (event.name === Types.Events.Name.RUN_TASK) {\n const {duration} = Helpers.Timing.eventTimingsMicroSeconds(event);\n if (duration > LONG_MAIN_THREAD_TASK_THRESHOLD) {\n storeWarning(event, 'LONG_TASK');\n }\n return;\n }\n\n if (Types.Events.isFireIdleCallback(event)) {\n const {duration} = Helpers.Timing.eventTimingsMilliSeconds(event);\n if (duration > event.args.data.allottedMilliseconds) {\n storeWarning(event, 'IDLE_CALLBACK_OVER_TIME');\n }\n return;\n }\n}\n\n/**\n * Reflows* are added a warning to if:\n * 1. They are forced/sync, meaning they are invoked by JS and finish\n * during the Script execution.\n * 2. Their duration exceeds a threshold.\n * - *Reflow: The style recalculation and layout steps in a render task.\n */\nfunction processForcedReflowWarning(event: Types.Events.Event): void {\n // Update the event and the JS invocation stacks.\n accomodateEventInStack(event, allEventsStack);\n accomodateEventInStack(event, jsInvokeStack, /* pushEventToStack */ Types.Events.isJSInvocationEvent(event));\n if (jsInvokeStack.length) {\n // Current event falls inside a JS call.\n if (event.name === Types.Events.Name.LAYOUT || event.name === Types.Events.Name.UPDATE_LAYOUT_TREE) {\n // A forced reflow happened. However we need to check if\n // the threshold is surpassed to add a warning. Accumulate the\n // event to check for this after the current Task is over.\n taskReflowEvents.push(event);\n return;\n }\n }\n if (allEventsStack.length === 1) {\n // We hit a new task. Check if the forced reflows in the previous\n // task exceeded the threshold and add a warning if so.\n const totalTime = taskReflowEvents.reduce((time, event) => time + (event.dur || 0), 0);\n if (totalTime >= FORCED_REFLOW_THRESHOLD) {\n taskReflowEvents.forEach(reflowEvent => storeWarning(reflowEvent, 'FORCED_REFLOW'));\n }\n taskReflowEvents.length = 0;\n }\n}\n\n/**\n * Updates a given trace event stack given a new event.\n */\nfunction accomodateEventInStack(event: Types.Events.Event, stack: Types.Events.Event[], pushEventToStack = true): void {\n let nextItem = stack.at(-1);\n while (nextItem && event.ts > nextItem.ts + (nextItem.dur || 0)) {\n stack.pop();\n nextItem = stack.at(-1);\n }\n if (!pushEventToStack) {\n return;\n }\n stack.push(event);\n}\n\nexport function deps(): HandlerName[] {\n return ['UserInteractions'];\n}\n\nexport async function finalize(): Promise<void> {\n // These events do exist on the UserInteractionsHandler, but we also put\n // them into the WarningsHandler so that the warnings handler can be the\n // source of truth and the way to look up all warnings for a given event.\n // Otherwise, we would have to look up warnings across multiple handlers for\n // a given event, which will start to get messy very quickly.\n const longInteractions = userInteractionsHandlerData().interactionsOverThreshold;\n for (const interaction of longInteractions) {\n storeWarning(interaction, 'LONG_INTERACTION');\n }\n}\n\nexport function data(): WarningsData {\n return {\n perEvent: warningsPerEvent,\n perWarning: eventsPerWarning,\n };\n}\n"]}
@@ -12,8 +12,8 @@ export interface EntityMappings {
12
12
  */
13
13
  eventsByEntity: Map<Entity, Types.Events.Event[]>;
14
14
  }
15
- export declare function getEntityForEvent(event: Types.Events.Event, entityByUrlCache: Map<string, Entity>): Entity | undefined;
16
- export declare function getEntityForUrl(url: string, entityByUrlCache: Map<string, Entity>): Entity | undefined;
15
+ export declare function getEntityForEvent(event: Types.Events.Event, entityCache: Map<string, Entity>): Entity | undefined;
16
+ export declare function getEntityForUrl(url: string, entityCache: Map<string, Entity>): Entity | undefined;
17
17
  export declare function getNonResolvedURL(entry: Types.Events.Event, parsedTrace?: ParsedTrace): Platform.DevToolsPath.UrlString | null;
18
18
  export declare function makeUpEntity(entityCache: Map<string, Entity>, url: string): Entity | undefined;
19
- export declare function updateEventForEntities(entry: Types.Events.Event, entityMappings: EntityMappings): void;
19
+ export declare function addEventToEntityMapping(event: Types.Events.Event, entityMappings: EntityMappings): void;
@@ -3,19 +3,15 @@
3
3
  // found in the LICENSE file.
4
4
  import * as ThirdPartyWeb from '../../../third_party/third-party-web/third-party-web.js';
5
5
  import * as Types from '../types/types.js';
6
- export function getEntityForEvent(event, entityByUrlCache) {
6
+ export function getEntityForEvent(event, entityCache) {
7
7
  const url = getNonResolvedURL(event);
8
8
  if (!url) {
9
9
  return;
10
10
  }
11
- return getEntityForUrl(url, entityByUrlCache);
11
+ return getEntityForUrl(url, entityCache);
12
12
  }
13
- export function getEntityForUrl(url, entityByUrlCache) {
14
- if (entityByUrlCache.has(url)) {
15
- return entityByUrlCache.get(url);
16
- }
17
- const entity = ThirdPartyWeb.ThirdPartyWeb.getEntity(url) ?? makeUpEntity(entityByUrlCache, url);
18
- return entity;
13
+ export function getEntityForUrl(url, entityCache) {
14
+ return ThirdPartyWeb.ThirdPartyWeb.getEntity(url) ?? makeUpEntity(entityCache, url);
19
15
  }
20
16
  export function getNonResolvedURL(entry, parsedTrace) {
21
17
  if (Types.Events.isProfileCall(entry)) {
@@ -107,17 +103,18 @@ function makeUpChromeExtensionEntity(entityCache, url, extensionName) {
107
103
  entityCache.set(origin, chromeExtensionEntity);
108
104
  return chromeExtensionEntity;
109
105
  }
110
- export function updateEventForEntities(entry, entityMappings) {
111
- const entity = getEntityForEvent(entry, entityMappings.createdEntityCache);
112
- if (entity) {
113
- if (entityMappings.eventsByEntity.has(entity)) {
114
- const events = entityMappings.eventsByEntity.get(entity) ?? [];
115
- events?.push(entry);
116
- }
117
- else {
118
- entityMappings.eventsByEntity.set(entity, [entry]);
119
- }
120
- entityMappings.entityByEvent.set(entry, entity);
106
+ export function addEventToEntityMapping(event, entityMappings) {
107
+ const entity = getEntityForEvent(event, entityMappings.createdEntityCache);
108
+ if (!entity) {
109
+ return;
110
+ }
111
+ const events = entityMappings.eventsByEntity.get(entity);
112
+ if (events) {
113
+ events.push(event);
114
+ }
115
+ else {
116
+ entityMappings.eventsByEntity.set(entity, [event]);
121
117
  }
118
+ entityMappings.entityByEvent.set(event, entity);
122
119
  }
123
120
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/helpers.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAG7B,OAAO,KAAK,aAAa,MAAM,yDAAyD,CAAC;AACzF,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAgB3C,MAAM,UAAU,iBAAiB,CAAC,KAAyB,EAAE,gBAAqC;IAChG,MAAM,GAAG,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO;IACT,CAAC;IACD,OAAO,eAAe,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,gBAAqC;IAChF,IAAI,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9B,OAAO,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IACD,MAAM,MAAM,GAAG,aAAa,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;IACjG,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC7B,KAAyB,EAAE,WAAyB;IACtD,IAAI,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC,SAAS,CAAC,GAAsC,CAAC;IAChE,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,CAAC,yBAAyB,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAA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;QACD,cAAc,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport type * as Platform from '../../../core/platform/platform.js';\nimport * as ThirdPartyWeb from '../../../third_party/third-party-web/third-party-web.js';\nimport * as Types from '../types/types.js';\n\nimport type {ParsedTrace} from './types.js';\n\nexport type Entity = typeof ThirdPartyWeb.ThirdPartyWeb.entities[number];\n\nexport interface EntityMappings {\n createdEntityCache: Map<string, Entity>;\n entityByEvent: Map<Types.Events.Event, Entity>;\n /**\n * This holds the entities that had to be created, because they were not found using the\n * ThirdPartyWeb database.\n */\n eventsByEntity: Map<Entity, Types.Events.Event[]>;\n}\n\nexport function getEntityForEvent(event: Types.Events.Event, entityByUrlCache: Map<string, Entity>): Entity|undefined {\n const url = getNonResolvedURL(event);\n if (!url) {\n return;\n }\n return getEntityForUrl(url, entityByUrlCache);\n}\n\nexport function getEntityForUrl(url: string, entityByUrlCache: Map<string, Entity>): Entity|undefined {\n if (entityByUrlCache.has(url)) {\n return entityByUrlCache.get(url);\n }\n const entity = ThirdPartyWeb.ThirdPartyWeb.getEntity(url) ?? makeUpEntity(entityByUrlCache, url);\n return entity;\n}\n\nexport function getNonResolvedURL(\n entry: Types.Events.Event, parsedTrace?: ParsedTrace): Platform.DevToolsPath.UrlString|null {\n if (Types.Events.isProfileCall(entry)) {\n return entry.callFrame.url as Platform.DevToolsPath.UrlString;\n }\n\n if (Types.Events.isSyntheticNetworkRequest(entry)) {\n return entry.args.data.url as Platform.DevToolsPath.UrlString;\n }\n\n if (entry.args?.data?.stackTrace && entry.args.data.stackTrace.length > 0) {\n return entry.args.data.stackTrace[0].url as Platform.DevToolsPath.UrlString;\n }\n\n // ParseHTML events store the URL under beginData, not data.\n if (Types.Events.isParseHTML(entry)) {\n return entry.args.beginData.url as Platform.DevToolsPath.UrlString;\n }\n\n if (parsedTrace) {\n // DecodeImage events use the URL from the relevant PaintImage event.\n if (Types.Events.isDecodeImage(entry)) {\n const paintEvent = parsedTrace.ImagePainting.paintImageForEvent.get(entry);\n return paintEvent ? getNonResolvedURL(paintEvent, parsedTrace) : null;\n }\n\n // DrawLazyPixelRef events use the URL from the relevant PaintImage event.\n if (Types.Events.isDrawLazyPixelRef(entry) && entry.args?.LazyPixelRef) {\n const paintEvent = parsedTrace.ImagePainting.paintImageByDrawLazyPixelRef.get(entry.args.LazyPixelRef);\n return paintEvent ? getNonResolvedURL(paintEvent, parsedTrace) : null;\n }\n }\n\n // For all other events, try to see if the URL is provided, else return null.\n if (entry.args?.data?.url) {\n return entry.args.data.url as Platform.DevToolsPath.UrlString;\n }\n\n return null;\n}\n\nexport function makeUpEntity(entityCache: Map<string, Entity>, url: string): Entity|undefined {\n if (url.startsWith('chrome-extension:')) {\n return makeUpChromeExtensionEntity(entityCache, url);\n }\n\n // Make up an entity only for valid http/https URLs.\n if (!url.startsWith('http')) {\n return;\n }\n\n // NOTE: Lighthouse uses a tld database to determine the root domain, but here\n // we are using third party web's database. Doesn't really work for the case of classifying\n // domains 3pweb doesn't know about, so it will just give us a guess.\n const rootDomain = ThirdPartyWeb.ThirdPartyWeb.getRootDomain(url);\n if (!rootDomain) {\n return;\n }\n\n if (entityCache.has(rootDomain)) {\n return entityCache.get(rootDomain);\n }\n\n const unrecognizedEntity = {\n name: rootDomain,\n company: rootDomain,\n category: '',\n categories: [],\n domains: [rootDomain],\n averageExecutionTime: 0,\n totalExecutionTime: 0,\n totalOccurrences: 0,\n isUnrecognized: true,\n };\n entityCache.set(rootDomain, unrecognizedEntity);\n return unrecognizedEntity;\n}\n\nfunction getChromeExtensionOrigin(url: URL): string {\n return url.protocol + '//' + url.host;\n}\n\nfunction makeUpChromeExtensionEntity(entityCache: Map<string, Entity>, url: string, extensionName?: string): Entity {\n const parsedUrl = new URL(url);\n const origin = getChromeExtensionOrigin(parsedUrl);\n const host = new URL(origin).host;\n const name = extensionName || host;\n\n const cachedEntity = entityCache.get(origin);\n if (cachedEntity) {\n return cachedEntity;\n }\n\n const chromeExtensionEntity = {\n name,\n company: name,\n category: 'Chrome Extension',\n homepage: 'https://chromewebstore.google.com/detail/' + host,\n categories: [],\n domains: [],\n averageExecutionTime: 0,\n totalExecutionTime: 0,\n totalOccurrences: 0,\n };\n\n entityCache.set(origin, chromeExtensionEntity);\n return chromeExtensionEntity;\n}\n\nexport function updateEventForEntities(entry: Types.Events.Event, entityMappings: EntityMappings): void {\n const entity = getEntityForEvent(entry, entityMappings.createdEntityCache);\n if (entity) {\n if (entityMappings.eventsByEntity.has(entity)) {\n const events = entityMappings.eventsByEntity.get(entity) ?? [];\n events?.push(entry);\n } else {\n entityMappings.eventsByEntity.set(entity, [entry]);\n }\n entityMappings.entityByEvent.set(entry, entity);\n }\n}\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/helpers.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAG7B,OAAO,KAAK,aAAa,MAAM,yDAAyD,CAAC;AACzF,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAgB3C,MAAM,UAAU,iBAAiB,CAAC,KAAyB,EAAE,WAAgC;IAC3F,MAAM,GAAG,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO;IACT,CAAC;IACD,OAAO,eAAe,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,WAAgC;IAC3E,OAAO,aAAa,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AACtF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC7B,KAAyB,EAAE,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CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACzD,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;SAAM,CAAC;QACN,cAAc,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,cAAc,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport type * as Platform from '../../../core/platform/platform.js';\nimport * as ThirdPartyWeb from '../../../third_party/third-party-web/third-party-web.js';\nimport * as Types from '../types/types.js';\n\nimport type {ParsedTrace} from './types.js';\n\nexport type Entity = typeof ThirdPartyWeb.ThirdPartyWeb.entities[number];\n\nexport interface EntityMappings {\n createdEntityCache: Map<string, Entity>;\n entityByEvent: Map<Types.Events.Event, Entity>;\n /**\n * This holds the entities that had to be created, because they were not found using the\n * ThirdPartyWeb database.\n */\n eventsByEntity: Map<Entity, Types.Events.Event[]>;\n}\n\nexport function getEntityForEvent(event: Types.Events.Event, entityCache: Map<string, Entity>): Entity|undefined {\n const url = getNonResolvedURL(event);\n if (!url) {\n return;\n }\n return getEntityForUrl(url, entityCache);\n}\n\nexport function getEntityForUrl(url: string, entityCache: Map<string, Entity>): Entity|undefined {\n return ThirdPartyWeb.ThirdPartyWeb.getEntity(url) ?? makeUpEntity(entityCache, url);\n}\n\nexport function getNonResolvedURL(\n entry: Types.Events.Event, parsedTrace?: ParsedTrace): Platform.DevToolsPath.UrlString|null {\n if (Types.Events.isProfileCall(entry)) {\n return entry.callFrame.url as Platform.DevToolsPath.UrlString;\n }\n\n if (Types.Events.isSyntheticNetworkRequest(entry)) {\n return entry.args.data.url as Platform.DevToolsPath.UrlString;\n }\n\n if (entry.args?.data?.stackTrace && entry.args.data.stackTrace.length > 0) {\n return entry.args.data.stackTrace[0].url as Platform.DevToolsPath.UrlString;\n }\n\n // ParseHTML events store the URL under beginData, not data.\n if (Types.Events.isParseHTML(entry)) {\n return entry.args.beginData.url as Platform.DevToolsPath.UrlString;\n }\n\n if (parsedTrace) {\n // DecodeImage events use the URL from the relevant PaintImage event.\n if (Types.Events.isDecodeImage(entry)) {\n const paintEvent = parsedTrace.ImagePainting.paintImageForEvent.get(entry);\n return paintEvent ? getNonResolvedURL(paintEvent, parsedTrace) : null;\n }\n\n // DrawLazyPixelRef events use the URL from the relevant PaintImage event.\n if (Types.Events.isDrawLazyPixelRef(entry) && entry.args?.LazyPixelRef) {\n const paintEvent = parsedTrace.ImagePainting.paintImageByDrawLazyPixelRef.get(entry.args.LazyPixelRef);\n return paintEvent ? getNonResolvedURL(paintEvent, parsedTrace) : null;\n }\n }\n\n // For all other events, try to see if the URL is provided, else return null.\n if (entry.args?.data?.url) {\n return entry.args.data.url as Platform.DevToolsPath.UrlString;\n }\n\n return null;\n}\n\nexport function makeUpEntity(entityCache: Map<string, Entity>, url: string): Entity|undefined {\n if (url.startsWith('chrome-extension:')) {\n return makeUpChromeExtensionEntity(entityCache, url);\n }\n\n // Make up an entity only for valid http/https URLs.\n if (!url.startsWith('http')) {\n return;\n }\n\n // NOTE: Lighthouse uses a tld database to determine the root domain, but here\n // we are using third party web's database. Doesn't really work for the case of classifying\n // domains 3pweb doesn't know about, so it will just give us a guess.\n const rootDomain = ThirdPartyWeb.ThirdPartyWeb.getRootDomain(url);\n if (!rootDomain) {\n return;\n }\n\n if (entityCache.has(rootDomain)) {\n return entityCache.get(rootDomain);\n }\n\n const unrecognizedEntity = {\n name: rootDomain,\n company: rootDomain,\n category: '',\n categories: [],\n domains: [rootDomain],\n averageExecutionTime: 0,\n totalExecutionTime: 0,\n totalOccurrences: 0,\n isUnrecognized: true,\n };\n entityCache.set(rootDomain, unrecognizedEntity);\n return unrecognizedEntity;\n}\n\nfunction getChromeExtensionOrigin(url: URL): string {\n return url.protocol + '//' + url.host;\n}\n\nfunction makeUpChromeExtensionEntity(entityCache: Map<string, Entity>, url: string, extensionName?: string): Entity {\n const parsedUrl = new URL(url);\n const origin = getChromeExtensionOrigin(parsedUrl);\n const host = new URL(origin).host;\n const name = extensionName || host;\n\n const cachedEntity = entityCache.get(origin);\n if (cachedEntity) {\n return cachedEntity;\n }\n\n const chromeExtensionEntity = {\n name,\n company: name,\n category: 'Chrome Extension',\n homepage: 'https://chromewebstore.google.com/detail/' + host,\n categories: [],\n domains: [],\n averageExecutionTime: 0,\n totalExecutionTime: 0,\n totalOccurrences: 0,\n };\n\n entityCache.set(origin, chromeExtensionEntity);\n return chromeExtensionEntity;\n}\n\nexport function addEventToEntityMapping(event: Types.Events.Event, entityMappings: EntityMappings): void {\n const entity = getEntityForEvent(event, entityMappings.createdEntityCache);\n if (!entity) {\n return;\n }\n\n const events = entityMappings.eventsByEntity.get(entity);\n if (events) {\n events.push(event);\n } else {\n entityMappings.eventsByEntity.set(entity, [event]);\n }\n\n entityMappings.entityByEvent.set(event, entity);\n}\n"]}
@@ -3,7 +3,7 @@ import type * as ModelHandlers from './ModelHandlers.js';
3
3
  export interface Handler {
4
4
  reset(): void;
5
5
  handleEvent(data: {}): void;
6
- finalize(): Promise<void>;
6
+ finalize(options?: Types.Configuration.ParseOptions): Promise<void>;
7
7
  data(): unknown;
8
8
  deps?(): HandlerName[];
9
9
  handleUserConfig?(config: Types.Configuration.Configuration): void;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/types.ts"],"names":[],"mappings":"","sourcesContent":["\n// 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.\nimport type * as Types from './../types/types.js';\nimport type * as ModelHandlers from './ModelHandlers.js';\n\nexport interface Handler {\n reset(): void;\n handleEvent(data: {}): void;\n finalize(): Promise<void>;\n data(): unknown;\n deps?(): HandlerName[];\n handleUserConfig?(config: Types.Configuration.Configuration): void;\n}\nexport type HandlerName = keyof typeof ModelHandlers;\n\n// This type maps Handler names to the return type of their data\n// function. So, for example, if we are given an object with a key of 'foo'\n// and a value which is a TraceHandler containing a data() function that\n// returns a string, this type will be { foo: string }.\n//\n// This allows us to model the behavior of the TraceProcessor in the model,\n// which takes an object with Handlers as part of its config, and\n// which ultimately returns an object keyed off the names of the\n// Handlers, and with values that are derived from each\n// Handler's data function.\n//\n// So, concretely, we provide a Handler for calculating the #time\n// bounds of a trace called TraceBounds, whose data() function returns a\n// TraceWindow. The HandlerData, therefore, would determine that the\n// TraceProcessor would contain a key called 'TraceBounds' whose value is\n// a TraceWindow.\nexport type EnabledHandlerDataWithMeta<T extends {[key: string]: Handler}> = {\n // We allow the user to configure which handlers are created by passing them\n // in when constructing a model instance. However, we then ensure that the\n // Meta handler is added to that, as the Model relies on some of the data\n // from the Meta handler when creating the file. Therefore, this type\n // explicitly defines that the Meta data is present, before then extending it\n // with the index type to represent all the other handlers.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: Readonly<ReturnType<typeof ModelHandlers['Meta']['data']>>,\n}&{\n // For every key in the object, look up the Handler's data function\n // and use its return type as the value for the object.\n [K in keyof T]: Readonly<ReturnType<T[K]['data']>>;\n};\n\nexport type HandlersWithMeta<T extends {[key: string]: Handler}> = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: typeof ModelHandlers.Meta,\n}&{\n [K in keyof T]: T[K];\n};\n\n// Represents the final parsed data from all of the handlers. If you instantiate a\n// TraceProcessor with a subset of handlers, you should instead use\n// `EnabledHandlerDataWithMeta<>`.\nexport type ParsedTrace = Readonly<EnabledHandlerDataWithMeta<typeof ModelHandlers>>;\n\ntype DeepWriteable<T> = {\n -readonly[P in keyof T]: DeepWriteable<T[P]>\n};\nexport type ParsedTraceMutable = DeepWriteable<ParsedTrace>;\n\nexport type Handlers = typeof ModelHandlers;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/types.ts"],"names":[],"mappings":"","sourcesContent":["\n// 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.\nimport type * as Types from './../types/types.js';\nimport type * as ModelHandlers from './ModelHandlers.js';\n\nexport interface Handler {\n reset(): void;\n handleEvent(data: {}): void;\n finalize(options?: Types.Configuration.ParseOptions): Promise<void>;\n data(): unknown;\n deps?(): HandlerName[];\n handleUserConfig?(config: Types.Configuration.Configuration): void;\n}\n\nexport type HandlerName = keyof typeof ModelHandlers;\n\n// This type maps Handler names to the return type of their data\n// function. So, for example, if we are given an object with a key of 'foo'\n// and a value which is a TraceHandler containing a data() function that\n// returns a string, this type will be { foo: string }.\n//\n// This allows us to model the behavior of the TraceProcessor in the model,\n// which takes an object with Handlers as part of its config, and\n// which ultimately returns an object keyed off the names of the\n// Handlers, and with values that are derived from each\n// Handler's data function.\n//\n// So, concretely, we provide a Handler for calculating the #time\n// bounds of a trace called TraceBounds, whose data() function returns a\n// TraceWindow. The HandlerData, therefore, would determine that the\n// TraceProcessor would contain a key called 'TraceBounds' whose value is\n// a TraceWindow.\nexport type EnabledHandlerDataWithMeta<T extends {[key: string]: Handler}> = {\n // We allow the user to configure which handlers are created by passing them\n // in when constructing a model instance. However, we then ensure that the\n // Meta handler is added to that, as the Model relies on some of the data\n // from the Meta handler when creating the file. Therefore, this type\n // explicitly defines that the Meta data is present, before then extending it\n // with the index type to represent all the other handlers.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: Readonly<ReturnType<typeof ModelHandlers['Meta']['data']>>,\n}&{\n // For every key in the object, look up the Handler's data function\n // and use its return type as the value for the object.\n [K in keyof T]: Readonly<ReturnType<T[K]['data']>>;\n};\n\nexport type HandlersWithMeta<T extends {[key: string]: Handler}> = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: typeof ModelHandlers.Meta,\n}&{\n [K in keyof T]: T[K];\n};\n\n// Represents the final parsed data from all of the handlers. If you instantiate a\n// TraceProcessor with a subset of handlers, you should instead use\n// `EnabledHandlerDataWithMeta<>`.\nexport type ParsedTrace = Readonly<EnabledHandlerDataWithMeta<typeof ModelHandlers>>;\n\ntype DeepWriteable<T> = {\n -readonly[P in keyof T]: DeepWriteable<T[P]>\n};\nexport type ParsedTraceMutable = DeepWriteable<ParsedTrace>;\n\nexport type Handlers = typeof ModelHandlers;\n"]}