@paulirish/trace_engine 0.0.68 → 0.0.69

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 (137) hide show
  1. package/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
  2. package/README.md +17 -1
  3. package/generated/protocol.d.ts +55 -13
  4. package/generated/protocol.js +1 -4
  5. package/locales/af.json +3 -6
  6. package/locales/am.json +3 -6
  7. package/locales/ar.json +3 -6
  8. package/locales/as.json +3 -6
  9. package/locales/az.json +3 -6
  10. package/locales/be.json +3 -6
  11. package/locales/bg.json +3 -6
  12. package/locales/bn.json +3 -6
  13. package/locales/bs.json +3 -6
  14. package/locales/ca.json +75 -78
  15. package/locales/cs.json +3 -6
  16. package/locales/cy.json +3 -6
  17. package/locales/da.json +3 -6
  18. package/locales/de.json +3 -6
  19. package/locales/el.json +3 -6
  20. package/locales/en-GB.json +3 -6
  21. package/locales/es-419.json +3 -6
  22. package/locales/es.json +3 -6
  23. package/locales/et.json +3 -6
  24. package/locales/eu.json +3 -6
  25. package/locales/fa.json +3 -6
  26. package/locales/fi.json +3 -6
  27. package/locales/fil.json +3 -6
  28. package/locales/fr-CA.json +37 -40
  29. package/locales/fr.json +3 -6
  30. package/locales/gl.json +18 -21
  31. package/locales/gu.json +3 -6
  32. package/locales/he.json +3 -6
  33. package/locales/hi.json +11 -14
  34. package/locales/hr.json +3 -6
  35. package/locales/hu.json +3 -6
  36. package/locales/hy.json +3 -6
  37. package/locales/id.json +3 -6
  38. package/locales/is.json +3 -6
  39. package/locales/it.json +3 -6
  40. package/locales/ja.json +3 -6
  41. package/locales/ka.json +3 -6
  42. package/locales/kk.json +3 -6
  43. package/locales/km.json +3 -6
  44. package/locales/kn.json +3 -6
  45. package/locales/ko.json +3 -6
  46. package/locales/ky.json +3 -6
  47. package/locales/lo.json +3 -6
  48. package/locales/lt.json +3 -6
  49. package/locales/lv.json +5 -8
  50. package/locales/mk.json +75 -78
  51. package/locales/ml.json +3 -6
  52. package/locales/mn.json +3 -6
  53. package/locales/mr.json +3 -6
  54. package/locales/ms.json +3 -6
  55. package/locales/my.json +3 -6
  56. package/locales/ne.json +29 -32
  57. package/locales/nl.json +3 -6
  58. package/locales/no.json +3 -6
  59. package/locales/or.json +3 -6
  60. package/locales/pa.json +3 -6
  61. package/locales/pl.json +3 -6
  62. package/locales/pt-PT.json +3 -6
  63. package/locales/pt.json +32 -35
  64. package/locales/ro.json +3 -6
  65. package/locales/ru.json +3 -6
  66. package/locales/si.json +3 -6
  67. package/locales/sk.json +3 -6
  68. package/locales/sl.json +3 -6
  69. package/locales/sq.json +3 -6
  70. package/locales/sr-Latn.json +3 -6
  71. package/locales/sr.json +3 -6
  72. package/locales/sv.json +3 -6
  73. package/locales/sw.json +4 -7
  74. package/locales/ta.json +3 -6
  75. package/locales/te.json +3 -6
  76. package/locales/th.json +3 -6
  77. package/locales/tr.json +3 -6
  78. package/locales/uk.json +3 -6
  79. package/locales/ur.json +3 -6
  80. package/locales/uz.json +3 -6
  81. package/locales/vi.json +3 -6
  82. package/locales/zh-HK.json +3 -6
  83. package/locales/zh-TW.json +3 -6
  84. package/locales/zh.json +3 -6
  85. package/locales/zu.json +3 -6
  86. package/models/trace/EventsSerializer.js +0 -7
  87. package/models/trace/EventsSerializer.js.map +1 -1
  88. package/models/trace/Processor.js +15 -7
  89. package/models/trace/Processor.js.map +1 -1
  90. package/models/trace/extras/ThirdParties.js +4 -6
  91. package/models/trace/extras/ThirdParties.js.map +1 -1
  92. package/models/trace/extras/TraceFilter.d.ts +1 -0
  93. package/models/trace/extras/TraceFilter.js +18 -8
  94. package/models/trace/extras/TraceFilter.js.map +1 -1
  95. package/models/trace/extras/TraceTree.d.ts +13 -16
  96. package/models/trace/extras/TraceTree.js +126 -101
  97. package/models/trace/extras/TraceTree.js.map +1 -1
  98. package/models/trace/handlers/ExtensionTraceDataHandler.d.ts +0 -5
  99. package/models/trace/handlers/ExtensionTraceDataHandler.js +0 -5
  100. package/models/trace/handlers/ExtensionTraceDataHandler.js.map +1 -1
  101. package/models/trace/handlers/FlowsHandler.js +9 -0
  102. package/models/trace/handlers/FlowsHandler.js.map +1 -1
  103. package/models/trace/handlers/MetaHandler.js +3 -0
  104. package/models/trace/handlers/MetaHandler.js.map +1 -1
  105. package/models/trace/handlers/RendererHandler.js +7 -6
  106. package/models/trace/handlers/RendererHandler.js.map +1 -1
  107. package/models/trace/handlers/SamplesHandler.d.ts +0 -1
  108. package/models/trace/handlers/SamplesHandler.js +4 -2
  109. package/models/trace/handlers/SamplesHandler.js.map +1 -1
  110. package/models/trace/handlers/ScriptsHandler.js +24 -22
  111. package/models/trace/handlers/ScriptsHandler.js.map +1 -1
  112. package/models/trace/handlers/types.d.ts +15 -0
  113. package/models/trace/handlers/types.js.map +1 -1
  114. package/models/trace/helpers/Extensions.js +1 -3
  115. package/models/trace/helpers/Extensions.js.map +1 -1
  116. package/models/trace/helpers/SamplesIntegrator.d.ts +17 -14
  117. package/models/trace/helpers/SamplesIntegrator.js +147 -84
  118. package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
  119. package/models/trace/helpers/Trace.js +19 -14
  120. package/models/trace/helpers/Trace.js.map +1 -1
  121. package/models/trace/helpers/TreeHelpers.d.ts +13 -1
  122. package/models/trace/helpers/TreeHelpers.js +35 -8
  123. package/models/trace/helpers/TreeHelpers.js.map +1 -1
  124. package/models/trace/insights/DuplicatedJavaScript.js +1 -2
  125. package/models/trace/insights/DuplicatedJavaScript.js.map +1 -1
  126. package/models/trace/insights/SlowCSSSelector.js +2 -2
  127. package/models/trace/insights/SlowCSSSelector.js.map +1 -1
  128. package/models/trace/lantern/metrics/LargestContentfulPaint.d.ts +1 -0
  129. package/models/trace/lantern/metrics/LargestContentfulPaint.js +17 -4
  130. package/models/trace/lantern/metrics/LargestContentfulPaint.js.map +1 -1
  131. package/models/trace/lantern/simulation/Simulator.d.ts +4 -0
  132. package/models/trace/lantern/simulation/Simulator.js +4 -1
  133. package/models/trace/lantern/simulation/Simulator.js.map +1 -1
  134. package/models/trace/types/TraceEvents.d.ts +21 -19
  135. package/models/trace/types/TraceEvents.js.map +1 -1
  136. package/package.json +1 -1
  137. package/test/test-trace-engine.mjs +20 -17
@@ -1 +1 @@
1
- {"version":3,"file":"ScriptsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/ScriptsHandler.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,MAAM,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAG/D,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,IAAI,IAAI,eAAe,EAAuB,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAC,IAAI,IAAI,0BAA0B,EAAC,MAAM,6BAA6B,CAAC;AAkC/E,IAAI,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;AAC3C,IAAI,gBAAgB,GAAG,IAAI,GAAG,EAAyB,CAAC;AAExD,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,KAAK;IACnB,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;IACvB,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAyB;IACnD,MAAM,eAAe,GAAG,CAAC,OAAsB,EAAE,gBAAwB,EAAU,EAAE;QACnF,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAA8B,CAAC;QACvE,MAAM,GAAG,GAAG,GAAG,OAAO,IAAI,QAAQ,EAAE,CAAC;QACrC,OAAO,QAAQ,CAAC,YAAY,CAAC,cAAc,CACvC,UAAU,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,EAAC,OAAO,EAAE,QAAQ,EAA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vE,CAAC,CAAC,CAAC,CAAC;IACN,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;KAClC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2025 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Common from '../../../core/common/common.js';\nimport * as Platform from '../../../core/platform/platform.js';\nimport type * as SDK from '../../../core/sdk/sdk.js';\nimport type * as Protocol from '../../../generated/protocol.js';\nimport * as Types from '../types/types.js';\n\nimport {data as metaHandlerData, type MetaHandlerData} from './MetaHandler.js';\nimport {data as networkRequestsHandlerData} from './NetworkRequestsHandler.js';\nimport type {FinalizeOptions, HandlerName} from './types.js';\n\nexport interface ScriptsData {\n /** Note: this is only populated when the \"Enhanced Traces\" feature is enabled. */\n scripts: Script[];\n}\n\nexport interface Script {\n isolate: string|number;\n scriptId: Protocol.Runtime.ScriptId;\n frame: string;\n ts: Types.Timing.Micro;\n inline: boolean;\n url?: string;\n sourceUrl?: string;\n content?: string;\n /**\n * Note: this is the literal text given as the sourceMappingURL value. It has not been resolved relative to the script url.\n * Since M138, data urls are never set here.\n */\n sourceMapUrl?: string;\n /** If true, the source map url was a data URL, so it got removed from the trace event. */\n sourceMapUrlElided?: boolean;\n sourceMap?: SDK.SourceMap.SourceMap;\n request?: Types.Events.SyntheticNetworkRequest;\n /** Lazily generated - use getScriptGeneratedSizes to access. */\n sizes?: GeneratedFileSizes;\n}\n\ntype GeneratedFileSizes = {\n errorMessage: string,\n}|{files: Record<string, number>, unmappedBytes: number, totalBytes: number};\n\nlet scriptById = new Map<string, Script>();\nlet frameIdByIsolate = new Map<string|number, string>();\n\nexport function deps(): HandlerName[] {\n return ['Meta', 'NetworkRequests'];\n}\n\nexport function reset(): void {\n scriptById = new Map();\n frameIdByIsolate = new Map();\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n const getOrMakeScript = (isolate: string|number, scriptIdAsNumber: number): Script => {\n const scriptId = String(scriptIdAsNumber) as Protocol.Runtime.ScriptId;\n const key = `${isolate}.${scriptId}`;\n return Platform.MapUtilities.getWithDefault(\n scriptById, key, () => ({isolate, scriptId, frame: '', ts: event.ts} as Script));\n };\n\n if (Types.Events.isRundownScriptCompiled(event) && event.args.data) {\n const {isolate, scriptId, frame} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.frame = frame;\n script.ts = event.ts;\n\n return;\n }\n\n if (Types.Events.isRundownScript(event)) {\n const {isolate, scriptId, url, sourceUrl, sourceMapUrl, sourceMapUrlElided} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n if (!script.frame) {\n script.frame = frameIdByIsolate.get(String(isolate)) ?? '';\n }\n script.url = url;\n script.ts = event.ts;\n if (sourceUrl) {\n script.sourceUrl = sourceUrl;\n }\n\n // Older traces may have data source map urls. Those can be very large, so a change\n // was made to elide them from the trace.\n // If elided, a fresh trace will fetch the source map from the Script model\n // (see TimelinePanel getExistingSourceMap). If not fresh, the source map is resolved\n // instead in this handler via `findCachedRawSourceMap`.\n if (sourceMapUrlElided) {\n script.sourceMapUrlElided = true;\n } else if (sourceMapUrl) {\n script.sourceMapUrl = sourceMapUrl;\n }\n return;\n }\n\n if (Types.Events.isRundownScriptSource(event)) {\n const {isolate, scriptId, sourceText} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.content = sourceText;\n return;\n }\n\n if (Types.Events.isRundownScriptSourceLarge(event)) {\n const {isolate, scriptId, sourceText} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.content = (script.content ?? '') + sourceText;\n return;\n }\n\n // Setup frameIdByIsolate, which is used only in the case that we are missing\n // rundown events for a script. We won't get a frame association from the rundown\n // events if the recording started only after the script was first compiled. In\n // that scenario, derive the frame via the isolate / FunctionCall events.\n // TODO: ideally, we put the frame on ScriptCatchup event. So much easier. This approach has some\n // issues.\n if (Types.Events.isFunctionCall(event) && event.args.data?.isolate && event.args.data.frame) {\n const {isolate, frame} = event.args.data;\n const existingValue = frameIdByIsolate.get(isolate);\n if (existingValue !== frame) {\n frameIdByIsolate.set(isolate, frame);\n\n // Update the scripts we discovered but without knowing their frame.\n for (const script of scriptById.values()) {\n if (!script.frame && script.isolate === isolate) {\n script.frame = frame;\n }\n }\n }\n }\n}\n\nfunction findFrame(meta: MetaHandlerData, frameId: string): Types.Events.TraceFrame|null {\n for (const frames of meta.frameByProcessId?.values()) {\n const frame = frames.get(frameId);\n if (frame) {\n return frame;\n }\n }\n\n return null;\n}\n\nfunction findNetworkRequest(networkRequests: Types.Events.SyntheticNetworkRequest[], script: Script):\n Types.Events.SyntheticNetworkRequest|null {\n if (!script.url) {\n return null;\n }\n\n return networkRequests.find(request => request.args.data.url === script.url) ?? null;\n}\n\nfunction computeMappingEndColumns(map: SDK.SourceMap.SourceMap): Map<SDK.SourceMap.SourceMapEntry, number> {\n const result = new Map<SDK.SourceMap.SourceMapEntry, number>();\n\n const mappings = map.mappings();\n for (let i = 0; i < mappings.length - 1; i++) {\n const mapping = mappings[i];\n const nextMapping = mappings[i + 1];\n if (mapping.lineNumber === nextMapping.lineNumber) {\n result.set(mapping, nextMapping.columnNumber);\n }\n }\n\n // Now, all but the last mapping on each line will have a value in this map.\n return result;\n}\n\n/**\n * Using a script's contents and source map, attribute every generated byte to an authored source file.\n */\nfunction computeGeneratedFileSizes(script: Script): GeneratedFileSizes {\n if (!script.sourceMap) {\n throw new Error('expected source map');\n }\n\n const map = script.sourceMap;\n const content = script.content ?? '';\n const contentLength = content.length;\n const lines = content.split('\\n');\n const files: Record<string, number> = {};\n const totalBytes = contentLength;\n let unmappedBytes = totalBytes;\n\n const mappingEndCols = computeMappingEndColumns(script.sourceMap);\n\n for (const mapping of map.mappings()) {\n const source = mapping.sourceURL;\n const lineNum = mapping.lineNumber;\n const colNum = mapping.columnNumber;\n const lastColNum = mappingEndCols.get(mapping);\n\n // Webpack sometimes emits null mappings.\n // https://github.com/mozilla/source-map/pull/303\n if (!source) {\n continue;\n }\n\n // Lines and columns are zero-based indices. Visually, lines are shown as a 1-based index.\n\n const line = lines[lineNum];\n if (line === null || line === undefined) {\n const errorMessage = `${map.url()} mapping for line out of bounds: ${lineNum + 1}`;\n return {errorMessage};\n }\n\n if (colNum > line.length) {\n const errorMessage = `${map.url()} mapping for column out of bounds: ${lineNum + 1}:${colNum}`;\n return {errorMessage};\n }\n\n let mappingLength = 0;\n if (lastColNum !== undefined) {\n if (lastColNum > line.length) {\n const errorMessage = `${map.url()} mapping for last column out of bounds: ${lineNum + 1}:${lastColNum}`;\n return {errorMessage};\n }\n mappingLength = lastColNum - colNum;\n } else {\n // Add +1 to account for the newline.\n mappingLength = line.length - colNum + 1;\n }\n files[source] = (files[source] || 0) + mappingLength;\n unmappedBytes -= mappingLength;\n }\n\n return {\n files,\n unmappedBytes,\n totalBytes,\n };\n}\n\nexport function getScriptGeneratedSizes(script: Script): GeneratedFileSizes|null {\n if (script.sourceMap && !script.sizes) {\n script.sizes = computeGeneratedFileSizes(script);\n }\n\n return script.sizes ?? null;\n}\n\nfunction findCachedRawSourceMap(script: Script, options: Types.Configuration.ParseOptions): SDK.SourceMap.SourceMapV3|\n undefined {\n if (options.isFreshRecording || !options.metadata?.sourceMaps) {\n // Exit if this is not a loaded trace w/ source maps in the metadata.\n return;\n }\n\n // For elided data url source maps, search the metadata source maps by script url.\n if (script.sourceMapUrlElided) {\n if (!script.url) {\n return;\n }\n\n const cachedSourceMap = options.metadata.sourceMaps.find(m => m.url === script.url);\n if (cachedSourceMap) {\n return cachedSourceMap.sourceMap;\n }\n\n return;\n }\n\n if (!script.sourceMapUrl) {\n return;\n }\n\n // Otherwise, search by source map url.\n // Note: early enhanced traces may have this field set for data urls. Ignore those,\n // as they were never stored in metadata sourcemap.\n const isDataUrl = script.sourceMapUrl.startsWith('data:');\n if (!isDataUrl) {\n const cachedSourceMap = options.metadata.sourceMaps.find(m => m.sourceMapUrl === script.sourceMapUrl);\n if (cachedSourceMap) {\n return cachedSourceMap.sourceMap;\n }\n }\n\n return;\n}\n\nexport async function finalize(options: FinalizeOptions): Promise<void> {\n const meta = metaHandlerData();\n const networkRequests = [...networkRequestsHandlerData().byId.values()];\n\n const documentUrls = new Set<string>();\n for (const frames of meta.frameByProcessId.values()) {\n for (const frame of frames.values()) {\n documentUrls.add(frame.url);\n }\n }\n\n for (const script of scriptById.values()) {\n script.request = findNetworkRequest(networkRequests, script) ?? undefined;\n script.inline = !!script.url && documentUrls.has(script.url);\n }\n\n if (!options.resolveSourceMap) {\n return;\n }\n\n const promises = [];\n for (const script of scriptById.values()) {\n // No frame or url means the script came from somewhere we don't care about.\n // Note: scripts from inline <SCRIPT> elements use the url of the HTML document,\n // so aren't ignored.\n if (!script.frame || !script.url || (!script.sourceMapUrl && !script.sourceMapUrlElided)) {\n continue;\n }\n\n const frameUrl = findFrame(meta, script.frame)?.url as Platform.DevToolsPath.UrlString | undefined;\n if (!frameUrl) {\n continue;\n }\n\n // If there is a `sourceURL` magic comment, resolve the compiledUrl against the frame url.\n // example: `// #sourceURL=foo.js` for target frame https://www.example.com/home -> https://www.example.com/home/foo.js\n let sourceUrl = script.url;\n if (script.sourceUrl) {\n sourceUrl = Common.ParsedURL.ParsedURL.completeURL(frameUrl, script.sourceUrl) ?? script.sourceUrl;\n }\n\n let sourceMapUrl;\n if (script.sourceMapUrl) {\n // Resolve the source map url. The value given by v8 may be relative, so resolve it here.\n // This process should match the one in `SourceMapManager.attachSourceMap`.\n sourceMapUrl =\n Common.ParsedURL.ParsedURL.completeURL(sourceUrl as Platform.DevToolsPath.UrlString, script.sourceMapUrl);\n if (!sourceMapUrl) {\n continue;\n }\n\n script.sourceMapUrl = sourceMapUrl;\n }\n\n const params: Types.Configuration.ResolveSourceMapParams = {\n scriptId: script.scriptId,\n scriptUrl: script.url as Platform.DevToolsPath.UrlString,\n sourceUrl: sourceUrl as Platform.DevToolsPath.UrlString,\n sourceMapUrl: sourceMapUrl ?? '' as Platform.DevToolsPath.UrlString,\n frame: script.frame as Protocol.Page.FrameId,\n cachedRawSourceMap: findCachedRawSourceMap(script, options),\n };\n const promise = options.resolveSourceMap(params).then(sourceMap => {\n if (sourceMap) {\n script.sourceMap = sourceMap;\n }\n });\n promises.push(promise.catch(e => {\n console.error('Uncaught error when resolving source map', params, e);\n }));\n }\n await Promise.all(promises);\n}\n\nexport function data(): ScriptsData {\n return {\n scripts: [...scriptById.values()],\n };\n}\n"]}
1
+ {"version":3,"file":"ScriptsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/ScriptsHandler.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,MAAM,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAG/D,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,IAAI,IAAI,eAAe,EAAuB,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAC,IAAI,IAAI,0BAA0B,EAAC,MAAM,6BAA6B,CAAC;AAkC/E,IAAI,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;AAC3C,IAAI,gBAAgB,GAAG,IAAI,GAAG,EAAyB,CAAC;AAExD,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,KAAK;IACnB,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;IACvB,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAyB;IACnD,MAAM,eAAe,GAAG,CAAC,OAAsB,EAAE,gBAAwB,EAAU,EAAE;QACnF,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAA8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,SAAS,CAAC;YAC/B,CAAC;QACH,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;YAC9B,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC,CAAC;IACN,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;KAClC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2025 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Common from '../../../core/common/common.js';\nimport * as Platform from '../../../core/platform/platform.js';\nimport type * as SDK from '../../../core/sdk/sdk.js';\nimport type * as Protocol from '../../../generated/protocol.js';\nimport * as Types from '../types/types.js';\n\nimport {data as metaHandlerData, type MetaHandlerData} from './MetaHandler.js';\nimport {data as networkRequestsHandlerData} from './NetworkRequestsHandler.js';\nimport type {FinalizeOptions, HandlerName} from './types.js';\n\nexport interface ScriptsData {\n /** Note: this is only populated when the \"Enhanced Traces\" feature is enabled. */\n scripts: Script[];\n}\n\nexport interface Script {\n isolate: string|number;\n scriptId: Protocol.Runtime.ScriptId;\n frame: string;\n ts: Types.Timing.Micro;\n inline: boolean;\n url?: string;\n sourceUrl?: string;\n content?: string;\n /**\n * Note: this is the literal text given as the sourceMappingURL value. It has not been resolved relative to the script url.\n * Since M138, data urls are never set here.\n */\n sourceMapUrl?: string;\n /** If true, the source map url was a data URL, so it got removed from the trace event. */\n sourceMapUrlElided?: boolean;\n sourceMap?: SDK.SourceMap.SourceMap;\n request?: Types.Events.SyntheticNetworkRequest;\n /** Lazily generated - use getScriptGeneratedSizes to access. */\n sizes?: GeneratedFileSizes;\n}\n\ntype GeneratedFileSizes = {\n errorMessage: string,\n}|{files: Record<string, number>, unmappedBytes: number, totalBytes: number};\n\nlet scriptById = new Map<string, Script>();\nlet frameIdByIsolate = new Map<string|number, string>();\n\nexport function deps(): HandlerName[] {\n return ['Meta', 'NetworkRequests'];\n}\n\nexport function reset(): void {\n scriptById = new Map();\n frameIdByIsolate = new Map();\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n const getOrMakeScript = (isolate: string|number, scriptIdAsNumber: number): Script => {\n const scriptId = String(scriptIdAsNumber) as Protocol.Runtime.ScriptId;\n const key = `${isolate}.${scriptId}`;\n return Platform.MapUtilities.getWithDefault(\n scriptById, key, () => ({isolate, scriptId, frame: '', ts: event.ts} as Script));\n };\n\n if (Types.Events.isRundownScriptCompiled(event) && event.args.data) {\n const {isolate, scriptId, frame} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.frame = frame;\n script.ts = event.ts;\n\n return;\n }\n\n if (Types.Events.isRundownScript(event)) {\n const {isolate, scriptId, url, sourceUrl, sourceMapUrl, sourceMapUrlElided} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n if (!script.frame) {\n script.frame = frameIdByIsolate.get(String(isolate)) ?? '';\n }\n script.url = url;\n script.ts = event.ts;\n if (sourceUrl) {\n script.sourceUrl = sourceUrl;\n }\n\n // Older traces may have data source map urls. Those can be very large, so a change\n // was made to elide them from the trace.\n // If elided, a fresh trace will fetch the source map from the Script model\n // (see TimelinePanel getExistingSourceMap). If not fresh, the source map is resolved\n // instead in this handler via `findCachedRawSourceMap`.\n if (sourceMapUrlElided) {\n script.sourceMapUrlElided = true;\n } else if (sourceMapUrl) {\n script.sourceMapUrl = sourceMapUrl;\n }\n return;\n }\n\n if (Types.Events.isRundownScriptSource(event)) {\n const {isolate, scriptId, sourceText} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.content = sourceText;\n return;\n }\n\n if (Types.Events.isRundownScriptSourceLarge(event)) {\n const {isolate, scriptId, sourceText} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.content = (script.content ?? '') + sourceText;\n return;\n }\n\n // Setup frameIdByIsolate, which is used only in the case that we are missing\n // rundown events for a script. We won't get a frame association from the rundown\n // events if the recording started only after the script was first compiled. In\n // that scenario, derive the frame via the isolate / FunctionCall events.\n // TODO: ideally, we put the frame on ScriptCatchup event. So much easier. This approach has some\n // issues.\n if (Types.Events.isFunctionCall(event) && event.args.data?.isolate && event.args.data.frame) {\n const {isolate, frame} = event.args.data;\n const existingValue = frameIdByIsolate.get(isolate);\n if (existingValue !== frame) {\n frameIdByIsolate.set(isolate, frame);\n\n // Update the scripts we discovered but without knowing their frame.\n for (const script of scriptById.values()) {\n if (!script.frame && script.isolate === isolate) {\n script.frame = frame;\n }\n }\n }\n }\n}\n\nfunction findFrame(meta: MetaHandlerData, frameId: string): Types.Events.TraceFrame|null {\n for (const frames of meta.frameByProcessId?.values()) {\n const frame = frames.get(frameId);\n if (frame) {\n return frame;\n }\n }\n\n return null;\n}\n\nfunction findNetworkRequest(networkRequests: Types.Events.SyntheticNetworkRequest[], script: Script):\n Types.Events.SyntheticNetworkRequest|null {\n if (!script.url) {\n return null;\n }\n\n return networkRequests.find(request => request.args.data.url === script.url) ?? null;\n}\n\n/**\n * Using a script's contents and source map, attribute every generated byte to an authored source file.\n */\nfunction computeGeneratedFileSizes(script: Script): GeneratedFileSizes {\n if (!script.sourceMap) {\n throw new Error('expected source map');\n }\n\n const map = script.sourceMap;\n const content = script.content ?? '';\n const contentLength = content.length;\n // Scanning newline offsets with indexOf('\\n') avoids allocating a substring per line with content.split('\\n').\n const lineLengths: number[] = [];\n for (let start = 0;;) {\n const newlineIndex = content.indexOf('\\n', start);\n if (newlineIndex === -1) {\n lineLengths.push(contentLength - start);\n break;\n }\n lineLengths.push(newlineIndex - start);\n start = newlineIndex + 1;\n }\n const files: Record<string, number> = {};\n const totalBytes = contentLength;\n let unmappedBytes = totalBytes;\n\n const mappings = map.mappings();\n for (let i = 0; i < mappings.length; i++) {\n const mapping = mappings[i];\n const source = mapping.sourceURL;\n const lineNum = mapping.lineNumber;\n const colNum = mapping.columnNumber;\n // map.mappings() is sorted by (lineNumber, columnNumber), so the end column on the same line is\n // mappings[i + 1].columnNumber.\n const nextMapping = mappings[i + 1];\n const lastColNum =\n nextMapping !== undefined && nextMapping.lineNumber === lineNum ? nextMapping.columnNumber : undefined;\n\n // Webpack sometimes emits null mappings.\n // https://github.com/mozilla/source-map/pull/303\n if (!source) {\n continue;\n }\n\n // Lines and columns are zero-based indices. Visually, lines are shown as a 1-based index.\n\n const lineLength = lineLengths[lineNum];\n if (lineLength === undefined) {\n const errorMessage = `${map.url()} mapping for line out of bounds: ${lineNum + 1}`;\n return {errorMessage};\n }\n\n if (colNum > lineLength) {\n const errorMessage = `${map.url()} mapping for column out of bounds: ${lineNum + 1}:${colNum}`;\n return {errorMessage};\n }\n\n let mappingLength = 0;\n if (lastColNum !== undefined) {\n if (lastColNum > lineLength) {\n const errorMessage = `${map.url()} mapping for last column out of bounds: ${lineNum + 1}:${lastColNum}`;\n return {errorMessage};\n }\n mappingLength = lastColNum - colNum;\n } else {\n // Add +1 to account for the newline.\n mappingLength = lineLength - colNum + 1;\n }\n files[source] = (files[source] || 0) + mappingLength;\n unmappedBytes -= mappingLength;\n }\n\n return {\n files,\n unmappedBytes,\n totalBytes,\n };\n}\n\nexport function getScriptGeneratedSizes(script: Script): GeneratedFileSizes|null {\n if (script.sourceMap && !script.sizes) {\n script.sizes = computeGeneratedFileSizes(script);\n }\n\n return script.sizes ?? null;\n}\n\nfunction findCachedRawSourceMap(script: Script, options: Types.Configuration.ParseOptions): SDK.SourceMap.SourceMapV3|\n undefined {\n if (options.isFreshRecording || !options.metadata?.sourceMaps) {\n // Exit if this is not a loaded trace w/ source maps in the metadata.\n return;\n }\n\n // For elided data url source maps, search the metadata source maps by script url.\n if (script.sourceMapUrlElided) {\n if (!script.url) {\n return;\n }\n\n const cachedSourceMap = options.metadata.sourceMaps.find(m => m.url === script.url);\n if (cachedSourceMap) {\n return cachedSourceMap.sourceMap;\n }\n\n return;\n }\n\n if (!script.sourceMapUrl) {\n return;\n }\n\n // Otherwise, search by source map url.\n // Note: early enhanced traces may have this field set for data urls. Ignore those,\n // as they were never stored in metadata sourcemap.\n const isDataUrl = script.sourceMapUrl.startsWith('data:');\n if (!isDataUrl) {\n const cachedSourceMap = options.metadata.sourceMaps.find(m => m.sourceMapUrl === script.sourceMapUrl);\n if (cachedSourceMap) {\n return cachedSourceMap.sourceMap;\n }\n }\n\n return;\n}\n\nexport async function finalize(options: FinalizeOptions): Promise<void> {\n frameIdByIsolate = new Map();\n const meta = metaHandlerData();\n const networkRequests = [...networkRequestsHandlerData().byId.values()];\n\n const documentUrls = new Set<string>();\n for (const frames of meta.frameByProcessId.values()) {\n for (const frame of frames.values()) {\n documentUrls.add(frame.url);\n }\n }\n\n for (const script of scriptById.values()) {\n script.request = findNetworkRequest(networkRequests, script) ?? undefined;\n script.inline = !!script.url && documentUrls.has(script.url);\n }\n\n if (!options.resolveSourceMap) {\n return;\n }\n\n const promises = [];\n for (const script of scriptById.values()) {\n // No frame or url means the script came from somewhere we don't care about.\n // Note: scripts from inline <SCRIPT> elements use the url of the HTML document,\n // so aren't ignored.\n if (!script.frame || !script.url || (!script.sourceMapUrl && !script.sourceMapUrlElided)) {\n continue;\n }\n\n const frameUrl = findFrame(meta, script.frame)?.url as Platform.DevToolsPath.UrlString | undefined;\n if (!frameUrl) {\n continue;\n }\n\n // If there is a `sourceURL` magic comment, resolve the compiledUrl against the frame url.\n // example: `// #sourceURL=foo.js` for target frame https://www.example.com/home -> https://www.example.com/home/foo.js\n let sourceUrl = script.url;\n if (script.sourceUrl) {\n sourceUrl = Common.ParsedURL.ParsedURL.completeURL(frameUrl, script.sourceUrl) ?? script.sourceUrl;\n }\n\n let sourceMapUrl;\n if (script.sourceMapUrl) {\n // Resolve the source map url. The value given by v8 may be relative, so resolve it here.\n // This process should match the one in `SourceMapManager.attachSourceMap`.\n sourceMapUrl =\n Common.ParsedURL.ParsedURL.completeURL(sourceUrl as Platform.DevToolsPath.UrlString, script.sourceMapUrl);\n if (!sourceMapUrl) {\n continue;\n }\n\n script.sourceMapUrl = sourceMapUrl;\n }\n\n const params: Types.Configuration.ResolveSourceMapParams = {\n scriptId: script.scriptId,\n scriptUrl: script.url as Platform.DevToolsPath.UrlString,\n sourceUrl: sourceUrl as Platform.DevToolsPath.UrlString,\n sourceMapUrl: sourceMapUrl ?? '' as Platform.DevToolsPath.UrlString,\n frame: script.frame as Protocol.Page.FrameId,\n cachedRawSourceMap: findCachedRawSourceMap(script, options),\n };\n const promise = options.resolveSourceMap(params).then(sourceMap => {\n if (sourceMap) {\n script.sourceMap = sourceMap;\n }\n });\n promises.push(promise.catch(e => {\n console.error('Uncaught error when resolving source map', params, e);\n }));\n }\n await Promise.all(promises);\n}\n\nexport function data(): ScriptsData {\n return {\n scripts: [...scriptById.values()],\n };\n}\n"]}
@@ -4,9 +4,24 @@ export type FinalizeOptions = Types.Configuration.ParseOptions & {
4
4
  allTraceEvents: readonly Types.Events.Event[];
5
5
  };
6
6
  export interface Handler {
7
+ /**
8
+ * The processor calls this before and after every parse. It must assign new
9
+ * containers and never empty exported ones in place, because the parsed
10
+ * trace keeps references to them.
11
+ */
7
12
  reset(): void;
8
13
  handleEvent(data: object): void;
14
+ /**
15
+ * Handlers may release intermediate state that `data()` does not return, but not
16
+ * state that they export or that dependent handlers read in their own
17
+ * `finalize()`.
18
+ */
9
19
  finalize(options?: FinalizeOptions): Promise<void>;
20
+ /**
21
+ * The processor reads this once after every `finalize()` has run. Consumers
22
+ * must use `processor.data` or `Model#parsedTrace()`, because handler state
23
+ * is reset after the parse.
24
+ */
10
25
  data(): unknown;
11
26
  deps?(): HandlerName[];
12
27
  handleUserConfig?(config: Types.Configuration.Configuration): void;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/types.ts"],"names":[],"mappings":"","sourcesContent":["\n// Copyright 2022 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\nimport type * as Types from './../types/types.js';\nimport type * as ModelHandlers from './ModelHandlers.js';\n\nexport type FinalizeOptions = Types.Configuration.ParseOptions&{\n allTraceEvents: readonly Types.Events.Event[],\n};\n\nexport interface Handler {\n reset(): void;\n handleEvent(data: object): void;\n finalize(options?: FinalizeOptions): Promise<void>;\n data(): unknown;\n deps?(): HandlerName[];\n handleUserConfig?(config: Types.Configuration.Configuration): void;\n}\n\nexport type HandlerName = keyof typeof ModelHandlers;\n\n/**\n * This type maps Handler names to the return type of their data\n * function. So, for example, if we are given an object with a key of 'foo'\n * and a value which is a TraceHandler containing a data() function that\n * returns a string, this type will be { foo: string }.\n *\n * This allows us to model the behavior of the TraceProcessor in the model,\n * which takes an object with Handlers as part of its config, and\n * which ultimately returns an object keyed off the names of the\n * Handlers, and with values that are derived from each\n * Handler's data function.\n *\n * So, concretely, we provide a Handler for calculating the #time\n * bounds of a trace called TraceBounds, whose data() function returns a\n * TraceWindow. The HandlerData, therefore, would determine that the\n * TraceProcessor would contain a key called 'TraceBounds' whose value is\n * a TraceWindow.\n **/\nexport type EnabledHandlerDataWithMeta<T extends Record<string, Handler>> = {\n // We allow the user to configure which handlers are created by passing them\n // in when constructing a model instance. However, we then ensure that the\n // Meta handler is added to that, as the Model relies on some of the data\n // from the Meta handler when creating the file. Therefore, this type\n // explicitly defines that the Meta data is present, before then extending it\n // with the index type to represent all the other handlers.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: Readonly<ReturnType<typeof ModelHandlers['Meta']['data']>>,\n}&{\n // For every key in the object, look up the Handler's data function\n // and use its return type as the value for the object.\n [K in keyof T]: Readonly<ReturnType<T[K]['data']>>;\n};\n\nexport type HandlersWithMeta<T extends Record<string, Handler>> = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: typeof ModelHandlers.Meta,\n}&{\n [K in keyof T]: T[K];\n};\n\n/**\n * Represents the final data from all of the handlers. If you instantiate a\n * TraceProcessor with a subset of handlers, you should instead use\n * `EnabledHandlerDataWithMeta<>`.\n **/\nexport type HandlerData = Readonly<EnabledHandlerDataWithMeta<typeof ModelHandlers>>;\n\ntype DeepWriteable<T> = {\n -readonly[P in keyof T]: DeepWriteable<T[P]>\n};\nexport type HandlerDataMutable = DeepWriteable<HandlerData>;\n\nexport type Handlers = typeof ModelHandlers;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/types.ts"],"names":[],"mappings":"","sourcesContent":["\n// Copyright 2022 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\nimport type * as Types from './../types/types.js';\nimport type * as ModelHandlers from './ModelHandlers.js';\n\nexport type FinalizeOptions = Types.Configuration.ParseOptions&{\n allTraceEvents: readonly Types.Events.Event[],\n};\n\nexport interface Handler {\n /**\n * The processor calls this before and after every parse. It must assign new\n * containers and never empty exported ones in place, because the parsed\n * trace keeps references to them.\n */\n reset(): void;\n handleEvent(data: object): void;\n /**\n * Handlers may release intermediate state that `data()` does not return, but not\n * state that they export or that dependent handlers read in their own\n * `finalize()`.\n */\n finalize(options?: FinalizeOptions): Promise<void>;\n /**\n * The processor reads this once after every `finalize()` has run. Consumers\n * must use `processor.data` or `Model#parsedTrace()`, because handler state\n * is reset after the parse.\n */\n data(): unknown;\n deps?(): HandlerName[];\n handleUserConfig?(config: Types.Configuration.Configuration): void;\n}\n\nexport type HandlerName = keyof typeof ModelHandlers;\n\n/**\n * This type maps Handler names to the return type of their data\n * function. So, for example, if we are given an object with a key of 'foo'\n * and a value which is a TraceHandler containing a data() function that\n * returns a string, this type will be { foo: string }.\n *\n * This allows us to model the behavior of the TraceProcessor in the model,\n * which takes an object with Handlers as part of its config, and\n * which ultimately returns an object keyed off the names of the\n * Handlers, and with values that are derived from each\n * Handler's data function.\n *\n * So, concretely, we provide a Handler for calculating the #time\n * bounds of a trace called TraceBounds, whose data() function returns a\n * TraceWindow. The HandlerData, therefore, would determine that the\n * TraceProcessor would contain a key called 'TraceBounds' whose value is\n * a TraceWindow.\n **/\nexport type EnabledHandlerDataWithMeta<T extends Record<string, Handler>> = {\n // We allow the user to configure which handlers are created by passing them\n // in when constructing a model instance. However, we then ensure that the\n // Meta handler is added to that, as the Model relies on some of the data\n // from the Meta handler when creating the file. Therefore, this type\n // explicitly defines that the Meta data is present, before then extending it\n // with the index type to represent all the other handlers.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: Readonly<ReturnType<typeof ModelHandlers['Meta']['data']>>,\n}&{\n // For every key in the object, look up the Handler's data function\n // and use its return type as the value for the object.\n [K in keyof T]: Readonly<ReturnType<T[K]['data']>>;\n};\n\nexport type HandlersWithMeta<T extends Record<string, Handler>> = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: typeof ModelHandlers.Meta,\n}&{\n [K in keyof T]: T[K];\n};\n\n/**\n * Represents the final data from all of the handlers. If you instantiate a\n * TraceProcessor with a subset of handlers, you should instead use\n * `EnabledHandlerDataWithMeta<>`.\n **/\nexport type HandlerData = Readonly<EnabledHandlerDataWithMeta<typeof ModelHandlers>>;\n\ntype DeepWriteable<T> = {\n -readonly[P in keyof T]: DeepWriteable<T[P]>\n};\nexport type HandlerDataMutable = DeepWriteable<HandlerData>;\n\nexport type Handlers = typeof ModelHandlers;\n"]}
@@ -30,9 +30,7 @@ export function buildTrackDataFromExtensionEntries(extensionEntries, extensionTr
30
30
  for (const entries of Object.values(trackData.entriesByTrack)) {
31
31
  sortTraceEventsInPlace(entries);
32
32
  if (canBuildTreesFromEvents(entries)) {
33
- for (const [entry, node] of treify(entries).entryToNode) {
34
- entryToNode.set(entry, node);
35
- }
33
+ treify(entries, undefined, entryToNode);
36
34
  }
37
35
  }
38
36
  extensionTrackData.push(trackData);
@@ -1 +1 @@
1
- {"version":3,"file":"Extensions.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/helpers/Ext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AC3E,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IACD,gEAAgE;IAChE,kBAAkB;IAClB,KAAK,MAAM,SAAS,IAAI,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC;QAC7C,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC;YAC9D,sBAAsB,CAAC,OAAO,CAAC,CAAC;YAChC,IAAI,uBAAuB,CAAC,OAAO,CAAC,EAAE,CAAC;gBACrC,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;oBACxD,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;gBAC/B,CAAC;YACH,CAAC;QACH,CAAC;QACD,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,EAAC,kBAAkB,EAAE,WAAW,EAAC,CAAC;AAC3C,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\nimport type * as Types from '../types/types.js';\n\nimport {sortTraceEventsInPlace} from './Trace.js';\nimport {canBuildTreesFromEvents, type TraceEntryNode, treify} from './TreeHelpers.js';\n\nexport function buildTrackDataFromExtensionEntries(\n extensionEntries: Types.Extensions.SyntheticExtensionTrackEntry[],\n extensionTrackData: Types.Extensions.ExtensionTrackData[],\n entryToNode: Map<Types.Events.Event, TraceEntryNode>,\n ): {\n extensionTrackData: Types.Extensions.ExtensionTrackData[],\n entryToNode?: Map<Types.Events.Event, TraceEntryNode>,\n} {\n const dataByTrack = new Map<string, Types.Extensions.ExtensionTrackData>();\n for (const entry of extensionEntries) {\n // Batch data by track group. For each batch, add the data of every\n // track in the group. In cases where no track group is provided,\n // we use the standalone track data, but use a fixed prefix in the\n // batch key to prevent collisions where a track group has the\n // same name as a standalone track.\n const key = entry.devtoolsObj.trackGroup || `track-name-${entry.devtoolsObj.track}`;\n const batchedData = Platform.MapUtilities.getWithDefault(\n dataByTrack, key, () => ({\n name: entry.devtoolsObj.trackGroup || entry.devtoolsObj.track,\n isTrackGroup: Boolean(entry.devtoolsObj.trackGroup),\n entriesByTrack: {[entry.devtoolsObj.track]: []},\n }));\n\n if (!batchedData.entriesByTrack[entry.devtoolsObj.track]) {\n batchedData.entriesByTrack[entry.devtoolsObj.track] = [];\n }\n const entriesInTrack = batchedData.entriesByTrack[entry.devtoolsObj.track];\n entriesInTrack.push(entry);\n }\n // Calculate self time if possible for track entries, on a track\n // by track basis.\n for (const trackData of dataByTrack.values()) {\n for (const entries of Object.values(trackData.entriesByTrack)) {\n sortTraceEventsInPlace(entries);\n if (canBuildTreesFromEvents(entries)) {\n for (const [entry, node] of treify(entries).entryToNode) {\n entryToNode.set(entry, node);\n }\n }\n }\n extensionTrackData.push(trackData);\n }\n return {extensionTrackData, entryToNode};\n}\n"]}
1
+ {"version":3,"file":"Extensions.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/helpers/Extensions.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAG/D,OAAO,EAAC,sBAAsB,EAAC,MAAM,YAAY,CAAC;AAClD,OAAO,EAAC,uBAAuB,EAAuB,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAEtF,MAAM,UAAU,kCAAkC,CAC9C,gBAAiE,EACjE,kBAAyD,EACzD,WAAoD;IAKtD,MAAM,WAAW,GAAG,IAAI,GAAG,EAA+C,CAAC;IAC3E,KAAK,MAAM,KAAK,IAAI,gBAAgB,EAAE,CAAC;QACrC,mEAAmE;QACnE,iEAAiE;QACjE,kEAAkE;QAClE,8DAA8D;QAC9D,mCAAmC;QACnC,MAAM,GAAG,GAAG,KAA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AkB,EAAE,WAAW,EAAC,CAAC;AAC3C,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\nimport type * as Types from '../types/types.js';\n\nimport {sortTraceEventsInPlace} from './Trace.js';\nimport {canBuildTreesFromEvents, type TraceEntryNode, treify} from './TreeHelpers.js';\n\nexport function buildTrackDataFromExtensionEntries(\n extensionEntries: Types.Extensions.SyntheticExtensionTrackEntry[],\n extensionTrackData: Types.Extensions.ExtensionTrackData[],\n entryToNode: Map<Types.Events.Event, TraceEntryNode>,\n ): {\n extensionTrackData: Types.Extensions.ExtensionTrackData[],\n entryToNode?: Map<Types.Events.Event, TraceEntryNode>,\n} {\n const dataByTrack = new Map<string, Types.Extensions.ExtensionTrackData>();\n for (const entry of extensionEntries) {\n // Batch data by track group. For each batch, add the data of every\n // track in the group. In cases where no track group is provided,\n // we use the standalone track data, but use a fixed prefix in the\n // batch key to prevent collisions where a track group has the\n // same name as a standalone track.\n const key = entry.devtoolsObj.trackGroup || `track-name-${entry.devtoolsObj.track}`;\n const batchedData = Platform.MapUtilities.getWithDefault(\n dataByTrack, key, () => ({\n name: entry.devtoolsObj.trackGroup || entry.devtoolsObj.track,\n isTrackGroup: Boolean(entry.devtoolsObj.trackGroup),\n entriesByTrack: {[entry.devtoolsObj.track]: []},\n }));\n\n if (!batchedData.entriesByTrack[entry.devtoolsObj.track]) {\n batchedData.entriesByTrack[entry.devtoolsObj.track] = [];\n }\n const entriesInTrack = batchedData.entriesByTrack[entry.devtoolsObj.track];\n entriesInTrack.push(entry);\n }\n // Calculate self time if possible for track entries, on a track\n // by track basis.\n for (const trackData of dataByTrack.values()) {\n for (const entries of Object.values(trackData.entriesByTrack)) {\n sortTraceEventsInPlace(entries);\n if (canBuildTreesFromEvents(entries)) {\n treify(entries, undefined, entryToNode);\n }\n }\n extensionTrackData.push(trackData);\n }\n return {extensionTrackData, entryToNode};\n}\n"]}
@@ -14,14 +14,16 @@ import * as Types from '../types/types.js';
14
14
  * the shape of a complete trace events and can be treated as flame
15
15
  * chart entries in the timeline.
16
16
  *
17
- * The approach to build the profile calls consists in tracking the
18
- * current stack as the following events happen (in order):
19
- * 1. A sample was done.
20
- * 2. A trace event started.
21
- * 3. A trace event ended.
22
- * Depending on the event and on the data that's coming with it the
23
- * stack is updated by adding or removing JS calls to it and updating
24
- * the duration of the calls in the tracking stack.
17
+ * `buildProfileCalls()` streams the two chronologically ordered inputs
18
+ * (sorted `traceEvents` and sorted `#profileModel.samples`) with two
19
+ * cursors and a single reusable scratch `SyntheticProfileCall`, avoiding
20
+ * per-sample event and merged-array allocations. As the cursors advance,
21
+ * the integrator tracks the active JS call stack across three transitions:
22
+ * 1. A trace event ended (its `ts + dur` precedes or equals the next item).
23
+ * 2. A CPU sample was taken.
24
+ * 3. A trace event started.
25
+ * Depending on the transition, the integrator opens, extends, or truncates
26
+ * JS calls on `#currentJSStack`.
25
27
  *
26
28
  * note: Although this approach has been implemented since long ago, and
27
29
  * is relatively efficient (adds a complexity over the trace parsing of
@@ -38,14 +40,15 @@ export declare class SamplesIntegrator {
38
40
  */
39
41
  jsSampleEvents: Types.Events.SyntheticJSSample[];
40
42
  constructor(profileModel: CPUProfile.CPUProfileDataModel.CPUProfileDataModel, profileId: Types.Events.ProfileID, pid: Types.Events.ProcessID, tid: Types.Events.ThreadID, configuration?: Types.Configuration.Configuration);
41
- buildProfileCalls(traceEvents: Types.Events.Event[]): Types.Events.SyntheticProfileCall[];
42
43
  /**
43
- * Builds the initial calls with no duration from samples. Their
44
- * purpose is to be merged with the trace event array being parsed so
45
- * that they can be traversed in order with them and their duration
46
- * can be updated as the SampleIntegrator callbacks are invoked.
44
+ * Approximates JS call durations by streaming sorted `traceEvents` and
45
+ * `#profileModel.samples` in chronological order with two cursors.
46
+ *
47
+ * `traceEvents` must already be sorted with `sortTraceEventsInPlace()`
48
+ * (`#profileModel.samples` and `timestamps` are sorted during
49
+ * `CPUProfileDataModel` construction).
47
50
  */
48
- callsFromProfileSamples(): Types.Events.SyntheticProfileCall[];
51
+ buildProfileCalls(traceEvents: Types.Events.Event[]): Types.Events.SyntheticProfileCall[];
49
52
  static framesAreEqual(frame1: Protocol.Runtime.CallFrame, frame2: Protocol.Runtime.CallFrame): boolean;
50
53
  static showNativeName(name: string, runtimeCallStatsEnabled: boolean): boolean;
51
54
  static nativeGroup(nativeName: string): SamplesIntegrator.NativeGroups | null;
@@ -4,7 +4,7 @@
4
4
  var _a;
5
5
  import * as Types from '../types/types.js';
6
6
  import { milliToMicro } from './Timing.js';
7
- import { extractSampleTraceId, makeProfileCall, mergeEventsInOrder, sortTraceEventsInPlace } from './Trace.js';
7
+ import { eventTimeComparator, extractSampleTraceId, makeProfileCall, sortTraceEventsInPlace, } from './Trace.js';
8
8
  /**
9
9
  * This is a helper that integrates CPU profiling data coming in the
10
10
  * shape of samples, with trace events. Samples indicate what the JS
@@ -18,14 +18,16 @@ import { extractSampleTraceId, makeProfileCall, mergeEventsInOrder, sortTraceEve
18
18
  * the shape of a complete trace events and can be treated as flame
19
19
  * chart entries in the timeline.
20
20
  *
21
- * The approach to build the profile calls consists in tracking the
22
- * current stack as the following events happen (in order):
23
- * 1. A sample was done.
24
- * 2. A trace event started.
25
- * 3. A trace event ended.
26
- * Depending on the event and on the data that's coming with it the
27
- * stack is updated by adding or removing JS calls to it and updating
28
- * the duration of the calls in the tracking stack.
21
+ * `buildProfileCalls()` streams the two chronologically ordered inputs
22
+ * (sorted `traceEvents` and sorted `#profileModel.samples`) with two
23
+ * cursors and a single reusable scratch `SyntheticProfileCall`, avoiding
24
+ * per-sample event and merged-array allocations. As the cursors advance,
25
+ * the integrator tracks the active JS call stack across three transitions:
26
+ * 1. A trace event ended (its `ts + dur` precedes or equals the next item).
27
+ * 2. A CPU sample was taken.
28
+ * 3. A trace event started.
29
+ * Depending on the transition, the integrator opens, extends, or truncates
30
+ * JS calls on `#currentJSStack`.
29
31
  *
30
32
  * note: Although this approach has been implemented since long ago, and
31
33
  * is relatively efficient (adds a complexity over the trace parsing of
@@ -83,13 +85,14 @@ export class SamplesIntegrator {
83
85
  */
84
86
  #profileModel;
85
87
  /**
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.
88
+ * Because GC nodes don't have a stack, the integrator attaches the stack
89
+ * of the preceding sample to them. This map records which node provides
90
+ * the stack for each GC sample, keyed by `sampleIndex` (all GC samples
91
+ * share one `gcNode` ID with different preceding stacks, and samples do
92
+ * not have distinct `ProfileCall` object identities during the merge).
89
93
  * 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.
94
+ * are used during the construction of profile calls to infer the
95
+ * duration of the executed code when a GC node is sampled.
93
96
  */
94
97
  #nodeForGC = new Map();
95
98
  #engineConfig;
@@ -106,47 +109,106 @@ export class SamplesIntegrator {
106
109
  this.#engineConfig = configuration || Types.Configuration.defaults();
107
110
  this.#profileId = profileId;
108
111
  }
112
+ /**
113
+ * Approximates JS call durations by streaming sorted `traceEvents` and
114
+ * `#profileModel.samples` in chronological order with two cursors.
115
+ *
116
+ * `traceEvents` must already be sorted with `sortTraceEventsInPlace()`
117
+ * (`#profileModel.samples` and `timestamps` are sorted during
118
+ * `CPUProfileDataModel` construction).
119
+ */
109
120
  buildProfileCalls(traceEvents) {
110
- const mergedEvents = mergeEventsInOrder(traceEvents, this.callsFromProfileSamples());
111
- const stack = [];
112
- for (let i = 0; i < mergedEvents.length; i++) {
113
- const event = mergedEvents[i];
114
- // Because instant trace events have no duration, they don't provide
115
- // useful information for possible changes in the duration of calls
116
- // in the JS stack.
117
- if (event.ph === Types.Events.Phase.INSTANT && !extractSampleTraceId(event)) {
118
- continue;
119
- }
120
- if (stack.length === 0) {
121
- if (Types.Events.isProfileCall(event)) {
122
- this.#onProfileCall(event);
121
+ // Pre-index GC substitute stacks (and debug-mode JSSample events) before streaming.
122
+ this.#prepareSamples();
123
+ const samples = this.#profileModel.samples;
124
+ const timestamps = this.#profileModel.timestamps;
125
+ const numSamples = samples ? samples.length : 0;
126
+ // Reused mutable scratch event representing the current CPU sample at
127
+ // `sampleCursor - 1`. Only `nodeId`, `callFrame`, `sampleIndex`, and `ts`
128
+ // vary per sample (`profileId`, `pid`, `tid`, `ph`, and `dur: 0` remain
129
+ // constant for this integrator instance).
130
+ //
131
+ // Invariant: `sampleEvent` must NEVER be pushed onto `stack`,
132
+ // `#currentJSStack`, `#constructedProfileCalls`, or retained by reference.
133
+ // `#onProfileCall()` -> `#extractStackTrace()` reads its scalar fields and
134
+ // allocates fresh `SyntheticProfileCall` objects for opened stack frames.
135
+ let sampleEvent = null;
136
+ let sampleCursor = 0;
137
+ const advanceSample = () => {
138
+ while (sampleCursor < numSamples) {
139
+ const index = sampleCursor++;
140
+ const node = this.#profileModel.nodeByIndex(index);
141
+ if (!node) {
123
142
  continue;
124
143
  }
125
- stack.push(event);
126
- this.#onTraceEventStart(event);
127
- continue;
144
+ const ts = milliToMicro(Types.Timing.Milli(timestamps[index]));
145
+ if (sampleEvent === null) {
146
+ sampleEvent = makeProfileCall(node, this.#profileId, index, ts, this.#processId, this.#threadId);
147
+ }
148
+ else {
149
+ sampleEvent.nodeId = node.id;
150
+ sampleEvent.callFrame = node.callFrame;
151
+ sampleEvent.sampleIndex = index;
152
+ sampleEvent.ts = ts;
153
+ }
154
+ return sampleEvent;
128
155
  }
129
- const parentEvent = stack.at(-1);
130
- if (parentEvent === undefined) {
131
- continue;
156
+ return null;
157
+ };
158
+ let traceCursor = 0;
159
+ const numTraceEvents = traceEvents.length;
160
+ const advanceTrace = () => {
161
+ while (traceCursor < numTraceEvents) {
162
+ const traceEvent = traceEvents[traceCursor++];
163
+ // Instant events have zero duration and cannot change JS call durations
164
+ // unless they carry a `sampleTraceId` stack snapshot.
165
+ if (traceEvent.ph === Types.Events.Phase.INSTANT && !extractSampleTraceId(traceEvent)) {
166
+ continue;
167
+ }
168
+ return traceEvent;
132
169
  }
133
- const begin = event.ts;
134
- const parentBegin = parentEvent.ts;
135
- const parentDuration = parentEvent.dur || 0;
136
- const parentEnd = parentBegin + parentDuration;
137
- const startsAfterParent = begin >= parentEnd;
138
- if (startsAfterParent) {
170
+ return null;
171
+ };
172
+ const stack = [];
173
+ const unwindExpiredTraceEvents = (ts) => {
174
+ let parentEvent = stack.at(-1);
175
+ while (parentEvent !== undefined && ts >= parentEvent.ts + (parentEvent.dur || 0)) {
139
176
  this.#onTraceEventEnd(parentEvent);
140
177
  stack.pop();
141
- i--;
142
- continue;
178
+ parentEvent = stack.at(-1);
143
179
  }
180
+ return parentEvent;
181
+ };
182
+ let nextSample = advanceSample();
183
+ let nextTraceEvent = advanceTrace();
184
+ while (nextTraceEvent !== null || nextSample !== null) {
185
+ // Match `mergeEventsInOrder` tie-breaking at identical timestamps (`ts`):
186
+ // - Trace events with `dur > 0` end after a 0-duration sample, so
187
+ // `eventTimeComparator` returns `-1` and the trace event is pushed onto
188
+ // `stack` first as the sample's parent execution context.
189
+ // - Zero-duration trace events (`(dur ?? 0) === 0`, such as instant
190
+ // events with a `sampleTraceId`) tie on both start and end time, so
191
+ // `eventTimeComparator` prioritizes the `ProfileCall` (returns `1`) and
192
+ // the sample updates `#currentJSStack` first to parent the trace event.
193
+ const useSample = nextSample !== null && (nextTraceEvent === null || eventTimeComparator(nextTraceEvent, nextSample) > 0);
194
+ const event = useSample ? nextSample : nextTraceEvent;
195
+ if (event === null) {
196
+ break;
197
+ }
198
+ const parentEvent = unwindExpiredTraceEvents(event.ts);
144
199
  if (Types.Events.isProfileCall(event)) {
145
200
  this.#onProfileCall(event, parentEvent);
146
- continue;
147
201
  }
148
- this.#onTraceEventStart(event, parentEvent);
149
- stack.push(event);
202
+ else {
203
+ this.#onTraceEventStart(event, parentEvent);
204
+ stack.push(event);
205
+ }
206
+ if (useSample) {
207
+ nextSample = advanceSample();
208
+ }
209
+ else {
210
+ nextTraceEvent = advanceTrace();
211
+ }
150
212
  }
151
213
  while (stack.length) {
152
214
  const last = stack.pop();
@@ -157,6 +219,39 @@ export class SamplesIntegrator {
157
219
  sortTraceEventsInPlace(this.jsSampleEvents);
158
220
  return this.#constructedProfileCalls;
159
221
  }
222
+ /**
223
+ * Pre-indexes the preceding non-GC node for each GC sample in `#nodeForGC`
224
+ * (keyed by `sampleIndex`) so `#stackNodesForProfileCall()` can resolve GC
225
+ * stacks during the streaming merge without per-sample `ProfileCall` objects.
226
+ *
227
+ * When `debugMode` is enabled, this pass also populates `jsSampleEvents`
228
+ * before `buildProfileCalls()` appends any `sampleTraceId` sample events.
229
+ */
230
+ #prepareSamples() {
231
+ const samples = this.#profileModel.samples;
232
+ const timestamps = this.#profileModel.timestamps;
233
+ if (!samples) {
234
+ return;
235
+ }
236
+ let prevNode;
237
+ for (let i = 0; i < samples.length; i++) {
238
+ const node = this.#profileModel.nodeByIndex(i);
239
+ if (!node) {
240
+ continue;
241
+ }
242
+ if (this.#engineConfig.debugMode) {
243
+ const timestamp = milliToMicro(Types.Timing.Milli(timestamps[i]));
244
+ const call = makeProfileCall(node, this.#profileId, i, timestamp, this.#processId, this.#threadId);
245
+ const traceId = this.#profileModel.traceIds?.[i];
246
+ this.jsSampleEvents.push(this.#makeJSSampleEvent(call, timestamp, traceId));
247
+ }
248
+ if (node.id === this.#profileModel.gcNode?.id && prevNode) {
249
+ this.#nodeForGC.set(i, prevNode);
250
+ continue;
251
+ }
252
+ prevNode = node;
253
+ }
254
+ }
160
255
  #onTraceEventStart(event, parent) {
161
256
  // Top level events cannot be nested into JS frames so we reset
162
257
  // the stack when we find one.
@@ -201,11 +296,16 @@ export class SamplesIntegrator {
201
296
  // be incorrect.
202
297
  this.#lockedJsStackDepth.push(this.#currentJSStack.length);
203
298
  }
299
+ /**
300
+ * Integrates a CPU sample into `#currentJSStack`. During `buildProfileCalls()`,
301
+ * `event` is typically the mutable scratch `sampleEvent` and must never be
302
+ * retained by reference.
303
+ */
204
304
  #onProfileCall(event, parent) {
205
305
  if ((parent && Types.Events.isJSInvocationEvent(parent)) || this.#fakeJSInvocation) {
206
306
  this.#extractStackTrace(event);
207
307
  }
208
- else if (Types.Events.isProfileCall(event) && this.#currentJSStack.length === 0) {
308
+ else if (this.#currentJSStack.length === 0) {
209
309
  // Force JS Samples to show up even if we are not inside a JS
210
310
  // invocation event, because we can be missing the start of JS
211
311
  // invocation events if we start tracing half-way through. Pretend
@@ -223,43 +323,6 @@ export class SamplesIntegrator {
223
323
  const endTime = Types.Timing.Micro(event.ts + (event.dur ?? 0));
224
324
  this.#truncateJSStack(this.#lockedJsStackDepth.pop() || 0, endTime);
225
325
  }
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() {
233
- const samples = this.#profileModel.samples;
234
- const timestamps = this.#profileModel.timestamps;
235
- if (!samples) {
236
- return [];
237
- }
238
- const calls = [];
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
- if (this.#engineConfig.debugMode) {
249
- const traceId = this.#profileModel.traceIds?.[i];
250
- this.jsSampleEvents.push(this.#makeJSSampleEvent(call, timestamp, traceId));
251
- }
252
- if (node.id === this.#profileModel.gcNode?.id && prevNode) {
253
- // GC samples have no stack, so we just put GC node on top of the
254
- // last recorded sample. Cache the previous sample for future
255
- // reference.
256
- this.#nodeForGC.set(call, prevNode);
257
- continue;
258
- }
259
- prevNode = node;
260
- }
261
- return calls;
262
- }
263
326
  /**
264
327
  * Given a synthetic profile call, returns the profile nodes of the
265
328
  * stack trace that profile call belongs to based on its nodeId,
@@ -275,7 +338,7 @@ export class SamplesIntegrator {
275
338
  if (isGarbageCollection) {
276
339
  // Because GC don't have a stack, we use the stack of the previous
277
340
  // sample.
278
- node = this.#nodeForGC.get(profileCall) || null;
341
+ node = this.#nodeForGC.get(profileCall.sampleIndex) || null;
279
342
  }
280
343
  if (!sampledNode || !node) {
281
344
  return [];