@paulirish/trace_engine 0.0.67 → 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 (169) hide show
  1. package/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
  2. package/README.md +17 -1
  3. package/core/common/ParsedURL.d.ts +0 -2
  4. package/core/common/ParsedURL.js +3 -3
  5. package/core/common/ParsedURL.js.map +1 -1
  6. package/core/platform/StringUtilities.d.ts +15 -4
  7. package/core/platform/StringUtilities.js +48 -12
  8. package/core/platform/StringUtilities.js.map +1 -1
  9. package/generated/protocol.d.ts +89 -19
  10. package/generated/protocol.js +9 -4
  11. package/locales/af.json +12 -12
  12. package/locales/am.json +19 -19
  13. package/locales/ar.json +56 -56
  14. package/locales/as.json +69 -69
  15. package/locales/az.json +22 -22
  16. package/locales/be.json +46 -46
  17. package/locales/bg.json +17 -17
  18. package/locales/bn.json +76 -76
  19. package/locales/bs.json +23 -23
  20. package/locales/ca.json +14 -14
  21. package/locales/cs.json +13 -13
  22. package/locales/cy.json +21 -21
  23. package/locales/da.json +12 -12
  24. package/locales/de.json +10 -10
  25. package/locales/el.json +14 -14
  26. package/locales/en-GB.json +73 -73
  27. package/locales/en-US.json +3 -6
  28. package/locales/en-XL.json +3 -6
  29. package/locales/es-419.json +64 -64
  30. package/locales/es.json +44 -44
  31. package/locales/et.json +48 -48
  32. package/locales/eu.json +18 -18
  33. package/locales/fa.json +39 -39
  34. package/locales/fi.json +11 -11
  35. package/locales/fil.json +34 -34
  36. package/locales/fr-CA.json +49 -49
  37. package/locales/fr.json +18 -18
  38. package/locales/gl.json +33 -33
  39. package/locales/gu.json +39 -39
  40. package/locales/he.json +72 -72
  41. package/locales/hi.json +40 -40
  42. package/locales/hr.json +26 -26
  43. package/locales/hu.json +56 -56
  44. package/locales/hy.json +19 -19
  45. package/locales/id.json +68 -68
  46. package/locales/is.json +11 -11
  47. package/locales/it.json +44 -44
  48. package/locales/ja.json +15 -15
  49. package/locales/ka.json +68 -68
  50. package/locales/kk.json +44 -44
  51. package/locales/km.json +18 -18
  52. package/locales/kn.json +28 -28
  53. package/locales/ko.json +11 -11
  54. package/locales/ky.json +22 -22
  55. package/locales/lo.json +33 -33
  56. package/locales/lt.json +9 -9
  57. package/locales/lv.json +35 -35
  58. package/locales/mk.json +18 -18
  59. package/locales/ml.json +19 -19
  60. package/locales/mn.json +40 -40
  61. package/locales/mr.json +12 -12
  62. package/locales/ms.json +15 -15
  63. package/locales/my.json +62 -62
  64. package/locales/ne.json +42 -42
  65. package/locales/nl.json +33 -33
  66. package/locales/no.json +17 -17
  67. package/locales/or.json +54 -54
  68. package/locales/pa.json +24 -24
  69. package/locales/pl.json +32 -32
  70. package/locales/pt-PT.json +12 -12
  71. package/locales/pt.json +41 -41
  72. package/locales/ro.json +11 -11
  73. package/locales/ru.json +40 -40
  74. package/locales/si.json +36 -36
  75. package/locales/sk.json +65 -65
  76. package/locales/sl.json +13 -13
  77. package/locales/sq.json +21 -21
  78. package/locales/sr-Latn.json +17 -17
  79. package/locales/sr.json +17 -17
  80. package/locales/sv.json +13 -13
  81. package/locales/sw.json +69 -69
  82. package/locales/ta.json +39 -39
  83. package/locales/te.json +38 -38
  84. package/locales/th.json +38 -38
  85. package/locales/tr.json +17 -17
  86. package/locales/uk.json +23 -23
  87. package/locales/ur.json +13 -13
  88. package/locales/uz.json +15 -15
  89. package/locales/vi.json +43 -43
  90. package/locales/zh-HK.json +38 -38
  91. package/locales/zh-TW.json +35 -35
  92. package/locales/zh.json +73 -73
  93. package/locales/zu.json +53 -53
  94. package/models/cpu_profile/CPUProfileDataModel.d.ts +0 -33
  95. package/models/cpu_profile/CPUProfileDataModel.js +14 -14
  96. package/models/cpu_profile/CPUProfileDataModel.js.map +1 -1
  97. package/models/cpu_profile/ProfileTreeModel.d.ts +1 -2
  98. package/models/cpu_profile/ProfileTreeModel.js +4 -4
  99. package/models/cpu_profile/ProfileTreeModel.js.map +1 -1
  100. package/models/trace/EventsSerializer.js +1 -13
  101. package/models/trace/EventsSerializer.js.map +1 -1
  102. package/models/trace/LanternComputationData.js +36 -10
  103. package/models/trace/LanternComputationData.js.map +1 -1
  104. package/models/trace/ModelImpl.js +0 -2
  105. package/models/trace/ModelImpl.js.map +1 -1
  106. package/models/trace/Processor.js +16 -8
  107. package/models/trace/Processor.js.map +1 -1
  108. package/models/trace/extras/ThirdParties.js +4 -6
  109. package/models/trace/extras/ThirdParties.js.map +1 -1
  110. package/models/trace/extras/TraceFilter.d.ts +1 -0
  111. package/models/trace/extras/TraceFilter.js +18 -8
  112. package/models/trace/extras/TraceFilter.js.map +1 -1
  113. package/models/trace/extras/TraceTree.d.ts +13 -16
  114. package/models/trace/extras/TraceTree.js +161 -110
  115. package/models/trace/extras/TraceTree.js.map +1 -1
  116. package/models/trace/handlers/ExtensionTraceDataHandler.d.ts +0 -5
  117. package/models/trace/handlers/ExtensionTraceDataHandler.js +0 -5
  118. package/models/trace/handlers/ExtensionTraceDataHandler.js.map +1 -1
  119. package/models/trace/handlers/FlowsHandler.js +34 -19
  120. package/models/trace/handlers/FlowsHandler.js.map +1 -1
  121. package/models/trace/handlers/InitiatorsHandler.js +22 -34
  122. package/models/trace/handlers/InitiatorsHandler.js.map +1 -1
  123. package/models/trace/handlers/LayoutShiftsHandler.js +2 -6
  124. package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
  125. package/models/trace/handlers/MetaHandler.js +3 -0
  126. package/models/trace/handlers/MetaHandler.js.map +1 -1
  127. package/models/trace/handlers/NetworkRequestsHandler.js +12 -6
  128. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
  129. package/models/trace/handlers/RendererHandler.js +7 -6
  130. package/models/trace/handlers/RendererHandler.js.map +1 -1
  131. package/models/trace/handlers/SamplesHandler.d.ts +0 -1
  132. package/models/trace/handlers/SamplesHandler.js +11 -6
  133. package/models/trace/handlers/SamplesHandler.js.map +1 -1
  134. package/models/trace/handlers/ScriptsHandler.js +24 -22
  135. package/models/trace/handlers/ScriptsHandler.js.map +1 -1
  136. package/models/trace/handlers/types.d.ts +15 -0
  137. package/models/trace/handlers/types.js.map +1 -1
  138. package/models/trace/helpers/Extensions.js +1 -3
  139. package/models/trace/helpers/Extensions.js.map +1 -1
  140. package/models/trace/helpers/SamplesIntegrator.d.ts +17 -14
  141. package/models/trace/helpers/SamplesIntegrator.js +147 -84
  142. package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
  143. package/models/trace/helpers/SyntheticEvents.d.ts +0 -8
  144. package/models/trace/helpers/SyntheticEvents.js +10 -33
  145. package/models/trace/helpers/SyntheticEvents.js.map +1 -1
  146. package/models/trace/helpers/Trace.js +19 -14
  147. package/models/trace/helpers/Trace.js.map +1 -1
  148. package/models/trace/helpers/TreeHelpers.d.ts +13 -1
  149. package/models/trace/helpers/TreeHelpers.js +35 -8
  150. package/models/trace/helpers/TreeHelpers.js.map +1 -1
  151. package/models/trace/insights/DuplicatedJavaScript.js +1 -2
  152. package/models/trace/insights/DuplicatedJavaScript.js.map +1 -1
  153. package/models/trace/insights/RenderBlocking.js +3 -1
  154. package/models/trace/insights/RenderBlocking.js.map +1 -1
  155. package/models/trace/insights/SlowCSSSelector.js +2 -2
  156. package/models/trace/insights/SlowCSSSelector.js.map +1 -1
  157. package/models/trace/lantern/metrics/LargestContentfulPaint.d.ts +6 -1
  158. package/models/trace/lantern/metrics/LargestContentfulPaint.js +130 -5
  159. package/models/trace/lantern/metrics/LargestContentfulPaint.js.map +1 -1
  160. package/models/trace/lantern/simulation/Simulator.d.ts +4 -0
  161. package/models/trace/lantern/simulation/Simulator.js +8 -1
  162. package/models/trace/lantern/simulation/Simulator.js.map +1 -1
  163. package/models/trace/lantern/types/Lantern.d.ts +4 -0
  164. package/models/trace/lantern/types/Lantern.js.map +1 -1
  165. package/models/trace/types/TraceEvents.d.ts +21 -19
  166. package/models/trace/types/TraceEvents.js.map +1 -1
  167. package/package.json +1 -1
  168. package/test/test-trace-engine.mjs +20 -17
  169. package/third_party/legacy-javascript/lib/legacy-javascript.js +2 -2
@@ -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 [];
@@ -1 +1 @@
1
- {"version":3,"file":"SamplesIntegrator.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/helpers/SamplesIntegrator.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;;AAI7B,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AACzC,OAAO,EAAC,oBAAoB,EAAE,eAAe,EAAE,kBAAkB,EAAE,sBAAsB,EAAC,MAAM,YAAY,CAAC;AAE7G;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,iBAAiB;IAC5B;;;;OAIG;IACH,wBAAwB,GAAwC,EAAE,CAAC;IACnE;;;;;;OAMG;IACH,eAAe,GAAwC,EAAE,CAAC;IAC1D;;OAEG;IACH,UAAU,CAAyB;IACnC;;OAEG;IACH,SAAS,CAAwB;IACjC;;;;;;;OAOG;IACH,mBAAmB,GAAa,EAAE,CAAC;IACnC;;;;;;;;;OASG;IACH,iBAAiB,GAAG,KAAK,CAAC;IAC1B;;;OAGG;IACH,aAAa,CAAqD;IAClE;;;;;;;;OAQG;IACH,UAAU,GAAG,IAAI,GAAG,EAA8E,CAAC;IAEnG,aAAa,CAAoC;IACjD,UAAU,CAAyB;IAEnC;;;OAGG;IACH,cAAc,GAAqC,EAAE,CAAC;IAEtD,YACI,YAAgE,EAAE,SAAiC,EACnG,GAA2B,EAAE,GAA0B,EAAE,aAAiD;QAC5G,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QACtB,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,KAAK,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;QACrE,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,iBAAiB,CAAC,WAAiC;QACjD,MAAM,YA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C,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;QAClF,MAAM,OAAO,GAAG,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;QACnD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;;AAED,WAAiB,iBAAiB;IAChC,IAAY,YAGX;IAHD,WAAY,YAAY;QACtB,mCAAmB,CAAA;QACnB,+BAAe,CAAA;IACjB,CAAC,EAHW,YAAY,GAAZ,kBAAA,YAAY,KAAZ,kBAAA,YAAY,QAGvB;AACH,CAAC,EALgB,iBAAiB,KAAjB,iBAAiB,QAKjC","sourcesContent":["// Copyright 2023 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 type * as Protocol from '../../../generated/protocol.js';\nimport type * as CPUProfile from '../../cpu_profile/cpu_profile.js';\nimport * as Types from '../types/types.js';\n\nimport {milliToMicro} from './Timing.js';\nimport {extractSampleTraceId, makeProfileCall, mergeEventsInOrder, sortTraceEventsInPlace} from './Trace.js';\n\n/**\n * This is a helper that integrates CPU profiling data coming in the\n * shape of samples, with trace events. Samples indicate what the JS\n * stack trace looked at a given point in time, but they don't have\n * duration. The SamplesIntegrator task is to make an approximation\n * of what the duration of each JS call was, given the sample data and\n * given the trace events profiled during that time. At the end of its\n * execution, the SamplesIntegrator returns an array of ProfileCalls\n * (under SamplesIntegrator::buildProfileCalls()), which\n * represent JS calls, with a call frame and duration. These calls have\n * the shape of a complete trace events and can be treated as flame\n * chart entries in the timeline.\n *\n * The approach to build the profile calls consists in tracking the\n * current stack as the following events happen (in order):\n * 1. A sample was done.\n * 2. A trace event started.\n * 3. A trace event ended.\n * Depending on the event and on the data that's coming with it the\n * stack is updated by adding or removing JS calls to it and updating\n * the duration of the calls in the tracking stack.\n *\n * note: Although this approach has been implemented since long ago, and\n * is relatively efficient (adds a complexity over the trace parsing of\n * O(n) where n is the number of samples) it has proven to be faulty.\n * It might be worthwhile experimenting with improvements or with a\n * completely different approach. Improving the approach is tracked in\n * crbug.com/1417439\n */\nexport class SamplesIntegrator {\n /**\n * The result of running the samples integrator. Holds the JS calls\n * with their approximated duration after integrating samples into the\n * trace event tree.\n */\n #constructedProfileCalls: Types.Events.SyntheticProfileCall[] = [];\n /**\n * tracks the state of the JS stack at each point in time to update\n * the profile call durations as new events arrive. This doesn't only\n * happen with new profile calls (in which case we would compare the\n * stack in them) but also with trace events (in which case we would\n * update the duration of the events we are tracking at the moment).\n */\n #currentJSStack: Types.Events.SyntheticProfileCall[] = [];\n /**\n * Process holding the CPU profile and trace events.\n */\n #processId: Types.Events.ProcessID;\n /**\n * Thread holding the CPU profile and trace events.\n */\n #threadId: Types.Events.ThreadID;\n /**\n * Tracks the depth of the JS stack at the moment a trace event starts\n * or ends. It is assumed that for the duration of a trace event, the\n * JS stack's depth cannot decrease, since JS calls that started\n * before a trace event cannot end during the trace event. So as trace\n * events arrive, we store the \"locked\" amount of JS frames that were\n * in the stack before the event came.\n */\n #lockedJsStackDepth: number[] = [];\n /**\n * Used to keep track when samples should be integrated even if they\n * are not children of invocation trace events. This is used in two cases:\n * 1. We start tracing half-way through, so we miss the start of JS\n * invocation events.\n * 2. On threads (like Web Workers) without real JS invocation parent events,\n * but where trace events (like SchedulePostMessage) integrate stack traces.\n * Enabling fake JS mode allows subsequent samples to be processed and\n * eventually correct the stack, preventing a deadlock.\n */\n #fakeJSInvocation = false;\n /**\n * The parsed CPU profile, holding the tree hierarchy of JS frames and\n * the sample data.\n */\n #profileModel: CPUProfile.CPUProfileDataModel.CPUProfileDataModel;\n /**\n * Because GC nodes don't have a stack, we artificially add a stack to\n * them which corresponds to that of the previous sample. This map\n * tracks which node is used for the stack of a GC call.\n * Note that GC samples are not shown in the flamechart, however they\n * are used during the construction of for profile calls, as we can\n * infer information about the duration of the executed code when a\n * GC node is sampled.\n */\n #nodeForGC = new Map<Types.Events.SyntheticProfileCall, CPUProfile.ProfileTreeModel.ProfileNode>();\n\n #engineConfig: Types.Configuration.Configuration;\n #profileId: Types.Events.ProfileID;\n\n /**\n * Keeps track of the individual samples from the CPU Profile.\n * Only used with Debug Mode experiment enabled.\n */\n jsSampleEvents: Types.Events.SyntheticJSSample[] = [];\n\n constructor(\n profileModel: CPUProfile.CPUProfileDataModel.CPUProfileDataModel, profileId: Types.Events.ProfileID,\n pid: Types.Events.ProcessID, tid: Types.Events.ThreadID, configuration?: Types.Configuration.Configuration) {\n this.#profileModel = profileModel;\n this.#threadId = tid;\n this.#processId = pid;\n this.#engineConfig = configuration || Types.Configuration.defaults();\n this.#profileId = profileId;\n }\n\n buildProfileCalls(traceEvents: Types.Events.Event[]): Types.Events.SyntheticProfileCall[] {\n const mergedEvents = mergeEventsInOrder(traceEvents, this.callsFromProfileSamples());\n const stack = [];\n for (let i = 0; i < mergedEvents.length; i++) {\n const event = mergedEvents[i];\n // Because instant trace events have no duration, they don't provide\n // useful information for possible changes in the duration of calls\n // in the JS stack.\n if (event.ph === Types.Events.Phase.INSTANT && !extractSampleTraceId(event)) {\n continue;\n }\n if (stack.length === 0) {\n if (Types.Events.isProfileCall(event)) {\n this.#onProfileCall(event);\n continue;\n }\n stack.push(event);\n this.#onTraceEventStart(event);\n continue;\n }\n\n const parentEvent = stack.at(-1);\n if (parentEvent === undefined) {\n continue;\n }\n const begin = event.ts;\n const parentBegin = parentEvent.ts;\n const parentDuration = parentEvent.dur || 0;\n const parentEnd = parentBegin + parentDuration;\n\n const startsAfterParent = begin >= parentEnd;\n if (startsAfterParent) {\n this.#onTraceEventEnd(parentEvent);\n stack.pop();\n i--;\n continue;\n }\n if (Types.Events.isProfileCall(event)) {\n this.#onProfileCall(event, parentEvent);\n continue;\n }\n this.#onTraceEventStart(event, parentEvent);\n stack.push(event);\n }\n while (stack.length) {\n const last = stack.pop();\n if (last) {\n this.#onTraceEventEnd(last);\n }\n }\n sortTraceEventsInPlace(this.jsSampleEvents);\n return this.#constructedProfileCalls;\n }\n\n #onTraceEventStart(event: Types.Events.Event, parent?: Types.Events.Event): void {\n // Top level events cannot be nested into JS frames so we reset\n // the stack when we find one.\n if (event.name === Types.Events.Name.RUN_MICROTASKS || event.name === Types.Events.Name.RUN_TASK) {\n this.#lockedJsStackDepth = [];\n this.#truncateJSStack(0, event.ts);\n this.#fakeJSInvocation = false;\n }\n\n if (this.#fakeJSInvocation) {\n this.#truncateJSStack(this.#lockedJsStackDepth.pop() || 0, event.ts);\n this.#fakeJSInvocation = false;\n }\n this.#extractStackTrace(event);\n if (extractSampleTraceId(event)) {\n const hasJSInvocationParent = parent && Types.Events.isJSInvocationEvent(parent);\n if (!hasJSInvocationParent) {\n // If the event has a sampleTraceId (meaning it has a stack trace) but\n // no JS invocation parent, we enter fake JS mode. This ensures that\n // subsequent samples on this thread are processed, allowing the stack\n // to be correctly updated/truncated. Without this, subsequent samples\n // would be ignored because the stack is non-empty but we are not\n // considered to be in JS.\n this.#fakeJSInvocation = true;\n }\n }\n // Keep track of the call frames in the stack before the event\n // happened. For the duration of this event, these frames cannot\n // change (none can be terminated before this event finishes).\n //\n // Also, every frame that is opened after this event, is considered\n // to be a descendant of the event. So once the event finishes, the\n // frames that were opened after it, need to be closed (see\n // onEndEvent).\n //\n // TODO(crbug.com/1417439):\n // The assumption that every frame opened after an event is a\n // descendant of the event is incorrect. For example, a JS call that\n // parents a trace event might have been sampled after the event was\n // dispatched. In this case the JS call would be discarded if this\n // event isn't an invocation event, otherwise the call will be\n // considered a child of the event. In both cases, the result would\n // be incorrect.\n this.#lockedJsStackDepth.push(this.#currentJSStack.length);\n }\n\n #onProfileCall(event: Types.Events.SyntheticProfileCall, parent?: Types.Events.Event): void {\n if ((parent && Types.Events.isJSInvocationEvent(parent)) || this.#fakeJSInvocation) {\n this.#extractStackTrace(event);\n } else if (Types.Events.isProfileCall(event) && this.#currentJSStack.length === 0) {\n // Force JS Samples to show up even if we are not inside a JS\n // invocation event, because we can be missing the start of JS\n // invocation events if we start tracing half-way through. Pretend\n // we have a top-level JS invocation event.\n this.#fakeJSInvocation = true;\n const stackDepthBefore = this.#currentJSStack.length;\n this.#extractStackTrace(event);\n this.#lockedJsStackDepth.push(stackDepthBefore);\n }\n }\n\n #onTraceEventEnd(event: Types.Events.Event): void {\n // Because the event has ended, any frames that happened after\n // this event are terminated. Frames that are ancestors to this\n // event are extended to cover its ending.\n const endTime = Types.Timing.Micro(event.ts + (event.dur ?? 0));\n this.#truncateJSStack(this.#lockedJsStackDepth.pop() || 0, endTime);\n }\n\n /**\n * Builds the initial calls with no duration from samples. Their\n * purpose is to be merged with the trace event array being parsed so\n * that they can be traversed in order with them and their duration\n * can be updated as the SampleIntegrator callbacks are invoked.\n */\n callsFromProfileSamples(): Types.Events.SyntheticProfileCall[] {\n const samples = this.#profileModel.samples;\n const timestamps = this.#profileModel.timestamps;\n if (!samples) {\n return [];\n }\n const calls: Types.Events.SyntheticProfileCall[] = [];\n let prevNode;\n for (let i = 0; i < samples.length; i++) {\n const node = this.#profileModel.nodeByIndex(i);\n const timestamp = milliToMicro(Types.Timing.Milli(timestamps[i]));\n if (!node) {\n continue;\n }\n const call = makeProfileCall(node, this.#profileId, i, timestamp, this.#processId, this.#threadId);\n calls.push(call);\n\n if (this.#engineConfig.debugMode) {\n const traceId = this.#profileModel.traceIds?.[i];\n this.jsSampleEvents.push(this.#makeJSSampleEvent(call, timestamp, traceId));\n }\n if (node.id === this.#profileModel.gcNode?.id && prevNode) {\n // GC samples have no stack, so we just put GC node on top of the\n // last recorded sample. Cache the previous sample for future\n // reference.\n this.#nodeForGC.set(call, prevNode);\n continue;\n }\n prevNode = node;\n }\n return calls;\n }\n\n /**\n * Given a synthetic profile call, returns the profile nodes of the\n * stack trace that profile call belongs to based on its nodeId,\n * ordered from the bottom of the stack to the top. The root node is\n * omitted. The node of the input profile call will be at the top of\n * the returned stack (last position), meaning that any other frames\n * that were effectively above it are omitted.\n */\n #stackNodesForProfileCall(profileCall: Types.Events.SyntheticProfileCall): CPUProfile.ProfileTreeModel.ProfileNode[] {\n const sampledNode = this.#profileModel.nodeById(profileCall.nodeId);\n let node = sampledNode;\n const isGarbageCollection = node?.id === this.#profileModel.gcNode?.id;\n if (isGarbageCollection) {\n // Because GC don't have a stack, we use the stack of the previous\n // sample.\n node = this.#nodeForGC.get(profileCall) || null;\n }\n if (!sampledNode || !node) {\n return [];\n }\n // `node.depth` is 0 based, so to set the size of the array we need\n // to add 1 to its value.\n const nodes = new Array<CPUProfile.ProfileTreeModel.ProfileNode>(node.depth + 1 + Number(isGarbageCollection));\n // Add the stack trace in reverse order (bottom first).\n let i = nodes.length - 1;\n if (isGarbageCollection) {\n // Place the garbage collection node on top of the stack.\n nodes[i--] = sampledNode;\n }\n // The root node has a depth of -1, so the loop stops before it.\n while (node && i >= 0) {\n nodes[i--] = node;\n node = node.parent;\n }\n return nodes;\n }\n\n /**\n * Returns a profile call for the node sampled with the given trace id,\n * or null if the profile has no node for it.\n */\n #callForSampleTraceId(traceId: number, timestamp: Types.Timing.Micro): Types.Events.SyntheticProfileCall|null {\n const nodeId = this.#profileModel.traceIds?.[traceId];\n const node = nodeId && this.#profileModel.nodeById(nodeId);\n if (!node) {\n return null;\n }\n const callForTraceId = makeProfileCall(node, this.#profileId, -1, timestamp, this.#processId, this.#threadId);\n if (this.#engineConfig.debugMode) {\n this.jsSampleEvents.push(this.#makeJSSampleEvent(callForTraceId, timestamp, traceId));\n }\n return callForTraceId;\n }\n\n /**\n * Update tracked stack using this event's call stack.\n */\n #extractStackTrace(event: Types.Events.Event): void {\n const traceId = extractSampleTraceId(event);\n const callForTraceId = traceId ? this.#callForSampleTraceId(traceId, event.ts) : null;\n const stackSource = callForTraceId ?? (Types.Events.isProfileCall(event) ? event : null);\n if (!stackSource) {\n // The event carries no stack of its own, so merging the tracked\n // stack with itself only updates the durations of its frames.\n this.#mergeWithCurrentStack(event, this.#currentJSStack);\n return;\n }\n\n const stackNodes = this.#stackNodesForProfileCall(stackSource);\n let i = this.#mergeWithCurrentStack(event, stackNodes);\n for (; i < stackNodes.length; ++i) {\n const node = stackNodes[i];\n if (node.id === this.#profileModel.programNode?.id || node.id === this.#profileModel.root?.id ||\n node.id === this.#profileModel.idleNode?.id || node.id === this.#profileModel.gcNode?.id) {\n // Skip (root), (program) and (idle) frames, since this are not\n // relevant for web profiling and we don't want to show them in\n // the timeline.\n continue;\n }\n // Profile calls are only created for the frames that are added to\n // the tracked stack, rather than for every frame of every sample.\n const call = makeProfileCall(node, stackSource.profileId, stackSource.sampleIndex, stackSource.ts,\n this.#processId, this.#threadId);\n this.#currentJSStack.push(call);\n this.#constructedProfileCalls.push(call);\n }\n }\n\n /**\n * Merges the given stack with the tracked stack: the durations of\n * the shared frames are extended to cover the event, and the tracked\n * stack is truncated where the two stacks differ.\n * @returns the index of the first frame in the given stack that is\n * not shared with the tracked stack.\n */\n #mergeWithCurrentStack<T extends {callFrame: Protocol.Runtime.CallFrame}>(event: Types.Events.Event,\n stackTrace: T[]): number {\n SamplesIntegrator.filterStackFrames(stackTrace, this.#engineConfig);\n\n const endTime = event.ts + (event.dur || 0);\n const minFrames = Math.min(stackTrace.length, this.#currentJSStack.length);\n let i;\n // Merge a sample's stack frames with the stack frames we have\n // so far if we detect they are equivalent.\n // Graphically\n // This:\n // Current stack trace Sample\n // [-------A------] [A]\n // [-------B------] [B]\n // [-------C------] [C]\n // ^ t = x1 ^ t = x2\n\n // Becomes this:\n // New stack trace after merge\n // [--------A-------]\n // [--------B-------]\n // [--------C-------]\n // ^ t = x2\n for (i = this.#lockedJsStackDepth.at(-1) || 0; i < minFrames; ++i) {\n const newFrame = stackTrace[i].callFrame;\n const oldFrame = this.#currentJSStack[i].callFrame;\n if (!SamplesIntegrator.framesAreEqual(newFrame, oldFrame)) {\n break;\n }\n // Scoot the right edge of this callFrame to the right\n this.#currentJSStack[i].dur =\n Types.Timing.Micro(Math.max(this.#currentJSStack[i].dur || 0, endTime - this.#currentJSStack[i].ts));\n }\n\n // If there are call frames in the sample that differ with the stack\n // we have, update the stack, but keeping the common frames in place\n // Graphically\n // This:\n // Current stack trace Sample\n // [-------A------] [A]\n // [-------B------] [B]\n // [-------C------] [C]\n // [-------D------] [E]\n // ^ t = x1 ^ t = x2\n // Becomes this:\n // New stack trace after merge\n // [--------A-------]\n // [--------B-------]\n // [--------C-------]\n // [E]\n // ^ t = x2\n // This method only truncates the tracked stack; the caller pushes\n // the differing frames (E in the diagram above).\n this.#truncateJSStack(i, event.ts);\n return i;\n }\n\n /**\n * When a call stack that differs from the one we are tracking has\n * been detected in the samples, the latter is \"truncated\" by\n * setting the ending time of its call frames and removing the top\n * call frames that aren't shared with the new call stack. This way,\n * we can update the tracked stack with the new call frames on top.\n * @param depth the amount of call frames from bottom to top that\n * should be kept in the tracking stack trace. AKA amount of shared\n * call frames between two stacks.\n * @param time the new end of the call frames in the stack.\n */\n #truncateJSStack(depth: number, time: Types.Timing.Micro): void {\n if (this.#lockedJsStackDepth.length) {\n const lockedDepth = this.#lockedJsStackDepth.at(-1);\n if (lockedDepth && depth < lockedDepth) {\n console.error(`Child stack is shallower (${depth}) than the parent stack (${lockedDepth}) at ${time}`);\n depth = lockedDepth;\n }\n }\n if (this.#currentJSStack.length < depth) {\n console.error(`Trying to truncate higher than the current stack size at ${time}`);\n depth = this.#currentJSStack.length;\n }\n for (let k = 0; k < this.#currentJSStack.length; ++k) {\n this.#currentJSStack[k].dur = Types.Timing.Micro(Math.max(time - this.#currentJSStack[k].ts, 0));\n }\n this.#currentJSStack.length = depth;\n }\n\n #makeJSSampleEvent(call: Types.Events.SyntheticProfileCall, timestamp: Types.Timing.Micro, traceId?: number):\n Types.Events.SyntheticJSSample {\n const JSSampleEvent: Types.Events.SyntheticJSSample = {\n name: Types.Events.Name.JS_SAMPLE,\n cat: 'devtools.timeline',\n args: {\n data: {traceId, stackTrace: this.#stackNodesForProfileCall(call).map(node => node.callFrame)},\n },\n ph: Types.Events.Phase.INSTANT,\n ts: timestamp,\n dur: Types.Timing.Micro(0),\n pid: this.#processId,\n tid: this.#threadId,\n };\n return JSSampleEvent;\n }\n\n static framesAreEqual(frame1: Protocol.Runtime.CallFrame, frame2: Protocol.Runtime.CallFrame): boolean {\n return frame1.scriptId === frame2.scriptId && frame1.functionName === frame2.functionName &&\n frame1.lineNumber === frame2.lineNumber;\n }\n\n static showNativeName(name: string, runtimeCallStatsEnabled: boolean): boolean {\n return runtimeCallStatsEnabled && Boolean(SamplesIntegrator.nativeGroup(name));\n }\n\n static nativeGroup(nativeName: string): SamplesIntegrator.NativeGroups|null {\n if (nativeName.startsWith('Parse')) {\n return SamplesIntegrator.NativeGroups.PARSE;\n }\n if (nativeName.startsWith('Compile') || nativeName.startsWith('Recompile')) {\n return SamplesIntegrator.NativeGroups.COMPILE;\n }\n return null;\n }\n\n static isNativeRuntimeFrame(frame: Protocol.Runtime.CallFrame): boolean {\n return frame.url === 'native V8Runtime';\n }\n\n static filterStackFrames<T extends {callFrame: Protocol.Runtime.CallFrame}>(\n stack: T[], engineConfig: Types.Configuration.Configuration): void {\n const showAllEvents = engineConfig.showAllEvents;\n if (showAllEvents) {\n return;\n }\n let j = 0;\n for (let i = 0; i < stack.length; ++i) {\n const frame = stack[i].callFrame;\n const nativeRuntimeFrame = SamplesIntegrator.isNativeRuntimeFrame(frame);\n if (nativeRuntimeFrame) {\n continue;\n }\n stack[j++] = stack[i];\n }\n stack.length = j;\n }\n\n static createFakeTraceFromCpuProfile(profile: Protocol.Profiler.Profile, tid: Types.Events.ThreadID):\n Types.File.TraceFile {\n if (!profile) {\n return {traceEvents: [], metadata: {}};\n }\n // The |Name.CPU_PROFILE| will let MetaHandler to set |traceIsGeneric| to false\n // The start time and duration is important here because we'll use them to determine the traceBounds\n // We use the start and end time of the profile (which is longer than all samples), so the Performance\n // panel won't truncate this time period.\n const cpuProfileEvent: Types.Events.SyntheticCpuProfile = {\n cat: 'disabled-by-default-devtools.timeline',\n name: Types.Events.Name.CPU_PROFILE,\n ph: Types.Events.Phase.COMPLETE,\n pid: Types.Events.ProcessID(1),\n tid,\n ts: Types.Timing.Micro(profile.startTime),\n dur: Types.Timing.Micro(profile.endTime - profile.startTime),\n args: {data: {cpuProfile: profile}},\n // Create an arbitrary profile id.\n id: '0x1' as Types.Events.ProfileID,\n };\n\n return {\n traceEvents: [cpuProfileEvent],\n metadata: {\n dataOrigin: Types.File.DataOrigin.CPU_PROFILE,\n },\n };\n }\n\n static extractCpuProfileFromFakeTrace(traceEvents: readonly Types.Events.Event[]): Protocol.Profiler.Profile {\n const profileEvent = traceEvents.find(e => Types.Events.isSyntheticCpuProfile(e));\n const profile = profileEvent?.args.data.cpuProfile;\n if (!profile) {\n throw new Error('Missing cpuProfile data');\n }\n return profile;\n }\n}\n\nexport namespace SamplesIntegrator {\n export enum NativeGroups {\n COMPILE = 'Compile',\n PARSE = 'Parse',\n }\n}\n"]}
1
+ {"version":3,"file":"SamplesIntegrator.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/helpers/SamplesIntegrator.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;;AAI7B,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,iBAAiB;IAC5B;;;;OAIG;IACH,wBAAwB,GAAwC,EAAE,CAAC;IACnE;;;;;;OAMG;IACH,eAAe,GAAwC,EAAE,CAAC;IAC1D;;OAEG;IACH,UAAU,CAAyB;IACnC;;OAEG;IACH,SAAS,CAAwB;IACjC;;;;;;;OAOG;IACH,mBAAmB,GAAa,EAAE,CAAC;IACnC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AO,OAAO,CAAC;IACjB,CAAC;CACF;;AAED,WAAiB,iBAAiB;IAChC,IAAY,YAGX;IAHD,WAAY,YAAY;QACtB,mCAAmB,CAAA;QACnB,+BAAe,CAAA;IACjB,CAAC,EAHW,YAAY,GAAZ,kBAAA,YAAY,KAAZ,kBAAA,YAAY,QAGvB;AACH,CAAC,EALgB,iBAAiB,KAAjB,iBAAiB,QAKjC","sourcesContent":["// Copyright 2023 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 type * as Protocol from '../../../generated/protocol.js';\nimport type * as CPUProfile from '../../cpu_profile/cpu_profile.js';\nimport * as Types from '../types/types.js';\n\nimport {milliToMicro} from './Timing.js';\nimport {\n eventTimeComparator,\n extractSampleTraceId,\n makeProfileCall,\n sortTraceEventsInPlace,\n} from './Trace.js';\n\n/**\n * This is a helper that integrates CPU profiling data coming in the\n * shape of samples, with trace events. Samples indicate what the JS\n * stack trace looked at a given point in time, but they don't have\n * duration. The SamplesIntegrator task is to make an approximation\n * of what the duration of each JS call was, given the sample data and\n * given the trace events profiled during that time. At the end of its\n * execution, the SamplesIntegrator returns an array of ProfileCalls\n * (under SamplesIntegrator::buildProfileCalls()), which\n * represent JS calls, with a call frame and duration. These calls have\n * the shape of a complete trace events and can be treated as flame\n * chart entries in the timeline.\n *\n * `buildProfileCalls()` streams the two chronologically ordered inputs\n * (sorted `traceEvents` and sorted `#profileModel.samples`) with two\n * cursors and a single reusable scratch `SyntheticProfileCall`, avoiding\n * per-sample event and merged-array allocations. As the cursors advance,\n * the integrator tracks the active JS call stack across three transitions:\n * 1. A trace event ended (its `ts + dur` precedes or equals the next item).\n * 2. A CPU sample was taken.\n * 3. A trace event started.\n * Depending on the transition, the integrator opens, extends, or truncates\n * JS calls on `#currentJSStack`.\n *\n * note: Although this approach has been implemented since long ago, and\n * is relatively efficient (adds a complexity over the trace parsing of\n * O(n) where n is the number of samples) it has proven to be faulty.\n * It might be worthwhile experimenting with improvements or with a\n * completely different approach. Improving the approach is tracked in\n * crbug.com/1417439\n */\nexport class SamplesIntegrator {\n /**\n * The result of running the samples integrator. Holds the JS calls\n * with their approximated duration after integrating samples into the\n * trace event tree.\n */\n #constructedProfileCalls: Types.Events.SyntheticProfileCall[] = [];\n /**\n * tracks the state of the JS stack at each point in time to update\n * the profile call durations as new events arrive. This doesn't only\n * happen with new profile calls (in which case we would compare the\n * stack in them) but also with trace events (in which case we would\n * update the duration of the events we are tracking at the moment).\n */\n #currentJSStack: Types.Events.SyntheticProfileCall[] = [];\n /**\n * Process holding the CPU profile and trace events.\n */\n #processId: Types.Events.ProcessID;\n /**\n * Thread holding the CPU profile and trace events.\n */\n #threadId: Types.Events.ThreadID;\n /**\n * Tracks the depth of the JS stack at the moment a trace event starts\n * or ends. It is assumed that for the duration of a trace event, the\n * JS stack's depth cannot decrease, since JS calls that started\n * before a trace event cannot end during the trace event. So as trace\n * events arrive, we store the \"locked\" amount of JS frames that were\n * in the stack before the event came.\n */\n #lockedJsStackDepth: number[] = [];\n /**\n * Used to keep track when samples should be integrated even if they\n * are not children of invocation trace events. This is used in two cases:\n * 1. We start tracing half-way through, so we miss the start of JS\n * invocation events.\n * 2. On threads (like Web Workers) without real JS invocation parent events,\n * but where trace events (like SchedulePostMessage) integrate stack traces.\n * Enabling fake JS mode allows subsequent samples to be processed and\n * eventually correct the stack, preventing a deadlock.\n */\n #fakeJSInvocation = false;\n /**\n * The parsed CPU profile, holding the tree hierarchy of JS frames and\n * the sample data.\n */\n #profileModel: CPUProfile.CPUProfileDataModel.CPUProfileDataModel;\n /**\n * Because GC nodes don't have a stack, the integrator attaches the stack\n * of the preceding sample to them. This map records which node provides\n * the stack for each GC sample, keyed by `sampleIndex` (all GC samples\n * share one `gcNode` ID with different preceding stacks, and samples do\n * not have distinct `ProfileCall` object identities during the merge).\n * Note that GC samples are not shown in the flamechart, however they\n * are used during the construction of profile calls to infer the\n * duration of the executed code when a GC node is sampled.\n */\n #nodeForGC = new Map<number, CPUProfile.ProfileTreeModel.ProfileNode>();\n\n #engineConfig: Types.Configuration.Configuration;\n #profileId: Types.Events.ProfileID;\n\n /**\n * Keeps track of the individual samples from the CPU Profile.\n * Only used with Debug Mode experiment enabled.\n */\n jsSampleEvents: Types.Events.SyntheticJSSample[] = [];\n\n constructor(\n profileModel: CPUProfile.CPUProfileDataModel.CPUProfileDataModel, profileId: Types.Events.ProfileID,\n pid: Types.Events.ProcessID, tid: Types.Events.ThreadID, configuration?: Types.Configuration.Configuration) {\n this.#profileModel = profileModel;\n this.#threadId = tid;\n this.#processId = pid;\n this.#engineConfig = configuration || Types.Configuration.defaults();\n this.#profileId = profileId;\n }\n\n /**\n * Approximates JS call durations by streaming sorted `traceEvents` and\n * `#profileModel.samples` in chronological order with two cursors.\n *\n * `traceEvents` must already be sorted with `sortTraceEventsInPlace()`\n * (`#profileModel.samples` and `timestamps` are sorted during\n * `CPUProfileDataModel` construction).\n */\n buildProfileCalls(traceEvents: Types.Events.Event[]): Types.Events.SyntheticProfileCall[] {\n // Pre-index GC substitute stacks (and debug-mode JSSample events) before streaming.\n this.#prepareSamples();\n const samples = this.#profileModel.samples;\n const timestamps = this.#profileModel.timestamps;\n const numSamples = samples ? samples.length : 0;\n // Reused mutable scratch event representing the current CPU sample at\n // `sampleCursor - 1`. Only `nodeId`, `callFrame`, `sampleIndex`, and `ts`\n // vary per sample (`profileId`, `pid`, `tid`, `ph`, and `dur: 0` remain\n // constant for this integrator instance).\n //\n // Invariant: `sampleEvent` must NEVER be pushed onto `stack`,\n // `#currentJSStack`, `#constructedProfileCalls`, or retained by reference.\n // `#onProfileCall()` -> `#extractStackTrace()` reads its scalar fields and\n // allocates fresh `SyntheticProfileCall` objects for opened stack frames.\n let sampleEvent: Types.Events.SyntheticProfileCall|null = null;\n let sampleCursor = 0;\n const advanceSample = (): Types.Events.SyntheticProfileCall|null => {\n while (sampleCursor < numSamples) {\n const index = sampleCursor++;\n const node = this.#profileModel.nodeByIndex(index);\n if (!node) {\n continue;\n }\n const ts = milliToMicro(Types.Timing.Milli(timestamps[index]));\n if (sampleEvent === null) {\n sampleEvent = makeProfileCall(node, this.#profileId, index, ts, this.#processId, this.#threadId);\n } else {\n sampleEvent.nodeId = node.id;\n sampleEvent.callFrame = node.callFrame;\n sampleEvent.sampleIndex = index;\n sampleEvent.ts = ts;\n }\n return sampleEvent;\n }\n return null;\n };\n\n let traceCursor = 0;\n const numTraceEvents = traceEvents.length;\n const advanceTrace = (): Types.Events.Event|null => {\n while (traceCursor < numTraceEvents) {\n const traceEvent = traceEvents[traceCursor++];\n // Instant events have zero duration and cannot change JS call durations\n // unless they carry a `sampleTraceId` stack snapshot.\n if (traceEvent.ph === Types.Events.Phase.INSTANT && !extractSampleTraceId(traceEvent)) {\n continue;\n }\n return traceEvent;\n }\n return null;\n };\n\n const stack: Types.Events.Event[] = [];\n const unwindExpiredTraceEvents = (ts: Types.Timing.Micro): Types.Events.Event|undefined => {\n let parentEvent = stack.at(-1);\n while (parentEvent !== undefined && ts >= parentEvent.ts + (parentEvent.dur || 0)) {\n this.#onTraceEventEnd(parentEvent);\n stack.pop();\n parentEvent = stack.at(-1);\n }\n return parentEvent;\n };\n\n let nextSample = advanceSample();\n let nextTraceEvent = advanceTrace();\n while (nextTraceEvent !== null || nextSample !== null) {\n // Match `mergeEventsInOrder` tie-breaking at identical timestamps (`ts`):\n // - Trace events with `dur > 0` end after a 0-duration sample, so\n // `eventTimeComparator` returns `-1` and the trace event is pushed onto\n // `stack` first as the sample's parent execution context.\n // - Zero-duration trace events (`(dur ?? 0) === 0`, such as instant\n // events with a `sampleTraceId`) tie on both start and end time, so\n // `eventTimeComparator` prioritizes the `ProfileCall` (returns `1`) and\n // the sample updates `#currentJSStack` first to parent the trace event.\n const useSample =\n nextSample !== null && (nextTraceEvent === null || eventTimeComparator(nextTraceEvent, nextSample) > 0);\n const event = useSample ? nextSample : nextTraceEvent;\n if (event === null) {\n break;\n }\n\n const parentEvent = unwindExpiredTraceEvents(event.ts);\n if (Types.Events.isProfileCall(event)) {\n this.#onProfileCall(event, parentEvent);\n } else {\n this.#onTraceEventStart(event, parentEvent);\n stack.push(event);\n }\n\n if (useSample) {\n nextSample = advanceSample();\n } else {\n nextTraceEvent = advanceTrace();\n }\n }\n while (stack.length) {\n const last = stack.pop();\n if (last) {\n this.#onTraceEventEnd(last);\n }\n }\n sortTraceEventsInPlace(this.jsSampleEvents);\n return this.#constructedProfileCalls;\n }\n\n /**\n * Pre-indexes the preceding non-GC node for each GC sample in `#nodeForGC`\n * (keyed by `sampleIndex`) so `#stackNodesForProfileCall()` can resolve GC\n * stacks during the streaming merge without per-sample `ProfileCall` objects.\n *\n * When `debugMode` is enabled, this pass also populates `jsSampleEvents`\n * before `buildProfileCalls()` appends any `sampleTraceId` sample events.\n */\n #prepareSamples(): void {\n const samples = this.#profileModel.samples;\n const timestamps = this.#profileModel.timestamps;\n if (!samples) {\n return;\n }\n let prevNode: CPUProfile.ProfileTreeModel.ProfileNode|undefined;\n for (let i = 0; i < samples.length; i++) {\n const node = this.#profileModel.nodeByIndex(i);\n if (!node) {\n continue;\n }\n if (this.#engineConfig.debugMode) {\n const timestamp = milliToMicro(Types.Timing.Milli(timestamps[i]));\n const call = makeProfileCall(node, this.#profileId, i, timestamp, this.#processId, this.#threadId);\n const traceId = this.#profileModel.traceIds?.[i];\n this.jsSampleEvents.push(this.#makeJSSampleEvent(call, timestamp, traceId));\n }\n if (node.id === this.#profileModel.gcNode?.id && prevNode) {\n this.#nodeForGC.set(i, prevNode);\n continue;\n }\n prevNode = node;\n }\n }\n\n #onTraceEventStart(event: Types.Events.Event, parent?: Types.Events.Event): void {\n // Top level events cannot be nested into JS frames so we reset\n // the stack when we find one.\n if (event.name === Types.Events.Name.RUN_MICROTASKS || event.name === Types.Events.Name.RUN_TASK) {\n this.#lockedJsStackDepth = [];\n this.#truncateJSStack(0, event.ts);\n this.#fakeJSInvocation = false;\n }\n\n if (this.#fakeJSInvocation) {\n this.#truncateJSStack(this.#lockedJsStackDepth.pop() || 0, event.ts);\n this.#fakeJSInvocation = false;\n }\n this.#extractStackTrace(event);\n if (extractSampleTraceId(event)) {\n const hasJSInvocationParent = parent && Types.Events.isJSInvocationEvent(parent);\n if (!hasJSInvocationParent) {\n // If the event has a sampleTraceId (meaning it has a stack trace) but\n // no JS invocation parent, we enter fake JS mode. This ensures that\n // subsequent samples on this thread are processed, allowing the stack\n // to be correctly updated/truncated. Without this, subsequent samples\n // would be ignored because the stack is non-empty but we are not\n // considered to be in JS.\n this.#fakeJSInvocation = true;\n }\n }\n // Keep track of the call frames in the stack before the event\n // happened. For the duration of this event, these frames cannot\n // change (none can be terminated before this event finishes).\n //\n // Also, every frame that is opened after this event, is considered\n // to be a descendant of the event. So once the event finishes, the\n // frames that were opened after it, need to be closed (see\n // onEndEvent).\n //\n // TODO(crbug.com/1417439):\n // The assumption that every frame opened after an event is a\n // descendant of the event is incorrect. For example, a JS call that\n // parents a trace event might have been sampled after the event was\n // dispatched. In this case the JS call would be discarded if this\n // event isn't an invocation event, otherwise the call will be\n // considered a child of the event. In both cases, the result would\n // be incorrect.\n this.#lockedJsStackDepth.push(this.#currentJSStack.length);\n }\n\n /**\n * Integrates a CPU sample into `#currentJSStack`. During `buildProfileCalls()`,\n * `event` is typically the mutable scratch `sampleEvent` and must never be\n * retained by reference.\n */\n #onProfileCall(event: Types.Events.SyntheticProfileCall, parent?: Types.Events.Event): void {\n if ((parent && Types.Events.isJSInvocationEvent(parent)) || this.#fakeJSInvocation) {\n this.#extractStackTrace(event);\n } else if (this.#currentJSStack.length === 0) {\n // Force JS Samples to show up even if we are not inside a JS\n // invocation event, because we can be missing the start of JS\n // invocation events if we start tracing half-way through. Pretend\n // we have a top-level JS invocation event.\n this.#fakeJSInvocation = true;\n const stackDepthBefore = this.#currentJSStack.length;\n this.#extractStackTrace(event);\n this.#lockedJsStackDepth.push(stackDepthBefore);\n }\n }\n\n #onTraceEventEnd(event: Types.Events.Event): void {\n // Because the event has ended, any frames that happened after\n // this event are terminated. Frames that are ancestors to this\n // event are extended to cover its ending.\n const endTime = Types.Timing.Micro(event.ts + (event.dur ?? 0));\n this.#truncateJSStack(this.#lockedJsStackDepth.pop() || 0, endTime);\n }\n\n /**\n * Given a synthetic profile call, returns the profile nodes of the\n * stack trace that profile call belongs to based on its nodeId,\n * ordered from the bottom of the stack to the top. The root node is\n * omitted. The node of the input profile call will be at the top of\n * the returned stack (last position), meaning that any other frames\n * that were effectively above it are omitted.\n */\n #stackNodesForProfileCall(profileCall: Types.Events.SyntheticProfileCall): CPUProfile.ProfileTreeModel.ProfileNode[] {\n const sampledNode = this.#profileModel.nodeById(profileCall.nodeId);\n let node = sampledNode;\n const isGarbageCollection = node?.id === this.#profileModel.gcNode?.id;\n if (isGarbageCollection) {\n // Because GC don't have a stack, we use the stack of the previous\n // sample.\n node = this.#nodeForGC.get(profileCall.sampleIndex) || null;\n }\n if (!sampledNode || !node) {\n return [];\n }\n // `node.depth` is 0 based, so to set the size of the array we need\n // to add 1 to its value.\n const nodes = new Array<CPUProfile.ProfileTreeModel.ProfileNode>(node.depth + 1 + Number(isGarbageCollection));\n // Add the stack trace in reverse order (bottom first).\n let i = nodes.length - 1;\n if (isGarbageCollection) {\n // Place the garbage collection node on top of the stack.\n nodes[i--] = sampledNode;\n }\n // The root node has a depth of -1, so the loop stops before it.\n while (node && i >= 0) {\n nodes[i--] = node;\n node = node.parent;\n }\n return nodes;\n }\n\n /**\n * Returns a profile call for the node sampled with the given trace id,\n * or null if the profile has no node for it.\n */\n #callForSampleTraceId(traceId: number, timestamp: Types.Timing.Micro): Types.Events.SyntheticProfileCall|null {\n const nodeId = this.#profileModel.traceIds?.[traceId];\n const node = nodeId && this.#profileModel.nodeById(nodeId);\n if (!node) {\n return null;\n }\n const callForTraceId = makeProfileCall(node, this.#profileId, -1, timestamp, this.#processId, this.#threadId);\n if (this.#engineConfig.debugMode) {\n this.jsSampleEvents.push(this.#makeJSSampleEvent(callForTraceId, timestamp, traceId));\n }\n return callForTraceId;\n }\n\n /**\n * Update tracked stack using this event's call stack.\n */\n #extractStackTrace(event: Types.Events.Event): void {\n const traceId = extractSampleTraceId(event);\n const callForTraceId = traceId ? this.#callForSampleTraceId(traceId, event.ts) : null;\n const stackSource = callForTraceId ?? (Types.Events.isProfileCall(event) ? event : null);\n if (!stackSource) {\n // The event carries no stack of its own, so merging the tracked\n // stack with itself only updates the durations of its frames.\n this.#mergeWithCurrentStack(event, this.#currentJSStack);\n return;\n }\n\n const stackNodes = this.#stackNodesForProfileCall(stackSource);\n let i = this.#mergeWithCurrentStack(event, stackNodes);\n for (; i < stackNodes.length; ++i) {\n const node = stackNodes[i];\n if (node.id === this.#profileModel.programNode?.id || node.id === this.#profileModel.root?.id ||\n node.id === this.#profileModel.idleNode?.id || node.id === this.#profileModel.gcNode?.id) {\n // Skip (root), (program) and (idle) frames, since this are not\n // relevant for web profiling and we don't want to show them in\n // the timeline.\n continue;\n }\n // Profile calls are only created for the frames that are added to\n // the tracked stack, rather than for every frame of every sample.\n const call = makeProfileCall(node, stackSource.profileId, stackSource.sampleIndex, stackSource.ts,\n this.#processId, this.#threadId);\n this.#currentJSStack.push(call);\n this.#constructedProfileCalls.push(call);\n }\n }\n\n /**\n * Merges the given stack with the tracked stack: the durations of\n * the shared frames are extended to cover the event, and the tracked\n * stack is truncated where the two stacks differ.\n * @returns the index of the first frame in the given stack that is\n * not shared with the tracked stack.\n */\n #mergeWithCurrentStack<T extends {callFrame: Protocol.Runtime.CallFrame}>(event: Types.Events.Event,\n stackTrace: T[]): number {\n SamplesIntegrator.filterStackFrames(stackTrace, this.#engineConfig);\n\n const endTime = event.ts + (event.dur || 0);\n const minFrames = Math.min(stackTrace.length, this.#currentJSStack.length);\n let i;\n // Merge a sample's stack frames with the stack frames we have\n // so far if we detect they are equivalent.\n // Graphically\n // This:\n // Current stack trace Sample\n // [-------A------] [A]\n // [-------B------] [B]\n // [-------C------] [C]\n // ^ t = x1 ^ t = x2\n\n // Becomes this:\n // New stack trace after merge\n // [--------A-------]\n // [--------B-------]\n // [--------C-------]\n // ^ t = x2\n for (i = this.#lockedJsStackDepth.at(-1) || 0; i < minFrames; ++i) {\n const newFrame = stackTrace[i].callFrame;\n const oldFrame = this.#currentJSStack[i].callFrame;\n if (!SamplesIntegrator.framesAreEqual(newFrame, oldFrame)) {\n break;\n }\n // Scoot the right edge of this callFrame to the right\n this.#currentJSStack[i].dur =\n Types.Timing.Micro(Math.max(this.#currentJSStack[i].dur || 0, endTime - this.#currentJSStack[i].ts));\n }\n\n // If there are call frames in the sample that differ with the stack\n // we have, update the stack, but keeping the common frames in place\n // Graphically\n // This:\n // Current stack trace Sample\n // [-------A------] [A]\n // [-------B------] [B]\n // [-------C------] [C]\n // [-------D------] [E]\n // ^ t = x1 ^ t = x2\n // Becomes this:\n // New stack trace after merge\n // [--------A-------]\n // [--------B-------]\n // [--------C-------]\n // [E]\n // ^ t = x2\n // This method only truncates the tracked stack; the caller pushes\n // the differing frames (E in the diagram above).\n this.#truncateJSStack(i, event.ts);\n return i;\n }\n\n /**\n * When a call stack that differs from the one we are tracking has\n * been detected in the samples, the latter is \"truncated\" by\n * setting the ending time of its call frames and removing the top\n * call frames that aren't shared with the new call stack. This way,\n * we can update the tracked stack with the new call frames on top.\n * @param depth the amount of call frames from bottom to top that\n * should be kept in the tracking stack trace. AKA amount of shared\n * call frames between two stacks.\n * @param time the new end of the call frames in the stack.\n */\n #truncateJSStack(depth: number, time: Types.Timing.Micro): void {\n if (this.#lockedJsStackDepth.length) {\n const lockedDepth = this.#lockedJsStackDepth.at(-1);\n if (lockedDepth && depth < lockedDepth) {\n console.error(`Child stack is shallower (${depth}) than the parent stack (${lockedDepth}) at ${time}`);\n depth = lockedDepth;\n }\n }\n if (this.#currentJSStack.length < depth) {\n console.error(`Trying to truncate higher than the current stack size at ${time}`);\n depth = this.#currentJSStack.length;\n }\n for (let k = 0; k < this.#currentJSStack.length; ++k) {\n this.#currentJSStack[k].dur = Types.Timing.Micro(Math.max(time - this.#currentJSStack[k].ts, 0));\n }\n this.#currentJSStack.length = depth;\n }\n\n #makeJSSampleEvent(call: Types.Events.SyntheticProfileCall, timestamp: Types.Timing.Micro, traceId?: number):\n Types.Events.SyntheticJSSample {\n const JSSampleEvent: Types.Events.SyntheticJSSample = {\n name: Types.Events.Name.JS_SAMPLE,\n cat: 'devtools.timeline',\n args: {\n data: {traceId, stackTrace: this.#stackNodesForProfileCall(call).map(node => node.callFrame)},\n },\n ph: Types.Events.Phase.INSTANT,\n ts: timestamp,\n dur: Types.Timing.Micro(0),\n pid: this.#processId,\n tid: this.#threadId,\n };\n return JSSampleEvent;\n }\n\n static framesAreEqual(frame1: Protocol.Runtime.CallFrame, frame2: Protocol.Runtime.CallFrame): boolean {\n return frame1.scriptId === frame2.scriptId && frame1.functionName === frame2.functionName &&\n frame1.lineNumber === frame2.lineNumber;\n }\n\n static showNativeName(name: string, runtimeCallStatsEnabled: boolean): boolean {\n return runtimeCallStatsEnabled && Boolean(SamplesIntegrator.nativeGroup(name));\n }\n\n static nativeGroup(nativeName: string): SamplesIntegrator.NativeGroups|null {\n if (nativeName.startsWith('Parse')) {\n return SamplesIntegrator.NativeGroups.PARSE;\n }\n if (nativeName.startsWith('Compile') || nativeName.startsWith('Recompile')) {\n return SamplesIntegrator.NativeGroups.COMPILE;\n }\n return null;\n }\n\n static isNativeRuntimeFrame(frame: Protocol.Runtime.CallFrame): boolean {\n return frame.url === 'native V8Runtime';\n }\n\n static filterStackFrames<T extends {callFrame: Protocol.Runtime.CallFrame}>(\n stack: T[], engineConfig: Types.Configuration.Configuration): void {\n const showAllEvents = engineConfig.showAllEvents;\n if (showAllEvents) {\n return;\n }\n let j = 0;\n for (let i = 0; i < stack.length; ++i) {\n const frame = stack[i].callFrame;\n const nativeRuntimeFrame = SamplesIntegrator.isNativeRuntimeFrame(frame);\n if (nativeRuntimeFrame) {\n continue;\n }\n stack[j++] = stack[i];\n }\n stack.length = j;\n }\n\n static createFakeTraceFromCpuProfile(profile: Protocol.Profiler.Profile, tid: Types.Events.ThreadID):\n Types.File.TraceFile {\n if (!profile) {\n return {traceEvents: [], metadata: {}};\n }\n // The |Name.CPU_PROFILE| will let MetaHandler to set |traceIsGeneric| to false\n // The start time and duration is important here because we'll use them to determine the traceBounds\n // We use the start and end time of the profile (which is longer than all samples), so the Performance\n // panel won't truncate this time period.\n const cpuProfileEvent: Types.Events.SyntheticCpuProfile = {\n cat: 'disabled-by-default-devtools.timeline',\n name: Types.Events.Name.CPU_PROFILE,\n ph: Types.Events.Phase.COMPLETE,\n pid: Types.Events.ProcessID(1),\n tid,\n ts: Types.Timing.Micro(profile.startTime),\n dur: Types.Timing.Micro(profile.endTime - profile.startTime),\n args: {data: {cpuProfile: profile}},\n // Create an arbitrary profile id.\n id: '0x1' as Types.Events.ProfileID,\n };\n\n return {\n traceEvents: [cpuProfileEvent],\n metadata: {\n dataOrigin: Types.File.DataOrigin.CPU_PROFILE,\n },\n };\n }\n\n static extractCpuProfileFromFakeTrace(traceEvents: readonly Types.Events.Event[]): Protocol.Profiler.Profile {\n const profileEvent = traceEvents.find(e => Types.Events.isSyntheticCpuProfile(e));\n const profile = profileEvent?.args.data.cpuProfile;\n if (!profile) {\n throw new Error('Missing cpuProfile data');\n }\n return profile;\n }\n}\n\nexport namespace SamplesIntegrator {\n export enum NativeGroups {\n COMPILE = 'Compile',\n PARSE = 'Parse',\n }\n}\n"]}
@@ -7,14 +7,6 @@ export declare class SyntheticEventsManager {
7
7
  static reset(): void;
8
8
  static registerSyntheticEvent<T extends Types.Events.SyntheticBased>(syntheticEvent: Omit<T, '_tag'>): T;
9
9
  private constructor();
10
- /**
11
- * Clears the transient raw event index map.
12
- * During trace parsing, this map provides O(1) lookups for registering synthetic events.
13
- * Once parsing is complete, queries look up synthetic events exclusively by index in
14
- * `#syntheticTraces`, so this map is discarded to reclaim memory.
15
- */
16
- clearRegistrationIndex(): void;
17
10
  syntheticEventForRawEventIndex(rawEventIndex: number): Types.Events.SyntheticBased;
18
- getSyntheticTraces(): Types.Events.SyntheticBased[];
19
11
  getRawTraceEvents(): readonly Types.Events.Event[];
20
12
  }
@@ -4,12 +4,14 @@
4
4
  let activeManager = null;
5
5
  export class SyntheticEventsManager {
6
6
  /**
7
- * All synthetic entries created in a trace from
8
- * corresponding trace events.
9
- * (ProfileCalls and layout shift clusters are excluded
10
- * because they are not based on a real trace event.)
7
+ * All synthetic entries created in a trace, keyed by the raw trace event
8
+ * they are based on. (ProfileCalls and layout shift clusters are excluded
9
+ * because they are not based on a real trace event.) Keying by the raw
10
+ * event rather than by its index in the raw events array means
11
+ * registration does not need to look up the index, which would require a
12
+ * map of every raw event in the trace.
11
13
  */
12
- #syntheticTraces = [];
14
+ #syntheticEventByRawEvent = new WeakMap();
13
15
  /**
14
16
  * All raw entries from a trace.
15
17
  */
@@ -46,49 +48,24 @@ export class SyntheticEventsManager {
46
48
  constructor(rawEvents) {
47
49
  this.#rawTraceEvents = rawEvents;
48
50
  }
49
- #rawEventIndexes = null;
50
- #getRawEventIndex(event) {
51
- if (!this.#rawEventIndexes) {
52
- this.#rawEventIndexes = new Map();
53
- for (let i = 0; i < this.#rawTraceEvents.length; i++) {
54
- this.#rawEventIndexes.set(this.#rawTraceEvents[i], i);
55
- }
56
- }
57
- return this.#rawEventIndexes.get(event) ?? -1;
58
- }
59
- /**
60
- * Clears the transient raw event index map.
61
- * During trace parsing, this map provides O(1) lookups for registering synthetic events.
62
- * Once parsing is complete, queries look up synthetic events exclusively by index in
63
- * `#syntheticTraces`, so this map is discarded to reclaim memory.
64
- */
65
- clearRegistrationIndex() {
66
- this.#rawEventIndexes = null;
67
- }
68
51
  /**
69
52
  * Registers and returns a branded synthetic event. Synthetic events need to
70
53
  * be created with this method to ensure they are registered and made
71
54
  * available to load events using serialized keys.
72
55
  */
73
56
  #registerSyntheticEvent(syntheticEvent) {
74
- const rawIndex = this.#getRawEventIndex(syntheticEvent.rawSourceEvent);
75
- if (rawIndex < 0) {
76
- throw new Error('Attempted to register a synthetic event paired to an unknown raw event.');
77
- }
78
57
  const eventAsSynthetic = syntheticEvent;
79
- this.#syntheticTraces[rawIndex] = eventAsSynthetic;
58
+ this.#syntheticEventByRawEvent.set(syntheticEvent.rawSourceEvent, eventAsSynthetic);
80
59
  return eventAsSynthetic;
81
60
  }
82
61
  syntheticEventForRawEventIndex(rawEventIndex) {
83
- const syntheticEvent = this.#syntheticTraces.at(rawEventIndex);
62
+ const rawEvent = this.#rawTraceEvents.at(rawEventIndex);
63
+ const syntheticEvent = rawEvent && this.#syntheticEventByRawEvent.get(rawEvent);
84
64
  if (!syntheticEvent) {
85
65
  throw new Error(`Attempted to get a synthetic event from an unknown raw event index: ${rawEventIndex}`);
86
66
  }
87
67
  return syntheticEvent;
88
68
  }
89
- getSyntheticTraces() {
90
- return this.#syntheticTraces;
91
- }
92
69
  getRawTraceEvents() {
93
70
  return this.#rawTraceEvents;
94
71
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SyntheticEvents.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/helpers/SyntheticEvents.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAI7B,IAAI,aAAa,GAAgC,IAAI,CAAC;AAEtD,MAAM,OAAO,sBAAsB;IACjC;;;;;OAKG;IACH,gBAAgB,GAAkC,EAAE,CAAC;IACrD;;OAEG;IACH,eAAe,GAAkC,EAAE,CAAC;IAEpD,MAAM,CAAC,QAAQ,CAAC,OAA+B;QAC7C,aAAa,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,SAAwC;QAC/D,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC,SAAS,CAAC,CAAC;QACtD,sBAAsB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACzC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,gBAAgB;QACrB,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,I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QAAQ,GAAG,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;QAC7F,CAAC;QACD,MAAM,gBAAgB,GAAG,cAAmB,CAAC;QAC7C,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,gBAAgB,CAAC;QACnD,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED,8BAA8B,CAAC,aAAqB;QAClD,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;QAC/D,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,uEAAuE,aAAa,EAAE,CAAC,CAAC;QAC1G,CAAC;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,kBAAkB;QAChB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;CACF","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 type * as Types from '../types/types.js';\n\nlet activeManager: SyntheticEventsManager|null = null;\n\nexport class SyntheticEventsManager {\n /**\n * All synthetic entries created in a trace from\n * corresponding trace events.\n * (ProfileCalls and layout shift clusters are excluded\n * because they are not based on a real trace event.)\n */\n #syntheticTraces: Types.Events.SyntheticBased[] = [];\n /**\n * All raw entries from a trace.\n */\n #rawTraceEvents: readonly Types.Events.Event[] = [];\n\n static activate(manager: SyntheticEventsManager): void {\n activeManager = manager;\n }\n\n static createAndActivate(rawEvents: readonly Types.Events.Event[]): SyntheticEventsManager {\n const manager = new SyntheticEventsManager(rawEvents);\n SyntheticEventsManager.activate(manager);\n return manager;\n }\n\n static getActiveManager(): SyntheticEventsManager {\n if (!activeManager) {\n throw new Error('Attempted to get a SyntheticEventsManager without initializing');\n }\n return activeManager;\n }\n\n static reset(): void {\n activeManager = null;\n }\n\n static registerSyntheticEvent<T extends Types.Events.SyntheticBased>(syntheticEvent: Omit<T, '_tag'>): T {\n try {\n return SyntheticEventsManager.getActiveManager().#registerSyntheticEvent(syntheticEvent);\n } catch {\n // If no active manager has been initialized, we assume the trace engine is\n // not running as part of the Performance panel. In this case we don't\n // register synthetic events because we don't need to support timeline\n // modifications serialization.\n return syntheticEvent as T;\n }\n }\n\n private constructor(rawEvents: readonly Types.Events.Event[]) {\n this.#rawTraceEvents = rawEvents;\n }\n\n #rawEventIndexes: Map<Types.Events.Event, number>|null = null;\n\n #getRawEventIndex(event: Types.Events.Event): number {\n if (!this.#rawEventIndexes) {\n this.#rawEventIndexes = new Map();\n for (let i = 0; i < this.#rawTraceEvents.length; i++) {\n this.#rawEventIndexes.set(this.#rawTraceEvents[i], i);\n }\n }\n return this.#rawEventIndexes.get(event) ?? -1;\n }\n\n /**\n * Clears the transient raw event index map.\n * During trace parsing, this map provides O(1) lookups for registering synthetic events.\n * Once parsing is complete, queries look up synthetic events exclusively by index in\n * `#syntheticTraces`, so this map is discarded to reclaim memory.\n */\n clearRegistrationIndex(): void {\n this.#rawEventIndexes = null;\n }\n\n /**\n * Registers and returns a branded synthetic event. Synthetic events need to\n * be created with this method to ensure they are registered and made\n * available to load events using serialized keys.\n */\n #registerSyntheticEvent<T extends Types.Events.SyntheticBased>(syntheticEvent: Omit<T, '_tag'>): T {\n const rawIndex = this.#getRawEventIndex(syntheticEvent.rawSourceEvent);\n if (rawIndex < 0) {\n throw new Error('Attempted to register a synthetic event paired to an unknown raw event.');\n }\n const eventAsSynthetic = syntheticEvent as T;\n this.#syntheticTraces[rawIndex] = eventAsSynthetic;\n return eventAsSynthetic;\n }\n\n syntheticEventForRawEventIndex(rawEventIndex: number): Types.Events.SyntheticBased {\n const syntheticEvent = this.#syntheticTraces.at(rawEventIndex);\n if (!syntheticEvent) {\n throw new Error(`Attempted to get a synthetic event from an unknown raw event index: ${rawEventIndex}`);\n }\n return syntheticEvent;\n }\n\n getSyntheticTraces(): Types.Events.SyntheticBased[] {\n return this.#syntheticTraces;\n }\n\n getRawTraceEvents(): readonly Types.Events.Event[] {\n return this.#rawTraceEvents;\n }\n}\n"]}
1
+ {"version":3,"file":"SyntheticEvents.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/helpers/SyntheticEvents.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAI7B,IAAI,aAAa,GAAgC,IAAI,CAAC;AAEtD,MAAM,OAAO,sBAAsB;IACjC;;;;;;;OAOG;IACH,yBAAyB,GAAG,IAAI,OAAO,EAAmD,CAAC;IAC3F;;OAEG;IACH,eAAe,GAAkC,EAAE,CAAC;IAEpD,MAAM,CAAC,QAAQ,CAAC,OAA+B;QAC7C,aAAa,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,SAAwC;QAC/D,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC,SAAS,CAAC,CAAC;QACtD,sBAAsB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACzC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,gBAAgB;QACrB,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;QACpF,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,KAAK;QACV,aAAa,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,sBAAsB,CAAwC,cAA+B;QAClG,IAAI,CAAC;YACH,OAAO,sBAAsB,CAAC,gBAAgB,EAAE,CAAC,uBAAuB,CAAC,cAAc,CAAC,CAAC;QAC3F,CAAC;QAAC,MAAM,CAAC;YACP,2EAA2E;YAC3E,sEAAsE;YACtE,sEAAsE;YACtE,+BAA+B;YAC/B,OAAO,cAAmB,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,YAAoB,SAAwC;QAC1D,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACH,uBAAuB,CAAwC,cAA+B;QAC5F,MAAM,gBAAgB,GAAG,cAAmB,CAAC;QAC7C,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,cAAc,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;QACpF,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED,8BAA8B,CAAC,aAAqB;QAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;QACxD,MAAM,cAAc,GAAG,QAAQ,IAAI,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAChF,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,uEAAuE,aAAa,EAAE,CAAC,CAAC;QAC1G,CAAC;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;CACF","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 type * as Types from '../types/types.js';\n\nlet activeManager: SyntheticEventsManager|null = null;\n\nexport class SyntheticEventsManager {\n /**\n * All synthetic entries created in a trace, keyed by the raw trace event\n * they are based on. (ProfileCalls and layout shift clusters are excluded\n * because they are not based on a real trace event.) Keying by the raw\n * event rather than by its index in the raw events array means\n * registration does not need to look up the index, which would require a\n * map of every raw event in the trace.\n */\n #syntheticEventByRawEvent = new WeakMap<Types.Events.Event, Types.Events.SyntheticBased>();\n /**\n * All raw entries from a trace.\n */\n #rawTraceEvents: readonly Types.Events.Event[] = [];\n\n static activate(manager: SyntheticEventsManager): void {\n activeManager = manager;\n }\n\n static createAndActivate(rawEvents: readonly Types.Events.Event[]): SyntheticEventsManager {\n const manager = new SyntheticEventsManager(rawEvents);\n SyntheticEventsManager.activate(manager);\n return manager;\n }\n\n static getActiveManager(): SyntheticEventsManager {\n if (!activeManager) {\n throw new Error('Attempted to get a SyntheticEventsManager without initializing');\n }\n return activeManager;\n }\n\n static reset(): void {\n activeManager = null;\n }\n\n static registerSyntheticEvent<T extends Types.Events.SyntheticBased>(syntheticEvent: Omit<T, '_tag'>): T {\n try {\n return SyntheticEventsManager.getActiveManager().#registerSyntheticEvent(syntheticEvent);\n } catch {\n // If no active manager has been initialized, we assume the trace engine is\n // not running as part of the Performance panel. In this case we don't\n // register synthetic events because we don't need to support timeline\n // modifications serialization.\n return syntheticEvent as T;\n }\n }\n\n private constructor(rawEvents: readonly Types.Events.Event[]) {\n this.#rawTraceEvents = rawEvents;\n }\n\n /**\n * Registers and returns a branded synthetic event. Synthetic events need to\n * be created with this method to ensure they are registered and made\n * available to load events using serialized keys.\n */\n #registerSyntheticEvent<T extends Types.Events.SyntheticBased>(syntheticEvent: Omit<T, '_tag'>): T {\n const eventAsSynthetic = syntheticEvent as T;\n this.#syntheticEventByRawEvent.set(syntheticEvent.rawSourceEvent, eventAsSynthetic);\n return eventAsSynthetic;\n }\n\n syntheticEventForRawEventIndex(rawEventIndex: number): Types.Events.SyntheticBased {\n const rawEvent = this.#rawTraceEvents.at(rawEventIndex);\n const syntheticEvent = rawEvent && this.#syntheticEventByRawEvent.get(rawEvent);\n if (!syntheticEvent) {\n throw new Error(`Attempted to get a synthetic event from an unknown raw event index: ${rawEventIndex}`);\n }\n return syntheticEvent;\n }\n\n getRawTraceEvents(): readonly Types.Events.Event[] {\n return this.#rawTraceEvents;\n }\n}\n"]}