@paulirish/trace_engine 0.0.10 → 0.0.11

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 (205) hide show
  1. package/analyze-trace.mjs +1 -1
  2. package/core/platform/DevToolsPath.d.ts +4 -13
  3. package/core/platform/DevToolsPath.js +7 -4
  4. package/core/platform/DevToolsPath.js.map +1 -7
  5. package/core/platform/MimeType.d.ts +27 -0
  6. package/core/platform/MimeType.js +119 -86
  7. package/core/platform/MimeType.js.map +1 -7
  8. package/core/platform/Timing.d.ts +7 -0
  9. package/core/platform/Timing.js +7 -4
  10. package/core/platform/Timing.js.map +1 -7
  11. package/core/platform/UIString.d.ts +2 -5
  12. package/core/platform/UIString.js +5 -2
  13. package/core/platform/UIString.js.map +1 -7
  14. package/core/platform/UserVisibleError.js +19 -10
  15. package/core/platform/UserVisibleError.js.map +1 -7
  16. package/core/platform/array-utilities.d.ts +48 -10
  17. package/core/platform/array-utilities.js +160 -124
  18. package/core/platform/array-utilities.js.map +1 -7
  19. package/core/platform/brand.d.ts +14 -0
  20. package/core/platform/brand.js +5 -1
  21. package/core/platform/brand.js.map +1 -7
  22. package/core/platform/date-utilities.js +10 -6
  23. package/core/platform/date-utilities.js.map +1 -7
  24. package/core/platform/dom-utilities.d.ts +3 -1
  25. package/core/platform/dom-utilities.js +94 -83
  26. package/core/platform/dom-utilities.js.map +1 -7
  27. package/core/platform/keyboard-utilities.d.ts +2 -0
  28. package/core/platform/keyboard-utilities.js +15 -24
  29. package/core/platform/keyboard-utilities.js.map +1 -7
  30. package/core/platform/map-utilities.d.ts +4 -0
  31. package/core/platform/map-utilities.js +66 -60
  32. package/core/platform/map-utilities.js.map +1 -7
  33. package/core/platform/number-utilities.js +66 -55
  34. package/core/platform/number-utilities.js.map +1 -7
  35. package/core/platform/platform.d.ts +5 -1
  36. package/core/platform/platform.js +54 -37
  37. package/core/platform/platform.js.map +1 -7
  38. package/core/platform/promise-utilities.d.ts +10 -0
  39. package/core/platform/promise-utilities.js +16 -8
  40. package/core/platform/promise-utilities.js.map +1 -7
  41. package/core/platform/set-utilities.js +20 -17
  42. package/core/platform/set-utilities.js.map +1 -7
  43. package/core/platform/string-utilities.d.ts +32 -1
  44. package/core/platform/string-utilities.js +453 -379
  45. package/core/platform/string-utilities.js.map +1 -7
  46. package/core/platform/typescript-utilities.d.ts +5 -5
  47. package/core/platform/typescript-utilities.js +19 -7
  48. package/core/platform/typescript-utilities.js.map +1 -7
  49. package/generated/protocol.d.ts +2081 -347
  50. package/generated/protocol.js +5 -2230
  51. package/models/cpu_profile/CPUProfileDataModel.d.ts +77 -0
  52. package/models/cpu_profile/CPUProfileDataModel.js +492 -359
  53. package/models/cpu_profile/CPUProfileDataModel.js.map +1 -7
  54. package/models/cpu_profile/ProfileTreeModel.d.ts +29 -0
  55. package/models/cpu_profile/ProfileTreeModel.js +87 -82
  56. package/models/cpu_profile/ProfileTreeModel.js.map +1 -7
  57. package/models/cpu_profile/cpu_profile.d.ts +3 -0
  58. package/models/cpu_profile/cpu_profile.js +7 -7
  59. package/models/cpu_profile/cpu_profile.js.map +1 -7
  60. package/models/trace/EntriesFilter.d.ts +55 -0
  61. package/models/trace/EntriesFilter.js +227 -166
  62. package/models/trace/EntriesFilter.js.map +1 -7
  63. package/models/trace/LegacyTracingModel.js.map +1 -7
  64. package/models/trace/ModelImpl.d.ts +110 -0
  65. package/models/trace/ModelImpl.js +161 -102
  66. package/models/trace/ModelImpl.js.map +1 -7
  67. package/models/trace/Processor.d.ts +36 -0
  68. package/models/trace/Processor.js +197 -163
  69. package/models/trace/Processor.js.map +1 -7
  70. package/models/trace/TracingManager.js.map +1 -7
  71. package/models/trace/extras/FetchNodes.d.ts +46 -0
  72. package/models/trace/extras/FetchNodes.js +132 -91
  73. package/models/trace/extras/FetchNodes.js.map +1 -7
  74. package/models/trace/extras/FilmStrip.d.ts +19 -0
  75. package/models/trace/extras/FilmStrip.js +38 -31
  76. package/models/trace/extras/FilmStrip.js.map +1 -7
  77. package/models/trace/extras/MainThreadActivity.d.ts +2 -0
  78. package/models/trace/extras/MainThreadActivity.js +72 -56
  79. package/models/trace/extras/MainThreadActivity.js.map +1 -7
  80. package/models/trace/extras/Metadata.d.ts +2 -0
  81. package/models/trace/extras/Metadata.js +42 -26
  82. package/models/trace/extras/Metadata.js.map +1 -7
  83. package/models/trace/extras/extras.js.map +1 -7
  84. package/models/trace/handlers/AnimationHandler.d.ts +8 -0
  85. package/models/trace/handlers/AnimationHandler.js +22 -20
  86. package/models/trace/handlers/AnimationHandler.js.map +1 -7
  87. package/models/trace/handlers/AuctionWorkletsHandler.d.ts +8 -0
  88. package/models/trace/handlers/AuctionWorkletsHandler.js +143 -89
  89. package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -7
  90. package/models/trace/handlers/FramesHandler.d.ts +76 -0
  91. package/models/trace/handlers/FramesHandler.js +424 -355
  92. package/models/trace/handlers/FramesHandler.js.map +1 -7
  93. package/models/trace/handlers/GPUHandler.d.ts +11 -0
  94. package/models/trace/handlers/GPUHandler.js +41 -37
  95. package/models/trace/handlers/GPUHandler.js.map +1 -7
  96. package/models/trace/handlers/InitiatorsHandler.d.ts +10 -0
  97. package/models/trace/handlers/InitiatorsHandler.js +164 -113
  98. package/models/trace/handlers/InitiatorsHandler.js.map +1 -7
  99. package/models/trace/handlers/InvalidationsHandler.d.ts +10 -0
  100. package/models/trace/handlers/InvalidationsHandler.js +101 -79
  101. package/models/trace/handlers/InvalidationsHandler.js.map +1 -7
  102. package/models/trace/handlers/LargestImagePaintHandler.d.ts +5 -0
  103. package/models/trace/handlers/LargestImagePaintHandler.js +32 -12
  104. package/models/trace/handlers/LargestImagePaintHandler.js.map +1 -7
  105. package/models/trace/handlers/LargestTextPaintHandler.d.ts +5 -0
  106. package/models/trace/handlers/LargestTextPaintHandler.js +20 -12
  107. package/models/trace/handlers/LargestTextPaintHandler.js.map +1 -7
  108. package/models/trace/handlers/LayerTreeHandler.d.ts +13 -0
  109. package/models/trace/handlers/LayerTreeHandler.js +96 -70
  110. package/models/trace/handlers/LayerTreeHandler.js.map +1 -7
  111. package/models/trace/handlers/LayoutShiftsHandler.d.ts +44 -0
  112. package/models/trace/handlers/LayoutShiftsHandler.js +304 -227
  113. package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -7
  114. package/models/trace/handlers/MemoryHandler.d.ts +7 -0
  115. package/models/trace/handlers/MemoryHandler.js +14 -11
  116. package/models/trace/handlers/MemoryHandler.js.map +1 -7
  117. package/models/trace/handlers/MetaHandler.d.ts +37 -0
  118. package/models/trace/handlers/MetaHandler.js +314 -226
  119. package/models/trace/handlers/MetaHandler.js.map +1 -7
  120. package/models/trace/handlers/ModelHandlers.d.ts +21 -0
  121. package/models/trace/handlers/ModelHandlers.js +25 -22
  122. package/models/trace/handlers/ModelHandlers.js.map +1 -7
  123. package/models/trace/handlers/NetworkRequestsHandler.d.ts +17 -0
  124. package/models/trace/handlers/NetworkRequestsHandler.js +342 -218
  125. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -7
  126. package/models/trace/handlers/PageLoadMetricsHandler.d.ts +67 -0
  127. package/models/trace/handlers/PageLoadMetricsHandler.js +357 -284
  128. package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -7
  129. package/models/trace/handlers/RendererHandler.d.ts +101 -0
  130. package/models/trace/handlers/RendererHandler.js +295 -191
  131. package/models/trace/handlers/RendererHandler.js.map +1 -7
  132. package/models/trace/handlers/SamplesHandler.d.ts +46 -0
  133. package/models/trace/handlers/SamplesHandler.js +195 -158
  134. package/models/trace/handlers/SamplesHandler.js.map +1 -7
  135. package/models/trace/handlers/ScreenshotsHandler.d.ts +7 -0
  136. package/models/trace/handlers/ScreenshotsHandler.js +63 -41
  137. package/models/trace/handlers/ScreenshotsHandler.js.map +1 -7
  138. package/models/trace/handlers/Threads.d.ts +33 -0
  139. package/models/trace/handlers/Threads.js +85 -67
  140. package/models/trace/handlers/Threads.js.map +1 -7
  141. package/models/trace/handlers/UserInteractionsHandler.d.ts +57 -0
  142. package/models/trace/handlers/UserInteractionsHandler.js +240 -141
  143. package/models/trace/handlers/UserInteractionsHandler.js.map +1 -7
  144. package/models/trace/handlers/UserTimingsHandler.d.ts +28 -0
  145. package/models/trace/handlers/UserTimingsHandler.js +91 -80
  146. package/models/trace/handlers/UserTimingsHandler.js.map +1 -7
  147. package/models/trace/handlers/WarningsHandler.d.ts +14 -0
  148. package/models/trace/handlers/WarningsHandler.js +100 -62
  149. package/models/trace/handlers/WarningsHandler.js.map +1 -7
  150. package/models/trace/handlers/WorkersHandler.d.ts +11 -0
  151. package/models/trace/handlers/WorkersHandler.js +40 -38
  152. package/models/trace/handlers/WorkersHandler.js.map +1 -7
  153. package/models/trace/handlers/handlers.d.ts +3 -0
  154. package/models/trace/handlers/handlers.js +7 -4
  155. package/models/trace/handlers/handlers.js.map +1 -7
  156. package/models/trace/handlers/types.d.ts +45 -0
  157. package/models/trace/handlers/types.js +15 -15
  158. package/models/trace/handlers/types.js.map +1 -7
  159. package/models/trace/helpers/SamplesIntegrator.d.ts +49 -0
  160. package/models/trace/helpers/SamplesIntegrator.js +381 -204
  161. package/models/trace/helpers/SamplesIntegrator.js.map +1 -7
  162. package/models/trace/helpers/Timing.d.ts +26 -0
  163. package/models/trace/helpers/Timing.js +131 -110
  164. package/models/trace/helpers/Timing.js.map +1 -7
  165. package/models/trace/helpers/Trace.d.ts +37 -0
  166. package/models/trace/helpers/Trace.js +200 -166
  167. package/models/trace/helpers/Trace.js.map +1 -7
  168. package/models/trace/helpers/TreeHelpers.d.ts +90 -0
  169. package/models/trace/helpers/TreeHelpers.js +203 -100
  170. package/models/trace/helpers/TreeHelpers.js.map +1 -7
  171. package/models/trace/helpers/helpers.d.ts +4 -0
  172. package/models/trace/helpers/helpers.js +8 -5
  173. package/models/trace/helpers/helpers.js.map +1 -7
  174. package/models/trace/root-causes/LayoutShift.d.ts +119 -0
  175. package/models/trace/root-causes/LayoutShift.js +470 -323
  176. package/models/trace/root-causes/LayoutShift.js.map +1 -7
  177. package/models/trace/root-causes/RootCauses.d.ts +14 -0
  178. package/models/trace/root-causes/RootCauses.js +9 -6
  179. package/models/trace/root-causes/RootCauses.js.map +1 -7
  180. package/models/trace/root-causes/root-causes.d.ts +1 -0
  181. package/models/trace/root-causes/root-causes.js +5 -2
  182. package/models/trace/root-causes/root-causes.js.map +1 -7
  183. package/models/trace/trace.d.ts +11 -0
  184. package/models/trace/trace.js +17 -23
  185. package/models/trace/trace.js.map +1 -7
  186. package/models/trace/types/Configuration.d.ts +33 -0
  187. package/models/trace/types/Configuration.js +25 -14
  188. package/models/trace/types/Configuration.js.map +1 -7
  189. package/models/trace/types/File.d.ts +23 -0
  190. package/models/trace/types/File.js +5 -6
  191. package/models/trace/types/File.js.map +1 -7
  192. package/models/trace/types/Timing.d.ts +25 -0
  193. package/models/trace/types/Timing.js +10 -11
  194. package/models/trace/types/Timing.js.map +1 -7
  195. package/models/trace/types/TraceEvents.d.ts +1571 -0
  196. package/models/trace/types/TraceEvents.js +174 -381
  197. package/models/trace/types/TraceEvents.js.map +1 -7
  198. package/models/trace/types/types.d.ts +4 -0
  199. package/models/trace/types/types.js +8 -5
  200. package/models/trace/types/types.js.map +1 -7
  201. package/package.json +1 -1
  202. package/TracingManager.js +0 -0
  203. package/extras/extras.js +0 -0
  204. package/trace.mjs +0 -6980
  205. package/trace.mjs.map +0 -8
@@ -1,168 +1,267 @@
1
- import * as Helpers from "../helpers/helpers.js";
2
- import * as Types from "../types/types.js";
3
- import { HandlerState } from "./types.js";
1
+ // Copyright 2022 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ import * as Helpers from '../helpers/helpers.js';
5
+ import * as Types from '../types/types.js';
6
+ // This handler serves two purposes. It generates a list of events that are
7
+ // used to show user clicks in the timeline. It is also used to gather
8
+ // EventTimings into Interactions, which we use to show interactions and
9
+ // highlight long interactions to the user, along with INP.
10
+ // We don't need to know which process / thread these events occurred in,
11
+ // because they are effectively global, so we just track all that we find.
4
12
  const allEvents = [];
5
13
  export const LONG_INTERACTION_THRESHOLD = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(200));
6
14
  let longestInteractionEvent = null;
7
15
  const interactionEvents = [];
8
16
  const interactionEventsWithNoNesting = [];
9
- const eventTimingEndEventsById = /* @__PURE__ */ new Map();
17
+ const eventTimingEndEventsById = new Map();
10
18
  const eventTimingStartEventsForInteractions = [];
11
- let handlerState = HandlerState.UNINITIALIZED;
19
+ let handlerState = 1 /* HandlerState.UNINITIALIZED */;
12
20
  export function reset() {
13
- allEvents.length = 0;
14
- interactionEvents.length = 0;
15
- eventTimingStartEventsForInteractions.length = 0;
16
- eventTimingEndEventsById.clear();
17
- interactionEventsWithNoNesting.length = 0;
18
- longestInteractionEvent = null;
19
- handlerState = HandlerState.INITIALIZED;
21
+ allEvents.length = 0;
22
+ interactionEvents.length = 0;
23
+ eventTimingStartEventsForInteractions.length = 0;
24
+ eventTimingEndEventsById.clear();
25
+ interactionEventsWithNoNesting.length = 0;
26
+ longestInteractionEvent = null;
27
+ handlerState = 2 /* HandlerState.INITIALIZED */;
20
28
  }
21
29
  export function handleEvent(event) {
22
- if (handlerState !== HandlerState.INITIALIZED) {
23
- throw new Error("Handler is not initialized");
24
- }
25
- if (!Types.TraceEvents.isTraceEventEventTiming(event)) {
26
- return;
27
- }
28
- if (Types.TraceEvents.isTraceEventEventTimingEnd(event)) {
29
- eventTimingEndEventsById.set(event.id, event);
30
- }
31
- allEvents.push(event);
32
- if (!event.args.data || !Types.TraceEvents.isTraceEventEventTimingStart(event)) {
33
- return;
34
- }
35
- const { duration, interactionId } = event.args.data;
36
- if (duration < 1 || interactionId === void 0 || interactionId === 0) {
37
- return;
38
- }
39
- eventTimingStartEventsForInteractions.push(event);
30
+ if (handlerState !== 2 /* HandlerState.INITIALIZED */) {
31
+ throw new Error('Handler is not initialized');
32
+ }
33
+ if (!Types.TraceEvents.isTraceEventEventTiming(event)) {
34
+ return;
35
+ }
36
+ if (Types.TraceEvents.isTraceEventEventTimingEnd(event)) {
37
+ // Store the end event; for each start event that is an interaction, we need the matching end event to calculate the duration correctly.
38
+ eventTimingEndEventsById.set(event.id, event);
39
+ }
40
+ allEvents.push(event);
41
+ // From this point on we want to find events that represent interactions.
42
+ // These events are always start events - those are the ones that contain all
43
+ // the metadata about the interaction.
44
+ if (!event.args.data || !Types.TraceEvents.isTraceEventEventTimingStart(event)) {
45
+ return;
46
+ }
47
+ const { duration, interactionId } = event.args.data;
48
+ // We exclude events for the sake of interactions if:
49
+ // 1. They have no duration.
50
+ // 2. They have no interactionId
51
+ // 3. They have an interactionId of 0: this indicates that it's not an
52
+ // interaction that we care about because it hasn't had its own interactionId
53
+ // set (0 is the default on the backend).
54
+ // See: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/responsiveness_metrics.cc;l=133;drc=40c209a9c365ebb9f16fb99dfe78c7fe768b9594
55
+ if (duration < 1 || interactionId === undefined || interactionId === 0) {
56
+ return;
57
+ }
58
+ // Store the start event. In the finalize() function we will pair this with
59
+ // its end event and create the synthetic interaction event.
60
+ eventTimingStartEventsForInteractions.push(event);
40
61
  }
41
- const pointerEventTypes = /* @__PURE__ */ new Set([
42
- "pointerdown",
43
- "touchstart",
44
- "pointerup",
45
- "touchend",
46
- "mousedown",
47
- "mouseup",
48
- "click"
62
+ /**
63
+ * See https://web.dev/better-responsiveness-metric/#interaction-types for the
64
+ * table that defines these sets.
65
+ **/
66
+ const pointerEventTypes = new Set([
67
+ 'pointerdown',
68
+ 'touchstart',
69
+ 'pointerup',
70
+ 'touchend',
71
+ 'mousedown',
72
+ 'mouseup',
73
+ 'click',
49
74
  ]);
50
- const keyboardEventTypes = /* @__PURE__ */ new Set([
51
- "keydown",
52
- "keypress",
53
- "keyup"
75
+ const keyboardEventTypes = new Set([
76
+ 'keydown',
77
+ 'keypress',
78
+ 'keyup',
54
79
  ]);
55
80
  export function categoryOfInteraction(interaction) {
56
- if (pointerEventTypes.has(interaction.type)) {
57
- return "POINTER";
58
- }
59
- if (keyboardEventTypes.has(interaction.type)) {
60
- return "KEYBOARD";
61
- }
62
- return "OTHER";
63
- }
64
- export function removeNestedInteractions(interactions) {
65
- const earliestEventForEndTimePerCategory = {
66
- POINTER: /* @__PURE__ */ new Map(),
67
- KEYBOARD: /* @__PURE__ */ new Map(),
68
- OTHER: /* @__PURE__ */ new Map()
69
- };
70
- function storeEventIfEarliestForCategoryAndEndTime(interaction) {
71
- const category = categoryOfInteraction(interaction);
72
- const earliestEventForEndTime = earliestEventForEndTimePerCategory[category];
73
- const endTime = Types.Timing.MicroSeconds(interaction.ts + interaction.dur);
74
- const earliestCurrentEvent = earliestEventForEndTime.get(endTime);
75
- if (!earliestCurrentEvent) {
76
- earliestEventForEndTime.set(endTime, interaction);
77
- return;
81
+ if (pointerEventTypes.has(interaction.type)) {
82
+ return 'POINTER';
78
83
  }
79
- if (interaction.ts < earliestCurrentEvent.ts) {
80
- earliestEventForEndTime.set(endTime, interaction);
81
- } else if (interaction.ts === earliestCurrentEvent.ts && interaction.interactionId === earliestCurrentEvent.interactionId) {
82
- const currentEventProcessingTime = earliestCurrentEvent.processingEnd - earliestCurrentEvent.processingStart;
83
- const newEventProcessingTime = interaction.processingEnd - interaction.processingStart;
84
- if (newEventProcessingTime > currentEventProcessingTime) {
85
- earliestEventForEndTime.set(endTime, interaction);
86
- }
84
+ if (keyboardEventTypes.has(interaction.type)) {
85
+ return 'KEYBOARD';
87
86
  }
88
- if (interaction.processingStart < earliestCurrentEvent.processingStart) {
89
- earliestCurrentEvent.processingStart = interaction.processingStart;
90
- writeSyntheticTimespans(earliestCurrentEvent);
87
+ return 'OTHER';
88
+ }
89
+ /**
90
+ * We define a set of interactions as nested where:
91
+ * 1. Their end times align.
92
+ * 2. The longest interaction's start time is earlier than all other
93
+ * interactions with the same end time.
94
+ * 3. The interactions are of the same category [each interaction is either
95
+ * categorised as keyboard, or pointer.]
96
+ *
97
+ * =============A=[pointerup]=
98
+ * ====B=[pointerdown]=
99
+ * ===C=[pointerdown]==
100
+ * ===D=[pointerup]===
101
+ *
102
+ * In this example, B, C and D are all nested and therefore should not be
103
+ * returned from this function.
104
+ *
105
+ * However, in this example we would only consider B nested (under A) and D
106
+ * nested (under C). A and C both stay because they are of different types.
107
+ * ========A=[keydown]====
108
+ * =======B=[keyup]=====
109
+ * ====C=[pointerdown]=
110
+ * =D=[pointerup]=
111
+ **/
112
+ export function removeNestedInteractions(interactions) {
113
+ /**
114
+ * Because we nest events only that are in the same category, we store the
115
+ * longest event for a given end time by category.
116
+ **/
117
+ const earliestEventForEndTimePerCategory = {
118
+ POINTER: new Map(),
119
+ KEYBOARD: new Map(),
120
+ OTHER: new Map(),
121
+ };
122
+ function storeEventIfEarliestForCategoryAndEndTime(interaction) {
123
+ const category = categoryOfInteraction(interaction);
124
+ const earliestEventForEndTime = earliestEventForEndTimePerCategory[category];
125
+ const endTime = Types.Timing.MicroSeconds(interaction.ts + interaction.dur);
126
+ const earliestCurrentEvent = earliestEventForEndTime.get(endTime);
127
+ if (!earliestCurrentEvent) {
128
+ earliestEventForEndTime.set(endTime, interaction);
129
+ return;
130
+ }
131
+ if (interaction.ts < earliestCurrentEvent.ts) {
132
+ earliestEventForEndTime.set(endTime, interaction);
133
+ }
134
+ else if (interaction.ts === earliestCurrentEvent.ts &&
135
+ interaction.interactionId === earliestCurrentEvent.interactionId) {
136
+ // We have seen in traces that the same interaction can have multiple
137
+ // events (e.g. a 'click' and a 'pointerdown'). Often only one of these
138
+ // events will have an event handler bound to it which caused delay on
139
+ // the main thread, and the others will not. This leads to a situation
140
+ // where if we pick one of the events that had no event handler, its
141
+ // processing time (processingEnd - processingStart) will be 0, but if we
142
+ // had picked the event that had the slow event handler, we would show
143
+ // correctly the main thread delay due to the event handler.
144
+ // So, if we find events with the same interactionId and the same
145
+ // begin/end times, we pick the one with the largest (processingEnd -
146
+ // processingStart) time in order to make sure we find the event with the
147
+ // worst main thread delay, as that is the one the user should care
148
+ // about.
149
+ const currentEventProcessingTime = earliestCurrentEvent.processingEnd - earliestCurrentEvent.processingStart;
150
+ const newEventProcessingTime = interaction.processingEnd - interaction.processingStart;
151
+ // Use the new interaction if it has a longer processing time than the existing one.
152
+ if (newEventProcessingTime > currentEventProcessingTime) {
153
+ earliestEventForEndTime.set(endTime, interaction);
154
+ }
155
+ }
156
+ // Maximize the processing time based on the "children" interactions.
157
+ // We pick the earliest start processing time, and the latest end
158
+ // processing time to avoid under-reporting.
159
+ if (interaction.processingStart < earliestCurrentEvent.processingStart) {
160
+ earliestCurrentEvent.processingStart = interaction.processingStart;
161
+ writeSyntheticTimespans(earliestCurrentEvent);
162
+ }
163
+ if (interaction.processingEnd > earliestCurrentEvent.processingEnd) {
164
+ earliestCurrentEvent.processingEnd = interaction.processingEnd;
165
+ writeSyntheticTimespans(earliestCurrentEvent);
166
+ }
91
167
  }
92
- if (interaction.processingEnd > earliestCurrentEvent.processingEnd) {
93
- earliestCurrentEvent.processingEnd = interaction.processingEnd;
94
- writeSyntheticTimespans(earliestCurrentEvent);
168
+ for (const interaction of interactions) {
169
+ storeEventIfEarliestForCategoryAndEndTime(interaction);
95
170
  }
96
- }
97
- for (const interaction of interactions) {
98
- storeEventIfEarliestForCategoryAndEndTime(interaction);
99
- }
100
- const keptEvents = Object.values(earliestEventForEndTimePerCategory).flatMap((eventsByEndTime) => Array.from(eventsByEndTime.values()));
101
- keptEvents.sort((eventA, eventB) => {
102
- return eventA.ts - eventB.ts;
103
- });
104
- return keptEvents;
171
+ // Combine all the events that we have kept from all the per-category event
172
+ // maps back into an array and sort them by timestamp.
173
+ const keptEvents = Object.values(earliestEventForEndTimePerCategory)
174
+ .flatMap(eventsByEndTime => Array.from(eventsByEndTime.values()));
175
+ keptEvents.sort((eventA, eventB) => {
176
+ return eventA.ts - eventB.ts;
177
+ });
178
+ return keptEvents;
105
179
  }
106
180
  function writeSyntheticTimespans(event) {
107
- const startEvent = event.args.data.beginEvent;
108
- const endEvent = event.args.data.endEvent;
109
- event.inputDelay = Types.Timing.MicroSeconds(event.processingStart - startEvent.ts);
110
- event.mainThreadHandling = Types.Timing.MicroSeconds(event.processingEnd - event.processingStart);
111
- event.presentationDelay = Types.Timing.MicroSeconds(endEvent.ts - event.processingEnd);
181
+ const startEvent = event.args.data.beginEvent;
182
+ const endEvent = event.args.data.endEvent;
183
+ event.inputDelay = Types.Timing.MicroSeconds(event.processingStart - startEvent.ts);
184
+ event.mainThreadHandling = Types.Timing.MicroSeconds(event.processingEnd - event.processingStart);
185
+ event.presentationDelay = Types.Timing.MicroSeconds(endEvent.ts - event.processingEnd);
112
186
  }
113
187
  export async function finalize() {
114
- for (const interactionStartEvent of eventTimingStartEventsForInteractions) {
115
- const endEvent = eventTimingEndEventsById.get(interactionStartEvent.id);
116
- if (!endEvent) {
117
- continue;
118
- }
119
- if (!interactionStartEvent.args.data?.type || !interactionStartEvent.args.data?.interactionId) {
120
- continue;
188
+ // For each interaction start event, find the async end event by the ID, and then create the Synthetic Interaction event.
189
+ for (const interactionStartEvent of eventTimingStartEventsForInteractions) {
190
+ const endEvent = eventTimingEndEventsById.get(interactionStartEvent.id);
191
+ if (!endEvent) {
192
+ // If we cannot find an end event, bail and drop this event.
193
+ continue;
194
+ }
195
+ if (!interactionStartEvent.args.data?.type || !interactionStartEvent.args.data?.interactionId) {
196
+ // A valid interaction event that we care about has to have a type (e.g.
197
+ // pointerdown, keyup).
198
+ //
199
+ // We also need to ensure it has an interactionId. We already checked
200
+ // this in the handleEvent() function, but we do it here also to satisfy
201
+ // TypeScript.
202
+ continue;
203
+ }
204
+ // In the future we will add microsecond timestamps to the trace events,
205
+ // but until then we can use the millisecond precision values that are in
206
+ // the trace event. To adjust them to be relative to the event.ts and the
207
+ // trace timestamps, for both processingStart and processingEnd we subtract
208
+ // the event timestamp (NOT event.ts, but the timeStamp millisecond value
209
+ // emitted in args.data), and then add that value to the event.ts. This
210
+ // will give us a processingStart and processingEnd time in microseconds
211
+ // that is relative to event.ts, and can be used when drawing boxes.
212
+ // There is some inaccuracy here as we are converting milliseconds to microseconds, but it is good enough until the backend emits more accurate numbers.
213
+ const processingStartRelativeToTraceTime = Types.Timing.MicroSeconds(Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.processingStart) -
214
+ Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.timeStamp) +
215
+ interactionStartEvent.ts);
216
+ const processingEndRelativeToTraceTime = Types.Timing.MicroSeconds((Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.processingEnd) -
217
+ Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.timeStamp)) +
218
+ interactionStartEvent.ts);
219
+ const interactionEvent = {
220
+ // Use the start event to define the common fields.
221
+ cat: interactionStartEvent.cat,
222
+ name: interactionStartEvent.name,
223
+ pid: interactionStartEvent.pid,
224
+ tid: interactionStartEvent.tid,
225
+ ph: interactionStartEvent.ph,
226
+ processingStart: processingStartRelativeToTraceTime,
227
+ processingEnd: processingEndRelativeToTraceTime,
228
+ // These will be set in writeSyntheticTimespans()
229
+ inputDelay: Types.Timing.MicroSeconds(-1),
230
+ mainThreadHandling: Types.Timing.MicroSeconds(-1),
231
+ presentationDelay: Types.Timing.MicroSeconds(-1),
232
+ args: {
233
+ data: {
234
+ beginEvent: interactionStartEvent,
235
+ endEvent: endEvent,
236
+ },
237
+ },
238
+ ts: interactionStartEvent.ts,
239
+ dur: Types.Timing.MicroSeconds(endEvent.ts - interactionStartEvent.ts),
240
+ type: interactionStartEvent.args.data.type,
241
+ interactionId: interactionStartEvent.args.data.interactionId,
242
+ };
243
+ writeSyntheticTimespans(interactionEvent);
244
+ interactionEvents.push(interactionEvent);
121
245
  }
122
- const processingStartRelativeToTraceTime = Types.Timing.MicroSeconds(Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.processingStart) - Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.timeStamp) + interactionStartEvent.ts);
123
- const processingEndRelativeToTraceTime = Types.Timing.MicroSeconds(Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.processingEnd) - Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.timeStamp) + interactionStartEvent.ts);
124
- const interactionEvent = {
125
- cat: interactionStartEvent.cat,
126
- name: interactionStartEvent.name,
127
- pid: interactionStartEvent.pid,
128
- tid: interactionStartEvent.tid,
129
- ph: interactionStartEvent.ph,
130
- processingStart: processingStartRelativeToTraceTime,
131
- processingEnd: processingEndRelativeToTraceTime,
132
- inputDelay: Types.Timing.MicroSeconds(-1),
133
- mainThreadHandling: Types.Timing.MicroSeconds(-1),
134
- presentationDelay: Types.Timing.MicroSeconds(-1),
135
- args: {
136
- data: {
137
- beginEvent: interactionStartEvent,
138
- endEvent
246
+ handlerState = 3 /* HandlerState.FINALIZED */;
247
+ interactionEventsWithNoNesting.push(...removeNestedInteractions(interactionEvents));
248
+ // Pick the longest interactions from the set that were not nested, as we
249
+ // know those are the set of the largest interactions.
250
+ for (const interactionEvent of interactionEventsWithNoNesting) {
251
+ if (!longestInteractionEvent || longestInteractionEvent.dur < interactionEvent.dur) {
252
+ longestInteractionEvent = interactionEvent;
139
253
  }
140
- },
141
- ts: interactionStartEvent.ts,
142
- dur: Types.Timing.MicroSeconds(endEvent.ts - interactionStartEvent.ts),
143
- type: interactionStartEvent.args.data.type,
144
- interactionId: interactionStartEvent.args.data.interactionId
145
- };
146
- writeSyntheticTimespans(interactionEvent);
147
- interactionEvents.push(interactionEvent);
148
- }
149
- handlerState = HandlerState.FINALIZED;
150
- interactionEventsWithNoNesting.push(...removeNestedInteractions(interactionEvents));
151
- for (const interactionEvent of interactionEventsWithNoNesting) {
152
- if (!longestInteractionEvent || longestInteractionEvent.dur < interactionEvent.dur) {
153
- longestInteractionEvent = interactionEvent;
154
254
  }
155
- }
156
255
  }
157
256
  export function data() {
158
- return {
159
- allEvents: [...allEvents],
160
- interactionEvents: [...interactionEvents],
161
- interactionEventsWithNoNesting: [...interactionEventsWithNoNesting],
162
- longestInteractionEvent,
163
- interactionsOverThreshold: new Set(interactionEvents.filter((event) => {
164
- return event.dur > LONG_INTERACTION_THRESHOLD;
165
- }))
166
- };
257
+ return {
258
+ allEvents: [...allEvents],
259
+ interactionEvents: [...interactionEvents],
260
+ interactionEventsWithNoNesting: [...interactionEventsWithNoNesting],
261
+ longestInteractionEvent,
262
+ interactionsOverThreshold: new Set(interactionEvents.filter(event => {
263
+ return event.dur > LONG_INTERACTION_THRESHOLD;
264
+ })),
265
+ };
167
266
  }
168
- //# sourceMappingURL=UserInteractionsHandler.js.map
267
+ //# sourceMappingURL=UserInteractionsHandler.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../../../front_end/models/trace/handlers/UserInteractionsHandler.ts"],
4
- "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 Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {HandlerState} from './types.js';\n\n// This handler serves two purposes. It generates a list of events that are\n// used to show user clicks in the timeline. It is also used to gather\n// EventTimings into Interactions, which we use to show interactions and\n// highlight long interactions to the user, along with INP.\n\n// We don't need to know which process / thread these events occurred in,\n// because they are effectively global, so we just track all that we find.\nconst allEvents: Types.TraceEvents.TraceEventEventTiming[] = [];\n\nexport const LONG_INTERACTION_THRESHOLD = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(200));\n\nexport interface UserInteractionsData {\n /** All the user events we found in the trace */\n allEvents: readonly Types.TraceEvents.TraceEventEventTiming[];\n /** All the interaction events we found in the trace that had an\n * interactionId and a duration > 0\n **/\n interactionEvents: readonly Types.TraceEvents.SyntheticInteractionPair[];\n /** If the user rapidly generates interaction events (think typing into a\n * text box), in the UI we only really want to show the user the longest\n * interaction in that set.\n * For example picture interactions like this:\n * ===[interaction A]==========\n * =[interaction B]======\n * =[interaction C]=\n *\n * These events all end at the same time, and so in this instance we only want\n * to show the first interaction A on the timeline, as that is the longest one\n * and the one the developer should be focusing on. So this array of events is\n * all the interaction events filtered down, removing any nested interactions\n * entirely.\n **/\n interactionEventsWithNoNesting: readonly Types.TraceEvents.SyntheticInteractionPair[];\n // The longest duration interaction event. Can be null if the trace has no interaction events.\n longestInteractionEvent: Readonly<Types.TraceEvents.SyntheticInteractionPair>|null;\n // All interactions that went over the interaction threshold (200ms, see https://web.dev/inp/)\n interactionsOverThreshold: Readonly<Set<Types.TraceEvents.SyntheticInteractionPair>>;\n}\n\nlet longestInteractionEvent: Types.TraceEvents.SyntheticInteractionPair|null = null;\n\nconst interactionEvents: Types.TraceEvents.SyntheticInteractionPair[] = [];\nconst interactionEventsWithNoNesting: Types.TraceEvents.SyntheticInteractionPair[] = [];\nconst eventTimingEndEventsById = new Map<string, Types.TraceEvents.TraceEventEventTimingEnd>();\nconst eventTimingStartEventsForInteractions: Types.TraceEvents.TraceEventEventTimingBegin[] = [];\nlet handlerState = HandlerState.UNINITIALIZED;\n\nexport function reset(): void {\n allEvents.length = 0;\n interactionEvents.length = 0;\n eventTimingStartEventsForInteractions.length = 0;\n eventTimingEndEventsById.clear();\n interactionEventsWithNoNesting.length = 0;\n longestInteractionEvent = null;\n handlerState = HandlerState.INITIALIZED;\n}\n\nexport function handleEvent(event: Types.TraceEvents.TraceEventData): void {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Handler is not initialized');\n }\n\n if (!Types.TraceEvents.isTraceEventEventTiming(event)) {\n return;\n }\n\n if (Types.TraceEvents.isTraceEventEventTimingEnd(event)) {\n // Store the end event; for each start event that is an interaction, we need the matching end event to calculate the duration correctly.\n eventTimingEndEventsById.set(event.id, event);\n }\n\n allEvents.push(event);\n\n // From this point on we want to find events that represent interactions.\n // These events are always start events - those are the ones that contain all\n // the metadata about the interaction.\n if (!event.args.data || !Types.TraceEvents.isTraceEventEventTimingStart(event)) {\n return;\n }\n const {duration, interactionId} = event.args.data;\n // We exclude events for the sake of interactions if:\n // 1. They have no duration.\n // 2. They have no interactionId\n // 3. They have an interactionId of 0: this indicates that it's not an\n // interaction that we care about because it hasn't had its own interactionId\n // set (0 is the default on the backend).\n // See: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/responsiveness_metrics.cc;l=133;drc=40c209a9c365ebb9f16fb99dfe78c7fe768b9594\n\n if (duration < 1 || interactionId === undefined || interactionId === 0) {\n return;\n }\n\n // Store the start event. In the finalize() function we will pair this with\n // its end event and create the synthetic interaction event.\n eventTimingStartEventsForInteractions.push(event);\n}\n\n/**\n * See https://web.dev/better-responsiveness-metric/#interaction-types for the\n * table that defines these sets.\n **/\nconst pointerEventTypes = new Set([\n 'pointerdown',\n 'touchstart',\n 'pointerup',\n 'touchend',\n 'mousedown',\n 'mouseup',\n 'click',\n]);\n\nconst keyboardEventTypes = new Set([\n 'keydown',\n 'keypress',\n 'keyup',\n]);\n\nexport type InteractionCategory = 'KEYBOARD'|'POINTER'|'OTHER';\nexport function categoryOfInteraction(interaction: Types.TraceEvents.SyntheticInteractionPair): InteractionCategory {\n if (pointerEventTypes.has(interaction.type)) {\n return 'POINTER';\n }\n if (keyboardEventTypes.has(interaction.type)) {\n return 'KEYBOARD';\n }\n\n return 'OTHER';\n}\n\n/**\n * We define a set of interactions as nested where:\n * 1. Their end times align.\n * 2. The longest interaction's start time is earlier than all other\n * interactions with the same end time.\n * 3. The interactions are of the same category [each interaction is either\n * categorised as keyboard, or pointer.]\n *\n * =============A=[pointerup]=\n * ====B=[pointerdown]=\n * ===C=[pointerdown]==\n * ===D=[pointerup]===\n *\n * In this example, B, C and D are all nested and therefore should not be\n * returned from this function.\n *\n * However, in this example we would only consider B nested (under A) and D\n * nested (under C). A and C both stay because they are of different types.\n * ========A=[keydown]====\n * =======B=[keyup]=====\n * ====C=[pointerdown]=\n * =D=[pointerup]=\n **/\nexport function removeNestedInteractions(interactions: readonly Types.TraceEvents.SyntheticInteractionPair[]):\n readonly Types.TraceEvents.SyntheticInteractionPair[] {\n /**\n * Because we nest events only that are in the same category, we store the\n * longest event for a given end time by category.\n **/\n const earliestEventForEndTimePerCategory:\n Record<InteractionCategory, Map<Types.Timing.MicroSeconds, Types.TraceEvents.SyntheticInteractionPair>> = {\n POINTER: new Map(),\n KEYBOARD: new Map(),\n OTHER: new Map(),\n };\n\n function storeEventIfEarliestForCategoryAndEndTime(interaction: Types.TraceEvents.SyntheticInteractionPair): void {\n const category = categoryOfInteraction(interaction);\n const earliestEventForEndTime = earliestEventForEndTimePerCategory[category];\n const endTime = Types.Timing.MicroSeconds(interaction.ts + interaction.dur);\n\n const earliestCurrentEvent = earliestEventForEndTime.get(endTime);\n if (!earliestCurrentEvent) {\n earliestEventForEndTime.set(endTime, interaction);\n return;\n }\n if (interaction.ts < earliestCurrentEvent.ts) {\n earliestEventForEndTime.set(endTime, interaction);\n } else if (\n interaction.ts === earliestCurrentEvent.ts &&\n interaction.interactionId === earliestCurrentEvent.interactionId) {\n // We have seen in traces that the same interaction can have multiple\n // events (e.g. a 'click' and a 'pointerdown'). Often only one of these\n // events will have an event handler bound to it which caused delay on\n // the main thread, and the others will not. This leads to a situation\n // where if we pick one of the events that had no event handler, its\n // processing time (processingEnd - processingStart) will be 0, but if we\n // had picked the event that had the slow event handler, we would show\n // correctly the main thread delay due to the event handler.\n // So, if we find events with the same interactionId and the same\n // begin/end times, we pick the one with the largest (processingEnd -\n // processingStart) time in order to make sure we find the event with the\n // worst main thread delay, as that is the one the user should care\n // about.\n const currentEventProcessingTime = earliestCurrentEvent.processingEnd - earliestCurrentEvent.processingStart;\n const newEventProcessingTime = interaction.processingEnd - interaction.processingStart;\n\n // Use the new interaction if it has a longer processing time than the existing one.\n if (newEventProcessingTime > currentEventProcessingTime) {\n earliestEventForEndTime.set(endTime, interaction);\n }\n }\n\n // Maximize the processing time based on the \"children\" interactions.\n // We pick the earliest start processing time, and the latest end\n // processing time to avoid under-reporting.\n if (interaction.processingStart < earliestCurrentEvent.processingStart) {\n earliestCurrentEvent.processingStart = interaction.processingStart;\n writeSyntheticTimespans(earliestCurrentEvent);\n }\n if (interaction.processingEnd > earliestCurrentEvent.processingEnd) {\n earliestCurrentEvent.processingEnd = interaction.processingEnd;\n writeSyntheticTimespans(earliestCurrentEvent);\n }\n }\n\n for (const interaction of interactions) {\n storeEventIfEarliestForCategoryAndEndTime(interaction);\n }\n\n // Combine all the events that we have kept from all the per-category event\n // maps back into an array and sort them by timestamp.\n const keptEvents = Object.values(earliestEventForEndTimePerCategory)\n .flatMap(eventsByEndTime => Array.from(eventsByEndTime.values()));\n keptEvents.sort((eventA, eventB) => {\n return eventA.ts - eventB.ts;\n });\n return keptEvents;\n}\n\nfunction writeSyntheticTimespans(event: Types.TraceEvents.SyntheticInteractionPair): void {\n const startEvent = event.args.data.beginEvent;\n const endEvent = event.args.data.endEvent;\n\n event.inputDelay = Types.Timing.MicroSeconds(event.processingStart - startEvent.ts);\n event.mainThreadHandling = Types.Timing.MicroSeconds(event.processingEnd - event.processingStart);\n event.presentationDelay = Types.Timing.MicroSeconds(endEvent.ts - event.processingEnd);\n}\n\nexport async function finalize(): Promise<void> {\n // For each interaction start event, find the async end event by the ID, and then create the Synthetic Interaction event.\n for (const interactionStartEvent of eventTimingStartEventsForInteractions) {\n const endEvent = eventTimingEndEventsById.get(interactionStartEvent.id);\n if (!endEvent) {\n // If we cannot find an end event, bail and drop this event.\n continue;\n }\n if (!interactionStartEvent.args.data?.type || !interactionStartEvent.args.data?.interactionId) {\n // A valid interaction event that we care about has to have a type (e.g.\n // pointerdown, keyup).\n //\n // We also need to ensure it has an interactionId. We already checked\n // this in the handleEvent() function, but we do it here also to satisfy\n // TypeScript.\n continue;\n }\n\n // In the future we will add microsecond timestamps to the trace events,\n // but until then we can use the millisecond precision values that are in\n // the trace event. To adjust them to be relative to the event.ts and the\n // trace timestamps, for both processingStart and processingEnd we subtract\n // the event timestamp (NOT event.ts, but the timeStamp millisecond value\n // emitted in args.data), and then add that value to the event.ts. This\n // will give us a processingStart and processingEnd time in microseconds\n // that is relative to event.ts, and can be used when drawing boxes.\n // There is some inaccuracy here as we are converting milliseconds to microseconds, but it is good enough until the backend emits more accurate numbers.\n const processingStartRelativeToTraceTime = Types.Timing.MicroSeconds(\n Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.processingStart) -\n Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.timeStamp) +\n interactionStartEvent.ts,\n );\n\n const processingEndRelativeToTraceTime = Types.Timing.MicroSeconds(\n (Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.processingEnd) -\n Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.timeStamp)) +\n interactionStartEvent.ts);\n\n const interactionEvent: Types.TraceEvents.SyntheticInteractionPair = {\n // Use the start event to define the common fields.\n cat: interactionStartEvent.cat,\n name: interactionStartEvent.name,\n pid: interactionStartEvent.pid,\n tid: interactionStartEvent.tid,\n ph: interactionStartEvent.ph,\n processingStart: processingStartRelativeToTraceTime,\n processingEnd: processingEndRelativeToTraceTime,\n // These will be set in writeSyntheticTimespans()\n inputDelay: Types.Timing.MicroSeconds(-1),\n mainThreadHandling: Types.Timing.MicroSeconds(-1),\n presentationDelay: Types.Timing.MicroSeconds(-1),\n args: {\n data: {\n beginEvent: interactionStartEvent,\n endEvent: endEvent,\n },\n },\n ts: interactionStartEvent.ts,\n dur: Types.Timing.MicroSeconds(endEvent.ts - interactionStartEvent.ts),\n type: interactionStartEvent.args.data.type,\n interactionId: interactionStartEvent.args.data.interactionId,\n };\n writeSyntheticTimespans(interactionEvent);\n\n interactionEvents.push(interactionEvent);\n }\n\n handlerState = HandlerState.FINALIZED;\n interactionEventsWithNoNesting.push(...removeNestedInteractions(interactionEvents));\n\n // Pick the longest interactions from the set that were not nested, as we\n // know those are the set of the largest interactions.\n for (const interactionEvent of interactionEventsWithNoNesting) {\n if (!longestInteractionEvent || longestInteractionEvent.dur < interactionEvent.dur) {\n longestInteractionEvent = interactionEvent;\n }\n }\n}\n\nexport function data(): UserInteractionsData {\n return {\n allEvents: [...allEvents],\n interactionEvents: [...interactionEvents],\n interactionEventsWithNoNesting: [...interactionEventsWithNoNesting],\n longestInteractionEvent,\n interactionsOverThreshold: new Set(interactionEvents.filter(event => {\n return event.dur > LONG_INTERACTION_THRESHOLD;\n })),\n };\n}\n"],
5
- "mappings": "AAIA;AACA;AAEA;AASA,MAAM,YAAuD;AAEtD,aAAM,6BAA6B,QAAQ,OAAO,2BAA2B,MAAM,OAAO,aAAa;AA8B9G,IAAI,0BAA2E;AAE/E,MAAM,oBAAkE;AACxE,MAAM,iCAA+E;AACrF,MAAM,2BAA2B,oBAAI;AACrC,MAAM,wCAAwF;AAC9F,IAAI,eAAe,aAAa;AAEzB,wBAAuB;AAC5B,YAAU,SAAS;AACnB,oBAAkB,SAAS;AAC3B,wCAAsC,SAAS;AAC/C,2BAAyB;AACzB,iCAA+B,SAAS;AACxC,4BAA0B;AAC1B,iBAAe,aAAa;AAAA;AAGvB,4BAAqB,OAA+C;AACzE,MAAI,iBAAiB,aAAa,aAAa;AAC7C,UAAM,IAAI,MAAM;AAAA;AAGlB,MAAI,CAAC,MAAM,YAAY,wBAAwB,QAAQ;AACrD;AAAA;AAGF,MAAI,MAAM,YAAY,2BAA2B,QAAQ;AAEvD,6BAAyB,IAAI,MAAM,IAAI;AAAA;AAGzC,YAAU,KAAK;AAKf,MAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,YAAY,6BAA6B,QAAQ;AAC9E;AAAA;AAEF,QAAM,EAAC,UAAU,kBAAiB,MAAM,KAAK;AAS7C,MAAI,WAAW,KAAK,kBAAkB,UAAa,kBAAkB,GAAG;AACtE;AAAA;AAKF,wCAAsC,KAAK;AAAA;AAO7C,MAAM,oBAAoB,oBAAI,IAAI;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAC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A;AAAA;AAAA,MAGJ,IAAI,sBAAsB;AAAA,MAC1B,KAAK,MAAM,OAAO,aAAa,SAAS,KAAK,sBAAsB;AAAA,MACnE,MAAM,sBAAsB,KAAK,KAAK;AAAA,MACtC,eAAe,sBAAsB,KAAK,KAAK;AAAA;AAEjD,4BAAwB;AAExB,sBAAkB,KAAK;AAAA;AAGzB,iBAAe,aAAa;AAC5B,iCAA+B,KAAK,GAAG,yBAAyB;AAIhE,aAAW,oBAAoB,gCAAgC;AAC7D,QAAI,CAAC,2BAA2B,wBAAwB,MAAM,iBAAiB,KAAK;AAClF,gCAA0B;AAAA;AAAA;AAAA;AAKzB,uBAAsC;AAC3C,SAAO;AAAA,IACL,WAAW,CAAC,GAAG;AAAA,IACf,mBAAmB,CAAC,GAAG;AAAA,IACvB,gCAAgC,CAAC,GAAG;AAAA,IACpC;AAAA,IACA,2BAA2B,IAAI,IAAI,kBAAkB,OAAO,WAAS;AACnE,aAAO,MAAM,MAAM;AAAA;AAAA;AAAA;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"UserInteractionsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/UserInteractionsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAI3C,2EAA2E;AAC3E,sEAAsE;AACtE,wEAAwE;AACxE,2DAA2D;AAE3D,yEAAyE;AACzE,0EAA0E;AAC1E,MAAM,SAAS,GAA8C,EAAE,CAAC;AAEhE,MAAM,CAAC,MAAM,0BAA0B,GAAG,OAAO,CAAC,MAAM,CAAC,0BAA0B,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;AA8BpH,IAAI,uBAAuB,GAAoD,IAAI,CAAC;AAEpF,MAAM,iBAAiB,GAAiD,EAAE,CAAC;AAC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SAAS,EAAE,CAAC,GAAG,SAAS,CAAC;QACzB,iBAAiB,EAAE,CAAC,GAAG,iBAAiB,CAAC;QACzC,8BAA8B,EAAE,CAAC,GAAG,8BAA8B,CAAC;QACnE,uBAAuB;QACvB,yBAAyB,EAAE,IAAI,GAAG,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YAClE,OAAO,KAAK,CAAC,GAAG,GAAG,0BAA0B,CAAC;QAChD,CAAC,CAAC,CAAC;KACJ,CAAC;AACJ,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 Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {HandlerState} from './types.js';\n\n// This handler serves two purposes. It generates a list of events that are\n// used to show user clicks in the timeline. It is also used to gather\n// EventTimings into Interactions, which we use to show interactions and\n// highlight long interactions to the user, along with INP.\n\n// We don't need to know which process / thread these events occurred in,\n// because they are effectively global, so we just track all that we find.\nconst allEvents: Types.TraceEvents.TraceEventEventTiming[] = [];\n\nexport const LONG_INTERACTION_THRESHOLD = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(200));\n\nexport interface UserInteractionsData {\n /** All the user events we found in the trace */\n allEvents: readonly Types.TraceEvents.TraceEventEventTiming[];\n /** All the interaction events we found in the trace that had an\n * interactionId and a duration > 0\n **/\n interactionEvents: readonly Types.TraceEvents.SyntheticInteractionPair[];\n /** If the user rapidly generates interaction events (think typing into a\n * text box), in the UI we only really want to show the user the longest\n * interaction in that set.\n * For example picture interactions like this:\n * ===[interaction A]==========\n * =[interaction B]======\n * =[interaction C]=\n *\n * These events all end at the same time, and so in this instance we only want\n * to show the first interaction A on the timeline, as that is the longest one\n * and the one the developer should be focusing on. So this array of events is\n * all the interaction events filtered down, removing any nested interactions\n * entirely.\n **/\n interactionEventsWithNoNesting: readonly Types.TraceEvents.SyntheticInteractionPair[];\n // The longest duration interaction event. Can be null if the trace has no interaction events.\n longestInteractionEvent: Readonly<Types.TraceEvents.SyntheticInteractionPair>|null;\n // All interactions that went over the interaction threshold (200ms, see https://web.dev/inp/)\n interactionsOverThreshold: Readonly<Set<Types.TraceEvents.SyntheticInteractionPair>>;\n}\n\nlet longestInteractionEvent: Types.TraceEvents.SyntheticInteractionPair|null = null;\n\nconst interactionEvents: Types.TraceEvents.SyntheticInteractionPair[] = [];\nconst interactionEventsWithNoNesting: Types.TraceEvents.SyntheticInteractionPair[] = [];\nconst eventTimingEndEventsById = new Map<string, Types.TraceEvents.TraceEventEventTimingEnd>();\nconst eventTimingStartEventsForInteractions: Types.TraceEvents.TraceEventEventTimingBegin[] = [];\nlet handlerState = HandlerState.UNINITIALIZED;\n\nexport function reset(): void {\n allEvents.length = 0;\n interactionEvents.length = 0;\n eventTimingStartEventsForInteractions.length = 0;\n eventTimingEndEventsById.clear();\n interactionEventsWithNoNesting.length = 0;\n longestInteractionEvent = null;\n handlerState = HandlerState.INITIALIZED;\n}\n\nexport function handleEvent(event: Types.TraceEvents.TraceEventData): void {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Handler is not initialized');\n }\n\n if (!Types.TraceEvents.isTraceEventEventTiming(event)) {\n return;\n }\n\n if (Types.TraceEvents.isTraceEventEventTimingEnd(event)) {\n // Store the end event; for each start event that is an interaction, we need the matching end event to calculate the duration correctly.\n eventTimingEndEventsById.set(event.id, event);\n }\n\n allEvents.push(event);\n\n // From this point on we want to find events that represent interactions.\n // These events are always start events - those are the ones that contain all\n // the metadata about the interaction.\n if (!event.args.data || !Types.TraceEvents.isTraceEventEventTimingStart(event)) {\n return;\n }\n const {duration, interactionId} = event.args.data;\n // We exclude events for the sake of interactions if:\n // 1. They have no duration.\n // 2. They have no interactionId\n // 3. They have an interactionId of 0: this indicates that it's not an\n // interaction that we care about because it hasn't had its own interactionId\n // set (0 is the default on the backend).\n // See: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/responsiveness_metrics.cc;l=133;drc=40c209a9c365ebb9f16fb99dfe78c7fe768b9594\n\n if (duration < 1 || interactionId === undefined || interactionId === 0) {\n return;\n }\n\n // Store the start event. In the finalize() function we will pair this with\n // its end event and create the synthetic interaction event.\n eventTimingStartEventsForInteractions.push(event);\n}\n\n/**\n * See https://web.dev/better-responsiveness-metric/#interaction-types for the\n * table that defines these sets.\n **/\nconst pointerEventTypes = new Set([\n 'pointerdown',\n 'touchstart',\n 'pointerup',\n 'touchend',\n 'mousedown',\n 'mouseup',\n 'click',\n]);\n\nconst keyboardEventTypes = new Set([\n 'keydown',\n 'keypress',\n 'keyup',\n]);\n\nexport type InteractionCategory = 'KEYBOARD'|'POINTER'|'OTHER';\nexport function categoryOfInteraction(interaction: Types.TraceEvents.SyntheticInteractionPair): InteractionCategory {\n if (pointerEventTypes.has(interaction.type)) {\n return 'POINTER';\n }\n if (keyboardEventTypes.has(interaction.type)) {\n return 'KEYBOARD';\n }\n\n return 'OTHER';\n}\n\n/**\n * We define a set of interactions as nested where:\n * 1. Their end times align.\n * 2. The longest interaction's start time is earlier than all other\n * interactions with the same end time.\n * 3. The interactions are of the same category [each interaction is either\n * categorised as keyboard, or pointer.]\n *\n * =============A=[pointerup]=\n * ====B=[pointerdown]=\n * ===C=[pointerdown]==\n * ===D=[pointerup]===\n *\n * In this example, B, C and D are all nested and therefore should not be\n * returned from this function.\n *\n * However, in this example we would only consider B nested (under A) and D\n * nested (under C). A and C both stay because they are of different types.\n * ========A=[keydown]====\n * =======B=[keyup]=====\n * ====C=[pointerdown]=\n * =D=[pointerup]=\n **/\nexport function removeNestedInteractions(interactions: readonly Types.TraceEvents.SyntheticInteractionPair[]):\n readonly Types.TraceEvents.SyntheticInteractionPair[] {\n /**\n * Because we nest events only that are in the same category, we store the\n * longest event for a given end time by category.\n **/\n const earliestEventForEndTimePerCategory:\n Record<InteractionCategory, Map<Types.Timing.MicroSeconds, Types.TraceEvents.SyntheticInteractionPair>> = {\n POINTER: new Map(),\n KEYBOARD: new Map(),\n OTHER: new Map(),\n };\n\n function storeEventIfEarliestForCategoryAndEndTime(interaction: Types.TraceEvents.SyntheticInteractionPair): void {\n const category = categoryOfInteraction(interaction);\n const earliestEventForEndTime = earliestEventForEndTimePerCategory[category];\n const endTime = Types.Timing.MicroSeconds(interaction.ts + interaction.dur);\n\n const earliestCurrentEvent = earliestEventForEndTime.get(endTime);\n if (!earliestCurrentEvent) {\n earliestEventForEndTime.set(endTime, interaction);\n return;\n }\n if (interaction.ts < earliestCurrentEvent.ts) {\n earliestEventForEndTime.set(endTime, interaction);\n } else if (\n interaction.ts === earliestCurrentEvent.ts &&\n interaction.interactionId === earliestCurrentEvent.interactionId) {\n // We have seen in traces that the same interaction can have multiple\n // events (e.g. a 'click' and a 'pointerdown'). Often only one of these\n // events will have an event handler bound to it which caused delay on\n // the main thread, and the others will not. This leads to a situation\n // where if we pick one of the events that had no event handler, its\n // processing time (processingEnd - processingStart) will be 0, but if we\n // had picked the event that had the slow event handler, we would show\n // correctly the main thread delay due to the event handler.\n // So, if we find events with the same interactionId and the same\n // begin/end times, we pick the one with the largest (processingEnd -\n // processingStart) time in order to make sure we find the event with the\n // worst main thread delay, as that is the one the user should care\n // about.\n const currentEventProcessingTime = earliestCurrentEvent.processingEnd - earliestCurrentEvent.processingStart;\n const newEventProcessingTime = interaction.processingEnd - interaction.processingStart;\n\n // Use the new interaction if it has a longer processing time than the existing one.\n if (newEventProcessingTime > currentEventProcessingTime) {\n earliestEventForEndTime.set(endTime, interaction);\n }\n }\n\n // Maximize the processing time based on the \"children\" interactions.\n // We pick the earliest start processing time, and the latest end\n // processing time to avoid under-reporting.\n if (interaction.processingStart < earliestCurrentEvent.processingStart) {\n earliestCurrentEvent.processingStart = interaction.processingStart;\n writeSyntheticTimespans(earliestCurrentEvent);\n }\n if (interaction.processingEnd > earliestCurrentEvent.processingEnd) {\n earliestCurrentEvent.processingEnd = interaction.processingEnd;\n writeSyntheticTimespans(earliestCurrentEvent);\n }\n }\n\n for (const interaction of interactions) {\n storeEventIfEarliestForCategoryAndEndTime(interaction);\n }\n\n // Combine all the events that we have kept from all the per-category event\n // maps back into an array and sort them by timestamp.\n const keptEvents = Object.values(earliestEventForEndTimePerCategory)\n .flatMap(eventsByEndTime => Array.from(eventsByEndTime.values()));\n keptEvents.sort((eventA, eventB) => {\n return eventA.ts - eventB.ts;\n });\n return keptEvents;\n}\n\nfunction writeSyntheticTimespans(event: Types.TraceEvents.SyntheticInteractionPair): void {\n const startEvent = event.args.data.beginEvent;\n const endEvent = event.args.data.endEvent;\n\n event.inputDelay = Types.Timing.MicroSeconds(event.processingStart - startEvent.ts);\n event.mainThreadHandling = Types.Timing.MicroSeconds(event.processingEnd - event.processingStart);\n event.presentationDelay = Types.Timing.MicroSeconds(endEvent.ts - event.processingEnd);\n}\n\nexport async function finalize(): Promise<void> {\n // For each interaction start event, find the async end event by the ID, and then create the Synthetic Interaction event.\n for (const interactionStartEvent of eventTimingStartEventsForInteractions) {\n const endEvent = eventTimingEndEventsById.get(interactionStartEvent.id);\n if (!endEvent) {\n // If we cannot find an end event, bail and drop this event.\n continue;\n }\n if (!interactionStartEvent.args.data?.type || !interactionStartEvent.args.data?.interactionId) {\n // A valid interaction event that we care about has to have a type (e.g.\n // pointerdown, keyup).\n //\n // We also need to ensure it has an interactionId. We already checked\n // this in the handleEvent() function, but we do it here also to satisfy\n // TypeScript.\n continue;\n }\n\n // In the future we will add microsecond timestamps to the trace events,\n // but until then we can use the millisecond precision values that are in\n // the trace event. To adjust them to be relative to the event.ts and the\n // trace timestamps, for both processingStart and processingEnd we subtract\n // the event timestamp (NOT event.ts, but the timeStamp millisecond value\n // emitted in args.data), and then add that value to the event.ts. This\n // will give us a processingStart and processingEnd time in microseconds\n // that is relative to event.ts, and can be used when drawing boxes.\n // There is some inaccuracy here as we are converting milliseconds to microseconds, but it is good enough until the backend emits more accurate numbers.\n const processingStartRelativeToTraceTime = Types.Timing.MicroSeconds(\n Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.processingStart) -\n Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.timeStamp) +\n interactionStartEvent.ts,\n );\n\n const processingEndRelativeToTraceTime = Types.Timing.MicroSeconds(\n (Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.processingEnd) -\n Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.timeStamp)) +\n interactionStartEvent.ts);\n\n const interactionEvent: Types.TraceEvents.SyntheticInteractionPair = {\n // Use the start event to define the common fields.\n cat: interactionStartEvent.cat,\n name: interactionStartEvent.name,\n pid: interactionStartEvent.pid,\n tid: interactionStartEvent.tid,\n ph: interactionStartEvent.ph,\n processingStart: processingStartRelativeToTraceTime,\n processingEnd: processingEndRelativeToTraceTime,\n // These will be set in writeSyntheticTimespans()\n inputDelay: Types.Timing.MicroSeconds(-1),\n mainThreadHandling: Types.Timing.MicroSeconds(-1),\n presentationDelay: Types.Timing.MicroSeconds(-1),\n args: {\n data: {\n beginEvent: interactionStartEvent,\n endEvent: endEvent,\n },\n },\n ts: interactionStartEvent.ts,\n dur: Types.Timing.MicroSeconds(endEvent.ts - interactionStartEvent.ts),\n type: interactionStartEvent.args.data.type,\n interactionId: interactionStartEvent.args.data.interactionId,\n };\n writeSyntheticTimespans(interactionEvent);\n\n interactionEvents.push(interactionEvent);\n }\n\n handlerState = HandlerState.FINALIZED;\n interactionEventsWithNoNesting.push(...removeNestedInteractions(interactionEvents));\n\n // Pick the longest interactions from the set that were not nested, as we\n // know those are the set of the largest interactions.\n for (const interactionEvent of interactionEventsWithNoNesting) {\n if (!longestInteractionEvent || longestInteractionEvent.dur < interactionEvent.dur) {\n longestInteractionEvent = interactionEvent;\n }\n }\n}\n\nexport function data(): UserInteractionsData {\n return {\n allEvents: [...allEvents],\n interactionEvents: [...interactionEvents],\n interactionEventsWithNoNesting: [...interactionEventsWithNoNesting],\n longestInteractionEvent,\n interactionsOverThreshold: new Set(interactionEvents.filter(event => {\n return event.dur > LONG_INTERACTION_THRESHOLD;\n })),\n };\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import * as Types from '../types/types.js';
2
+ export interface UserTimingsData {
3
+ /**
4
+ * Events triggered with the performance.measure() API.
5
+ * https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure
6
+ */
7
+ performanceMeasures: readonly Types.TraceEvents.SyntheticUserTimingPair[];
8
+ /**
9
+ * Events triggered with the performance.mark() API.
10
+ * https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark
11
+ */
12
+ performanceMarks: readonly Types.TraceEvents.TraceEventPerformanceMark[];
13
+ /**
14
+ * Events triggered with the console.time(), console.timeEnd() and
15
+ * console.timeLog() API.
16
+ * https://developer.mozilla.org/en-US/docs/Web/API/console/time
17
+ */
18
+ consoleTimings: readonly Types.TraceEvents.SyntheticConsoleTimingPair[];
19
+ /**
20
+ * Events triggered with the console.timeStamp() API
21
+ * https://developer.mozilla.org/en-US/docs/Web/API/console/timeStamp
22
+ */
23
+ timestampEvents: readonly Types.TraceEvents.TraceEventTimeStamp[];
24
+ }
25
+ export declare function reset(): void;
26
+ export declare function handleEvent(event: Types.TraceEvents.TraceEventData): void;
27
+ export declare function finalize(): Promise<void>;
28
+ export declare function data(): UserTimingsData;