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,544 @@
1
+ // Copyright 2023 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 type * as Protocol from '../../../generated/protocol.js';
6
+ import type * as CPUProfile from '../../cpu_profile/cpu_profile.js';
7
+ import * as Types from '../types/types.js';
8
+
9
+ import {milliToMicro} from './Timing.js';
10
+ import {extractSampleTraceId, makeProfileCall, mergeEventsInOrder, sortTraceEventsInPlace} from './Trace.js';
11
+
12
+ /**
13
+ * This is a helper that integrates CPU profiling data coming in the
14
+ * shape of samples, with trace events. Samples indicate what the JS
15
+ * stack trace looked at a given point in time, but they don't have
16
+ * duration. The SamplesIntegrator task is to make an approximation
17
+ * of what the duration of each JS call was, given the sample data and
18
+ * given the trace events profiled during that time. At the end of its
19
+ * execution, the SamplesIntegrator returns an array of ProfileCalls
20
+ * (under SamplesIntegrator::buildProfileCalls()), which
21
+ * represent JS calls, with a call frame and duration. These calls have
22
+ * the shape of a complete trace events and can be treated as flame
23
+ * chart entries in the timeline.
24
+ *
25
+ * The approach to build the profile calls consists in tracking the
26
+ * current stack as the following events happen (in order):
27
+ * 1. A sample was done.
28
+ * 2. A trace event started.
29
+ * 3. A trace event ended.
30
+ * Depending on the event and on the data that's coming with it the
31
+ * stack is updated by adding or removing JS calls to it and updating
32
+ * the duration of the calls in the tracking stack.
33
+ *
34
+ * note: Although this approach has been implemented since long ago, and
35
+ * is relatively efficient (adds a complexity over the trace parsing of
36
+ * O(n) where n is the number of samples) it has proven to be faulty.
37
+ * It might be worthwhile experimenting with improvements or with a
38
+ * completely different approach. Improving the approach is tracked in
39
+ * crbug.com/1417439
40
+ */
41
+ export class SamplesIntegrator {
42
+ /**
43
+ * The result of running the samples integrator. Holds the JS calls
44
+ * with their approximated duration after integrating samples into the
45
+ * trace event tree.
46
+ */
47
+ #constructedProfileCalls: Types.Events.SyntheticProfileCall[] = [];
48
+ /**
49
+ * tracks the state of the JS stack at each point in time to update
50
+ * the profile call durations as new events arrive. This doesn't only
51
+ * happen with new profile calls (in which case we would compare the
52
+ * stack in them) but also with trace events (in which case we would
53
+ * update the duration of the events we are tracking at the moment).
54
+ */
55
+ #currentJSStack: Types.Events.SyntheticProfileCall[] = [];
56
+ /**
57
+ * Process holding the CPU profile and trace events.
58
+ */
59
+ #processId: Types.Events.ProcessID;
60
+ /**
61
+ * Thread holding the CPU profile and trace events.
62
+ */
63
+ #threadId: Types.Events.ThreadID;
64
+ /**
65
+ * Tracks the depth of the JS stack at the moment a trace event starts
66
+ * or ends. It is assumed that for the duration of a trace event, the
67
+ * JS stack's depth cannot decrease, since JS calls that started
68
+ * before a trace event cannot end during the trace event. So as trace
69
+ * events arrive, we store the "locked" amount of JS frames that were
70
+ * in the stack before the event came.
71
+ */
72
+ #lockedJsStackDepth: number[] = [];
73
+ /**
74
+ * Used to keep track when samples should be integrated even if they
75
+ * are not children of invocation trace events. This is useful in
76
+ * cases where we can be missing the start of JS invocation events if
77
+ * we start tracing half-way through.
78
+ */
79
+ #fakeJSInvocation = false;
80
+ /**
81
+ * The parsed CPU profile, holding the tree hierarchy of JS frames and
82
+ * the sample data.
83
+ */
84
+ #profileModel: CPUProfile.CPUProfileDataModel.CPUProfileDataModel;
85
+ /**
86
+ * Because GC nodes don't have a stack, we artificially add a stack to
87
+ * them which corresponds to that of the previous sample. This map
88
+ * tracks which node is used for the stack of a GC call.
89
+ * Note that GC samples are not shown in the flamechart, however they
90
+ * are used during the construction of for profile calls, as we can
91
+ * infer information about the duration of the executed code when a
92
+ * GC node is sampled.
93
+ */
94
+ #nodeForGC = new Map<Types.Events.SyntheticProfileCall, CPUProfile.ProfileTreeModel.ProfileNode>();
95
+
96
+ #engineConfig: Types.Configuration.Configuration;
97
+ #profileId: Types.Events.ProfileID;
98
+
99
+ /**
100
+ * Keeps track of the individual samples from the CPU Profile.
101
+ * Only used with Debug Mode experiment enabled.
102
+ */
103
+ jsSampleEvents: Types.Events.SyntheticJSSample[] = [];
104
+
105
+ constructor(
106
+ profileModel: CPUProfile.CPUProfileDataModel.CPUProfileDataModel, profileId: Types.Events.ProfileID,
107
+ pid: Types.Events.ProcessID, tid: Types.Events.ThreadID, configuration?: Types.Configuration.Configuration) {
108
+ this.#profileModel = profileModel;
109
+ this.#threadId = tid;
110
+ this.#processId = pid;
111
+ this.#engineConfig = configuration || Types.Configuration.defaults();
112
+ this.#profileId = profileId;
113
+ }
114
+
115
+ buildProfileCalls(traceEvents: Types.Events.Event[]): Types.Events.SyntheticProfileCall[] {
116
+ const mergedEvents = mergeEventsInOrder(traceEvents, this.callsFromProfileSamples());
117
+ const stack = [];
118
+ for (let i = 0; i < mergedEvents.length; i++) {
119
+ const event = mergedEvents[i];
120
+ // Because instant trace events have no duration, they don't provide
121
+ // useful information for possible changes in the duration of calls
122
+ // in the JS stack.
123
+ if (event.ph === Types.Events.Phase.INSTANT && !extractSampleTraceId(event)) {
124
+ continue;
125
+ }
126
+ if (stack.length === 0) {
127
+ if (Types.Events.isProfileCall(event)) {
128
+ this.#onProfileCall(event);
129
+ continue;
130
+ }
131
+ stack.push(event);
132
+ this.#onTraceEventStart(event);
133
+ continue;
134
+ }
135
+
136
+ const parentEvent = stack.at(-1);
137
+ if (parentEvent === undefined) {
138
+ continue;
139
+ }
140
+ const begin = event.ts;
141
+ const parentBegin = parentEvent.ts;
142
+ const parentDuration = parentEvent.dur || 0;
143
+ const parentEnd = parentBegin + parentDuration;
144
+
145
+ const startsAfterParent = begin >= parentEnd;
146
+ if (startsAfterParent) {
147
+ this.#onTraceEventEnd(parentEvent);
148
+ stack.pop();
149
+ i--;
150
+ continue;
151
+ }
152
+ if (Types.Events.isProfileCall(event)) {
153
+ this.#onProfileCall(event, parentEvent);
154
+ continue;
155
+ }
156
+ this.#onTraceEventStart(event);
157
+ stack.push(event);
158
+ }
159
+ while (stack.length) {
160
+ const last = stack.pop();
161
+ if (last) {
162
+ this.#onTraceEventEnd(last);
163
+ }
164
+ }
165
+ sortTraceEventsInPlace(this.jsSampleEvents);
166
+ return this.#constructedProfileCalls;
167
+ }
168
+
169
+ #onTraceEventStart(event: Types.Events.Event): void {
170
+ // Top level events cannot be nested into JS frames so we reset
171
+ // the stack when we find one.
172
+ if (event.name === Types.Events.Name.RUN_MICROTASKS || event.name === Types.Events.Name.RUN_TASK) {
173
+ this.#lockedJsStackDepth = [];
174
+ this.#truncateJSStack(0, event.ts);
175
+ this.#fakeJSInvocation = false;
176
+ }
177
+
178
+ if (this.#fakeJSInvocation) {
179
+ this.#truncateJSStack(this.#lockedJsStackDepth.pop() || 0, event.ts);
180
+ this.#fakeJSInvocation = false;
181
+ }
182
+ this.#extractStackTrace(event);
183
+ // Keep track of the call frames in the stack before the event
184
+ // happened. For the duration of this event, these frames cannot
185
+ // change (none can be terminated before this event finishes).
186
+ //
187
+ // Also, every frame that is opened after this event, is considered
188
+ // to be a descendant of the event. So once the event finishes, the
189
+ // frames that were opened after it, need to be closed (see
190
+ // onEndEvent).
191
+ //
192
+ // TODO(crbug.com/1417439):
193
+ // The assumption that every frame opened after an event is a
194
+ // descendant of the event is incorrect. For example, a JS call that
195
+ // parents a trace event might have been sampled after the event was
196
+ // dispatched. In this case the JS call would be discarded if this
197
+ // event isn't an invocation event, otherwise the call will be
198
+ // considered a child of the event. In both cases, the result would
199
+ // be incorrect.
200
+ this.#lockedJsStackDepth.push(this.#currentJSStack.length);
201
+ }
202
+
203
+ #onProfileCall(event: Types.Events.SyntheticProfileCall, parent?: Types.Events.Event): void {
204
+ if ((parent && Types.Events.isJSInvocationEvent(parent)) || this.#fakeJSInvocation) {
205
+ this.#extractStackTrace(event);
206
+ } else if (Types.Events.isProfileCall(event) && this.#currentJSStack.length === 0) {
207
+ // Force JS Samples to show up even if we are not inside a JS
208
+ // invocation event, because we can be missing the start of JS
209
+ // invocation events if we start tracing half-way through. Pretend
210
+ // we have a top-level JS invocation event.
211
+ this.#fakeJSInvocation = true;
212
+ const stackDepthBefore = this.#currentJSStack.length;
213
+ this.#extractStackTrace(event);
214
+ this.#lockedJsStackDepth.push(stackDepthBefore);
215
+ }
216
+ }
217
+
218
+ #onTraceEventEnd(event: Types.Events.Event): void {
219
+ // Because the event has ended, any frames that happened after
220
+ // this event are terminated. Frames that are ancestors to this
221
+ // event are extended to cover its ending.
222
+ const endTime = Types.Timing.Micro(event.ts + (event.dur ?? 0));
223
+ this.#truncateJSStack(this.#lockedJsStackDepth.pop() || 0, endTime);
224
+ }
225
+
226
+ /**
227
+ * Builds the initial calls with no duration from samples. Their
228
+ * purpose is to be merged with the trace event array being parsed so
229
+ * that they can be traversed in order with them and their duration
230
+ * can be updated as the SampleIntegrator callbacks are invoked.
231
+ */
232
+ callsFromProfileSamples(): Types.Events.SyntheticProfileCall[] {
233
+ const samples = this.#profileModel.samples;
234
+ const timestamps = this.#profileModel.timestamps;
235
+ if (!samples) {
236
+ return [];
237
+ }
238
+ const calls: Types.Events.SyntheticProfileCall[] = [];
239
+ let prevNode;
240
+ for (let i = 0; i < samples.length; i++) {
241
+ const node = this.#profileModel.nodeByIndex(i);
242
+ const timestamp = milliToMicro(Types.Timing.Milli(timestamps[i]));
243
+ if (!node) {
244
+ continue;
245
+ }
246
+ const call = makeProfileCall(node, this.#profileId, i, timestamp, this.#processId, this.#threadId);
247
+ calls.push(call);
248
+
249
+ if (this.#engineConfig.debugMode) {
250
+ const traceId = this.#profileModel.traceIds?.[i];
251
+ this.jsSampleEvents.push(this.#makeJSSampleEvent(call, timestamp, traceId));
252
+ }
253
+ if (node.id === this.#profileModel.gcNode?.id && prevNode) {
254
+ // GC samples have no stack, so we just put GC node on top of the
255
+ // last recorded sample. Cache the previous sample for future
256
+ // reference.
257
+ this.#nodeForGC.set(call, prevNode);
258
+ continue;
259
+ }
260
+ prevNode = node;
261
+ }
262
+ return calls;
263
+ }
264
+
265
+ /**
266
+ * Given a synthetic profile call, returns an array of profile calls
267
+ * representing the stack trace that profile call belongs to based on
268
+ * its nodeId. The input profile call will be at the top of the
269
+ * returned stack (last position), meaning that any other frames that
270
+ * were effectively above it are omitted.
271
+ * @param profileCall
272
+ * @param overrideTimeStamp a custom timestamp to use for the returned
273
+ * profile calls. If not defined, the timestamp of the input
274
+ * profileCall is used instead. This param is useful for example when
275
+ * creating the profile calls for a sample with a trace id, since the
276
+ * timestamp of the corresponding trace event should be used instead
277
+ * of the sample's.
278
+ */
279
+
280
+ #makeProfileCallsForStack(profileCall: Types.Events.SyntheticProfileCall, overrideTimeStamp?: Types.Timing.Micro):
281
+ Types.Events.SyntheticProfileCall[] {
282
+ let node = this.#profileModel.nodeById(profileCall.nodeId);
283
+ const isGarbageCollection = node?.id === this.#profileModel.gcNode?.id;
284
+ if (isGarbageCollection) {
285
+ // Because GC don't have a stack, we use the stack of the previous
286
+ // sample.
287
+ node = this.#nodeForGC.get(profileCall) || null;
288
+ }
289
+ if (!node) {
290
+ return [];
291
+ }
292
+ // `node.depth` is 0 based, so to set the size of the array we need
293
+ // to add 1 to its value.
294
+ const callFrames = new Array<Types.Events.SyntheticProfileCall>(node.depth + 1 + Number(isGarbageCollection));
295
+ // Add the stack trace in reverse order (bottom first).
296
+ let i = callFrames.length - 1;
297
+ if (isGarbageCollection) {
298
+ // Place the garbage collection call frame on top of the stack.
299
+ callFrames[i--] = profileCall;
300
+ }
301
+
302
+ // Many of these ProfileCalls will be GC'd later when we estimate the frame
303
+ // durations
304
+ while (node) {
305
+ callFrames[i--] = makeProfileCall(
306
+ node, profileCall.profileId, profileCall.sampleIndex, overrideTimeStamp ?? profileCall.ts, this.#processId,
307
+ this.#threadId);
308
+ node = node.parent;
309
+ }
310
+ return callFrames;
311
+ }
312
+
313
+ #getStackForSampleTraceId(traceId: number, timestamp: Types.Timing.Micro): Types.Events.SyntheticProfileCall[]|null {
314
+ const nodeId = this.#profileModel.traceIds?.[traceId];
315
+ const node = nodeId && this.#profileModel.nodeById(nodeId);
316
+ const maybeCallForTraceId =
317
+ node && makeProfileCall(node, this.#profileId, -1, timestamp, this.#processId, this.#threadId);
318
+ if (!maybeCallForTraceId) {
319
+ return null;
320
+ }
321
+ if (this.#engineConfig.debugMode) {
322
+ this.jsSampleEvents.push(this.#makeJSSampleEvent(maybeCallForTraceId, timestamp, traceId));
323
+ }
324
+ return this.#makeProfileCallsForStack(maybeCallForTraceId);
325
+ }
326
+ /**
327
+ * Update tracked stack using this event's call stack.
328
+ */
329
+ #extractStackTrace(event: Types.Events.Event): void {
330
+ let stackTrace = this.#currentJSStack;
331
+ if (Types.Events.isProfileCall(event)) {
332
+ stackTrace = this.#makeProfileCallsForStack(event);
333
+ }
334
+ const traceId = extractSampleTraceId(event);
335
+ const maybeCallForTraceId = traceId && this.#getStackForSampleTraceId(traceId, event.ts);
336
+ if (maybeCallForTraceId) {
337
+ stackTrace = maybeCallForTraceId;
338
+ }
339
+
340
+ SamplesIntegrator.filterStackFrames(stackTrace, this.#engineConfig);
341
+
342
+ const endTime = event.ts + (event.dur || 0);
343
+ const minFrames = Math.min(stackTrace.length, this.#currentJSStack.length);
344
+ let i;
345
+ // Merge a sample's stack frames with the stack frames we have
346
+ // so far if we detect they are equivalent.
347
+ // Graphically
348
+ // This:
349
+ // Current stack trace Sample
350
+ // [-------A------] [A]
351
+ // [-------B------] [B]
352
+ // [-------C------] [C]
353
+ // ^ t = x1 ^ t = x2
354
+
355
+ // Becomes this:
356
+ // New stack trace after merge
357
+ // [--------A-------]
358
+ // [--------B-------]
359
+ // [--------C-------]
360
+ // ^ t = x2
361
+ for (i = this.#lockedJsStackDepth.at(-1) || 0; i < minFrames; ++i) {
362
+ const newFrame = stackTrace[i].callFrame;
363
+ const oldFrame = this.#currentJSStack[i].callFrame;
364
+ if (!SamplesIntegrator.framesAreEqual(newFrame, oldFrame)) {
365
+ break;
366
+ }
367
+ // Scoot the right edge of this callFrame to the right
368
+ this.#currentJSStack[i].dur =
369
+ Types.Timing.Micro(Math.max(this.#currentJSStack[i].dur || 0, endTime - this.#currentJSStack[i].ts));
370
+ }
371
+
372
+ // If there are call frames in the sample that differ with the stack
373
+ // we have, update the stack, but keeping the common frames in place
374
+ // Graphically
375
+ // This:
376
+ // Current stack trace Sample
377
+ // [-------A------] [A]
378
+ // [-------B------] [B]
379
+ // [-------C------] [C]
380
+ // [-------D------] [E]
381
+ // ^ t = x1 ^ t = x2
382
+ // Becomes this:
383
+ // New stack trace after merge
384
+ // [--------A-------]
385
+ // [--------B-------]
386
+ // [--------C-------]
387
+ // [E]
388
+ // ^ t = x2
389
+ this.#truncateJSStack(i, event.ts);
390
+
391
+ for (; i < stackTrace.length; ++i) {
392
+ const call = stackTrace[i];
393
+ if (call.nodeId === this.#profileModel.programNode?.id || call.nodeId === this.#profileModel.root?.id ||
394
+ call.nodeId === this.#profileModel.idleNode?.id || call.nodeId === this.#profileModel.gcNode?.id) {
395
+ // Skip (root), (program) and (idle) frames, since this are not
396
+ // relevant for web profiling and we don't want to show them in
397
+ // the timeline.
398
+ continue;
399
+ }
400
+ this.#currentJSStack.push(call);
401
+ this.#constructedProfileCalls.push(call);
402
+ }
403
+ }
404
+
405
+ /**
406
+ * When a call stack that differs from the one we are tracking has
407
+ * been detected in the samples, the latter is "truncated" by
408
+ * setting the ending time of its call frames and removing the top
409
+ * call frames that aren't shared with the new call stack. This way,
410
+ * we can update the tracked stack with the new call frames on top.
411
+ * @param depth the amount of call frames from bottom to top that
412
+ * should be kept in the tracking stack trace. AKA amount of shared
413
+ * call frames between two stacks.
414
+ * @param time the new end of the call frames in the stack.
415
+ */
416
+ #truncateJSStack(depth: number, time: Types.Timing.Micro): void {
417
+ if (this.#lockedJsStackDepth.length) {
418
+ const lockedDepth = this.#lockedJsStackDepth.at(-1);
419
+ if (lockedDepth && depth < lockedDepth) {
420
+ console.error(`Child stack is shallower (${depth}) than the parent stack (${lockedDepth}) at ${time}`);
421
+ depth = lockedDepth;
422
+ }
423
+ }
424
+ if (this.#currentJSStack.length < depth) {
425
+ console.error(`Trying to truncate higher than the current stack size at ${time}`);
426
+ depth = this.#currentJSStack.length;
427
+ }
428
+ for (let k = 0; k < this.#currentJSStack.length; ++k) {
429
+ this.#currentJSStack[k].dur = Types.Timing.Micro(Math.max(time - this.#currentJSStack[k].ts, 0));
430
+ }
431
+ this.#currentJSStack.length = depth;
432
+ }
433
+
434
+ #makeJSSampleEvent(call: Types.Events.SyntheticProfileCall, timestamp: Types.Timing.Micro, traceId?: number):
435
+ Types.Events.SyntheticJSSample {
436
+ const JSSampleEvent: Types.Events.SyntheticJSSample = {
437
+ name: Types.Events.Name.JS_SAMPLE,
438
+ cat: 'devtools.timeline',
439
+ args: {
440
+ data: {traceId, stackTrace: this.#makeProfileCallsForStack(call).map(e => e.callFrame)},
441
+ },
442
+ ph: Types.Events.Phase.INSTANT,
443
+ ts: timestamp,
444
+ dur: Types.Timing.Micro(0),
445
+ pid: this.#processId,
446
+ tid: this.#threadId,
447
+ };
448
+ return JSSampleEvent;
449
+ }
450
+
451
+ static framesAreEqual(frame1: Protocol.Runtime.CallFrame, frame2: Protocol.Runtime.CallFrame): boolean {
452
+ return frame1.scriptId === frame2.scriptId && frame1.functionName === frame2.functionName &&
453
+ frame1.lineNumber === frame2.lineNumber;
454
+ }
455
+
456
+ static showNativeName(name: string, runtimeCallStatsEnabled: boolean): boolean {
457
+ return runtimeCallStatsEnabled && Boolean(SamplesIntegrator.nativeGroup(name));
458
+ }
459
+
460
+ static nativeGroup(nativeName: string): SamplesIntegrator.NativeGroups|null {
461
+ if (nativeName.startsWith('Parse')) {
462
+ return SamplesIntegrator.NativeGroups.PARSE;
463
+ }
464
+ if (nativeName.startsWith('Compile') || nativeName.startsWith('Recompile')) {
465
+ return SamplesIntegrator.NativeGroups.COMPILE;
466
+ }
467
+ return null;
468
+ }
469
+
470
+ static isNativeRuntimeFrame(frame: Protocol.Runtime.CallFrame): boolean {
471
+ return frame.url === 'native V8Runtime';
472
+ }
473
+
474
+ static filterStackFrames(stack: Types.Events.SyntheticProfileCall[], engineConfig: Types.Configuration.Configuration):
475
+ void {
476
+ const showAllEvents = engineConfig.showAllEvents;
477
+ if (showAllEvents) {
478
+ return;
479
+ }
480
+ let previousNativeFrameName: string|null = null;
481
+ let j = 0;
482
+ for (let i = 0; i < stack.length; ++i) {
483
+ const frame = stack[i].callFrame;
484
+ const nativeRuntimeFrame = SamplesIntegrator.isNativeRuntimeFrame(frame);
485
+ if (nativeRuntimeFrame &&
486
+ !SamplesIntegrator.showNativeName(frame.functionName, engineConfig.includeRuntimeCallStats)) {
487
+ continue;
488
+ }
489
+ const nativeFrameName = nativeRuntimeFrame ? SamplesIntegrator.nativeGroup(frame.functionName) : null;
490
+ if (previousNativeFrameName && previousNativeFrameName === nativeFrameName) {
491
+ continue;
492
+ }
493
+ previousNativeFrameName = nativeFrameName;
494
+ stack[j++] = stack[i];
495
+ }
496
+ stack.length = j;
497
+ }
498
+
499
+ static createFakeTraceFromCpuProfile(profile: Protocol.Profiler.Profile, tid: Types.Events.ThreadID):
500
+ Types.File.TraceFile {
501
+ if (!profile) {
502
+ return {traceEvents: [], metadata: {}};
503
+ }
504
+ // The |Name.CPU_PROFILE| will let MetaHandler to set |traceIsGeneric| to false
505
+ // The start time and duration is important here because we'll use them to determine the traceBounds
506
+ // We use the start and end time of the profile (which is longer than all samples), so the Performance
507
+ // panel won't truncate this time period.
508
+ const cpuProfileEvent: Types.Events.SyntheticCpuProfile = {
509
+ cat: 'disabled-by-default-devtools.timeline',
510
+ name: Types.Events.Name.CPU_PROFILE,
511
+ ph: Types.Events.Phase.COMPLETE,
512
+ pid: Types.Events.ProcessID(1),
513
+ tid,
514
+ ts: Types.Timing.Micro(profile.startTime),
515
+ dur: Types.Timing.Micro(profile.endTime - profile.startTime),
516
+ args: {data: {cpuProfile: profile}},
517
+ // Create an arbitrary profile id.
518
+ id: '0x1' as Types.Events.ProfileID,
519
+ };
520
+
521
+ return {
522
+ traceEvents: [cpuProfileEvent],
523
+ metadata: {
524
+ dataOrigin: Types.File.DataOrigin.CPU_PROFILE,
525
+ }
526
+ };
527
+ }
528
+
529
+ static extractCpuProfileFromFakeTrace(traceEvents: readonly Types.Events.Event[]): Protocol.Profiler.Profile {
530
+ const profileEvent = traceEvents.find(e => Types.Events.isSyntheticCpuProfile(e));
531
+ const profile = profileEvent?.args.data.cpuProfile;
532
+ if (!profile) {
533
+ throw new Error('Missing cpuProfile data');
534
+ }
535
+ return profile;
536
+ }
537
+ }
538
+
539
+ export namespace SamplesIntegrator {
540
+ export const enum NativeGroups {
541
+ COMPILE = 'Compile',
542
+ PARSE = 'Parse',
543
+ }
544
+ }
@@ -0,0 +1,87 @@
1
+ // Copyright 2024 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 type * as Types from '../types/types.js';
6
+
7
+ let activeManager: SyntheticEventsManager|null = null;
8
+
9
+ export class SyntheticEventsManager {
10
+ /**
11
+ * All synthetic entries created in a trace from a corresponding trace events.
12
+ * (ProfileCalls are excluded because they are not based on a real trace event)
13
+ */
14
+ #syntheticTraces: Types.Events.SyntheticBased[] = [];
15
+ /**
16
+ * All raw entries from a trace.
17
+ */
18
+ #rawTraceEvents: readonly Types.Events.Event[] = [];
19
+
20
+ static activate(manager: SyntheticEventsManager): void {
21
+ activeManager = manager;
22
+ }
23
+
24
+ static createAndActivate(rawEvents: readonly Types.Events.Event[]): SyntheticEventsManager {
25
+ const manager = new SyntheticEventsManager(rawEvents);
26
+ SyntheticEventsManager.activate(manager);
27
+ return manager;
28
+ }
29
+
30
+ static getActiveManager(): SyntheticEventsManager {
31
+ if (!activeManager) {
32
+ throw new Error('Attempted to get a SyntheticEventsManager without initializing');
33
+ }
34
+ return activeManager;
35
+ }
36
+
37
+ static reset(): void {
38
+ activeManager = null;
39
+ }
40
+
41
+ static registerSyntheticEvent<T extends Types.Events.SyntheticBased>(syntheticEvent: Omit<T, '_tag'>): T {
42
+ try {
43
+ return SyntheticEventsManager.getActiveManager().#registerSyntheticEvent(syntheticEvent);
44
+ } catch {
45
+ // If no active manager has been initialized, we assume the trace engine is
46
+ // not running as part of the Performance panel. In this case we don't
47
+ // register synthetic events because we don't need to support timeline
48
+ // modifications serialization.
49
+ return syntheticEvent as T;
50
+ }
51
+ }
52
+
53
+ private constructor(rawEvents: readonly Types.Events.Event[]) {
54
+ this.#rawTraceEvents = rawEvents;
55
+ }
56
+
57
+ /**
58
+ * Registers and returns a branded synthetic event. Synthetic events need to
59
+ * be created with this method to ensure they are registered and made
60
+ * available to load events using serialized keys.
61
+ */
62
+ #registerSyntheticEvent<T extends Types.Events.SyntheticBased>(syntheticEvent: Omit<T, '_tag'>): T {
63
+ const rawIndex = this.#rawTraceEvents.indexOf(syntheticEvent.rawSourceEvent);
64
+ if (rawIndex < 0) {
65
+ throw new Error('Attempted to register a synthetic event paired to an unknown raw event.');
66
+ }
67
+ const eventAsSynthetic = syntheticEvent as T;
68
+ this.#syntheticTraces[rawIndex] = eventAsSynthetic;
69
+ return eventAsSynthetic;
70
+ }
71
+
72
+ syntheticEventForRawEventIndex(rawEventIndex: number): Types.Events.SyntheticBased {
73
+ const syntheticEvent = this.#syntheticTraces.at(rawEventIndex);
74
+ if (!syntheticEvent) {
75
+ throw new Error(`Attempted to get a synthetic event from an unknown raw event index: ${rawEventIndex}`);
76
+ }
77
+ return syntheticEvent;
78
+ }
79
+
80
+ getSyntheticTraces(): Types.Events.SyntheticBased[] {
81
+ return this.#syntheticTraces;
82
+ }
83
+
84
+ getRawTraceEvents(): readonly Types.Events.Event[] {
85
+ return this.#rawTraceEvents;
86
+ }
87
+ }