devtools-tracing 1.0.0

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 (397) hide show
  1. package/generate.ts +643 -0
  2. package/index.ts +16 -0
  3. package/lib/front_end/core/common/App.ts +7 -0
  4. package/lib/front_end/core/common/AppProvider.ts +32 -0
  5. package/lib/front_end/core/common/Base64.ts +47 -0
  6. package/lib/front_end/core/common/CharacterIdMap.ts +30 -0
  7. package/lib/front_end/core/common/Color.ts +2506 -0
  8. package/lib/front_end/core/common/ColorConverter.ts +402 -0
  9. package/lib/front_end/core/common/ColorUtils.ts +252 -0
  10. package/lib/front_end/core/common/Console.ts +114 -0
  11. package/lib/front_end/core/common/Debouncer.ts +15 -0
  12. package/lib/front_end/core/common/EventTarget.ts +52 -0
  13. package/lib/front_end/core/common/Gzip.ts +74 -0
  14. package/lib/front_end/core/common/JavaScriptMetaData.ts +29 -0
  15. package/lib/front_end/core/common/Lazy.ts +31 -0
  16. package/lib/front_end/core/common/Linkifier.ts +55 -0
  17. package/lib/front_end/core/common/MapWithDefault.ts +26 -0
  18. package/lib/front_end/core/common/Mutex.ts +55 -0
  19. package/lib/front_end/core/common/Object.ts +145 -0
  20. package/lib/front_end/core/common/ParsedURL.ts +554 -0
  21. package/lib/front_end/core/common/Progress.ts +180 -0
  22. package/lib/front_end/core/common/QueryParamHandler.ts +7 -0
  23. package/lib/front_end/core/common/ResolverBase.ts +85 -0
  24. package/lib/front_end/core/common/ResourceType.ts +588 -0
  25. package/lib/front_end/core/common/ReturnToPanel.ts +17 -0
  26. package/lib/front_end/core/common/Revealer.ts +192 -0
  27. package/lib/front_end/core/common/Runnable.ts +41 -0
  28. package/lib/front_end/core/common/SegmentedRange.ts +87 -0
  29. package/lib/front_end/core/common/SettingRegistration.ts +339 -0
  30. package/lib/front_end/core/common/Settings.ts +1497 -0
  31. package/lib/front_end/core/common/SimpleHistoryManager.ts +124 -0
  32. package/lib/front_end/core/common/StringOutputStream.ts +26 -0
  33. package/lib/front_end/core/common/TextDictionary.ts +48 -0
  34. package/lib/front_end/core/common/Throttler.ts +99 -0
  35. package/lib/front_end/core/common/Trie.ts +152 -0
  36. package/lib/front_end/core/common/Worker.ts +60 -0
  37. package/lib/front_end/core/common/common.ts +81 -0
  38. package/lib/front_end/core/host/AidaClient.ts +733 -0
  39. package/lib/front_end/core/host/GdpClient.ts +316 -0
  40. package/lib/front_end/core/host/InspectorFrontendHost.ts +648 -0
  41. package/lib/front_end/core/host/InspectorFrontendHostAPI.ts +551 -0
  42. package/lib/front_end/core/host/Platform.ts +76 -0
  43. package/lib/front_end/core/host/ResourceLoader.ts +282 -0
  44. package/lib/front_end/core/host/UserMetrics.ts +1230 -0
  45. package/lib/front_end/core/host/host.ts +23 -0
  46. package/lib/front_end/core/i18n/ByteUtilities.ts +82 -0
  47. package/lib/front_end/core/i18n/DevToolsLocale.ts +87 -0
  48. package/lib/front_end/core/i18n/NumberFormatter.ts +82 -0
  49. package/lib/front_end/core/i18n/i18n.ts +17 -0
  50. package/lib/front_end/core/i18n/i18nImpl.ts +204 -0
  51. package/lib/front_end/core/i18n/i18nTypes.ts +10 -0
  52. package/lib/front_end/core/i18n/locales.js +14 -0
  53. package/lib/front_end/core/i18n/time-utilities.ts +174 -0
  54. package/lib/front_end/core/platform/ArrayUtilities.ts +271 -0
  55. package/lib/front_end/core/platform/Brand.ts +23 -0
  56. package/lib/front_end/core/platform/Constructor.ts +10 -0
  57. package/lib/front_end/core/platform/DOMUtilities.ts +138 -0
  58. package/lib/front_end/core/platform/DateUtilities.ts +15 -0
  59. package/lib/front_end/core/platform/DevToolsPath.ts +53 -0
  60. package/lib/front_end/core/platform/KeyboardUtilities.ts +38 -0
  61. package/lib/front_end/core/platform/MapUtilities.ts +95 -0
  62. package/lib/front_end/core/platform/MimeType.ts +175 -0
  63. package/lib/front_end/core/platform/NumberUtilities.ts +80 -0
  64. package/lib/front_end/core/platform/StringUtilities.ts +588 -0
  65. package/lib/front_end/core/platform/Timing.ts +17 -0
  66. package/lib/front_end/core/platform/TypedArrayUtilities.ts +189 -0
  67. package/lib/front_end/core/platform/TypescriptUtilities.ts +86 -0
  68. package/lib/front_end/core/platform/UIString.ts +39 -0
  69. package/lib/front_end/core/platform/UserVisibleError.ts +28 -0
  70. package/lib/front_end/core/platform/platform.ts +45 -0
  71. package/lib/front_end/core/protocol_client/ConnectionTransport.ts +26 -0
  72. package/lib/front_end/core/protocol_client/InspectorBackend.ts +1050 -0
  73. package/lib/front_end/core/protocol_client/NodeURL.ts +42 -0
  74. package/lib/front_end/core/protocol_client/protocol_client.ts +13 -0
  75. package/lib/front_end/core/root/Runtime.ts +609 -0
  76. package/lib/front_end/core/root/root.ts +6 -0
  77. package/lib/front_end/core/sdk/AccessibilityModel.ts +353 -0
  78. package/lib/front_end/core/sdk/AnimationModel.ts +1041 -0
  79. package/lib/front_end/core/sdk/AutofillModel.ts +184 -0
  80. package/lib/front_end/core/sdk/CPUProfilerModel.ts +148 -0
  81. package/lib/front_end/core/sdk/CPUThrottlingManager.ts +282 -0
  82. package/lib/front_end/core/sdk/CSSContainerQuery.ts +139 -0
  83. package/lib/front_end/core/sdk/CSSFontFace.ts +40 -0
  84. package/lib/front_end/core/sdk/CSSLayer.ts +30 -0
  85. package/lib/front_end/core/sdk/CSSMatchedStyles.ts +1646 -0
  86. package/lib/front_end/core/sdk/CSSMedia.ts +121 -0
  87. package/lib/front_end/core/sdk/CSSMetadata.ts +1647 -0
  88. package/lib/front_end/core/sdk/CSSModel.ts +1128 -0
  89. package/lib/front_end/core/sdk/CSSProperty.ts +384 -0
  90. package/lib/front_end/core/sdk/CSSPropertyParser.ts +681 -0
  91. package/lib/front_end/core/sdk/CSSPropertyParserMatchers.ts +1395 -0
  92. package/lib/front_end/core/sdk/CSSQuery.ts +72 -0
  93. package/lib/front_end/core/sdk/CSSRule.ts +465 -0
  94. package/lib/front_end/core/sdk/CSSScope.ts +30 -0
  95. package/lib/front_end/core/sdk/CSSStartingStyle.ts +29 -0
  96. package/lib/front_end/core/sdk/CSSStyleDeclaration.ts +313 -0
  97. package/lib/front_end/core/sdk/CSSStyleSheetHeader.ts +196 -0
  98. package/lib/front_end/core/sdk/CSSSupports.ts +33 -0
  99. package/lib/front_end/core/sdk/CategorizedBreakpoint.ts +64 -0
  100. package/lib/front_end/core/sdk/ChildTargetManager.ts +314 -0
  101. package/lib/front_end/core/sdk/CompilerSourceMappingContentProvider.ts +62 -0
  102. package/lib/front_end/core/sdk/Connections.ts +293 -0
  103. package/lib/front_end/core/sdk/ConsoleModel.ts +808 -0
  104. package/lib/front_end/core/sdk/ConsoleModelTypes.ts +15 -0
  105. package/lib/front_end/core/sdk/Cookie.ts +319 -0
  106. package/lib/front_end/core/sdk/CookieModel.ts +239 -0
  107. package/lib/front_end/core/sdk/CookieParser.ts +185 -0
  108. package/lib/front_end/core/sdk/DOMDebuggerModel.ts +787 -0
  109. package/lib/front_end/core/sdk/DOMModel.ts +1961 -0
  110. package/lib/front_end/core/sdk/DebuggerModel.ts +1605 -0
  111. package/lib/front_end/core/sdk/EmulationModel.ts +648 -0
  112. package/lib/front_end/core/sdk/EnhancedTracesParser.ts +515 -0
  113. package/lib/front_end/core/sdk/EventBreakpointsModel.ts +183 -0
  114. package/lib/front_end/core/sdk/FrameAssociated.ts +11 -0
  115. package/lib/front_end/core/sdk/FrameManager.ts +259 -0
  116. package/lib/front_end/core/sdk/HeapProfilerModel.ts +225 -0
  117. package/lib/front_end/core/sdk/HttpReasonPhraseStrings.ts +77 -0
  118. package/lib/front_end/core/sdk/IOModel.ts +91 -0
  119. package/lib/front_end/core/sdk/IsolateManager.ts +257 -0
  120. package/lib/front_end/core/sdk/IssuesModel.ts +70 -0
  121. package/lib/front_end/core/sdk/LayerTreeBase.ts +169 -0
  122. package/lib/front_end/core/sdk/LogModel.ts +56 -0
  123. package/lib/front_end/core/sdk/NetworkManager.ts +2823 -0
  124. package/lib/front_end/core/sdk/NetworkRequest.ts +2253 -0
  125. package/lib/front_end/core/sdk/OverlayColorGenerator.ts +52 -0
  126. package/lib/front_end/core/sdk/OverlayModel.ts +1011 -0
  127. package/lib/front_end/core/sdk/OverlayPersistentHighlighter.ts +522 -0
  128. package/lib/front_end/core/sdk/PageLoad.ts +35 -0
  129. package/lib/front_end/core/sdk/PageResourceLoader.ts +435 -0
  130. package/lib/front_end/core/sdk/PaintProfiler.ts +110 -0
  131. package/lib/front_end/core/sdk/PerformanceMetricsModel.ts +84 -0
  132. package/lib/front_end/core/sdk/PreloadingModel.ts +863 -0
  133. package/lib/front_end/core/sdk/RehydratingConnection.ts +386 -0
  134. package/lib/front_end/core/sdk/RehydratingObject.ts +66 -0
  135. package/lib/front_end/core/sdk/RemoteObject.ts +1160 -0
  136. package/lib/front_end/core/sdk/Resource.ts +232 -0
  137. package/lib/front_end/core/sdk/ResourceTreeModel.ts +1160 -0
  138. package/lib/front_end/core/sdk/RuntimeModel.ts +732 -0
  139. package/lib/front_end/core/sdk/SDKModel.ts +65 -0
  140. package/lib/front_end/core/sdk/ScopeTreeCache.ts +45 -0
  141. package/lib/front_end/core/sdk/ScreenCaptureModel.ts +255 -0
  142. package/lib/front_end/core/sdk/Script.ts +534 -0
  143. package/lib/front_end/core/sdk/SecurityOriginManager.ts +76 -0
  144. package/lib/front_end/core/sdk/ServerSentEvents.ts +80 -0
  145. package/lib/front_end/core/sdk/ServerSentEventsProtocol.ts +122 -0
  146. package/lib/front_end/core/sdk/ServerTiming.ts +260 -0
  147. package/lib/front_end/core/sdk/ServiceWorkerCacheModel.ts +377 -0
  148. package/lib/front_end/core/sdk/ServiceWorkerManager.ts +605 -0
  149. package/lib/front_end/core/sdk/SourceMap.ts +867 -0
  150. package/lib/front_end/core/sdk/SourceMapCache.ts +54 -0
  151. package/lib/front_end/core/sdk/SourceMapFunctionRanges.ts +156 -0
  152. package/lib/front_end/core/sdk/SourceMapManager.ts +239 -0
  153. package/lib/front_end/core/sdk/SourceMapScopeChainEntry.ts +189 -0
  154. package/lib/front_end/core/sdk/SourceMapScopesInfo.ts +508 -0
  155. package/lib/front_end/core/sdk/StorageBucketsModel.ts +204 -0
  156. package/lib/front_end/core/sdk/StorageKeyManager.ts +98 -0
  157. package/lib/front_end/core/sdk/Target.ts +332 -0
  158. package/lib/front_end/core/sdk/TargetManager.ts +453 -0
  159. package/lib/front_end/core/sdk/TraceObject.ts +61 -0
  160. package/lib/front_end/core/sdk/WebAuthnModel.ts +104 -0
  161. package/lib/front_end/core/sdk/sdk.ts +174 -0
  162. package/lib/front_end/entrypoints/formatter_worker/FormatterActions.ts +59 -0
  163. package/lib/front_end/generated/InspectorBackendCommands.js +1617 -0
  164. package/lib/front_end/generated/SupportedCSSProperties.js +7512 -0
  165. package/lib/front_end/generated/protocol-proxy-api.d.ts +5022 -0
  166. package/lib/front_end/generated/protocol.ts +22014 -0
  167. package/lib/front_end/models/cpu_profile/CPUProfileDataModel.ts +571 -0
  168. package/lib/front_end/models/cpu_profile/ProfileTreeModel.ts +103 -0
  169. package/lib/front_end/models/cpu_profile/cpu_profile.ts +11 -0
  170. package/lib/front_end/models/formatter/FormatterWorkerPool.ts +219 -0
  171. package/lib/front_end/models/formatter/ScriptFormatter.ts +112 -0
  172. package/lib/front_end/models/formatter/formatter.ts +8 -0
  173. package/lib/front_end/models/text_utils/CodeMirrorUtils.ts +37 -0
  174. package/lib/front_end/models/text_utils/ContentData.ts +199 -0
  175. package/lib/front_end/models/text_utils/ContentProvider.ts +68 -0
  176. package/lib/front_end/models/text_utils/StaticContentProvider.ts +49 -0
  177. package/lib/front_end/models/text_utils/StreamingContentData.ts +108 -0
  178. package/lib/front_end/models/text_utils/Text.ts +90 -0
  179. package/lib/front_end/models/text_utils/TextCursor.ts +44 -0
  180. package/lib/front_end/models/text_utils/TextRange.ts +266 -0
  181. package/lib/front_end/models/text_utils/TextUtils.ts +401 -0
  182. package/lib/front_end/models/text_utils/WasmDisassembly.ts +87 -0
  183. package/lib/front_end/models/text_utils/text_utils.ts +27 -0
  184. package/lib/front_end/models/trace/EntityMapper.ts +141 -0
  185. package/lib/front_end/models/trace/EventsSerializer.ts +101 -0
  186. package/lib/front_end/models/trace/LanternComputationData.ts +438 -0
  187. package/lib/front_end/models/trace/ModelImpl.ts +236 -0
  188. package/lib/front_end/models/trace/Name.ts +136 -0
  189. package/lib/front_end/models/trace/Processor.ts +652 -0
  190. package/lib/front_end/models/trace/Styles.ts +1138 -0
  191. package/lib/front_end/models/trace/extras/FilmStrip.ts +78 -0
  192. package/lib/front_end/models/trace/extras/MainThreadActivity.ts +86 -0
  193. package/lib/front_end/models/trace/extras/ScriptDuplication.ts +236 -0
  194. package/lib/front_end/models/trace/extras/StackTraceForEvent.ts +203 -0
  195. package/lib/front_end/models/trace/extras/ThirdParties.ts +164 -0
  196. package/lib/front_end/models/trace/extras/TraceFilter.ts +62 -0
  197. package/lib/front_end/models/trace/extras/TraceTree.ts +701 -0
  198. package/lib/front_end/models/trace/extras/extras.ts +11 -0
  199. package/lib/front_end/models/trace/handlers/AnimationFramesHandler.ts +128 -0
  200. package/lib/front_end/models/trace/handlers/AnimationHandler.ts +36 -0
  201. package/lib/front_end/models/trace/handlers/AsyncJSCallsHandler.ts +239 -0
  202. package/lib/front_end/models/trace/handlers/AuctionWorkletsHandler.ts +183 -0
  203. package/lib/front_end/models/trace/handlers/DOMStatsHandler.ts +31 -0
  204. package/lib/front_end/models/trace/handlers/ExtensionTraceDataHandler.ts +306 -0
  205. package/lib/front_end/models/trace/handlers/FlowsHandler.ts +175 -0
  206. package/lib/front_end/models/trace/handlers/FramesHandler.ts +571 -0
  207. package/lib/front_end/models/trace/handlers/GPUHandler.ts +50 -0
  208. package/lib/front_end/models/trace/handlers/ImagePaintingHandler.ts +183 -0
  209. package/lib/front_end/models/trace/handlers/InitiatorsHandler.ts +193 -0
  210. package/lib/front_end/models/trace/handlers/InvalidationsHandler.ts +168 -0
  211. package/lib/front_end/models/trace/handlers/LargestImagePaintHandler.ts +109 -0
  212. package/lib/front_end/models/trace/handlers/LargestTextPaintHandler.ts +35 -0
  213. package/lib/front_end/models/trace/handlers/LayerTreeHandler.ts +123 -0
  214. package/lib/front_end/models/trace/handlers/LayoutShiftsHandler.ts +573 -0
  215. package/lib/front_end/models/trace/handlers/MemoryHandler.ts +31 -0
  216. package/lib/front_end/models/trace/handlers/MetaHandler.ts +525 -0
  217. package/lib/front_end/models/trace/handlers/ModelHandlers.ts +34 -0
  218. package/lib/front_end/models/trace/handlers/NetworkRequestsHandler.ts +672 -0
  219. package/lib/front_end/models/trace/handlers/PageFramesHandler.ts +52 -0
  220. package/lib/front_end/models/trace/handlers/PageLoadMetricsHandler.ts +460 -0
  221. package/lib/front_end/models/trace/handlers/RendererHandler.ts +428 -0
  222. package/lib/front_end/models/trace/handlers/SamplesHandler.ts +271 -0
  223. package/lib/front_end/models/trace/handlers/ScreenshotsHandler.ts +122 -0
  224. package/lib/front_end/models/trace/handlers/ScriptsHandler.ts +336 -0
  225. package/lib/front_end/models/trace/handlers/SelectorStatsHandler.ts +110 -0
  226. package/lib/front_end/models/trace/handlers/Threads.ts +139 -0
  227. package/lib/front_end/models/trace/handlers/UserInteractionsHandler.ts +400 -0
  228. package/lib/front_end/models/trace/handlers/UserTimingsHandler.ts +233 -0
  229. package/lib/front_end/models/trace/handlers/WarningsHandler.ts +162 -0
  230. package/lib/front_end/models/trace/handlers/WorkersHandler.ts +45 -0
  231. package/lib/front_end/models/trace/handlers/handlers.ts +8 -0
  232. package/lib/front_end/models/trace/handlers/helpers.ts +196 -0
  233. package/lib/front_end/models/trace/handlers/types.ts +75 -0
  234. package/lib/front_end/models/trace/helpers/Extensions.ts +54 -0
  235. package/lib/front_end/models/trace/helpers/Network.ts +129 -0
  236. package/lib/front_end/models/trace/helpers/SamplesIntegrator.ts +544 -0
  237. package/lib/front_end/models/trace/helpers/SyntheticEvents.ts +87 -0
  238. package/lib/front_end/models/trace/helpers/Timing.ts +248 -0
  239. package/lib/front_end/models/trace/helpers/Trace.ts +928 -0
  240. package/lib/front_end/models/trace/helpers/TreeHelpers.ts +320 -0
  241. package/lib/front_end/models/trace/helpers/helpers.ts +11 -0
  242. package/lib/front_end/models/trace/insights/CLSCulprits.ts +668 -0
  243. package/lib/front_end/models/trace/insights/Cache.ts +269 -0
  244. package/lib/front_end/models/trace/insights/Common.ts +453 -0
  245. package/lib/front_end/models/trace/insights/DOMSize.ts +223 -0
  246. package/lib/front_end/models/trace/insights/DocumentLatency.ts +319 -0
  247. package/lib/front_end/models/trace/insights/DuplicatedJavaScript.ts +126 -0
  248. package/lib/front_end/models/trace/insights/FontDisplay.ts +119 -0
  249. package/lib/front_end/models/trace/insights/ForcedReflow.ts +220 -0
  250. package/lib/front_end/models/trace/insights/INPBreakdown.ts +171 -0
  251. package/lib/front_end/models/trace/insights/ImageDelivery.ts +348 -0
  252. package/lib/front_end/models/trace/insights/LCPBreakdown.ts +268 -0
  253. package/lib/front_end/models/trace/insights/LCPDiscovery.ts +237 -0
  254. package/lib/front_end/models/trace/insights/LegacyJavaScript.ts +138 -0
  255. package/lib/front_end/models/trace/insights/Models.ts +22 -0
  256. package/lib/front_end/models/trace/insights/ModernHTTP.ts +257 -0
  257. package/lib/front_end/models/trace/insights/NetworkDependencyTree.ts +726 -0
  258. package/lib/front_end/models/trace/insights/RenderBlocking.ts +257 -0
  259. package/lib/front_end/models/trace/insights/SlowCSSSelector.ts +175 -0
  260. package/lib/front_end/models/trace/insights/Statistics.ts +101 -0
  261. package/lib/front_end/models/trace/insights/ThirdParties.ts +130 -0
  262. package/lib/front_end/models/trace/insights/Viewport.ts +138 -0
  263. package/lib/front_end/models/trace/insights/insights.ts +10 -0
  264. package/lib/front_end/models/trace/insights/types.ts +157 -0
  265. package/lib/front_end/models/trace/lantern/core/LanternError.ts +7 -0
  266. package/lib/front_end/models/trace/lantern/core/NetworkAnalyzer.ts +619 -0
  267. package/lib/front_end/models/trace/lantern/core/core.ts +6 -0
  268. package/lib/front_end/models/trace/lantern/graph/BaseNode.ts +345 -0
  269. package/lib/front_end/models/trace/lantern/graph/CPUNode.ts +80 -0
  270. package/lib/front_end/models/trace/lantern/graph/NetworkNode.ts +101 -0
  271. package/lib/front_end/models/trace/lantern/graph/PageDependencyGraph.ts +636 -0
  272. package/lib/front_end/models/trace/lantern/graph/graph.ts +8 -0
  273. package/lib/front_end/models/trace/lantern/lantern.ts +17 -0
  274. package/lib/front_end/models/trace/lantern/metrics/FirstContentfulPaint.ts +187 -0
  275. package/lib/front_end/models/trace/lantern/metrics/Interactive.ts +88 -0
  276. package/lib/front_end/models/trace/lantern/metrics/LargestContentfulPaint.ts +92 -0
  277. package/lib/front_end/models/trace/lantern/metrics/MaxPotentialFID.ts +72 -0
  278. package/lib/front_end/models/trace/lantern/metrics/Metric.ts +126 -0
  279. package/lib/front_end/models/trace/lantern/metrics/SpeedIndex.ts +126 -0
  280. package/lib/front_end/models/trace/lantern/metrics/TBTUtils.ts +82 -0
  281. package/lib/front_end/models/trace/lantern/metrics/TotalBlockingTime.ts +112 -0
  282. package/lib/front_end/models/trace/lantern/metrics/metrics.ts +12 -0
  283. package/lib/front_end/models/trace/lantern/simulation/ConnectionPool.ts +150 -0
  284. package/lib/front_end/models/trace/lantern/simulation/Constants.ts +46 -0
  285. package/lib/front_end/models/trace/lantern/simulation/DNSCache.ts +61 -0
  286. package/lib/front_end/models/trace/lantern/simulation/SimulationTimingMap.ts +196 -0
  287. package/lib/front_end/models/trace/lantern/simulation/Simulator.ts +556 -0
  288. package/lib/front_end/models/trace/lantern/simulation/TCPConnection.ts +192 -0
  289. package/lib/front_end/models/trace/lantern/simulation/simulation.ts +10 -0
  290. package/lib/front_end/models/trace/lantern/types/Lantern.ts +220 -0
  291. package/lib/front_end/models/trace/lantern/types/types.ts +5 -0
  292. package/lib/front_end/models/trace/trace.ts +33 -0
  293. package/lib/front_end/models/trace/types/Configuration.ts +110 -0
  294. package/lib/front_end/models/trace/types/Extensions.ts +136 -0
  295. package/lib/front_end/models/trace/types/File.ts +281 -0
  296. package/lib/front_end/models/trace/types/Overlays.ts +138 -0
  297. package/lib/front_end/models/trace/types/Timing.ts +30 -0
  298. package/lib/front_end/models/trace/types/TraceEvents.ts +3277 -0
  299. package/lib/front_end/models/trace/types/types.ts +10 -0
  300. package/lib/front_end/third_party/i18n/LICENSE +202 -0
  301. package/lib/front_end/third_party/i18n/README.chromium +15 -0
  302. package/lib/front_end/third_party/i18n/i18n-impl.ts +61 -0
  303. package/lib/front_end/third_party/i18n/i18n.ts +11 -0
  304. package/lib/front_end/third_party/i18n/localized-string-set.ts +129 -0
  305. package/lib/front_end/third_party/intl-messageformat/LICENSE +33 -0
  306. package/lib/front_end/third_party/intl-messageformat/README.chromium +24 -0
  307. package/lib/front_end/third_party/intl-messageformat/intl-messageformat-tsconfig.json +16 -0
  308. package/lib/front_end/third_party/intl-messageformat/intl-messageformat.ts +6 -0
  309. package/lib/front_end/third_party/intl-messageformat/package/LICENSE.md +33 -0
  310. package/lib/front_end/third_party/intl-messageformat/package/README.md +3 -0
  311. package/lib/front_end/third_party/intl-messageformat/package/index.d.ts +6 -0
  312. package/lib/front_end/third_party/intl-messageformat/package/index.d.ts.map +1 -0
  313. package/lib/front_end/third_party/intl-messageformat/package/index.js +13 -0
  314. package/lib/front_end/third_party/intl-messageformat/package/intl-messageformat.esm.d.ts +5 -0
  315. package/lib/front_end/third_party/intl-messageformat/package/intl-messageformat.esm.js +1710 -0
  316. package/lib/front_end/third_party/intl-messageformat/package/intl-messageformat.iife.js +1815 -0
  317. package/lib/front_end/third_party/intl-messageformat/package/lib/index.d.ts +6 -0
  318. package/lib/front_end/third_party/intl-messageformat/package/lib/index.d.ts.map +1 -0
  319. package/lib/front_end/third_party/intl-messageformat/package/lib/index.js +10 -0
  320. package/lib/front_end/third_party/intl-messageformat/package/lib/src/core.d.ts +34 -0
  321. package/lib/front_end/third_party/intl-messageformat/package/lib/src/core.d.ts.map +1 -0
  322. package/lib/front_end/third_party/intl-messageformat/package/lib/src/core.js +229 -0
  323. package/lib/front_end/third_party/intl-messageformat/package/lib/src/error.d.ts +28 -0
  324. package/lib/front_end/third_party/intl-messageformat/package/lib/src/error.d.ts.map +1 -0
  325. package/lib/front_end/third_party/intl-messageformat/package/lib/src/error.js +48 -0
  326. package/lib/front_end/third_party/intl-messageformat/package/lib/src/formatters.d.ts +34 -0
  327. package/lib/front_end/third_party/intl-messageformat/package/lib/src/formatters.d.ts.map +1 -0
  328. package/lib/front_end/third_party/intl-messageformat/package/lib/src/formatters.js +179 -0
  329. package/lib/front_end/third_party/intl-messageformat/package/package.json +42 -0
  330. package/lib/front_end/third_party/intl-messageformat/package/src/core.d.ts +34 -0
  331. package/lib/front_end/third_party/intl-messageformat/package/src/core.d.ts.map +1 -0
  332. package/lib/front_end/third_party/intl-messageformat/package/src/core.js +230 -0
  333. package/lib/front_end/third_party/intl-messageformat/package/src/error.d.ts +28 -0
  334. package/lib/front_end/third_party/intl-messageformat/package/src/error.d.ts.map +1 -0
  335. package/lib/front_end/third_party/intl-messageformat/package/src/error.js +51 -0
  336. package/lib/front_end/third_party/intl-messageformat/package/src/formatters.d.ts +34 -0
  337. package/lib/front_end/third_party/intl-messageformat/package/src/formatters.d.ts.map +1 -0
  338. package/lib/front_end/third_party/intl-messageformat/package/src/formatters.js +182 -0
  339. package/lib/front_end/third_party/intl-messageformat/package/src/icu-messageformat-parser/error.d.ts +79 -0
  340. package/lib/front_end/third_party/intl-messageformat/package/src/icu-messageformat-parser/index.d.ts +15 -0
  341. package/lib/front_end/third_party/intl-messageformat/package/src/icu-messageformat-parser/parser.d.ts +153 -0
  342. package/lib/front_end/third_party/intl-messageformat/package/src/icu-messageformat-parser/types.d.ts +139 -0
  343. package/lib/front_end/third_party/legacy-javascript/LICENSE +202 -0
  344. package/lib/front_end/third_party/legacy-javascript/README.chromium +13 -0
  345. package/lib/front_end/third_party/legacy-javascript/legacy-javascript-tsconfig.json +8 -0
  346. package/lib/front_end/third_party/legacy-javascript/legacy-javascript.ts +3 -0
  347. package/lib/front_end/third_party/legacy-javascript/lib/legacy-javascript.d.ts +18 -0
  348. package/lib/front_end/third_party/legacy-javascript/lib/legacy-javascript.js +943 -0
  349. package/lib/front_end/third_party/legacy-javascript/package.json +8 -0
  350. package/lib/front_end/third_party/legacy-javascript/rebuild.sh +9 -0
  351. package/lib/front_end/third_party/third-party-web/LICENSE +20 -0
  352. package/lib/front_end/third_party/third-party-web/README.chromium +13 -0
  353. package/lib/front_end/third_party/third-party-web/lib/nostats-subset.d.ts +2 -0
  354. package/lib/front_end/third_party/third-party-web/lib/nostats-subset.js +149 -0
  355. package/lib/front_end/third_party/third-party-web/package/LICENSE +20 -0
  356. package/lib/front_end/third_party/third-party-web/package/README.md +929 -0
  357. package/lib/front_end/third_party/third-party-web/package/dist/entities-httparchive-nostats.json +1 -0
  358. package/lib/front_end/third_party/third-party-web/package/dist/entities-httparchive.json +1 -0
  359. package/lib/front_end/third_party/third-party-web/package/dist/entities-nostats.json +1 -0
  360. package/lib/front_end/third_party/third-party-web/package/dist/entities.json +1 -0
  361. package/lib/front_end/third_party/third-party-web/package/facades.md +46 -0
  362. package/lib/front_end/third_party/third-party-web/package/httparchive-nostats-subset.d.ts +1 -0
  363. package/lib/front_end/third_party/third-party-web/package/httparchive-nostats-subset.js +1 -0
  364. package/lib/front_end/third_party/third-party-web/package/httparchive-subset.d.ts +1 -0
  365. package/lib/front_end/third_party/third-party-web/package/httparchive-subset.js +1 -0
  366. package/lib/front_end/third_party/third-party-web/package/lib/__snapshots__/index.test.js.snap +1006 -0
  367. package/lib/front_end/third_party/third-party-web/package/lib/create-entity-finder-api.js +139 -0
  368. package/lib/front_end/third_party/third-party-web/package/lib/create-entity-finder-api.test.js +44 -0
  369. package/lib/front_end/third_party/third-party-web/package/lib/entities.test.js +27 -0
  370. package/lib/front_end/third_party/third-party-web/package/lib/index.d.ts +34 -0
  371. package/lib/front_end/third_party/third-party-web/package/lib/index.js +3 -0
  372. package/lib/front_end/third_party/third-party-web/package/lib/index.test.js +246 -0
  373. package/lib/front_end/third_party/third-party-web/package/lib/markdown/faqs.partial.md +36 -0
  374. package/lib/front_end/third_party/third-party-web/package/lib/markdown/goals.partial.md +9 -0
  375. package/lib/front_end/third_party/third-party-web/package/lib/markdown/methodology.partial.md +5 -0
  376. package/lib/front_end/third_party/third-party-web/package/lib/markdown/template.md +151 -0
  377. package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2019-02-01.md +1 -0
  378. package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2019-03-01.md +1 -0
  379. package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2019-05-06.md +1 -0
  380. package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2019-05-13.md +14 -0
  381. package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2021-01-01.md +1 -0
  382. package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2024-07-01.md +3 -0
  383. package/lib/front_end/third_party/third-party-web/package/lib/subsets/httparchive-nostats.d.ts +1 -0
  384. package/lib/front_end/third_party/third-party-web/package/lib/subsets/httparchive-nostats.js +3 -0
  385. package/lib/front_end/third_party/third-party-web/package/lib/subsets/httparchive.d.ts +1 -0
  386. package/lib/front_end/third_party/third-party-web/package/lib/subsets/httparchive.js +3 -0
  387. package/lib/front_end/third_party/third-party-web/package/lib/subsets/nostats.d.ts +1 -0
  388. package/lib/front_end/third_party/third-party-web/package/lib/subsets/nostats.js +3 -0
  389. package/lib/front_end/third_party/third-party-web/package/nostats-subset.d.ts +1 -0
  390. package/lib/front_end/third_party/third-party-web/package/nostats-subset.js +1 -0
  391. package/lib/front_end/third_party/third-party-web/package/package.json +46 -0
  392. package/lib/front_end/third_party/third-party-web/package.json +8 -0
  393. package/lib/front_end/third_party/third-party-web/rebuild.sh +13 -0
  394. package/lib/front_end/third_party/third-party-web/third-party-web-tsconfig.json +8 -0
  395. package/lib/front_end/third_party/third-party-web/third-party-web.ts +3 -0
  396. package/package.json +24 -0
  397. package/patches/chrome-devtools-frontend+1.0.1533544.patch +187 -0
@@ -0,0 +1,428 @@
1
+ // Copyright 2022 The Chromium Authors
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import * as Platform from '../../../core/platform/platform.js';
6
+ import * as Helpers from '../helpers/helpers.js';
7
+ import * as Types from '../types/types.js';
8
+
9
+ import {data as auctionWorkletsData} from './AuctionWorkletsHandler.js';
10
+ import * as HandlerHelpers from './helpers.js';
11
+ import {data as metaHandlerData, type FrameProcessData} from './MetaHandler.js';
12
+ import {data as networkRequestHandlerData} from './NetworkRequestsHandler.js';
13
+ import {data as samplesHandlerData} from './SamplesHandler.js';
14
+ import type {HandlerName} from './types.js';
15
+
16
+ /**
17
+ * This handler builds the hierarchy of trace events and profile calls
18
+ * on each thread on each process.
19
+ *
20
+ * Throughout the code, trace events and profile calls are referred to
21
+ * as "entries", but note they are different types of data. Trace events
22
+ * come directly from the backend and it's the type the engine commonly
23
+ * refers to. Profile calls on the other hand are built in the frontend,
24
+ * and, for compatibility purposes, typed as an extension to the trace
25
+ * event type.
26
+ */
27
+
28
+ let processes = new Map<Types.Events.ProcessID, RendererProcess>();
29
+
30
+ let entityMappings: HandlerHelpers.EntityMappings = {
31
+ eventsByEntity: new Map<HandlerHelpers.Entity, Types.Events.Event[]>(),
32
+ entityByEvent: new Map<Types.Events.Event, HandlerHelpers.Entity>(),
33
+ createdEntityCache: new Map<string, HandlerHelpers.Entity>(),
34
+ entityByUrlCache: new Map<string, HandlerHelpers.Entity>(),
35
+ };
36
+
37
+ // We track the compositor tile worker thread name events so that at the end we
38
+ // can return these keyed by the process ID. These are used in the frontend to
39
+ // show the user the rasterization thread(s) on the main frame as tracks.
40
+ let compositorTileWorkers = Array<{
41
+ pid: Types.Events.ProcessID,
42
+ tid: Types.Events.ThreadID,
43
+ }>();
44
+ let entryToNode = new Map<Types.Events.Event, Helpers.TreeHelpers.TraceEntryNode>();
45
+
46
+ let completeEventStack: (Types.Events.SyntheticComplete)[] = [];
47
+
48
+ let config: Types.Configuration.Configuration = Types.Configuration.defaults();
49
+
50
+ const makeRendererProcess = (): RendererProcess => ({
51
+ url: null,
52
+ isOnMainFrame: false,
53
+ threads: new Map(),
54
+ });
55
+
56
+ const makeRendererThread = (): RendererThread => ({
57
+ name: null,
58
+ entries: [],
59
+ profileCalls: [],
60
+ layoutEvents: [],
61
+ recalcStyleEvents: [],
62
+ });
63
+
64
+ const getOrCreateRendererProcess =
65
+ (processes: Map<Types.Events.ProcessID, RendererProcess>, pid: Types.Events.ProcessID): RendererProcess => {
66
+ return Platform.MapUtilities.getWithDefault(processes, pid, makeRendererProcess);
67
+ };
68
+
69
+ const getOrCreateRendererThread = (process: RendererProcess, tid: Types.Events.ThreadID): RendererThread => {
70
+ return Platform.MapUtilities.getWithDefault(process.threads, tid, makeRendererThread);
71
+ };
72
+
73
+ export function handleUserConfig(userConfig: Types.Configuration.Configuration): void {
74
+ config = userConfig;
75
+ }
76
+
77
+ export function reset(): void {
78
+ processes = new Map();
79
+ entryToNode = new Map();
80
+ entityMappings = {
81
+ eventsByEntity: new Map<HandlerHelpers.Entity, Types.Events.Event[]>(),
82
+ entityByEvent: new Map<Types.Events.Event, HandlerHelpers.Entity>(),
83
+ createdEntityCache: new Map<string, HandlerHelpers.Entity>(),
84
+ entityByUrlCache: new Map<string, HandlerHelpers.Entity>(),
85
+ };
86
+ completeEventStack = [];
87
+ compositorTileWorkers = [];
88
+ }
89
+
90
+ export function handleEvent(event: Types.Events.Event): void {
91
+ if (Types.Events.isThreadName(event) && event.args.name?.startsWith('CompositorTileWorker')) {
92
+ compositorTileWorkers.push({
93
+ pid: event.pid,
94
+ tid: event.tid,
95
+ });
96
+ }
97
+
98
+ if (Types.Events.isBegin(event) || Types.Events.isEnd(event)) {
99
+ const process = getOrCreateRendererProcess(processes, event.pid);
100
+ const thread = getOrCreateRendererThread(process, event.tid);
101
+ const completeEvent = makeCompleteEvent(event);
102
+ if (!completeEvent) {
103
+ return;
104
+ }
105
+ thread.entries.push(completeEvent);
106
+ return;
107
+ }
108
+
109
+ if (Types.Events.isInstant(event) || Types.Events.isComplete(event)) {
110
+ const process = getOrCreateRendererProcess(processes, event.pid);
111
+ const thread = getOrCreateRendererThread(process, event.tid);
112
+ thread.entries.push(event);
113
+ }
114
+
115
+ if (Types.Events.isLayout(event)) {
116
+ const process = getOrCreateRendererProcess(processes, event.pid);
117
+ const thread = getOrCreateRendererThread(process, event.tid);
118
+ thread.layoutEvents.push(event);
119
+ }
120
+
121
+ if (Types.Events.isRecalcStyle(event)) {
122
+ const process = getOrCreateRendererProcess(processes, event.pid);
123
+ const thread = getOrCreateRendererThread(process, event.tid);
124
+ thread.recalcStyleEvents.push(event);
125
+ }
126
+ }
127
+
128
+ export async function finalize(): Promise<void> {
129
+ const {mainFrameId, rendererProcessesByFrame, threadsInProcess} = metaHandlerData();
130
+ entityMappings = networkRequestHandlerData().entityMappings;
131
+
132
+ assignMeta(processes, mainFrameId, rendererProcessesByFrame, threadsInProcess);
133
+ sanitizeProcesses(processes);
134
+ buildHierarchy(processes);
135
+ sanitizeThreads(processes);
136
+ }
137
+
138
+ export function data(): RendererHandlerData {
139
+ return {
140
+ processes,
141
+ compositorTileWorkers: gatherCompositorThreads(),
142
+ entryToNode,
143
+ entityMappings: {
144
+ entityByEvent: entityMappings.entityByEvent,
145
+ eventsByEntity: entityMappings.eventsByEntity,
146
+ createdEntityCache: entityMappings.createdEntityCache,
147
+ entityByUrlCache: entityMappings.entityByUrlCache,
148
+ },
149
+ };
150
+ }
151
+
152
+ function gatherCompositorThreads(): Map<Types.Events.ProcessID, Types.Events.ThreadID[]> {
153
+ const threadsByProcess = new Map<Types.Events.ProcessID, Types.Events.ThreadID[]>();
154
+ for (const worker of compositorTileWorkers) {
155
+ const byProcess = threadsByProcess.get(worker.pid) || [];
156
+ byProcess.push(worker.tid);
157
+ threadsByProcess.set(worker.pid, byProcess);
158
+ }
159
+ return threadsByProcess;
160
+ }
161
+
162
+ /**
163
+ * Steps through all the renderer processes we've located so far in the meta
164
+ * handler, obtaining their URL, checking whether they are the main frame, and
165
+ * collecting each one of their threads' name. This meta handler's data is
166
+ * assigned to the renderer handler's data.
167
+ */
168
+ export function assignMeta(
169
+ processes: Map<Types.Events.ProcessID, RendererProcess>, mainFrameId: string,
170
+ rendererProcessesByFrame: FrameProcessData,
171
+ threadsInProcess: Map<Types.Events.ProcessID, Map<Types.Events.ThreadID, Types.Events.ThreadName>>): void {
172
+ assignOrigin(processes, rendererProcessesByFrame);
173
+ assignIsMainFrame(processes, mainFrameId, rendererProcessesByFrame);
174
+ assignThreadName(processes, threadsInProcess);
175
+ }
176
+
177
+ /**
178
+ * Assigns origins to all threads in all processes.
179
+ * @see assignMeta
180
+ */
181
+ export function assignOrigin(
182
+ processes: Map<Types.Events.ProcessID, RendererProcess>, rendererProcessesByFrame: FrameProcessData): void {
183
+ for (const renderProcessesByPid of rendererProcessesByFrame.values()) {
184
+ for (const [pid, processWindows] of renderProcessesByPid) {
185
+ for (const processInfo of processWindows.flat()) {
186
+ const process = getOrCreateRendererProcess(processes, pid);
187
+ // Sometimes a single process is responsible with rendering multiple
188
+ // frames at the same time. For example, see https://crbug.com/1334563.
189
+ // When this happens, we'd still like to assign a single url per process
190
+ // so: 1) use the first frame rendered by this process as the url source
191
+ // and 2) if the last url is "about:blank", use the next frame's url,
192
+ // data from about:blank is irrelevant.
193
+ if (process.url === null || process.url === 'about:blank') {
194
+ // If we are here, it's because we care about this process and the URL. But before we store
195
+ // it, we check if it is a valid URL by trying to create a URL object. If it isn't, we won't
196
+ // set it, and this process will be filtered out later.
197
+ try {
198
+ new URL(processInfo.frame.url);
199
+ process.url = processInfo.frame.url;
200
+ } catch {
201
+ process.url = null;
202
+ }
203
+ }
204
+ }
205
+ }
206
+ }
207
+ }
208
+
209
+ /**
210
+ * Assigns whether or not a thread is the main frame to all threads in all processes.
211
+ * @see assignMeta
212
+ */
213
+ export function assignIsMainFrame(
214
+ processes: Map<Types.Events.ProcessID, RendererProcess>, mainFrameId: string,
215
+ rendererProcessesByFrame: FrameProcessData): void {
216
+ for (const [frameId, renderProcessesByPid] of rendererProcessesByFrame) {
217
+ for (const [pid] of renderProcessesByPid) {
218
+ const process = getOrCreateRendererProcess(processes, pid);
219
+ // We have this go in one direction; once a renderer has been flagged as
220
+ // being on the main frame, we don't unset it to false if were to show up
221
+ // in a subframe. Equally, if we already saw this renderer in a subframe,
222
+ // but it becomes the main frame, the flag would get updated.
223
+ if (frameId === mainFrameId) {
224
+ process.isOnMainFrame = true;
225
+ }
226
+ }
227
+ }
228
+ }
229
+
230
+ /**
231
+ * Assigns the thread name to all threads in all processes.
232
+ * @see assignMeta
233
+ */
234
+ export function assignThreadName(
235
+ processes: Map<Types.Events.ProcessID, RendererProcess>,
236
+ threadsInProcess: Map<Types.Events.ProcessID, Map<Types.Events.ThreadID, Types.Events.ThreadName>>): void {
237
+ for (const [pid, process] of processes) {
238
+ for (const [tid, threadInfo] of threadsInProcess.get(pid) ?? []) {
239
+ const thread = getOrCreateRendererThread(process, tid);
240
+ thread.name = threadInfo?.args.name ?? `${tid}`;
241
+ }
242
+ }
243
+ }
244
+
245
+ /**
246
+ * Removes unneeded trace data opportunistically stored while handling events.
247
+ * This currently does the following:
248
+ * - Deletes processes with an unknown origin.
249
+ */
250
+ export function sanitizeProcesses(processes: Map<Types.Events.ProcessID, RendererProcess>): void {
251
+ const auctionWorklets = auctionWorkletsData().worklets;
252
+ const metaData = metaHandlerData();
253
+ if (metaData.traceIsGeneric) {
254
+ return;
255
+ }
256
+ for (const [pid, process] of processes) {
257
+ // If the process had no url, or if it had a malformed url that could not be
258
+ // parsed for some reason, or if it's an "about:" origin, delete it.
259
+ // This is done because we don't really care about processes for which we
260
+ // can't provide actionable insights to the user (e.g. about:blank pages).
261
+ //
262
+ // There is one exception; AuctionWorklet processes get parsed in a
263
+ // separate handler, so at this point we check to see if the process has
264
+ // been found by the AuctionWorkletsHandler, and if so we update the URL.
265
+ // This ensures that we keep this process around and do not drop it due to
266
+ // the lack of a URL.
267
+ if (process.url === null) {
268
+ const maybeWorklet = auctionWorklets.get(pid);
269
+ if (maybeWorklet) {
270
+ process.url = maybeWorklet.host;
271
+ } else {
272
+ processes.delete(pid);
273
+ }
274
+ continue;
275
+ }
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Removes unneeded trace data opportunistically stored while handling events.
281
+ * This currently does the following:
282
+ * - Deletes threads with no roots.
283
+ */
284
+ export function sanitizeThreads(processes: Map<Types.Events.ProcessID, RendererProcess>): void {
285
+ for (const [, process] of processes) {
286
+ for (const [tid, thread] of process.threads) {
287
+ // If the thread has no roots, delete it. Otherwise, there's going to
288
+ // be space taken, even though nothing is rendered in the track manager.
289
+ if (!thread.tree?.roots.size) {
290
+ process.threads.delete(tid);
291
+ }
292
+ }
293
+ }
294
+ }
295
+
296
+ /**
297
+ * Creates a hierarchical structure from the trace events. Each thread in each
298
+ * process will contribute to their own individual hierarchy.
299
+ *
300
+ * The trace data comes in as a contiguous array of events, against which we
301
+ * make a couple of assumptions:
302
+ *
303
+ * 1. Events are temporally-ordered in terms of start time (though they're
304
+ * not necessarily ordered as such in the data stream).
305
+ * 2. If event B's start and end times are within event A's time boundaries
306
+ * we assume that A is the parent of B.
307
+ *
308
+ * Therefore we expect to reformulate something like:
309
+ *
310
+ * [ Task A ][ Task B ][ Task C ][ Task D ][ Task E ]
311
+ *
312
+ * Into something hierarchically-arranged like below:
313
+ *
314
+ * |------------- Task A -------------||-- Task E --|
315
+ * |-- Task B --||-- Task D --|
316
+ * |- Task C -|
317
+ */
318
+ export function buildHierarchy(
319
+ processes: Map<Types.Events.ProcessID, RendererProcess>,
320
+ options?: {filter: {has: (name: Types.Events.Name) => boolean}}): void {
321
+ const samplesData = samplesHandlerData();
322
+ for (const [pid, process] of processes) {
323
+ for (const [tid, thread] of process.threads) {
324
+ if (!thread.entries.length) {
325
+ thread.tree = Helpers.TreeHelpers.makeEmptyTraceEntryTree();
326
+ continue;
327
+ }
328
+ // Step 1. Massage the data.
329
+ Helpers.Trace.sortTraceEventsInPlace(thread.entries);
330
+ // Step 2. Inject profile calls from samples
331
+ const samplesDataForThread = samplesData.profilesInProcess.get(pid)?.get(tid);
332
+ if (samplesDataForThread) {
333
+ const cpuProfile = samplesDataForThread.parsedProfile;
334
+ const samplesIntegrator = cpuProfile &&
335
+ new Helpers.SamplesIntegrator.SamplesIntegrator(
336
+ cpuProfile, samplesDataForThread.profileId, pid, tid, config);
337
+ const profileCalls = samplesIntegrator?.buildProfileCalls(thread.entries);
338
+ if (samplesIntegrator && profileCalls) {
339
+ thread.entries = Helpers.Trace.mergeEventsInOrder(thread.entries, profileCalls);
340
+ thread.profileCalls = profileCalls;
341
+
342
+ // We'll also inject the instant JSSample events (in debug mode only)
343
+ const jsSamples = samplesIntegrator.jsSampleEvents;
344
+ if (jsSamples.length) {
345
+ thread.entries = Helpers.Trace.mergeEventsInOrder(thread.entries, jsSamples);
346
+ }
347
+ }
348
+ }
349
+ // Step 3. Build the tree.
350
+ const treeData = Helpers.TreeHelpers.treify(thread.entries, options);
351
+ thread.tree = treeData.tree;
352
+ // Update the entryToNode map with the entries from this thread
353
+ for (const [entry, node] of treeData.entryToNode) {
354
+ entryToNode.set(entry, node);
355
+ // Entity mapping is unrelated to the tree, but calling here as we need to call on every node anyway.
356
+ HandlerHelpers.addEventToEntityMapping(entry, entityMappings);
357
+ }
358
+ }
359
+ }
360
+ }
361
+
362
+ export function makeCompleteEvent(event: Types.Events.Begin|Types.Events.End): Types.Events.SyntheticComplete|null {
363
+ if (Types.Events.isEnd(event)) {
364
+ // Quietly ignore unbalanced close events, they're legit (we could
365
+ // have missed start one).
366
+ const beginEvent = completeEventStack.pop();
367
+ if (!beginEvent) {
368
+ return null;
369
+ }
370
+ if (beginEvent.name !== event.name || beginEvent.cat !== event.cat) {
371
+ console.error(
372
+ 'Begin/End events mismatch at ' + beginEvent.ts + ' (' + beginEvent.name + ') vs. ' + event.ts + ' (' +
373
+ event.name + ')');
374
+ return null;
375
+ }
376
+ // Update the begin event's duration using the timestamp of the end
377
+ // event.
378
+ beginEvent.dur = Types.Timing.Micro(event.ts - beginEvent.ts);
379
+ return null;
380
+ }
381
+
382
+ // Create a synthetic event using the begin event, when we find the
383
+ // matching end event later we will update its duration.
384
+ const syntheticComplete: Types.Events.SyntheticComplete = {
385
+ ...event,
386
+ ph: Types.Events.Phase.COMPLETE,
387
+ dur: Types.Timing.Micro(0),
388
+ };
389
+
390
+ completeEventStack.push(syntheticComplete);
391
+ return syntheticComplete;
392
+ }
393
+
394
+ export function deps(): HandlerName[] {
395
+ return ['Meta', 'Samples', 'AuctionWorklets', 'NetworkRequests'];
396
+ }
397
+
398
+ export interface RendererHandlerData {
399
+ processes: Map<Types.Events.ProcessID, RendererProcess>;
400
+ /**
401
+ * A map of all compositor workers (which we show in the UI as Rasterizers)
402
+ * by the process ID.
403
+ */
404
+ compositorTileWorkers: Map<Types.Events.ProcessID, Types.Events.ThreadID[]>;
405
+ entryToNode: Map<Types.Events.Event, Helpers.TreeHelpers.TraceEntryNode>;
406
+ entityMappings: HandlerHelpers.EntityMappings;
407
+ }
408
+
409
+ export interface RendererProcess {
410
+ // In an ideal world this would be modelled as a URL, but URLs cannot be sent
411
+ // between the main thread and workers, so we have to store it as a string.
412
+ url: string|null;
413
+ isOnMainFrame: boolean;
414
+ threads: Map<Types.Events.ThreadID, RendererThread>;
415
+ }
416
+
417
+ export interface RendererThread {
418
+ name: string|null;
419
+ /**
420
+ * Contains trace events and synthetic profile calls made from
421
+ * samples.
422
+ */
423
+ entries: Types.Events.Event[];
424
+ profileCalls: Types.Events.SyntheticProfileCall[];
425
+ layoutEvents: Types.Events.Layout[];
426
+ recalcStyleEvents: Types.Events.RecalcStyle[];
427
+ tree?: Helpers.TreeHelpers.TraceEntryTree;
428
+ }
@@ -0,0 +1,271 @@
1
+ // Copyright 2022 The Chromium Authors
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import * as Platform from '../../../core/platform/platform.js';
6
+ import type * as Protocol from '../../../generated/protocol.js';
7
+ import * as CPUProfile from '../../cpu_profile/cpu_profile.js';
8
+ import * as Helpers from '../helpers/helpers.js';
9
+ import * as Types from '../types/types.js';
10
+
11
+ let profilesInProcess = new Map<Types.Events.ProcessID, Map<Types.Events.ThreadID, ProfileData>>();
12
+ let entryToNode = new Map<Types.Events.Event, Helpers.TreeHelpers.TraceEntryNode>();
13
+
14
+ // The profile head, containing its metadata like its start
15
+ // time, comes in a "Profile" event. The sample data comes in
16
+ // "ProfileChunk" events. We match these ProfileChunks with their head
17
+ // using process and profile ids. However, in order to integrate sample
18
+ // data with trace data, we need the thread id that owns each profile.
19
+ // This thread id is extracted from the head event.
20
+ // For this reason, we have a preprocessed data structure, where events
21
+ // are matched by profile id, which we then finish processing to export
22
+ // events matched by thread id.
23
+ let preprocessedData = new Map<Types.Events.ProcessID, Map<Types.Events.ProfileID, PreprocessedData>>();
24
+
25
+ function parseCPUProfileData(parseOptions: Types.Configuration.ParseOptions): void {
26
+ for (const [processId, profiles] of preprocessedData) {
27
+ for (const [profileId, preProcessedData] of profiles) {
28
+ const threadId = preProcessedData.threadId;
29
+ if (!preProcessedData.rawProfile.nodes.length || threadId === undefined) {
30
+ continue;
31
+ }
32
+ const indexStack: number[] = [];
33
+
34
+ const profileModel = new CPUProfile.CPUProfileDataModel.CPUProfileDataModel(preProcessedData.rawProfile);
35
+ const profileTree = Helpers.TreeHelpers.makeEmptyTraceEntryTree();
36
+ profileTree.maxDepth = profileModel.maxDepth;
37
+
38
+ const finalizedData: ProfileData = {
39
+ rawProfile: preProcessedData.rawProfile,
40
+ parsedProfile: profileModel,
41
+ profileCalls: [],
42
+ profileTree,
43
+ profileId,
44
+ };
45
+ const dataByThread = Platform.MapUtilities.getWithDefault(profilesInProcess, processId, () => new Map());
46
+ dataByThread.set(threadId, finalizedData);
47
+
48
+ // Only need to build pure JS ProfileCalls if we're parsing a CPU Profile, otherwise SamplesIntegrator does the work.
49
+ if (parseOptions.isCPUProfile) {
50
+ buildProfileCallsForCPUProfile();
51
+ }
52
+
53
+ function buildProfileCallsForCPUProfile(): void {
54
+ profileModel.forEachFrame(openFrameCallback, closeFrameCallback);
55
+
56
+ function openFrameCallback(
57
+ depth: number, node: CPUProfile.ProfileTreeModel.ProfileNode, sampleIndex: number,
58
+ timeStampMilliseconds: number): void {
59
+ if (threadId === undefined) {
60
+ return;
61
+ }
62
+ const ts = Helpers.Timing.milliToMicro(Types.Timing.Milli(timeStampMilliseconds));
63
+ const nodeId = node.id as Helpers.TreeHelpers.TraceEntryNodeId;
64
+
65
+ const profileCall = Helpers.Trace.makeProfileCall(node, profileId, sampleIndex, ts, processId, threadId);
66
+ finalizedData.profileCalls.push(profileCall);
67
+ indexStack.push(finalizedData.profileCalls.length - 1);
68
+ const traceEntryNode = Helpers.TreeHelpers.makeEmptyTraceEntryNode(profileCall, nodeId);
69
+ entryToNode.set(profileCall, traceEntryNode);
70
+ traceEntryNode.depth = depth;
71
+ if (indexStack.length === 1) {
72
+ // First call in the stack is a root call.
73
+ finalizedData.profileTree?.roots.add(traceEntryNode);
74
+ }
75
+ }
76
+ function closeFrameCallback(
77
+ _depth: number, _node: CPUProfile.ProfileTreeModel.ProfileNode, _sampleIndex: number,
78
+ _timeStampMillis: number, durMs: number, selfTimeMs: number): void {
79
+ const profileCallIndex = indexStack.pop();
80
+ const profileCall = profileCallIndex !== undefined && finalizedData.profileCalls[profileCallIndex];
81
+ if (!profileCall) {
82
+ return;
83
+ }
84
+ const {callFrame, ts, pid, tid} = profileCall;
85
+ const traceEntryNode = entryToNode.get(profileCall);
86
+ if (callFrame === undefined || ts === undefined || pid === undefined || profileId === undefined ||
87
+ tid === undefined || traceEntryNode === undefined) {
88
+ return;
89
+ }
90
+ const dur = Helpers.Timing.milliToMicro(Types.Timing.Milli(durMs));
91
+ const selfTime = Helpers.Timing.milliToMicro(Types.Timing.Milli(selfTimeMs));
92
+ profileCall.dur = dur;
93
+ traceEntryNode.selfTime = selfTime;
94
+
95
+ const parentIndex = indexStack.at(-1);
96
+ const parent = parentIndex !== undefined && finalizedData.profileCalls.at(parentIndex);
97
+ const parentNode = parent && entryToNode.get(parent);
98
+ if (!parentNode) {
99
+ return;
100
+ }
101
+ traceEntryNode.parent = parentNode;
102
+ parentNode.children.push(traceEntryNode);
103
+ }
104
+ }
105
+ }
106
+ }
107
+ }
108
+
109
+ export function reset(): void {
110
+ preprocessedData = new Map();
111
+ profilesInProcess = new Map();
112
+ entryToNode = new Map();
113
+ }
114
+
115
+ export function handleEvent(event: Types.Events.Event): void {
116
+ /**
117
+ * A fake trace event created to support CDP.Profiler.Profiles in the
118
+ * trace engine.
119
+ */
120
+ if (Types.Events.isSyntheticCpuProfile(event)) {
121
+ // At the moment we are attaching to a single node target so we
122
+ // should only get a single CPU profile. The values of the process
123
+ // id and thread id are not really important, so we use the data
124
+ // in the fake event. Should multi-thread CPU profiling be supported
125
+ // we could use these fields in the event to pass thread info.
126
+ const profileData = getOrCreatePreProcessedData(event.pid, event.id);
127
+ profileData.rawProfile = event.args.data.cpuProfile;
128
+ profileData.threadId = event.tid;
129
+ return;
130
+ }
131
+
132
+ if (Types.Events.isProfile(event)) {
133
+ // Do not use event.args.data.startTime as it is in CLOCK_MONOTONIC domain,
134
+ // but use profileEvent.ts which has been translated to Perfetto's clock
135
+ // domain. Also convert from ms to us.
136
+ // Note: events are collected on a different thread than what's sampled.
137
+ // The correct process and thread ids are specified by the profile.
138
+ const profileData = getOrCreatePreProcessedData(event.pid, event.id);
139
+ profileData.rawProfile.startTime = event.ts;
140
+ profileData.threadId = event.tid;
141
+ return;
142
+ }
143
+ if (Types.Events.isProfileChunk(event)) {
144
+ const profileData = getOrCreatePreProcessedData(event.pid, event.id);
145
+ const cdpProfile = profileData.rawProfile;
146
+ const nodesAndSamples: Types.Events.PartialProfile = event.args?.data?.cpuProfile || {samples: []};
147
+ const samples = nodesAndSamples?.samples || [];
148
+ const traceIds = event.args?.data?.cpuProfile?.trace_ids;
149
+ for (const n of nodesAndSamples?.nodes || []) {
150
+ const lineNumber = typeof n.callFrame.lineNumber === 'undefined' ? -1 : n.callFrame.lineNumber;
151
+ const columnNumber = typeof n.callFrame.columnNumber === 'undefined' ? -1 : n.callFrame.columnNumber;
152
+
153
+ const scriptId = String(n.callFrame.scriptId) as Protocol.Runtime.ScriptId;
154
+ const url = n.callFrame.url || '';
155
+ const node = {
156
+ ...n,
157
+ callFrame: {
158
+ ...n.callFrame,
159
+ url,
160
+ lineNumber,
161
+ columnNumber,
162
+ scriptId,
163
+ },
164
+ };
165
+ cdpProfile.nodes.push(node);
166
+ }
167
+
168
+ const timeDeltas = event.args.data?.timeDeltas || [];
169
+ const lines = event.args.data?.lines || Array(samples.length).fill(0);
170
+ cdpProfile.samples?.push(...samples);
171
+ cdpProfile.timeDeltas?.push(...timeDeltas);
172
+ cdpProfile.lines?.push(...lines);
173
+
174
+ if (traceIds) {
175
+ cdpProfile.traceIds ??= {};
176
+ for (const key in traceIds) {
177
+ cdpProfile.traceIds[key] = traceIds[key];
178
+ }
179
+ }
180
+
181
+ if (cdpProfile.samples && cdpProfile.timeDeltas && cdpProfile.samples.length !== cdpProfile.timeDeltas.length) {
182
+ console.error('Failed to parse CPU profile.');
183
+ return;
184
+ }
185
+ if (!cdpProfile.endTime && cdpProfile.timeDeltas) {
186
+ const timeDeltas: number[] = cdpProfile.timeDeltas;
187
+ cdpProfile.endTime = timeDeltas.reduce((x, y) => x + y, cdpProfile.startTime);
188
+ }
189
+ return;
190
+ }
191
+ }
192
+
193
+ export async function finalize(parseOptions: Types.Configuration.ParseOptions = {}): Promise<void> {
194
+ parseCPUProfileData(parseOptions);
195
+ }
196
+
197
+ export function data(): SamplesHandlerData {
198
+ return {
199
+ profilesInProcess,
200
+ entryToNode,
201
+ };
202
+ }
203
+
204
+ function getOrCreatePreProcessedData(
205
+ processId: Types.Events.ProcessID, profileId: Types.Events.ProfileID): PreprocessedData {
206
+ const profileById = Platform.MapUtilities.getWithDefault(preprocessedData, processId, () => new Map());
207
+ return Platform.MapUtilities.getWithDefault<Types.Events.ProfileID, PreprocessedData>(
208
+ profileById, profileId, () => ({
209
+ rawProfile: {
210
+ startTime: 0,
211
+ endTime: 0,
212
+ nodes: [],
213
+ samples: [],
214
+ timeDeltas: [],
215
+ lines: [],
216
+ },
217
+ profileId,
218
+ }));
219
+ }
220
+
221
+ export interface SamplesHandlerData {
222
+ profilesInProcess: typeof profilesInProcess;
223
+ entryToNode: typeof entryToNode;
224
+ }
225
+
226
+ export interface ProfileData {
227
+ profileId: Types.Events.ProfileID;
228
+ rawProfile: CPUProfile.CPUProfileDataModel.ExtendedProfile;
229
+ parsedProfile: CPUProfile.CPUProfileDataModel.CPUProfileDataModel;
230
+ /**
231
+ * Contains the calls built from the CPU profile samples.
232
+ * Note: This doesn't contain real trace events coming from the
233
+ * browser, only calls synthetically typed as trace events for
234
+ * compatibility, as such it only makes sense to use them in pure CPU
235
+ * profiles.
236
+ *
237
+ * If you need the profile calls from a CPU profile obtained from a
238
+ * web trace, use the data exported by the RendererHandler instead.
239
+ */
240
+ profileCalls: Types.Events.SyntheticProfileCall[];
241
+ /**
242
+ * Contains the call tree built from the CPU profile samples.
243
+ * Similar to the profileCalls field, this tree does not contain nor
244
+ * take into account trace events, as such it only makes sense to use
245
+ * them in pure CPU profiles.
246
+ */
247
+ profileTree?: Helpers.TreeHelpers.TraceEntryTree;
248
+ }
249
+
250
+ interface PreprocessedData {
251
+ rawProfile: CPUProfile.CPUProfileDataModel.ExtendedProfile;
252
+ profileId: Types.Events.ProfileID;
253
+ threadId?: Types.Events.ThreadID;
254
+ }
255
+
256
+ /**
257
+ * Returns the name of a function for a given synthetic profile call.
258
+ * We first look to find the ProfileNode representing this call, and use its
259
+ * function name. This is preferred (and should always exist) because if we
260
+ * resolve sourcemaps, we will update this name. If that name is not present,
261
+ * we fall back to the function name that was in the callframe that we got
262
+ * when parsing the profile's trace data.
263
+ */
264
+ export function getProfileCallFunctionName(data: SamplesHandlerData, entry: Types.Events.SyntheticProfileCall): string {
265
+ const profile = data.profilesInProcess.get(entry.pid)?.get(entry.tid);
266
+ const node = profile?.parsedProfile.nodeById(entry.nodeId);
267
+ if (node?.functionName) {
268
+ return node.functionName;
269
+ }
270
+ return entry.callFrame.functionName;
271
+ }