@paulirish/trace_engine 0.0.23 → 0.0.24

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 (51) hide show
  1. package/generated/protocol.d.ts +48 -2
  2. package/models/trace/EntriesFilter.d.ts +14 -13
  3. package/models/trace/EntriesFilter.js +40 -38
  4. package/models/trace/EntriesFilter.js.map +1 -1
  5. package/models/trace/ModelImpl.d.ts +6 -4
  6. package/models/trace/ModelImpl.js +13 -4
  7. package/models/trace/ModelImpl.js.map +1 -1
  8. package/models/trace/Processor.js +6 -1
  9. package/models/trace/Processor.js.map +1 -1
  10. package/models/trace/extras/FetchNodes.js +1 -1
  11. package/models/trace/extras/FetchNodes.js.map +1 -1
  12. package/models/trace/extras/URLForEntry.d.ts +4 -0
  13. package/models/trace/extras/URLForEntry.js +35 -0
  14. package/models/trace/extras/URLForEntry.js.map +1 -0
  15. package/models/trace/extras/extras-tsconfig.json +1 -0
  16. package/models/trace/extras/extras.js.map +1 -1
  17. package/models/trace/handlers/AuctionWorkletsHandler.js +4 -2
  18. package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -1
  19. package/models/trace/handlers/InitiatorsHandler.js +1 -12
  20. package/models/trace/handlers/InitiatorsHandler.js.map +1 -1
  21. package/models/trace/handlers/LayoutShiftsHandler.d.ts +1 -0
  22. package/models/trace/handlers/LayoutShiftsHandler.js +10 -2
  23. package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
  24. package/models/trace/handlers/NetworkRequestsHandler.js +4 -3
  25. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
  26. package/models/trace/handlers/RendererHandler.d.ts +1 -0
  27. package/models/trace/handlers/RendererHandler.js +2 -0
  28. package/models/trace/handlers/RendererHandler.js.map +1 -1
  29. package/models/trace/handlers/ScreenshotsHandler.js +3 -2
  30. package/models/trace/handlers/ScreenshotsHandler.js.map +1 -1
  31. package/models/trace/handlers/UserInteractionsHandler.js +3 -2
  32. package/models/trace/handlers/UserInteractionsHandler.js.map +1 -1
  33. package/models/trace/helpers/SyntheticEvents.d.ts +30 -0
  34. package/models/trace/helpers/SyntheticEvents.js +87 -0
  35. package/models/trace/helpers/SyntheticEvents.js.map +1 -0
  36. package/models/trace/helpers/Trace.js +4 -2
  37. package/models/trace/helpers/Trace.js.map +1 -1
  38. package/models/trace/helpers/helpers-tsconfig.json +1 -0
  39. package/models/trace/helpers/helpers.d.ts +1 -0
  40. package/models/trace/helpers/helpers.js +1 -0
  41. package/models/trace/helpers/helpers.js.map +1 -1
  42. package/models/trace/insights/CumulativeLayoutShift.d.ts +7 -2
  43. package/models/trace/insights/CumulativeLayoutShift.js +130 -2
  44. package/models/trace/insights/CumulativeLayoutShift.js.map +1 -1
  45. package/models/trace/types/File.d.ts +11 -6
  46. package/models/trace/types/File.js +0 -3
  47. package/models/trace/types/File.js.map +1 -1
  48. package/models/trace/types/TraceEvents.d.ts +85 -12
  49. package/models/trace/types/TraceEvents.js +27 -3
  50. package/models/trace/types/TraceEvents.js.map +1 -1
  51. package/package.json +1 -1
@@ -1062,6 +1062,7 @@ export declare namespace Audits {
1062
1062
  allowedSites: string[];
1063
1063
  optOutPercentage: number;
1064
1064
  isOptOutTopLevel: boolean;
1065
+ operation: CookieOperation;
1065
1066
  }
1066
1067
  const enum ClientHintIssueReason {
1067
1068
  MetaTagAllowListInvalidOrigin = "MetaTagAllowListInvalidOrigin",
@@ -1116,7 +1117,8 @@ export declare namespace Audits {
1116
1117
  ThirdPartyCookiesBlocked = "ThirdPartyCookiesBlocked",
1117
1118
  NotSignedInWithIdp = "NotSignedInWithIdp",
1118
1119
  MissingTransientUserActivation = "MissingTransientUserActivation",
1119
- ReplacedByButtonMode = "ReplacedByButtonMode"
1120
+ ReplacedByButtonMode = "ReplacedByButtonMode",
1121
+ RelyingPartyOriginIsOpaque = "RelyingPartyOriginIsOpaque"
1120
1122
  }
1121
1123
  interface FederatedAuthUserInfoRequestIssueDetails {
1122
1124
  federatedAuthUserInfoRequestIssueReason: FederatedAuthUserInfoRequestIssueReason;
@@ -4364,6 +4366,25 @@ export declare namespace DOM {
4364
4366
  */
4365
4367
  nodeIds: NodeId[];
4366
4368
  }
4369
+ interface GetAnchorElementRequest {
4370
+ /**
4371
+ * Id of the positioned element from which to find the anchor.
4372
+ */
4373
+ nodeId: NodeId;
4374
+ /**
4375
+ * An optional anchor specifier, as defined in
4376
+ * https://www.w3.org/TR/css-anchor-position-1/#anchor-specifier.
4377
+ * If not provided, it will return the implicit anchor element for
4378
+ * the given positioned element.
4379
+ */
4380
+ anchorSpecifier?: string;
4381
+ }
4382
+ interface GetAnchorElementResponse extends ProtocolResponseWithError {
4383
+ /**
4384
+ * The anchor element of the given anchor query.
4385
+ */
4386
+ nodeId: NodeId;
4387
+ }
4367
4388
  /**
4368
4389
  * Fired when `Element`'s attribute is modified.
4369
4390
  */
@@ -7416,6 +7437,14 @@ export declare namespace Network {
7416
7437
  * Settled fetch event respondWith promise.
7417
7438
  */
7418
7439
  workerRespondWithSettled: number;
7440
+ /**
7441
+ * Started ServiceWorker static routing source evaluation.
7442
+ */
7443
+ workerRouterEvaluationStart?: number;
7444
+ /**
7445
+ * Started cache lookup when the source was evaluated to `cache`.
7446
+ */
7447
+ workerCacheLookupStart?: number;
7419
7448
  /**
7420
7449
  * Started sending request.
7421
7450
  */
@@ -7769,6 +7798,10 @@ export declare namespace Network {
7769
7798
  * field will be set, otherwise no value will be set.
7770
7799
  */
7771
7800
  matchedSourceType?: ServiceWorkerRouterSource;
7801
+ /**
7802
+ * The actual router source used.
7803
+ */
7804
+ actualSourceType?: ServiceWorkerRouterSource;
7772
7805
  }
7773
7806
  /**
7774
7807
  * HTTP response data.
@@ -9586,7 +9619,7 @@ export declare namespace Network {
9586
9619
  FailedPrecondition = "FailedPrecondition",
9587
9620
  ResourceExhausted = "ResourceExhausted",
9588
9621
  AlreadyExists = "AlreadyExists",
9589
- Unavailable = "Unavailable",
9622
+ ResourceLimited = "ResourceLimited",
9590
9623
  Unauthorized = "Unauthorized",
9591
9624
  BadResponse = "BadResponse",
9592
9625
  InternalError = "InternalError",
@@ -15966,6 +15999,19 @@ export declare namespace PWA {
15966
15999
  */
15967
16000
  targetId: Target.TargetID;
15968
16001
  }
16002
+ interface LaunchFilesInAppRequest {
16003
+ manifestId: string;
16004
+ files: string[];
16005
+ }
16006
+ interface LaunchFilesInAppResponse extends ProtocolResponseWithError {
16007
+ /**
16008
+ * IDs of the tab targets created as the result.
16009
+ */
16010
+ targetIds: Target.TargetID[];
16011
+ }
16012
+ interface OpenCurrentPageInAppRequest {
16013
+ manifestId: string;
16014
+ }
15969
16015
  }
15970
16016
  /**
15971
16017
  * Debugger domain exposes JavaScript debugging capabilities. It allows setting and removing
@@ -28,44 +28,45 @@ export interface PossibleFilterActions {
28
28
  * Once actions are applied, the invisibleEntries() method will return the
29
29
  * entries that are invisible, and this is the list of entries that should be
30
30
  * removed before rendering the resulting thread on the timeline.
31
- **/
31
+ */
32
32
  export declare class EntriesFilter {
33
33
  #private;
34
34
  constructor(entryToNodeMap: EntryToNodeMap);
35
35
  /**
36
36
  * Checks which actions can be applied on an entry. This allows us to only show possible actions in the Context Menu.
37
37
  * For example, if an entry has no children, COLLAPSE_FUNCTION will not change the FlameChart, therefore there is no need to show this action as an option.
38
- **/
38
+ */
39
39
  findPossibleActions(entry: Types.TraceEvents.SyntheticTraceEntry): PossibleFilterActions;
40
40
  /**
41
41
  * Returns the amount of entry descendants that belong to the hidden entries array.
42
- * **/
42
+ * */
43
43
  findHiddenDescendantsAmount(entry: Types.TraceEvents.SyntheticTraceEntry): number;
44
44
  /**
45
45
  * Returns the set of entries that are invisible given the set of applied actions.
46
- **/
46
+ */
47
47
  invisibleEntries(): Types.TraceEvents.TraceEventData[];
48
48
  /**
49
- * Sets invisible and modified entries. Called when a trace with annotations is loaded and some entries are set as hidden and modified.
49
+ * Sets hidden and expandable. Called when a trace with modifications is loaded and some entries are set as hidden and expandable.
50
50
  * Both arrays are set together because if there is one, the other must be present too.
51
- **/
52
- setInvisibleAndModifiedEntries(invisibleEntries: Types.TraceEvents.TraceEventData[], modifiedEntries: Types.TraceEvents.TraceEventData[]): void;
51
+ */
52
+ setHiddenAndExpandableEntries(invisibleEntries: Types.TraceEvents.TraceEventData[], expandableEntries: Types.TraceEvents.TraceEventData[]): void;
53
53
  inEntryInvisible(entry: Types.TraceEvents.TraceEventData): boolean;
54
54
  /**
55
- * Returns the array of entries that have a sign indicating that entries below are hidden.
56
- **/
57
- modifiedEntries(): Types.TraceEvents.TraceEventData[];
55
+ * Returns the array of entries that have a sign indicating that entries below are hidden,
56
+ * and so that they can be "expanded" to reveal their hidden children.
57
+ */
58
+ expandableEntries(): Types.TraceEvents.TraceEventData[];
58
59
  /**
59
60
  * Applies an action to hide entries or removes entries
60
61
  * from hidden entries array depending on the action.
61
- **/
62
+ */
62
63
  applyFilterAction(action: UserFilterAction): Types.TraceEvents.TraceEventData[];
63
64
  /**
64
65
  * If an entry was selected from a link instead of clicking on it,
65
66
  * it might be in the invisible entries array.
66
- * If it is, reveal it by resetting clidren the closest modified entry,
67
+ * If it is, reveal it by resetting clidren the closest expandable entry,
67
68
  */
68
69
  revealEntry(entry: Types.TraceEvents.SyntheticTraceEntry): void;
69
- isEntryModified(event: Types.TraceEvents.TraceEventData): boolean;
70
+ isEntryExpandable(event: Types.TraceEvents.TraceEventData): boolean;
70
71
  }
71
72
  export {};
@@ -13,7 +13,7 @@ import * as Types from './types/types.js';
13
13
  * Once actions are applied, the invisibleEntries() method will return the
14
14
  * entries that are invisible, and this is the list of entries that should be
15
15
  * removed before rendering the resulting thread on the timeline.
16
- **/
16
+ */
17
17
  export class EntriesFilter {
18
18
  // Maps from an individual TraceEvent entry to its representation as a
19
19
  // RendererEntryNode. We need this so we can then parse the tree structure
@@ -21,9 +21,10 @@ export class EntriesFilter {
21
21
  #entryToNode;
22
22
  // Track the set of invisible entries.
23
23
  #invisibleEntries = [];
24
- // List of entries whose children are modified. This list is used to
25
- // keep track of entries that should be identified in the UI as modified.
26
- #modifiedVisibleEntries = [];
24
+ // List of entries whose children are hidden. This list is used to
25
+ // keep track of entries that should be identified in the UI as "expandable",
26
+ // since they can be clicked to reveal their hidden children.
27
+ #expandableEntries = [];
27
28
  // Cache for descendants of entry that have already been gathered. The descendants
28
29
  // will never change so we can avoid running the potentially expensive search again.
29
30
  #entryToDescendantsMap = new Map();
@@ -33,7 +34,7 @@ export class EntriesFilter {
33
34
  /**
34
35
  * Checks which actions can be applied on an entry. This allows us to only show possible actions in the Context Menu.
35
36
  * For example, if an entry has no children, COLLAPSE_FUNCTION will not change the FlameChart, therefore there is no need to show this action as an option.
36
- **/
37
+ */
37
38
  findPossibleActions(entry) {
38
39
  const entryNode = this.#entryToNode.get(entry);
39
40
  if (!entryNode) {
@@ -62,7 +63,7 @@ export class EntriesFilter {
62
63
  }
63
64
  /**
64
65
  * Returns the amount of entry descendants that belong to the hidden entries array.
65
- * **/
66
+ * */
66
67
  findHiddenDescendantsAmount(entry) {
67
68
  const entryNode = this.#entryToNode.get(entry);
68
69
  if (!entryNode) {
@@ -73,31 +74,32 @@ export class EntriesFilter {
73
74
  }
74
75
  /**
75
76
  * Returns the set of entries that are invisible given the set of applied actions.
76
- **/
77
+ */
77
78
  invisibleEntries() {
78
79
  return this.#invisibleEntries;
79
80
  }
80
81
  /**
81
- * Sets invisible and modified entries. Called when a trace with annotations is loaded and some entries are set as hidden and modified.
82
+ * Sets hidden and expandable. Called when a trace with modifications is loaded and some entries are set as hidden and expandable.
82
83
  * Both arrays are set together because if there is one, the other must be present too.
83
- **/
84
- setInvisibleAndModifiedEntries(invisibleEntries, modifiedEntries) {
84
+ */
85
+ setHiddenAndExpandableEntries(invisibleEntries, expandableEntries) {
85
86
  this.#invisibleEntries.push(...invisibleEntries);
86
- this.#modifiedVisibleEntries.push(...modifiedEntries);
87
+ this.#expandableEntries.push(...expandableEntries);
87
88
  }
88
89
  inEntryInvisible(entry) {
89
90
  return this.#invisibleEntries.includes(entry);
90
91
  }
91
92
  /**
92
- * Returns the array of entries that have a sign indicating that entries below are hidden.
93
- **/
94
- modifiedEntries() {
95
- return this.#modifiedVisibleEntries;
93
+ * Returns the array of entries that have a sign indicating that entries below are hidden,
94
+ * and so that they can be "expanded" to reveal their hidden children.
95
+ */
96
+ expandableEntries() {
97
+ return this.#expandableEntries;
96
98
  }
97
99
  /**
98
100
  * Applies an action to hide entries or removes entries
99
101
  * from hidden entries array depending on the action.
100
- **/
102
+ */
101
103
  applyFilterAction(action) {
102
104
  // We apply new user action to the set of all entries, and mark
103
105
  // any that should be hidden by adding them to this set.
@@ -111,11 +113,11 @@ export class EntriesFilter {
111
113
  // children remain visible, so we just have to hide the entry that was
112
114
  // selected.
113
115
  entriesToHide.add(action.entry);
114
- // If parent node exists, add it to modifiedVisibleEntries, so it would be possible to uncollapse its' children.
116
+ // If parent node exists, add it to expandableEntries, so it would be possible to uncollapse its children.
115
117
  const actionNode = this.#entryToNode.get(action.entry) || null;
116
118
  const parentNode = actionNode && this.#findNextVisibleParent(actionNode);
117
119
  if (parentNode) {
118
- this.#addModifiedEntry(parentNode.entry);
120
+ this.#addExpandableEntry(parentNode.entry);
119
121
  }
120
122
  break;
121
123
  }
@@ -128,7 +130,7 @@ export class EntriesFilter {
128
130
  }
129
131
  const allDescendants = this.#findAllDescendantsOfNode(entryNode);
130
132
  allDescendants.forEach(descendant => entriesToHide.add(descendant));
131
- this.#addModifiedEntry(action.entry);
133
+ this.#addExpandableEntry(action.entry);
132
134
  break;
133
135
  }
134
136
  case "COLLAPSE_REPEATING_DESCENDANTS" /* FilterAction.COLLAPSE_REPEATING_DESCENDANTS */: {
@@ -140,13 +142,13 @@ export class EntriesFilter {
140
142
  const allRepeatingDescendants = this.#findAllRepeatingDescendantsOfNext(entryNode);
141
143
  allRepeatingDescendants.forEach(descendant => entriesToHide.add(descendant));
142
144
  if (entriesToHide.size > 0) {
143
- this.#addModifiedEntry(action.entry);
145
+ this.#addExpandableEntry(action.entry);
144
146
  }
145
147
  break;
146
148
  }
147
149
  case "UNDO_ALL_ACTIONS" /* FilterAction.UNDO_ALL_ACTIONS */: {
148
150
  this.#invisibleEntries = [];
149
- this.#modifiedVisibleEntries = [];
151
+ this.#expandableEntries = [];
150
152
  break;
151
153
  }
152
154
  case "RESET_CHILDREN" /* FilterAction.RESET_CHILDREN */: {
@@ -161,12 +163,12 @@ export class EntriesFilter {
161
163
  }
162
164
  /**
163
165
  * Add an entry to the array of entries that have a sign indicating that entries below are hidden.
164
- * Also, remove all of the child entries of the new modified entry from the modified array. Do that because
166
+ * Also, remove all of the child entries of the new expandable entry from the expandable array. Do that because
165
167
  * to draw the initiator from the closest visible entry, we need to get the closest entry that is
166
- * marked as modified and we do not want to get some that are hidden.
168
+ * marked as expandable and we do not want to get some that are hidden.
167
169
  */
168
- #addModifiedEntry(entry) {
169
- this.#modifiedVisibleEntries.push(entry);
170
+ #addExpandableEntry(entry) {
171
+ this.#expandableEntries.push(entry);
170
172
  const entryNode = this.#entryToNode.get(entry);
171
173
  if (!entryNode) {
172
174
  // Invalid node was given, just ignore and move on.
@@ -174,7 +176,7 @@ export class EntriesFilter {
174
176
  }
175
177
  const allDescendants = this.#findAllDescendantsOfNode(entryNode);
176
178
  if (allDescendants.length > 0) {
177
- this.#modifiedVisibleEntries = this.#modifiedVisibleEntries.filter(entry => {
179
+ this.#expandableEntries = this.#expandableEntries.filter(entry => {
178
180
  return !allDescendants.includes(entry);
179
181
  });
180
182
  }
@@ -241,7 +243,7 @@ export class EntriesFilter {
241
243
  /**
242
244
  * If an entry was selected from a link instead of clicking on it,
243
245
  * it might be in the invisible entries array.
244
- * If it is, reveal it by resetting clidren the closest modified entry,
246
+ * If it is, reveal it by resetting clidren the closest expandable entry,
245
247
  */
246
248
  revealEntry(entry) {
247
249
  const entryNode = this.#entryToNode.get(entry);
@@ -249,16 +251,16 @@ export class EntriesFilter {
249
251
  // Invalid node was given, just ignore and move on.
250
252
  return;
251
253
  }
252
- let closestModifiedParent = entryNode;
253
- while (closestModifiedParent.parent && !this.#modifiedVisibleEntries.includes(closestModifiedParent.entry)) {
254
- closestModifiedParent = closestModifiedParent.parent;
254
+ let closestExpandableParent = entryNode;
255
+ while (closestExpandableParent.parent && !this.#expandableEntries.includes(closestExpandableParent.entry)) {
256
+ closestExpandableParent = closestExpandableParent.parent;
255
257
  }
256
- this.#makeEntryChildrenVisible(closestModifiedParent.entry);
258
+ this.#makeEntryChildrenVisible(closestExpandableParent.entry);
257
259
  }
258
260
  /**
259
261
  * Removes all of the entry children from the
260
262
  * invisible entries array to make them visible.
261
- **/
263
+ */
262
264
  #makeEntryChildrenVisible(entry) {
263
265
  const entryNode = this.#entryToNode.get(entry);
264
266
  if (!entryNode) {
@@ -269,7 +271,7 @@ export class EntriesFilter {
269
271
  /**
270
272
  * Filter out all descendant of the node
271
273
  * from the invisible entries list.
272
- **/
274
+ */
273
275
  this.#invisibleEntries = this.#invisibleEntries.filter(entry => {
274
276
  if (descendants.includes(entry)) {
275
277
  return false;
@@ -277,18 +279,18 @@ export class EntriesFilter {
277
279
  return true;
278
280
  });
279
281
  /**
280
- * Filter out all descentants and entry from modified entries
282
+ * Filter out all descentants and entry from expandable entries
281
283
  * list to not show that some entries below those are hidden.
282
- **/
283
- this.#modifiedVisibleEntries = this.#modifiedVisibleEntries.filter(iterEntry => {
284
+ */
285
+ this.#expandableEntries = this.#expandableEntries.filter(iterEntry => {
284
286
  if (descendants.includes(iterEntry) || iterEntry === entry) {
285
287
  return false;
286
288
  }
287
289
  return true;
288
290
  });
289
291
  }
290
- isEntryModified(event) {
291
- return this.#modifiedVisibleEntries.includes(event);
292
+ isEntryExpandable(event) {
293
+ return this.#expandableEntries.includes(event);
292
294
  }
293
295
  }
294
296
  //# sourceMappingURL=EntriesFilter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntriesFilter.js","sourceRoot":"","sources":["../../../../../../front_end/models/trace/EntriesFilter.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,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BAAyB,CAAC,SAAS,CAAC,CAAC;QAE9D;;;YAGI;QACJ,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YAC7D,IAAI,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBAChC,OAAO,KAAK,CAAC;YACf,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;QAEH;;;YAGI;QACJ,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;YAC7E,IAAI,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;gBAC3D,OAAO,KAAK,CAAC;YACf,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;IAED,eAAe,CAAC,KAAuC;QACrD,OAAO,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["// Copyright 2023 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\nimport * as Platform from '../../core/platform/platform.js';\n\nimport * as Helpers from './helpers/helpers.js';\nimport * as Types from './types/types.js';\n\ntype EntryToNodeMap = Map<Types.TraceEvents.SyntheticTraceEntry, Helpers.TreeHelpers.TraceEntryNode>;\n\nexport const enum FilterAction {\n MERGE_FUNCTION = 'MERGE_FUNCTION',\n COLLAPSE_FUNCTION = 'COLLAPSE_FUNCTION',\n COLLAPSE_REPEATING_DESCENDANTS = 'COLLAPSE_REPEATING_DESCENDANTS',\n RESET_CHILDREN = 'RESET_CHILDREN',\n UNDO_ALL_ACTIONS = 'UNDO_ALL_ACTIONS',\n}\n\nexport interface UserFilterAction {\n type: FilterAction;\n entry: Types.TraceEvents.SyntheticTraceEntry;\n}\n\n// Object used to indicate to the Context Menu if an action is possible on the selected entry.\nexport interface PossibleFilterActions {\n [FilterAction.MERGE_FUNCTION]: boolean;\n [FilterAction.COLLAPSE_FUNCTION]: boolean;\n [FilterAction.COLLAPSE_REPEATING_DESCENDANTS]: boolean;\n [FilterAction.RESET_CHILDREN]: boolean;\n [FilterAction.UNDO_ALL_ACTIONS]: boolean;\n}\n\n/**\n * This class can take in a thread that has been generated by the\n * RendererHandler and apply certain actions to it in order to modify what is\n * shown to the user. These actions can be automatically applied by DevTools or\n * applied by the user.\n *\n * Once actions are applied, the invisibleEntries() method will return the\n * entries that are invisible, and this is the list of entries that should be\n * removed before rendering the resulting thread on the timeline.\n **/\nexport class EntriesFilter {\n // Maps from an individual TraceEvent entry to its representation as a\n // RendererEntryNode. We need this so we can then parse the tree structure\n // generated by the RendererHandler.\n #entryToNode: EntryToNodeMap;\n\n // Track the set of invisible entries.\n #invisibleEntries: Types.TraceEvents.TraceEventData[] = [];\n // List of entries whose children are modified. This list is used to\n // keep track of entries that should be identified in the UI as modified.\n #modifiedVisibleEntries: Types.TraceEvents.TraceEventData[] = [];\n // Cache for descendants of entry that have already been gathered. The descendants\n // will never change so we can avoid running the potentially expensive search again.\n #entryToDescendantsMap: Map<Helpers.TreeHelpers.TraceEntryNode, Types.TraceEvents.TraceEventData[]> = new Map();\n\n constructor(entryToNodeMap: EntryToNodeMap) {\n this.#entryToNode = entryToNodeMap;\n }\n\n /**\n * Checks which actions can be applied on an entry. This allows us to only show possible actions in the Context Menu.\n * For example, if an entry has no children, COLLAPSE_FUNCTION will not change the FlameChart, therefore there is no need to show this action as an option.\n **/\n findPossibleActions(entry: Types.TraceEvents.SyntheticTraceEntry): PossibleFilterActions {\n const entryNode = this.#entryToNode.get(entry);\n if (!entryNode) {\n // Invalid node was given, return no possible actions.\n return {\n [FilterAction.MERGE_FUNCTION]: false,\n [FilterAction.COLLAPSE_FUNCTION]: false,\n [FilterAction.COLLAPSE_REPEATING_DESCENDANTS]: false,\n [FilterAction.RESET_CHILDREN]: false,\n [FilterAction.UNDO_ALL_ACTIONS]: false,\n };\n }\n const entryParent = entryNode.parent;\n const allVisibleDescendants =\n this.#findAllDescendantsOfNode(entryNode).filter(descendant => !this.#invisibleEntries.includes(descendant));\n const allVisibleRepeatingDescendants = this.#findAllRepeatingDescendantsOfNext(entryNode).filter(\n descendant => !this.#invisibleEntries.includes(descendant));\n const allInVisibleDescendants =\n this.#findAllDescendantsOfNode(entryNode).filter(descendant => this.#invisibleEntries.includes(descendant));\n\n // If there are children to hide, indicate action as possible\n const possibleActions: PossibleFilterActions = {\n [FilterAction.MERGE_FUNCTION]: entryParent !== null,\n [FilterAction.COLLAPSE_FUNCTION]: allVisibleDescendants.length > 0,\n [FilterAction.COLLAPSE_REPEATING_DESCENDANTS]: allVisibleRepeatingDescendants.length > 0,\n [FilterAction.RESET_CHILDREN]: allInVisibleDescendants.length > 0,\n [FilterAction.UNDO_ALL_ACTIONS]: this.#invisibleEntries.length > 0,\n };\n return possibleActions;\n }\n\n /**\n * Returns the amount of entry descendants that belong to the hidden entries array.\n * **/\n findHiddenDescendantsAmount(entry: Types.TraceEvents.SyntheticTraceEntry): number {\n const entryNode = this.#entryToNode.get(entry);\n if (!entryNode) {\n return 0;\n }\n const allDescendants = this.#findAllDescendantsOfNode(entryNode);\n return allDescendants.filter(descendant => this.invisibleEntries().includes(descendant)).length;\n }\n\n /**\n * Returns the set of entries that are invisible given the set of applied actions.\n **/\n invisibleEntries(): Types.TraceEvents.TraceEventData[] {\n return this.#invisibleEntries;\n }\n\n /**\n * Sets invisible and modified entries. Called when a trace with annotations is loaded and some entries are set as hidden and modified.\n * Both arrays are set together because if there is one, the other must be present too.\n **/\n setInvisibleAndModifiedEntries(\n invisibleEntries: Types.TraceEvents.TraceEventData[], modifiedEntries: Types.TraceEvents.TraceEventData[]): void {\n this.#invisibleEntries.push(...invisibleEntries);\n this.#modifiedVisibleEntries.push(...modifiedEntries);\n }\n\n inEntryInvisible(entry: Types.TraceEvents.TraceEventData): boolean {\n return this.#invisibleEntries.includes(entry);\n }\n\n /**\n * Returns the array of entries that have a sign indicating that entries below are hidden.\n **/\n modifiedEntries(): Types.TraceEvents.TraceEventData[] {\n return this.#modifiedVisibleEntries;\n }\n\n /**\n * Applies an action to hide entries or removes entries\n * from hidden entries array depending on the action.\n **/\n applyFilterAction(action: UserFilterAction): Types.TraceEvents.TraceEventData[] {\n // We apply new user action to the set of all entries, and mark\n // any that should be hidden by adding them to this set.\n // Another approach would be to use splice() to remove items from the\n // array, but doing this would be a mutation of the arry for every hidden\n // event. Instead, we add entries to this set and return it as an array at the end.\n const entriesToHide = new Set<Types.TraceEvents.TraceEventData>();\n\n switch (action.type) {\n case FilterAction.MERGE_FUNCTION: {\n // The entry that was clicked on is merged into its parent. All its\n // children remain visible, so we just have to hide the entry that was\n // selected.\n entriesToHide.add(action.entry);\n // If parent node exists, add it to modifiedVisibleEntries, so it would be possible to uncollapse its' children.\n const actionNode = this.#entryToNode.get(action.entry) || null;\n const parentNode = actionNode && this.#findNextVisibleParent(actionNode);\n if (parentNode) {\n this.#addModifiedEntry(parentNode.entry);\n }\n break;\n }\n case FilterAction.COLLAPSE_FUNCTION: {\n // The entry itself remains visible, but all of its descendants are hidden.\n const entryNode = this.#entryToNode.get(action.entry);\n if (!entryNode) {\n // Invalid node was given, just ignore and move on.\n break;\n }\n const allDescendants = this.#findAllDescendantsOfNode(entryNode);\n allDescendants.forEach(descendant => entriesToHide.add(descendant));\n this.#addModifiedEntry(action.entry);\n break;\n }\n case FilterAction.COLLAPSE_REPEATING_DESCENDANTS: {\n const entryNode = this.#entryToNode.get(action.entry);\n if (!entryNode) {\n // Invalid node was given, just ignore and move on.\n break;\n }\n const allRepeatingDescendants = this.#findAllRepeatingDescendantsOfNext(entryNode);\n allRepeatingDescendants.forEach(descendant => entriesToHide.add(descendant));\n if (entriesToHide.size > 0) {\n this.#addModifiedEntry(action.entry);\n }\n break;\n }\n case FilterAction.UNDO_ALL_ACTIONS: {\n this.#invisibleEntries = [];\n this.#modifiedVisibleEntries = [];\n break;\n }\n case FilterAction.RESET_CHILDREN: {\n this.#makeEntryChildrenVisible(action.entry);\n break;\n }\n default:\n Platform.assertNever(action.type, `Unknown EntriesFilter action: ${action.type}`);\n }\n\n this.#invisibleEntries.push(...entriesToHide);\n\n return this.#invisibleEntries;\n }\n\n /**\n * Add an entry to the array of entries that have a sign indicating that entries below are hidden.\n * Also, remove all of the child entries of the new modified entry from the modified array. Do that because\n * to draw the initiator from the closest visible entry, we need to get the closest entry that is\n * marked as modified and we do not want to get some that are hidden.\n */\n #addModifiedEntry(entry: Types.TraceEvents.TraceEventData): void {\n this.#modifiedVisibleEntries.push(entry);\n const entryNode = this.#entryToNode.get(entry);\n if (!entryNode) {\n // Invalid node was given, just ignore and move on.\n return;\n }\n const allDescendants = this.#findAllDescendantsOfNode(entryNode);\n if (allDescendants.length > 0) {\n this.#modifiedVisibleEntries = this.#modifiedVisibleEntries.filter(entry => {\n return !allDescendants.includes(entry);\n });\n }\n }\n\n // The direct parent might be hidden by other actions, therefore we look for the next visible parent.\n #findNextVisibleParent(node: Helpers.TreeHelpers.TraceEntryNode): Helpers.TreeHelpers.TraceEntryNode|null {\n let parent = node.parent;\n while (parent && this.#invisibleEntries.includes(parent.entry)) {\n parent = parent.parent;\n }\n return parent;\n }\n\n #findAllDescendantsOfNode(root: Helpers.TreeHelpers.TraceEntryNode): Types.TraceEvents.TraceEventData[] {\n const cachedDescendants = this.#entryToDescendantsMap.get(root);\n if (cachedDescendants) {\n return cachedDescendants;\n }\n\n const descendants: Types.TraceEvents.TraceEventData[] = [];\n\n // Walk through all the descendants, starting at the root node.\n const children: Helpers.TreeHelpers.TraceEntryNode[] = [...root.children];\n while (children.length > 0) {\n const childNode = children.shift();\n if (childNode) {\n descendants.push(childNode.entry);\n const childNodeCachedDescendants = this.#entryToDescendantsMap.get(childNode);\n // If the descendants of a child are cached, get them from the cache instead of iterating through them again\n if (childNodeCachedDescendants) {\n descendants.push(...childNodeCachedDescendants);\n } else {\n children.push(...childNode.children);\n }\n }\n }\n\n this.#entryToDescendantsMap.set(root, descendants);\n return descendants;\n }\n\n #findAllRepeatingDescendantsOfNext(root: Helpers.TreeHelpers.TraceEntryNode):\n Types.TraceEvents.SyntheticTraceEntry[] {\n // Walk through all the ancestors, starting at the root node.\n const children: Helpers.TreeHelpers.TraceEntryNode[] = [...root.children];\n const repeatingNodes: Types.TraceEvents.SyntheticTraceEntry[] = [];\n const rootIsProfileCall = Types.TraceEvents.isProfileCall(root.entry);\n\n while (children.length > 0) {\n const childNode = children.shift();\n if (childNode) {\n const childIsProfileCall = Types.TraceEvents.isProfileCall(childNode.entry);\n if (/* Handle SyntheticProfileCalls */ rootIsProfileCall && childIsProfileCall) {\n const rootNodeEntry = root.entry as Types.TraceEvents.SyntheticProfileCall;\n const childNodeEntry = childNode.entry as Types.TraceEvents.SyntheticProfileCall;\n\n if (Helpers.SamplesIntegrator.SamplesIntegrator.framesAreEqual(\n rootNodeEntry.callFrame, childNodeEntry.callFrame)) {\n repeatingNodes.push(childNode.entry);\n }\n } /* Handle SyntheticRendererEvents */ else if (!rootIsProfileCall && !childIsProfileCall) {\n if (root.entry.name === childNode.entry.name) {\n repeatingNodes.push(childNode.entry);\n }\n }\n children.push(...childNode.children);\n }\n }\n\n return repeatingNodes;\n }\n\n /**\n * If an entry was selected from a link instead of clicking on it,\n * it might be in the invisible entries array.\n * If it is, reveal it by resetting clidren the closest modified entry,\n */\n revealEntry(entry: Types.TraceEvents.SyntheticTraceEntry): void {\n const entryNode = this.#entryToNode.get(entry);\n if (!entryNode) {\n // Invalid node was given, just ignore and move on.\n return;\n }\n let closestModifiedParent = entryNode;\n while (closestModifiedParent.parent && !this.#modifiedVisibleEntries.includes(closestModifiedParent.entry)) {\n closestModifiedParent = closestModifiedParent.parent;\n }\n this.#makeEntryChildrenVisible(closestModifiedParent.entry);\n }\n\n /**\n * Removes all of the entry children from the\n * invisible entries array to make them visible.\n **/\n #makeEntryChildrenVisible(entry: Types.TraceEvents.SyntheticTraceEntry): void {\n const entryNode = this.#entryToNode.get(entry);\n if (!entryNode) {\n // Invalid node was given, just ignore and move on.\n return;\n }\n const descendants = this.#findAllDescendantsOfNode(entryNode);\n\n /**\n * Filter out all descendant of the node\n * from the invisible entries list.\n **/\n this.#invisibleEntries = this.#invisibleEntries.filter(entry => {\n if (descendants.includes(entry)) {\n return false;\n }\n return true;\n });\n\n /**\n * Filter out all descentants and entry from modified entries\n * list to not show that some entries below those are hidden.\n **/\n this.#modifiedVisibleEntries = this.#modifiedVisibleEntries.filter(iterEntry => {\n if (descendants.includes(iterEntry) || iterEntry === entry) {\n return false;\n }\n return true;\n });\n }\n\n isEntryModified(event: Types.TraceEvents.TraceEventData): boolean {\n return this.#modifiedVisibleEntries.includes(event);\n }\n}\n"]}
1
+ {"version":3,"file":"EntriesFilter.js","sourceRoot":"","sources":["../../../../../../front_end/models/trace/EntriesFilter.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAC7B,OAAO,KAAK,QAAQ,MAAM,iCAAiC,CAAC;AAE5D,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AA0B1C;;;;;;;;;GASG;AACH,MAAM,OAAO,aAAa;IACxB,sEAAsE;IACtE,0EAA0E;IAC1E,oCAAoC;IACpC,YAAY,CAAiB;IAE7B,sCAAsC;IACtC,iBAAiB,GAAuC,EAAE,CAAC;IAC3D,kEAAkE;IAClE,6EAA6E;IAC7E,6DAA6D;IAC7D,kBAAkB,GAAuC,EAAE,CAAC;IAC5D,kFAAkF;IAClF,oFAAoF;IACpF,sBAAsB,GAAgF,IAAI,GAAG,EAAE,CAAC;IAEhH,YAAY,cAA8B;QACxC,IAAI,CAAC,YAAY,GAAG,cAAc,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,mBAAmB,CAAC,KAA4C;QAC9D,MAAM,SAAS,GAAG,IAA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AAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;CACF","sourcesContent":["// Copyright 2023 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\nimport * as Platform from '../../core/platform/platform.js';\n\nimport * as Helpers from './helpers/helpers.js';\nimport * as Types from './types/types.js';\n\ntype EntryToNodeMap = Map<Types.TraceEvents.SyntheticTraceEntry, Helpers.TreeHelpers.TraceEntryNode>;\n\nexport const enum FilterAction {\n MERGE_FUNCTION = 'MERGE_FUNCTION',\n COLLAPSE_FUNCTION = 'COLLAPSE_FUNCTION',\n COLLAPSE_REPEATING_DESCENDANTS = 'COLLAPSE_REPEATING_DESCENDANTS',\n RESET_CHILDREN = 'RESET_CHILDREN',\n UNDO_ALL_ACTIONS = 'UNDO_ALL_ACTIONS',\n}\n\nexport interface UserFilterAction {\n type: FilterAction;\n entry: Types.TraceEvents.SyntheticTraceEntry;\n}\n\n// Object used to indicate to the Context Menu if an action is possible on the selected entry.\nexport interface PossibleFilterActions {\n [FilterAction.MERGE_FUNCTION]: boolean;\n [FilterAction.COLLAPSE_FUNCTION]: boolean;\n [FilterAction.COLLAPSE_REPEATING_DESCENDANTS]: boolean;\n [FilterAction.RESET_CHILDREN]: boolean;\n [FilterAction.UNDO_ALL_ACTIONS]: boolean;\n}\n\n/**\n * This class can take in a thread that has been generated by the\n * RendererHandler and apply certain actions to it in order to modify what is\n * shown to the user. These actions can be automatically applied by DevTools or\n * applied by the user.\n *\n * Once actions are applied, the invisibleEntries() method will return the\n * entries that are invisible, and this is the list of entries that should be\n * removed before rendering the resulting thread on the timeline.\n */\nexport class EntriesFilter {\n // Maps from an individual TraceEvent entry to its representation as a\n // RendererEntryNode. We need this so we can then parse the tree structure\n // generated by the RendererHandler.\n #entryToNode: EntryToNodeMap;\n\n // Track the set of invisible entries.\n #invisibleEntries: Types.TraceEvents.TraceEventData[] = [];\n // List of entries whose children are hidden. This list is used to\n // keep track of entries that should be identified in the UI as \"expandable\",\n // since they can be clicked to reveal their hidden children.\n #expandableEntries: Types.TraceEvents.TraceEventData[] = [];\n // Cache for descendants of entry that have already been gathered. The descendants\n // will never change so we can avoid running the potentially expensive search again.\n #entryToDescendantsMap: Map<Helpers.TreeHelpers.TraceEntryNode, Types.TraceEvents.TraceEventData[]> = new Map();\n\n constructor(entryToNodeMap: EntryToNodeMap) {\n this.#entryToNode = entryToNodeMap;\n }\n\n /**\n * Checks which actions can be applied on an entry. This allows us to only show possible actions in the Context Menu.\n * For example, if an entry has no children, COLLAPSE_FUNCTION will not change the FlameChart, therefore there is no need to show this action as an option.\n */\n findPossibleActions(entry: Types.TraceEvents.SyntheticTraceEntry): PossibleFilterActions {\n const entryNode = this.#entryToNode.get(entry);\n if (!entryNode) {\n // Invalid node was given, return no possible actions.\n return {\n [FilterAction.MERGE_FUNCTION]: false,\n [FilterAction.COLLAPSE_FUNCTION]: false,\n [FilterAction.COLLAPSE_REPEATING_DESCENDANTS]: false,\n [FilterAction.RESET_CHILDREN]: false,\n [FilterAction.UNDO_ALL_ACTIONS]: false,\n };\n }\n const entryParent = entryNode.parent;\n const allVisibleDescendants =\n this.#findAllDescendantsOfNode(entryNode).filter(descendant => !this.#invisibleEntries.includes(descendant));\n const allVisibleRepeatingDescendants = this.#findAllRepeatingDescendantsOfNext(entryNode).filter(\n descendant => !this.#invisibleEntries.includes(descendant));\n const allInVisibleDescendants =\n this.#findAllDescendantsOfNode(entryNode).filter(descendant => this.#invisibleEntries.includes(descendant));\n\n // If there are children to hide, indicate action as possible\n const possibleActions: PossibleFilterActions = {\n [FilterAction.MERGE_FUNCTION]: entryParent !== null,\n [FilterAction.COLLAPSE_FUNCTION]: allVisibleDescendants.length > 0,\n [FilterAction.COLLAPSE_REPEATING_DESCENDANTS]: allVisibleRepeatingDescendants.length > 0,\n [FilterAction.RESET_CHILDREN]: allInVisibleDescendants.length > 0,\n [FilterAction.UNDO_ALL_ACTIONS]: this.#invisibleEntries.length > 0,\n };\n return possibleActions;\n }\n\n /**\n * Returns the amount of entry descendants that belong to the hidden entries array.\n * */\n findHiddenDescendantsAmount(entry: Types.TraceEvents.SyntheticTraceEntry): number {\n const entryNode = this.#entryToNode.get(entry);\n if (!entryNode) {\n return 0;\n }\n const allDescendants = this.#findAllDescendantsOfNode(entryNode);\n return allDescendants.filter(descendant => this.invisibleEntries().includes(descendant)).length;\n }\n\n /**\n * Returns the set of entries that are invisible given the set of applied actions.\n */\n invisibleEntries(): Types.TraceEvents.TraceEventData[] {\n return this.#invisibleEntries;\n }\n\n /**\n * Sets hidden and expandable. Called when a trace with modifications is loaded and some entries are set as hidden and expandable.\n * Both arrays are set together because if there is one, the other must be present too.\n */\n setHiddenAndExpandableEntries(\n invisibleEntries: Types.TraceEvents.TraceEventData[],\n expandableEntries: Types.TraceEvents.TraceEventData[]): void {\n this.#invisibleEntries.push(...invisibleEntries);\n this.#expandableEntries.push(...expandableEntries);\n }\n\n inEntryInvisible(entry: Types.TraceEvents.TraceEventData): boolean {\n return this.#invisibleEntries.includes(entry);\n }\n\n /**\n * Returns the array of entries that have a sign indicating that entries below are hidden,\n * and so that they can be \"expanded\" to reveal their hidden children.\n */\n expandableEntries(): Types.TraceEvents.TraceEventData[] {\n return this.#expandableEntries;\n }\n\n /**\n * Applies an action to hide entries or removes entries\n * from hidden entries array depending on the action.\n */\n applyFilterAction(action: UserFilterAction): Types.TraceEvents.TraceEventData[] {\n // We apply new user action to the set of all entries, and mark\n // any that should be hidden by adding them to this set.\n // Another approach would be to use splice() to remove items from the\n // array, but doing this would be a mutation of the arry for every hidden\n // event. Instead, we add entries to this set and return it as an array at the end.\n const entriesToHide = new Set<Types.TraceEvents.TraceEventData>();\n\n switch (action.type) {\n case FilterAction.MERGE_FUNCTION: {\n // The entry that was clicked on is merged into its parent. All its\n // children remain visible, so we just have to hide the entry that was\n // selected.\n entriesToHide.add(action.entry);\n // If parent node exists, add it to expandableEntries, so it would be possible to uncollapse its children.\n const actionNode = this.#entryToNode.get(action.entry) || null;\n const parentNode = actionNode && this.#findNextVisibleParent(actionNode);\n if (parentNode) {\n this.#addExpandableEntry(parentNode.entry);\n }\n break;\n }\n case FilterAction.COLLAPSE_FUNCTION: {\n // The entry itself remains visible, but all of its descendants are hidden.\n const entryNode = this.#entryToNode.get(action.entry);\n if (!entryNode) {\n // Invalid node was given, just ignore and move on.\n break;\n }\n const allDescendants = this.#findAllDescendantsOfNode(entryNode);\n allDescendants.forEach(descendant => entriesToHide.add(descendant));\n this.#addExpandableEntry(action.entry);\n break;\n }\n case FilterAction.COLLAPSE_REPEATING_DESCENDANTS: {\n const entryNode = this.#entryToNode.get(action.entry);\n if (!entryNode) {\n // Invalid node was given, just ignore and move on.\n break;\n }\n const allRepeatingDescendants = this.#findAllRepeatingDescendantsOfNext(entryNode);\n allRepeatingDescendants.forEach(descendant => entriesToHide.add(descendant));\n if (entriesToHide.size > 0) {\n this.#addExpandableEntry(action.entry);\n }\n break;\n }\n case FilterAction.UNDO_ALL_ACTIONS: {\n this.#invisibleEntries = [];\n this.#expandableEntries = [];\n break;\n }\n case FilterAction.RESET_CHILDREN: {\n this.#makeEntryChildrenVisible(action.entry);\n break;\n }\n default:\n Platform.assertNever(action.type, `Unknown EntriesFilter action: ${action.type}`);\n }\n\n this.#invisibleEntries.push(...entriesToHide);\n\n return this.#invisibleEntries;\n }\n\n /**\n * Add an entry to the array of entries that have a sign indicating that entries below are hidden.\n * Also, remove all of the child entries of the new expandable entry from the expandable array. Do that because\n * to draw the initiator from the closest visible entry, we need to get the closest entry that is\n * marked as expandable and we do not want to get some that are hidden.\n */\n #addExpandableEntry(entry: Types.TraceEvents.TraceEventData): void {\n this.#expandableEntries.push(entry);\n const entryNode = this.#entryToNode.get(entry);\n if (!entryNode) {\n // Invalid node was given, just ignore and move on.\n return;\n }\n const allDescendants = this.#findAllDescendantsOfNode(entryNode);\n if (allDescendants.length > 0) {\n this.#expandableEntries = this.#expandableEntries.filter(entry => {\n return !allDescendants.includes(entry);\n });\n }\n }\n\n // The direct parent might be hidden by other actions, therefore we look for the next visible parent.\n #findNextVisibleParent(node: Helpers.TreeHelpers.TraceEntryNode): Helpers.TreeHelpers.TraceEntryNode|null {\n let parent = node.parent;\n while (parent && this.#invisibleEntries.includes(parent.entry)) {\n parent = parent.parent;\n }\n return parent;\n }\n\n #findAllDescendantsOfNode(root: Helpers.TreeHelpers.TraceEntryNode): Types.TraceEvents.TraceEventData[] {\n const cachedDescendants = this.#entryToDescendantsMap.get(root);\n if (cachedDescendants) {\n return cachedDescendants;\n }\n\n const descendants: Types.TraceEvents.TraceEventData[] = [];\n\n // Walk through all the descendants, starting at the root node.\n const children: Helpers.TreeHelpers.TraceEntryNode[] = [...root.children];\n while (children.length > 0) {\n const childNode = children.shift();\n if (childNode) {\n descendants.push(childNode.entry);\n const childNodeCachedDescendants = this.#entryToDescendantsMap.get(childNode);\n // If the descendants of a child are cached, get them from the cache instead of iterating through them again\n if (childNodeCachedDescendants) {\n descendants.push(...childNodeCachedDescendants);\n } else {\n children.push(...childNode.children);\n }\n }\n }\n\n this.#entryToDescendantsMap.set(root, descendants);\n return descendants;\n }\n\n #findAllRepeatingDescendantsOfNext(root: Helpers.TreeHelpers.TraceEntryNode):\n Types.TraceEvents.SyntheticTraceEntry[] {\n // Walk through all the ancestors, starting at the root node.\n const children: Helpers.TreeHelpers.TraceEntryNode[] = [...root.children];\n const repeatingNodes: Types.TraceEvents.SyntheticTraceEntry[] = [];\n const rootIsProfileCall = Types.TraceEvents.isProfileCall(root.entry);\n\n while (children.length > 0) {\n const childNode = children.shift();\n if (childNode) {\n const childIsProfileCall = Types.TraceEvents.isProfileCall(childNode.entry);\n if (/* Handle SyntheticProfileCalls */ rootIsProfileCall && childIsProfileCall) {\n const rootNodeEntry = root.entry as Types.TraceEvents.SyntheticProfileCall;\n const childNodeEntry = childNode.entry as Types.TraceEvents.SyntheticProfileCall;\n\n if (Helpers.SamplesIntegrator.SamplesIntegrator.framesAreEqual(\n rootNodeEntry.callFrame, childNodeEntry.callFrame)) {\n repeatingNodes.push(childNode.entry);\n }\n } /* Handle SyntheticRendererEvents */ else if (!rootIsProfileCall && !childIsProfileCall) {\n if (root.entry.name === childNode.entry.name) {\n repeatingNodes.push(childNode.entry);\n }\n }\n children.push(...childNode.children);\n }\n }\n\n return repeatingNodes;\n }\n\n /**\n * If an entry was selected from a link instead of clicking on it,\n * it might be in the invisible entries array.\n * If it is, reveal it by resetting clidren the closest expandable entry,\n */\n revealEntry(entry: Types.TraceEvents.SyntheticTraceEntry): void {\n const entryNode = this.#entryToNode.get(entry);\n if (!entryNode) {\n // Invalid node was given, just ignore and move on.\n return;\n }\n let closestExpandableParent = entryNode;\n while (closestExpandableParent.parent && !this.#expandableEntries.includes(closestExpandableParent.entry)) {\n closestExpandableParent = closestExpandableParent.parent;\n }\n this.#makeEntryChildrenVisible(closestExpandableParent.entry);\n }\n\n /**\n * Removes all of the entry children from the\n * invisible entries array to make them visible.\n */\n #makeEntryChildrenVisible(entry: Types.TraceEvents.SyntheticTraceEntry): void {\n const entryNode = this.#entryToNode.get(entry);\n if (!entryNode) {\n // Invalid node was given, just ignore and move on.\n return;\n }\n const descendants = this.#findAllDescendantsOfNode(entryNode);\n\n /**\n * Filter out all descendant of the node\n * from the invisible entries list.\n */\n this.#invisibleEntries = this.#invisibleEntries.filter(entry => {\n if (descendants.includes(entry)) {\n return false;\n }\n return true;\n });\n\n /**\n * Filter out all descentants and entry from expandable entries\n * list to not show that some entries below those are hidden.\n */\n this.#expandableEntries = this.#expandableEntries.filter(iterEntry => {\n if (descendants.includes(iterEntry) || iterEntry === entry) {\n return false;\n }\n return true;\n });\n }\n\n isEntryExpandable(event: Types.TraceEvents.TraceEventData): boolean {\n return this.#expandableEntries.includes(event);\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import * as Handlers from './handlers/handlers.js';
2
+ import * as Helpers from './helpers/helpers.js';
2
3
  import type * as Insights from './insights/insights.js';
3
4
  import * as Types from './types/types.js';
4
5
  export interface ParseConfig {
@@ -20,7 +21,7 @@ export interface ParseConfig {
20
21
  **/
21
22
  export declare class Model<EnabledModelHandlers extends {
22
23
  [key: string]: Handlers.Types.TraceEventHandler;
23
- }> extends EventTarget {
24
+ } = typeof Handlers.ModelHandlers> extends EventTarget {
24
25
  #private;
25
26
  static createWithAllHandlers(config?: Types.Configuration.Configuration): Model<typeof Handlers.ModelHandlers>;
26
27
  constructor(handlers: EnabledModelHandlers, config?: Types.Configuration.Configuration);
@@ -58,9 +59,10 @@ export declare class Model<EnabledModelHandlers extends {
58
59
  */
59
60
  traceParsedData(index?: number): Handlers.Types.EnabledHandlerDataWithMeta<EnabledModelHandlers> | null;
60
61
  traceInsights(index?: number): Insights.Types.TraceInsightData<EnabledModelHandlers> | null;
61
- metadata(index: number): Types.File.MetaData | null;
62
- overrideAnnotations(index: number, newAnnotations: Types.File.Annotations): void;
63
- traceEvents(index: number): readonly Types.TraceEvents.TraceEventData[] | null;
62
+ metadata(index?: number): Types.File.MetaData | null;
63
+ overrideModifications(index: number, newModifications: Types.File.Modifications): void;
64
+ rawTraceEvents(index?: number): readonly Types.TraceEvents.TraceEventData[] | null;
65
+ syntheticTraceEventsManager(index?: number): Helpers.SyntheticEvents.SyntheticEventsManager | null;
64
66
  size(): number;
65
67
  deleteTraceByIndex(recordingIndex: number): void;
66
68
  getRecordingsAvailable(): string[];
@@ -21,6 +21,7 @@ import * as Types from './types/types.js';
21
21
  **/
22
22
  export class Model extends EventTarget {
23
23
  #traces = [];
24
+ #syntheticEventsManagerByTrace = [];
24
25
  #nextNumberByDomain = new Map();
25
26
  #recordingsAvailable = [];
26
27
  #lastRecordingIndex = 0;
@@ -83,11 +84,13 @@ export class Model extends EventTarget {
83
84
  try {
84
85
  // Wait for all outstanding promises before finishing the async execution,
85
86
  // but perform all tasks in parallel.
87
+ const syntheticEventsManager = Helpers.SyntheticEvents.SyntheticEventsManager.initSyntheticEventsManagerForTrace(traceEvents);
86
88
  await this.#processor.parse(traceEvents, isFreshRecording);
87
89
  this.#storeParsedFileData(file, this.#processor.traceParsedData, this.#processor.insights);
88
90
  // We only push the file onto this.#traces here once we know it's valid
89
91
  // and there's been no errors in the parsing.
90
92
  this.#traces.push(file);
93
+ this.#syntheticEventsManagerByTrace.push(syntheticEventsManager);
91
94
  }
92
95
  catch (e) {
93
96
  throw e;
@@ -131,23 +134,29 @@ export class Model extends EventTarget {
131
134
  }
132
135
  return this.#traces[index].traceInsights;
133
136
  }
134
- metadata(index) {
137
+ metadata(index = this.#traces.length - 1) {
135
138
  if (!this.#traces[index]) {
136
139
  return null;
137
140
  }
138
141
  return this.#traces[index].metadata;
139
142
  }
140
- overrideAnnotations(index, newAnnotations) {
143
+ overrideModifications(index, newModifications) {
141
144
  if (this.#traces[index]) {
142
- this.#traces[index].metadata.annotations = newAnnotations;
145
+ this.#traces[index].metadata.modifications = newModifications;
143
146
  }
144
147
  }
145
- traceEvents(index) {
148
+ rawTraceEvents(index = this.#traces.length - 1) {
146
149
  if (!this.#traces[index]) {
147
150
  return null;
148
151
  }
149
152
  return this.#traces[index].traceEvents;
150
153
  }
154
+ syntheticTraceEventsManager(index = this.#traces.length - 1) {
155
+ if (!this.#syntheticEventsManagerByTrace[index]) {
156
+ return null;
157
+ }
158
+ return this.#syntheticEventsManagerByTrace[index];
159
+ }
151
160
  size() {
152
161
  return this.#traces.length;
153
162
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ModelImpl.js","sourceRoot":"","sources":["../../../../../../front_end/models/trace/ModelImpl.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,iCAAiC,CAAC;AAE5D,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAC,uBAAuB,EAAE,cAAc,EAAC,MAAM,gBAAgB,CAAC;AACvE,OAAO,KA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I,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,WAAW,GAAG,cAAc,CAAC;QAC5D,CAAC;IACH,CAAC;IAED,WAAW,CAAC,KAAa;QACvB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC;IACzC,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,kBAAkB,CAAC,cAAsB;QACvC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;QACvC,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,sBAAsB;QACpB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAED,cAAc;QACZ,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF;AAiCD,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAEtB;IADnB,MAAM,CAAU,SAAS,GAAG,aAAa,CAAC;IAC1C,YAAmB,IAA0B;QAC3C,KAAK,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QADjB,SAAI,GAAJ,IAAI,CAAsB;IAE7C,CAAC;;AASH,MAAM,UAAU,yBAAyB,CAAC,SAA+B;IACvE,OAAO,SAAS,CAAC,IAAI,8CAA6B,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,SAA+B;IACvE,OAAO,SAAS,CAAC,IAAI,4DAAoC,CAAC;AAC5D,CAAC","sourcesContent":["// Copyright 2022 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../core/platform/platform.js';\n\nimport * as Handlers from './handlers/handlers.js';\nimport * as Helpers from './helpers/helpers.js';\nimport type * as Insights from './insights/insights.js';\nimport {TraceParseProgressEvent, TraceProcessor} from './Processor.js';\nimport * as Types from './types/types.js';\n\n// Note: this model is implemented in a way that can support multiple trace\n// processors. Currently there is only one implemented, but you will see\n// references to \"processors\" plural because it can easily be extended in the future.\n\nexport interface ParseConfig {\n metadata?: Types.File.MetaData;\n // Unused but will eventually be consumed by UIUtils Linkifier, etc.\n isFreshRecording?: boolean;\n}\n\n/**\n * The new trace engine model we are migrating to. The Model is responsible for\n * parsing arrays of raw trace events and storing the resulting data. It can\n * store multiple traces at once, and can return the data for any of them.\n * Currently as we migrate from the old engine to this, we are turning on the\n * model handlers incrementally as we need the data, to save performance costs\n * of running handlers that we do not use. Therefore, when the model is\n * constructed we pass through a set of handlers that should be used. Once we\n * have migrated all tracks in the Performance Panel to this model, we can\n * remove this ability to run a subset of handlers, as we will need all handlers\n * to be used at that point. For tests, if you want to construct a model with\n * all handlers, you can use the static `Model.createWithAllHandlers` method.\n **/\nexport class Model<EnabledModelHandlers extends {[key: string]: Handlers.Types.TraceEventHandler}> extends EventTarget {\n readonly #traces: ParsedTraceFile<EnabledModelHandlers>[] = [];\n readonly #nextNumberByDomain = new Map<string, number>();\n\n readonly #recordingsAvailable: string[] = [];\n #lastRecordingIndex = 0;\n #processor: TraceProcessor<Handlers.Types.HandlersWithMeta<EnabledModelHandlers>>;\n #config: Types.Configuration.Configuration = Types.Configuration.defaults();\n\n static createWithAllHandlers(config?: Types.Configuration.Configuration): Model<typeof Handlers.ModelHandlers> {\n return new Model(Handlers.ModelHandlers, config);\n }\n\n constructor(handlers: EnabledModelHandlers, config?: Types.Configuration.Configuration) {\n super();\n if (config) {\n this.#config = config;\n }\n this.#processor = new TraceProcessor(handlers, this.#config);\n }\n\n /**\n * Parses an array of trace events into a structured object containing all the\n * information parsed by the trace handlers.\n * You can `await` this function to pause execution until parsing is complete,\n * or instead rely on the `ModuleUpdateEvent` that is dispatched when the\n * parsing is finished.\n *\n * Once parsed, you then have to call the `traceParsedData` method, providing an\n * index of the trace you want to have the data for. This is because any model\n * can store a number of traces. Each trace is given an index, which starts at 0\n * and increments by one as a new trace is parsed.\n *\n * @example\n * // Awaiting the parse method() to block until parsing complete\n * await this.traceModel.parse(events);\n * const data = this.traceModel.traceParsedData(0)\n *\n * @example\n * // Using an event listener to be notified when tracing is complete.\n * this.traceModel.addEventListener(Trace.ModelUpdateEvent.eventName, (event) => {\n * if(event.data.data === 'done') {\n * // trace complete\n * const data = this.traceModel.traceParsedData(0);\n * }\n * });\n * void this.traceModel.parse(events);\n **/\n async parse(traceEvents: readonly Types.TraceEvents.TraceEventData[], config?: ParseConfig): Promise<void> {\n const metadata = config?.metadata || {};\n const isFreshRecording = config?.isFreshRecording || false;\n // During parsing, periodically update any listeners on each processors'\n // progress (if they have any updates).\n const onTraceUpdate = (event: Event): void => {\n const {data} = event as TraceParseProgressEvent;\n this.dispatchEvent(new ModelUpdateEvent({type: ModelUpdateType.PROGRESS_UPDATE, data: data}));\n };\n\n this.#processor.addEventListener(TraceParseProgressEvent.eventName, onTraceUpdate);\n\n // Create a parsed trace file. It will be populated with data from the processor.\n const file: ParsedTraceFile<EnabledModelHandlers> = {\n traceEvents,\n metadata,\n traceParsedData: null,\n traceInsights: null,\n };\n\n try {\n // Wait for all outstanding promises before finishing the async execution,\n // but perform all tasks in parallel.\n await this.#processor.parse(traceEvents, isFreshRecording);\n this.#storeParsedFileData(file, this.#processor.traceParsedData, this.#processor.insights);\n // We only push the file onto this.#traces here once we know it's valid\n // and there's been no errors in the parsing.\n this.#traces.push(file);\n } catch (e) {\n throw e;\n } finally {\n // All processors have finished parsing, no more updates are expected.\n this.#processor.removeEventListener(TraceParseProgressEvent.eventName, onTraceUpdate);\n // Finally, update any listeners that all processors are 'done'.\n this.dispatchEvent(new ModelUpdateEvent({type: ModelUpdateType.COMPLETE, data: 'done'}));\n }\n }\n\n #storeParsedFileData(\n file: ParsedTraceFile<EnabledModelHandlers>,\n data: Handlers.Types.EnabledHandlerDataWithMeta<EnabledModelHandlers>|null,\n insights: Insights.Types.TraceInsightData<EnabledModelHandlers>|null): void {\n file.traceParsedData = data;\n file.traceInsights = insights;\n this.#lastRecordingIndex++;\n let recordingName = `Trace ${this.#lastRecordingIndex}`;\n let origin: string|null = null;\n if (file.traceParsedData) {\n origin = Helpers.Trace.extractOriginFromTrace(file.traceParsedData.Meta.mainFrameURL);\n if (origin) {\n const nextSequenceForDomain = Platform.MapUtilities.getWithDefault(this.#nextNumberByDomain, origin, () => 1);\n recordingName = `${origin} (${nextSequenceForDomain})`;\n this.#nextNumberByDomain.set(origin, nextSequenceForDomain + 1);\n }\n }\n this.#recordingsAvailable.push(recordingName);\n }\n\n /**\n * Returns the parsed trace data indexed by the order in which it was stored.\n * If no index is given, the last stored parsed data is returned.\n */\n traceParsedData(index: number = this.#traces.length - 1):\n Handlers.Types.EnabledHandlerDataWithMeta<EnabledModelHandlers>|null {\n if (!this.#traces[index]) {\n return null;\n }\n\n return this.#traces[index].traceParsedData;\n }\n\n traceInsights(index: number = this.#traces.length - 1): Insights.Types.TraceInsightData<EnabledModelHandlers>|null {\n if (!this.#traces[index]) {\n return null;\n }\n\n return this.#traces[index].traceInsights;\n }\n\n metadata(index: number): Types.File.MetaData|null {\n if (!this.#traces[index]) {\n return null;\n }\n\n return this.#traces[index].metadata;\n }\n\n overrideAnnotations(index: number, newAnnotations: Types.File.Annotations): void {\n if (this.#traces[index]) {\n this.#traces[index].metadata.annotations = newAnnotations;\n }\n }\n\n traceEvents(index: number): readonly Types.TraceEvents.TraceEventData[]|null {\n if (!this.#traces[index]) {\n return null;\n }\n\n return this.#traces[index].traceEvents;\n }\n\n size(): number {\n return this.#traces.length;\n }\n\n deleteTraceByIndex(recordingIndex: number): void {\n this.#traces.splice(recordingIndex, 1);\n this.#recordingsAvailable.splice(recordingIndex, 1);\n }\n\n getRecordingsAvailable(): string[] {\n return this.#recordingsAvailable;\n }\n\n resetProcessor(): void {\n this.#processor.reset();\n }\n}\n\n/**\n * This parsed trace file is used by the Model. It keeps multiple instances\n * of these so that the user can swap between them. The key is that it is\n * essentially the TraceFile plus whatever the model has parsed from it.\n */\nexport type ParsedTraceFile<Handlers extends {[key: string]: Handlers.Types.TraceEventHandler}> = Types.File.TraceFile&{\n traceParsedData: Handlers.Types.EnabledHandlerDataWithMeta<Handlers>| null,\n traceInsights: Insights.Types.TraceInsightData<Handlers>| null,\n};\n\nexport const enum ModelUpdateType {\n COMPLETE = 'COMPLETE',\n PROGRESS_UPDATE = 'PROGRESS_UPDATE',\n}\n\nexport type ModelUpdateEventData = ModelUpdateEventComplete|ModelUpdateEventProgress;\n\nexport type ModelUpdateEventComplete = {\n type: ModelUpdateType.COMPLETE,\n data: 'done',\n};\nexport type ModelUpdateEventProgress = {\n type: ModelUpdateType.PROGRESS_UPDATE,\n data: TraceParseEventProgressData,\n};\n\nexport type TraceParseEventProgressData = {\n index: number,\n total: number,\n};\n\nexport class ModelUpdateEvent extends Event {\n static readonly eventName = 'modelupdate';\n constructor(public data: ModelUpdateEventData) {\n super(ModelUpdateEvent.eventName);\n }\n}\n\ndeclare global {\n interface HTMLElementEventMap {\n [ModelUpdateEvent.eventName]: ModelUpdateEvent;\n }\n}\n\nexport function isModelUpdateDataComplete(eventData: ModelUpdateEventData): eventData is ModelUpdateEventComplete {\n return eventData.type === ModelUpdateType.COMPLETE;\n}\n\nexport function isModelUpdateDataProgress(eventData: ModelUpdateEventData): eventData is ModelUpdateEventProgress {\n return eventData.type === ModelUpdateType.PROGRESS_UPDATE;\n}\n"]}
1
+ {"version":3,"file":"ModelImpl.js","sourceRoot":"","sources":["../../../../../../front_end/models/trace/ModelImpl.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,iCAAiC,CAAC;AAE5D,OAAO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AoB,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,sBAAsB;QACpB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAED,cAAc;QACZ,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF;AAiCD,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAEtB;IADnB,MAAM,CAAU,SAAS,GAAG,aAAa,CAAC;IAC1C,YAAmB,IAA0B;QAC3C,KAAK,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QADjB,SAAI,GAAJ,IAAI,CAAsB;IAE7C,CAAC;;AASH,MAAM,UAAU,yBAAyB,CAAC,SAA+B;IACvE,OAAO,SAAS,CAAC,IAAI,8CAA6B,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,SAA+B;IACvE,OAAO,SAAS,CAAC,IAAI,4DAAoC,CAAC;AAC5D,CAAC","sourcesContent":["// Copyright 2022 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../core/platform/platform.js';\n\nimport * as Handlers from './handlers/handlers.js';\nimport * as Helpers from './helpers/helpers.js';\nimport type * as Insights from './insights/insights.js';\nimport {TraceParseProgressEvent, TraceProcessor} from './Processor.js';\nimport * as Types from './types/types.js';\n\n// Note: this model is implemented in a way that can support multiple trace\n// processors. Currently there is only one implemented, but you will see\n// references to \"processors\" plural because it can easily be extended in the future.\n\nexport interface ParseConfig {\n metadata?: Types.File.MetaData;\n // Unused but will eventually be consumed by UIUtils Linkifier, etc.\n isFreshRecording?: boolean;\n}\n\n/**\n * The new trace engine model we are migrating to. The Model is responsible for\n * parsing arrays of raw trace events and storing the resulting data. It can\n * store multiple traces at once, and can return the data for any of them.\n * Currently as we migrate from the old engine to this, we are turning on the\n * model handlers incrementally as we need the data, to save performance costs\n * of running handlers that we do not use. Therefore, when the model is\n * constructed we pass through a set of handlers that should be used. Once we\n * have migrated all tracks in the Performance Panel to this model, we can\n * remove this ability to run a subset of handlers, as we will need all handlers\n * to be used at that point. For tests, if you want to construct a model with\n * all handlers, you can use the static `Model.createWithAllHandlers` method.\n **/\nexport class Model<EnabledModelHandlers extends {[key: string]: Handlers.Types.TraceEventHandler} =\n typeof Handlers.ModelHandlers> extends EventTarget {\n readonly #traces: ParsedTraceFile<EnabledModelHandlers>[] = [];\n readonly #syntheticEventsManagerByTrace: Helpers.SyntheticEvents.SyntheticEventsManager[] = [];\n readonly #nextNumberByDomain = new Map<string, number>();\n\n readonly #recordingsAvailable: string[] = [];\n #lastRecordingIndex = 0;\n #processor: TraceProcessor<Handlers.Types.HandlersWithMeta<EnabledModelHandlers>>;\n #config: Types.Configuration.Configuration = Types.Configuration.defaults();\n\n static createWithAllHandlers(config?: Types.Configuration.Configuration): Model<typeof Handlers.ModelHandlers> {\n return new Model(Handlers.ModelHandlers, config);\n }\n\n constructor(handlers: EnabledModelHandlers, config?: Types.Configuration.Configuration) {\n super();\n if (config) {\n this.#config = config;\n }\n this.#processor = new TraceProcessor(handlers, this.#config);\n }\n\n /**\n * Parses an array of trace events into a structured object containing all the\n * information parsed by the trace handlers.\n * You can `await` this function to pause execution until parsing is complete,\n * or instead rely on the `ModuleUpdateEvent` that is dispatched when the\n * parsing is finished.\n *\n * Once parsed, you then have to call the `traceParsedData` method, providing an\n * index of the trace you want to have the data for. This is because any model\n * can store a number of traces. Each trace is given an index, which starts at 0\n * and increments by one as a new trace is parsed.\n *\n * @example\n * // Awaiting the parse method() to block until parsing complete\n * await this.traceModel.parse(events);\n * const data = this.traceModel.traceParsedData(0)\n *\n * @example\n * // Using an event listener to be notified when tracing is complete.\n * this.traceModel.addEventListener(Trace.ModelUpdateEvent.eventName, (event) => {\n * if(event.data.data === 'done') {\n * // trace complete\n * const data = this.traceModel.traceParsedData(0);\n * }\n * });\n * void this.traceModel.parse(events);\n **/\n async parse(traceEvents: readonly Types.TraceEvents.TraceEventData[], config?: ParseConfig): Promise<void> {\n const metadata = config?.metadata || {};\n const isFreshRecording = config?.isFreshRecording || false;\n // During parsing, periodically update any listeners on each processors'\n // progress (if they have any updates).\n const onTraceUpdate = (event: Event): void => {\n const {data} = event as TraceParseProgressEvent;\n this.dispatchEvent(new ModelUpdateEvent({type: ModelUpdateType.PROGRESS_UPDATE, data: data}));\n };\n\n this.#processor.addEventListener(TraceParseProgressEvent.eventName, onTraceUpdate);\n\n // Create a parsed trace file. It will be populated with data from the processor.\n const file: ParsedTraceFile<EnabledModelHandlers> = {\n traceEvents,\n metadata,\n traceParsedData: null,\n traceInsights: null,\n };\n\n try {\n // Wait for all outstanding promises before finishing the async execution,\n // but perform all tasks in parallel.\n const syntheticEventsManager =\n Helpers.SyntheticEvents.SyntheticEventsManager.initSyntheticEventsManagerForTrace(traceEvents);\n await this.#processor.parse(traceEvents, isFreshRecording);\n this.#storeParsedFileData(file, this.#processor.traceParsedData, this.#processor.insights);\n // We only push the file onto this.#traces here once we know it's valid\n // and there's been no errors in the parsing.\n this.#traces.push(file);\n this.#syntheticEventsManagerByTrace.push(syntheticEventsManager);\n } catch (e) {\n throw e;\n } finally {\n // All processors have finished parsing, no more updates are expected.\n this.#processor.removeEventListener(TraceParseProgressEvent.eventName, onTraceUpdate);\n // Finally, update any listeners that all processors are 'done'.\n this.dispatchEvent(new ModelUpdateEvent({type: ModelUpdateType.COMPLETE, data: 'done'}));\n }\n }\n\n #storeParsedFileData(\n file: ParsedTraceFile<EnabledModelHandlers>,\n data: Handlers.Types.EnabledHandlerDataWithMeta<EnabledModelHandlers>|null,\n insights: Insights.Types.TraceInsightData<EnabledModelHandlers>|null): void {\n file.traceParsedData = data;\n file.traceInsights = insights;\n this.#lastRecordingIndex++;\n let recordingName = `Trace ${this.#lastRecordingIndex}`;\n let origin: string|null = null;\n if (file.traceParsedData) {\n origin = Helpers.Trace.extractOriginFromTrace(file.traceParsedData.Meta.mainFrameURL);\n if (origin) {\n const nextSequenceForDomain = Platform.MapUtilities.getWithDefault(this.#nextNumberByDomain, origin, () => 1);\n recordingName = `${origin} (${nextSequenceForDomain})`;\n this.#nextNumberByDomain.set(origin, nextSequenceForDomain + 1);\n }\n }\n this.#recordingsAvailable.push(recordingName);\n }\n\n /**\n * Returns the parsed trace data indexed by the order in which it was stored.\n * If no index is given, the last stored parsed data is returned.\n */\n traceParsedData(index: number = this.#traces.length - 1):\n Handlers.Types.EnabledHandlerDataWithMeta<EnabledModelHandlers>|null {\n if (!this.#traces[index]) {\n return null;\n }\n\n return this.#traces[index].traceParsedData;\n }\n\n traceInsights(index: number = this.#traces.length - 1): Insights.Types.TraceInsightData<EnabledModelHandlers>|null {\n if (!this.#traces[index]) {\n return null;\n }\n\n return this.#traces[index].traceInsights;\n }\n\n metadata(index: number = this.#traces.length - 1): Types.File.MetaData|null {\n if (!this.#traces[index]) {\n return null;\n }\n\n return this.#traces[index].metadata;\n }\n\n overrideModifications(index: number, newModifications: Types.File.Modifications): void {\n if (this.#traces[index]) {\n this.#traces[index].metadata.modifications = newModifications;\n }\n }\n\n rawTraceEvents(index: number = this.#traces.length - 1): readonly Types.TraceEvents.TraceEventData[]|null {\n if (!this.#traces[index]) {\n return null;\n }\n\n return this.#traces[index].traceEvents;\n }\n syntheticTraceEventsManager(index: number = this.#traces.length - 1): Helpers.SyntheticEvents.SyntheticEventsManager\n |null {\n if (!this.#syntheticEventsManagerByTrace[index]) {\n return null;\n }\n\n return this.#syntheticEventsManagerByTrace[index];\n }\n\n size(): number {\n return this.#traces.length;\n }\n\n deleteTraceByIndex(recordingIndex: number): void {\n this.#traces.splice(recordingIndex, 1);\n this.#recordingsAvailable.splice(recordingIndex, 1);\n }\n\n getRecordingsAvailable(): string[] {\n return this.#recordingsAvailable;\n }\n\n resetProcessor(): void {\n this.#processor.reset();\n }\n}\n\n/**\n * This parsed trace file is used by the Model. It keeps multiple instances\n * of these so that the user can swap between them. The key is that it is\n * essentially the TraceFile plus whatever the model has parsed from it.\n */\nexport type ParsedTraceFile<Handlers extends {[key: string]: Handlers.Types.TraceEventHandler}> = Types.File.TraceFile&{\n traceParsedData: Handlers.Types.EnabledHandlerDataWithMeta<Handlers>| null,\n traceInsights: Insights.Types.TraceInsightData<Handlers>| null,\n};\n\nexport const enum ModelUpdateType {\n COMPLETE = 'COMPLETE',\n PROGRESS_UPDATE = 'PROGRESS_UPDATE',\n}\n\nexport type ModelUpdateEventData = ModelUpdateEventComplete|ModelUpdateEventProgress;\n\nexport type ModelUpdateEventComplete = {\n type: ModelUpdateType.COMPLETE,\n data: 'done',\n};\nexport type ModelUpdateEventProgress = {\n type: ModelUpdateType.PROGRESS_UPDATE,\n data: TraceParseEventProgressData,\n};\n\nexport type TraceParseEventProgressData = {\n index: number,\n total: number,\n};\n\nexport class ModelUpdateEvent extends Event {\n static readonly eventName = 'modelupdate';\n constructor(public data: ModelUpdateEventData) {\n super(ModelUpdateEvent.eventName);\n }\n}\n\ndeclare global {\n interface HTMLElementEventMap {\n [ModelUpdateEvent.eventName]: ModelUpdateEvent;\n }\n}\n\nexport function isModelUpdateDataComplete(eventData: ModelUpdateEventData): eventData is ModelUpdateEventComplete {\n return eventData.type === ModelUpdateType.COMPLETE;\n}\n\nexport function isModelUpdateDataProgress(eventData: ModelUpdateEventData): eventData is ModelUpdateEventProgress {\n return eventData.type === ModelUpdateType.PROGRESS_UPDATE;\n}\n"]}