@paulirish/trace_engine 0.0.9 → 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 (292) hide show
  1. package/analyze-trace.mjs +1 -1
  2. package/core/platform/DevToolsPath.d.ts +23 -0
  3. package/core/platform/DevToolsPath.js +7 -0
  4. package/core/platform/DevToolsPath.js.map +1 -0
  5. package/core/platform/MimeType.d.ts +27 -0
  6. package/core/platform/MimeType.js +137 -0
  7. package/core/platform/MimeType.js.map +1 -0
  8. package/core/platform/Timing.d.ts +7 -0
  9. package/core/platform/Timing.js +13 -0
  10. package/core/platform/Timing.js.map +1 -0
  11. package/core/platform/UIString.d.ts +3 -0
  12. package/core/platform/UIString.js +5 -0
  13. package/core/platform/UIString.js.map +1 -0
  14. package/core/platform/UserVisibleError.d.ts +12 -0
  15. package/core/platform/UserVisibleError.js +23 -0
  16. package/core/platform/UserVisibleError.js.map +1 -0
  17. package/core/platform/array-utilities.d.ts +66 -0
  18. package/core/platform/array-utilities.js +199 -0
  19. package/core/platform/array-utilities.js.map +1 -0
  20. package/core/platform/brand.d.ts +14 -0
  21. package/core/platform/brand.js +5 -0
  22. package/core/platform/brand.js.map +1 -0
  23. package/core/platform/bundle-tsconfig.json +1 -0
  24. package/core/platform/date-utilities.d.ts +2 -0
  25. package/core/platform/date-utilities.js +14 -0
  26. package/core/platform/date-utilities.js.map +1 -0
  27. package/core/platform/dcheck-tsconfig.json +8 -0
  28. package/core/platform/dcheck.d.ts +4 -0
  29. package/core/platform/dcheck.js +5 -0
  30. package/core/platform/devtools_entrypoint-bundle-tsconfig-tsconfig.json +40 -0
  31. package/core/platform/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  32. package/core/platform/dom-utilities.d.ts +8 -0
  33. package/core/platform/dom-utilities.js +109 -0
  34. package/core/platform/dom-utilities.js.map +1 -0
  35. package/core/platform/keyboard-utilities.d.ts +17 -0
  36. package/core/platform/keyboard-utilities.js +22 -0
  37. package/core/platform/keyboard-utilities.js.map +1 -0
  38. package/core/platform/map-utilities.d.ts +18 -0
  39. package/core/platform/map-utilities.js +76 -0
  40. package/core/platform/map-utilities.js.map +1 -0
  41. package/core/platform/number-utilities.d.ts +15 -0
  42. package/core/platform/number-utilities.js +82 -0
  43. package/core/platform/number-utilities.js.map +1 -0
  44. package/core/platform/platform-tsconfig.json +59 -0
  45. package/core/platform/platform.d.ts +19 -0
  46. package/core/platform/platform.js +54 -0
  47. package/core/platform/platform.js.compressed +0 -0
  48. package/core/platform/platform.js.hash +1 -0
  49. package/core/platform/platform.js.map +1 -0
  50. package/core/platform/platform.prebundle.d.ts +15 -0
  51. package/core/platform/platform.prebundle.js +50 -0
  52. package/core/platform/platform.prebundle.js.map +1 -0
  53. package/core/platform/platform.prebundle.ts +64 -0
  54. package/core/platform/promise-utilities.d.ts +10 -0
  55. package/core/platform/promise-utilities.js +18 -0
  56. package/core/platform/promise-utilities.js.map +1 -0
  57. package/core/platform/set-utilities.d.ts +2 -0
  58. package/core/platform/set-utilities.js +23 -0
  59. package/core/platform/set-utilities.js.map +1 -0
  60. package/core/platform/string-utilities.d.ts +71 -0
  61. package/core/platform/string-utilities.js +513 -0
  62. package/core/platform/string-utilities.js.map +1 -0
  63. package/core/platform/typescript-utilities.d.ts +56 -0
  64. package/core/platform/typescript-utilities.js +25 -0
  65. package/core/platform/typescript-utilities.js.map +1 -0
  66. package/generated/protocol.d.ts +17923 -0
  67. package/generated/protocol.js +5 -0
  68. package/models/cpu_profile/CPUProfileDataModel.d.ts +77 -0
  69. package/models/cpu_profile/CPUProfileDataModel.js +508 -0
  70. package/models/cpu_profile/CPUProfileDataModel.js.map +1 -0
  71. package/models/cpu_profile/ProfileTreeModel.d.ts +29 -0
  72. package/models/cpu_profile/ProfileTreeModel.js +95 -0
  73. package/models/cpu_profile/ProfileTreeModel.js.map +1 -0
  74. package/models/cpu_profile/bundle-tsconfig.json +1 -0
  75. package/models/cpu_profile/cpu_profile-tsconfig.json +51 -0
  76. package/models/cpu_profile/cpu_profile.d.ts +3 -0
  77. package/models/cpu_profile/cpu_profile.js +7 -0
  78. package/models/cpu_profile/cpu_profile.js.map +1 -0
  79. package/models/cpu_profile/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  80. package/models/trace/EntriesFilter.d.ts +55 -0
  81. package/models/trace/EntriesFilter.js +243 -0
  82. package/models/trace/EntriesFilter.js.map +1 -0
  83. package/models/trace/LegacyTracingModel.d.ts +1 -0
  84. package/models/trace/LegacyTracingModel.js +1 -0
  85. package/models/trace/LegacyTracingModel.js.map +1 -0
  86. package/models/trace/ModelImpl.d.ts +110 -0
  87. package/models/trace/ModelImpl.js +175 -0
  88. package/models/trace/ModelImpl.js.map +1 -0
  89. package/models/trace/Processor.d.ts +36 -0
  90. package/models/trace/Processor.js +213 -0
  91. package/models/trace/Processor.js.map +1 -0
  92. package/models/trace/SDKServices.js +104 -0
  93. package/models/trace/SDKServices.js.map +7 -0
  94. package/models/trace/TraceProcessor.js +133 -0
  95. package/models/trace/TraceProcessor.js.map +7 -0
  96. package/models/trace/TracingManager.d.ts +1 -0
  97. package/models/trace/TracingManager.js +1 -0
  98. package/models/trace/TracingManager.js.map +1 -0
  99. package/models/trace/TreeManipulator.js +85 -0
  100. package/models/trace/TreeManipulator.js.map +7 -0
  101. package/models/trace/bundle-tsconfig.json +1 -0
  102. package/models/trace/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  103. package/models/trace/devtools_entrypoint-legacy-typescript-tsconfig.json +43 -0
  104. package/models/trace/extras/FetchNodes.d.ts +46 -0
  105. package/models/trace/extras/FetchNodes.js +145 -0
  106. package/models/trace/extras/FetchNodes.js.map +1 -0
  107. package/models/trace/extras/FilmStrip.d.ts +19 -0
  108. package/models/trace/extras/FilmStrip.js +44 -0
  109. package/models/trace/extras/FilmStrip.js.map +1 -0
  110. package/models/trace/extras/MainThreadActivity.d.ts +2 -0
  111. package/models/trace/extras/MainThreadActivity.js +77 -0
  112. package/models/trace/extras/MainThreadActivity.js.map +1 -0
  113. package/models/trace/extras/Metadata.d.ts +2 -0
  114. package/models/trace/extras/Metadata.js +44 -0
  115. package/models/trace/extras/Metadata.js.map +1 -0
  116. package/models/trace/extras/bundle-tsconfig.json +1 -0
  117. package/models/trace/extras/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  118. package/models/trace/extras/extras-tsconfig.json +59 -0
  119. package/models/trace/extras/extras.d.ts +1 -0
  120. package/models/trace/extras/extras.js +1 -0
  121. package/models/trace/extras/extras.js.map +1 -0
  122. package/models/trace/frames/TimelineFrameModel.js +392 -0
  123. package/models/trace/frames/TimelineFrameModel.js.map +7 -0
  124. package/models/trace/frames/bundle-tsconfig.json +1 -0
  125. package/models/trace/frames/devtools_entrypoint-bundle-typescript-tsconfig.json +43 -0
  126. package/models/trace/frames/frames-tsconfig.json +58 -0
  127. package/models/trace/frames/frames.js +5 -0
  128. package/models/trace/frames/frames.js.map +7 -0
  129. package/models/trace/handlers/AnimationHandler.d.ts +8 -0
  130. package/models/trace/handlers/AnimationHandler.js +32 -0
  131. package/models/trace/handlers/AnimationHandler.js.map +1 -0
  132. package/models/trace/handlers/AuctionWorkletsHandler.d.ts +8 -0
  133. package/models/trace/handlers/AuctionWorkletsHandler.js +160 -0
  134. package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -0
  135. package/models/trace/handlers/FramesHandler.d.ts +76 -0
  136. package/models/trace/handlers/FramesHandler.js +457 -0
  137. package/models/trace/handlers/FramesHandler.js.map +1 -0
  138. package/models/trace/handlers/GPUHandler.d.ts +11 -0
  139. package/models/trace/handlers/GPUHandler.js +54 -0
  140. package/models/trace/handlers/GPUHandler.js.map +1 -0
  141. package/models/trace/handlers/InitiatorsHandler.d.ts +10 -0
  142. package/models/trace/handlers/InitiatorsHandler.js +184 -0
  143. package/models/trace/handlers/InitiatorsHandler.js.map +1 -0
  144. package/models/trace/handlers/InvalidationsHandler.d.ts +10 -0
  145. package/models/trace/handlers/InvalidationsHandler.js +120 -0
  146. package/models/trace/handlers/InvalidationsHandler.js.map +1 -0
  147. package/models/trace/handlers/LargestImagePaintHandler.d.ts +5 -0
  148. package/models/trace/handlers/LargestImagePaintHandler.js +38 -0
  149. package/models/trace/handlers/LargestImagePaintHandler.js.map +1 -0
  150. package/models/trace/handlers/LargestTextPaintHandler.d.ts +5 -0
  151. package/models/trace/handlers/LargestTextPaintHandler.js +26 -0
  152. package/models/trace/handlers/LargestTextPaintHandler.js.map +1 -0
  153. package/models/trace/handlers/LayerTreeHandler.d.ts +13 -0
  154. package/models/trace/handlers/LayerTreeHandler.js +116 -0
  155. package/models/trace/handlers/LayerTreeHandler.js.map +1 -0
  156. package/models/trace/handlers/LayoutShiftsHandler.d.ts +44 -0
  157. package/models/trace/handlers/LayoutShiftsHandler.js +347 -0
  158. package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -0
  159. package/models/trace/handlers/MemoryHandler.d.ts +7 -0
  160. package/models/trace/handlers/MemoryHandler.js +20 -0
  161. package/models/trace/handlers/MemoryHandler.js.map +1 -0
  162. package/models/trace/handlers/MetaHandler.d.ts +37 -0
  163. package/models/trace/handlers/MetaHandler.js +338 -0
  164. package/models/trace/handlers/MetaHandler.js.map +1 -0
  165. package/models/trace/handlers/Migration.js +27 -0
  166. package/models/trace/handlers/Migration.js.map +7 -0
  167. package/models/trace/handlers/ModelHandlers.d.ts +21 -0
  168. package/models/trace/handlers/ModelHandlers.js +25 -0
  169. package/models/trace/handlers/ModelHandlers.js.map +1 -0
  170. package/models/trace/handlers/NetworkRequestsHandler.d.ts +17 -0
  171. package/models/trace/handlers/NetworkRequestsHandler.js +361 -0
  172. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -0
  173. package/models/trace/handlers/PageLoadMetricsHandler.d.ts +67 -0
  174. package/models/trace/handlers/PageLoadMetricsHandler.js +407 -0
  175. package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -0
  176. package/models/trace/handlers/RendererHandler.d.ts +101 -0
  177. package/models/trace/handlers/RendererHandler.js +325 -0
  178. package/models/trace/handlers/RendererHandler.js.map +1 -0
  179. package/models/trace/handlers/SamplesHandler.d.ts +46 -0
  180. package/models/trace/handlers/SamplesHandler.js +215 -0
  181. package/models/trace/handlers/SamplesHandler.js.map +1 -0
  182. package/models/trace/handlers/ScreenshotsHandler.d.ts +7 -0
  183. package/models/trace/handlers/ScreenshotsHandler.js +79 -0
  184. package/models/trace/handlers/ScreenshotsHandler.js.map +1 -0
  185. package/models/trace/handlers/Threads.d.ts +33 -0
  186. package/models/trace/handlers/Threads.js +95 -0
  187. package/models/trace/handlers/Threads.js.map +1 -0
  188. package/models/trace/handlers/UberFramesHandler.js +293 -0
  189. package/models/trace/handlers/UberFramesHandler.js.map +7 -0
  190. package/models/trace/handlers/UserInteractionsHandler.d.ts +57 -0
  191. package/models/trace/handlers/UserInteractionsHandler.js +267 -0
  192. package/models/trace/handlers/UserInteractionsHandler.js.map +1 -0
  193. package/models/trace/handlers/UserTimingsHandler.d.ts +28 -0
  194. package/models/trace/handlers/UserTimingsHandler.js +108 -0
  195. package/models/trace/handlers/UserTimingsHandler.js.map +1 -0
  196. package/models/trace/handlers/WarningsHandler.d.ts +14 -0
  197. package/models/trace/handlers/WarningsHandler.js +125 -0
  198. package/models/trace/handlers/WarningsHandler.js.map +1 -0
  199. package/models/trace/handlers/WorkersHandler.d.ts +11 -0
  200. package/models/trace/handlers/WorkersHandler.js +52 -0
  201. package/models/trace/handlers/WorkersHandler.js.map +1 -0
  202. package/models/trace/handlers/bundle-tsconfig.json +1 -0
  203. package/models/trace/handlers/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  204. package/models/trace/handlers/handlers-tsconfig.json +79 -0
  205. package/models/trace/handlers/handlers.d.ts +3 -0
  206. package/models/trace/handlers/handlers.js +7 -0
  207. package/models/trace/handlers/handlers.js.map +1 -0
  208. package/models/trace/handlers/types.d.ts +45 -0
  209. package/models/trace/handlers/types.js +18 -0
  210. package/models/trace/handlers/types.js.map +1 -0
  211. package/models/trace/helpers/SamplesIntegrator.d.ts +49 -0
  212. package/models/trace/helpers/SamplesIntegrator.js +397 -0
  213. package/models/trace/helpers/SamplesIntegrator.js.map +1 -0
  214. package/models/trace/helpers/Timing.d.ts +26 -0
  215. package/models/trace/helpers/Timing.js +162 -0
  216. package/models/trace/helpers/Timing.js.map +1 -0
  217. package/models/trace/helpers/Trace.d.ts +37 -0
  218. package/models/trace/helpers/Trace.js +230 -0
  219. package/models/trace/helpers/Trace.js.map +1 -0
  220. package/models/trace/helpers/TreeHelpers.d.ts +90 -0
  221. package/models/trace/helpers/TreeHelpers.js +222 -0
  222. package/models/trace/helpers/TreeHelpers.js.map +1 -0
  223. package/models/trace/helpers/bundle-tsconfig.json +1 -0
  224. package/models/trace/helpers/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  225. package/models/trace/helpers/helpers-tsconfig.json +59 -0
  226. package/models/trace/helpers/helpers.d.ts +4 -0
  227. package/models/trace/helpers/helpers.js +8 -0
  228. package/models/trace/helpers/helpers.js.map +1 -0
  229. package/models/trace/legacy-tsconfig.json +1 -0
  230. package/models/trace/root-causes/LayoutShift.d.ts +119 -0
  231. package/models/trace/root-causes/LayoutShift.js +517 -0
  232. package/models/trace/root-causes/LayoutShift.js.map +1 -0
  233. package/models/trace/root-causes/RootCauses.d.ts +14 -0
  234. package/models/trace/root-causes/RootCauses.js +11 -0
  235. package/models/trace/root-causes/RootCauses.js.map +1 -0
  236. package/models/trace/root-causes/bundle-tsconfig.json +1 -0
  237. package/models/trace/root-causes/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  238. package/models/trace/root-causes/root-causes-tsconfig.json +57 -0
  239. package/models/trace/root-causes/root-causes.d.ts +1 -0
  240. package/models/trace/root-causes/root-causes.js +5 -0
  241. package/models/trace/root-causes/root-causes.js.map +1 -0
  242. package/models/trace/sdk_services/DOMNodeLookup.js +41 -0
  243. package/models/trace/sdk_services/DOMNodeLookup.js.map +7 -0
  244. package/models/trace/sdk_services/LayoutShifts.js +68 -0
  245. package/models/trace/sdk_services/LayoutShifts.js.map +7 -0
  246. package/models/trace/sdk_services/bundle-tsconfig.json +1 -0
  247. package/models/trace/sdk_services/devtools_entrypoint-bundle-typescript-tsconfig.json +41 -0
  248. package/models/trace/sdk_services/sdk_services-tsconfig.json +57 -0
  249. package/models/trace/sdk_services/sdk_services.js +7 -0
  250. package/models/trace/sdk_services/sdk_services.js.map +7 -0
  251. package/models/trace/trace-legacy.js +16 -0
  252. package/models/trace/trace-legacy.js.map +7 -0
  253. package/models/trace/trace-tsconfig.json +69 -0
  254. package/models/trace/trace.d.ts +11 -0
  255. package/models/trace/trace.js +17 -0
  256. package/models/trace/trace.js.map +1 -0
  257. package/models/trace/types/Configuration.d.ts +33 -0
  258. package/models/trace/types/Configuration.js +29 -0
  259. package/models/trace/types/Configuration.js.map +1 -0
  260. package/models/trace/types/File.d.ts +23 -0
  261. package/models/trace/types/File.js +5 -0
  262. package/models/trace/types/File.js.map +1 -0
  263. package/models/trace/types/Timing.d.ts +25 -0
  264. package/models/trace/types/Timing.js +16 -0
  265. package/models/trace/types/Timing.js.map +1 -0
  266. package/models/trace/types/TraceEvents.d.ts +1571 -0
  267. package/models/trace/types/TraceEvents.js +388 -0
  268. package/models/trace/types/TraceEvents.js.map +1 -0
  269. package/models/trace/types/bundle-tsconfig.json +1 -0
  270. package/models/trace/types/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  271. package/models/trace/types/types-tsconfig.json +47 -0
  272. package/models/trace/types/types.d.ts +4 -0
  273. package/models/trace/types/types.js +8 -0
  274. package/models/trace/types/types.js.map +1 -0
  275. package/models/trace/worker/Processor.js +143 -0
  276. package/models/trace/worker/Processor.js.map +7 -0
  277. package/models/trace/worker/Types.js +1 -0
  278. package/models/trace/worker/Types.js.map +7 -0
  279. package/models/trace/worker/bundle-tsconfig.json +1 -0
  280. package/models/trace/worker/devtools_entrypoint-bundle-typescript-tsconfig.json +41 -0
  281. package/models/trace/worker/devtools_entrypoint-worker_entrypoint-typescript-tsconfig.json +41 -0
  282. package/models/trace/worker/processor-tsconfig.json +45 -0
  283. package/models/trace/worker/worker.js +7 -0
  284. package/models/trace/worker/worker.js.map +7 -0
  285. package/models/trace/worker/worker_entrypoint-tsconfig.json +1 -0
  286. package/models/trace/worker/worker_entrypoint.js +36 -0
  287. package/models/trace/worker/worker_entrypoint.js.map +7 -0
  288. package/package.json +2 -2
  289. package/TracingManager.js +0 -0
  290. package/extras/extras.js +0 -0
  291. package/trace.mjs +0 -6980
  292. package/trace.mjs.map +0 -8
@@ -0,0 +1,125 @@
1
+ // Copyright 2023 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 Platform from '../../../core/platform/platform.js';
5
+ import * as Helpers from '../helpers/helpers.js';
6
+ import * as Types from '../types/types.js';
7
+ import { data as userInteractionsHandlerData } from './UserInteractionsHandler.js';
8
+ const warningsPerEvent = new Map();
9
+ const eventsPerWarning = new Map();
10
+ /**
11
+ * Tracks the stack formed by nested trace events up to a given point
12
+ */
13
+ const allEventsStack = [];
14
+ /**
15
+ * Tracks the stack formed by JS invocation trace events up to a given point.
16
+ * F.e. FunctionCall, EvaluateScript, V8Execute.
17
+ * Not to be confused with ProfileCalls.
18
+ */
19
+ const jsInvokeStack = [];
20
+ /**
21
+ * Tracks reflow events in a task.
22
+ */
23
+ const taskReflowEvents = [];
24
+ export const FORCED_REFLOW_THRESHOLD = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(30));
25
+ export const LONG_MAIN_THREAD_TASK_THRESHOLD = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(50));
26
+ export function reset() {
27
+ warningsPerEvent.clear();
28
+ eventsPerWarning.clear();
29
+ allEventsStack.length = 0;
30
+ jsInvokeStack.length = 0;
31
+ taskReflowEvents.length = 0;
32
+ }
33
+ function storeWarning(event, warning) {
34
+ const existingWarnings = Platform.MapUtilities.getWithDefault(warningsPerEvent, event, () => []);
35
+ existingWarnings.push(warning);
36
+ warningsPerEvent.set(event, existingWarnings);
37
+ const existingEvents = Platform.MapUtilities.getWithDefault(eventsPerWarning, warning, () => []);
38
+ existingEvents.push(event);
39
+ eventsPerWarning.set(warning, existingEvents);
40
+ }
41
+ export function handleEvent(event) {
42
+ processForcedReflowWarning(event);
43
+ if (event.name === "RunTask" /* Types.TraceEvents.KnownEventName.RunTask */) {
44
+ const { duration } = Helpers.Timing.eventTimingsMicroSeconds(event);
45
+ if (duration > LONG_MAIN_THREAD_TASK_THRESHOLD) {
46
+ storeWarning(event, 'LONG_TASK');
47
+ }
48
+ return;
49
+ }
50
+ if (Types.TraceEvents.isTraceEventFireIdleCallback(event)) {
51
+ const { duration } = Helpers.Timing.eventTimingsMilliSeconds(event);
52
+ if (duration > event.args.data.allottedMilliseconds) {
53
+ storeWarning(event, 'IDLE_CALLBACK_OVER_TIME');
54
+ }
55
+ return;
56
+ }
57
+ }
58
+ /**
59
+ * Reflows* are added a warning to if:
60
+ * 1. They are forced/sync, meaning they are invoked by JS and finish
61
+ * during the Script execution.
62
+ * 2. Their duration exceeds a threshold.
63
+ * - *Reflow: The style recalculation and layout steps in a render task.
64
+ */
65
+ function processForcedReflowWarning(event) {
66
+ // Update the event and the JS invocation stacks.
67
+ accomodateEventInStack(event, allEventsStack);
68
+ accomodateEventInStack(event, jsInvokeStack, /* pushEventToStack */ Types.TraceEvents.isJSInvocationEvent(event));
69
+ if (jsInvokeStack.length) {
70
+ // Current event falls inside a JS call.
71
+ if (event.name === "Layout" /* Types.TraceEvents.KnownEventName.Layout */ ||
72
+ event.name === "RecalculateStyles" /* Types.TraceEvents.KnownEventName.RecalculateStyles */ ||
73
+ event.name === "UpdateLayoutTree" /* Types.TraceEvents.KnownEventName.UpdateLayoutTree */) {
74
+ // A forced reflow happened. However we need to check if
75
+ // the threshold is surpassed to add a warning. Accumulate the
76
+ // event to check for this after the current Task is over.
77
+ taskReflowEvents.push(event);
78
+ return;
79
+ }
80
+ }
81
+ if (allEventsStack.length === 1) {
82
+ // We hit a new task. Check if the forced reflows in the previous
83
+ // task exceeded the threshold and add a warning if so.
84
+ const totalTime = taskReflowEvents.reduce((time, event) => time + (event.dur || 0), 0);
85
+ if (totalTime >= FORCED_REFLOW_THRESHOLD) {
86
+ taskReflowEvents.forEach(reflowEvent => storeWarning(reflowEvent, 'FORCED_REFLOW'));
87
+ }
88
+ taskReflowEvents.length = 0;
89
+ }
90
+ }
91
+ /**
92
+ * Updates a given trace event stack given a new event.
93
+ */
94
+ function accomodateEventInStack(event, stack, pushEventToStack = true) {
95
+ let nextItem = stack.at(-1);
96
+ while (nextItem && event.ts > nextItem.ts + (nextItem.dur || 0)) {
97
+ stack.pop();
98
+ nextItem = stack.at(-1);
99
+ }
100
+ if (!pushEventToStack) {
101
+ return;
102
+ }
103
+ stack.push(event);
104
+ }
105
+ export function deps() {
106
+ return ['UserInteractions'];
107
+ }
108
+ export async function finalize() {
109
+ // These events do exist on the UserInteractionsHandler, but we also put
110
+ // them into the WarningsHandler so that the warnings handler can be the
111
+ // source of truth and the way to look up all warnings for a given event.
112
+ // Otherwise, we would have to look up warnings across multiple handlers for
113
+ // a given event, which will start to get messy very quickly.
114
+ const longInteractions = userInteractionsHandlerData().interactionsOverThreshold;
115
+ for (const interaction of longInteractions) {
116
+ storeWarning(interaction, 'LONG_INTERACTION');
117
+ }
118
+ }
119
+ export function data() {
120
+ return {
121
+ perEvent: new Map(warningsPerEvent),
122
+ perWarning: new Map(eventsPerWarning),
123
+ };
124
+ }
125
+ //# sourceMappingURL=WarningsHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WarningsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/WarningsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAC/D,O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AQ;IAC5B,wEAAwE;IACxE,wEAAwE;IACxE,yEAAyE;IACzE,4EAA4E;IAC5E,6DAA6D;IAC7D,MAAM,gBAAgB,GAAG,2BAA2B,EAAE,CAAC,yBAAyB,CAAC;IACjF,KAAK,MAAM,WAAW,IAAI,gBAAgB,EAAE;QAC1C,YAAY,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;KAC/C;AACH,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,QAAQ,EAAE,IAAI,GAAG,CAAC,gBAAgB,CAAC;QACnC,UAAU,EAAE,IAAI,GAAG,CAAC,gBAAgB,CAAC;KACtC,CAAC;AACJ,CAAC","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.\n\nimport * as Platform from '../../../core/platform/platform.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {type TraceEventHandlerName} from './types.js';\nimport {data as userInteractionsHandlerData} from './UserInteractionsHandler.js';\n\nexport interface WarningsData {\n // Tracks warnings keyed by the event.\n perEvent: Map<Types.TraceEvents.TraceEventData, Warning[]>;\n // The same data in reverse: for each type of warning, track the events.\n // Useful if we need to enumerate events by type of issue\n perWarning: Map<Warning, Types.TraceEvents.TraceEventData[]>;\n}\n\nexport type Warning = 'LONG_TASK'|'IDLE_CALLBACK_OVER_TIME'|'FORCED_REFLOW'|'LONG_INTERACTION';\n\nconst warningsPerEvent: WarningsData['perEvent'] = new Map();\nconst eventsPerWarning: WarningsData['perWarning'] = new Map();\n\n/**\n * Tracks the stack formed by nested trace events up to a given point\n */\nconst allEventsStack: Types.TraceEvents.TraceEventData[] = [];\n/**\n * Tracks the stack formed by JS invocation trace events up to a given point.\n * F.e. FunctionCall, EvaluateScript, V8Execute.\n * Not to be confused with ProfileCalls.\n */\nconst jsInvokeStack: Types.TraceEvents.TraceEventData[] = [];\n/**\n * Tracks reflow events in a task.\n */\nconst taskReflowEvents: Types.TraceEvents.TraceEventData[] = [];\n\nexport const FORCED_REFLOW_THRESHOLD = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(30));\n\nexport const LONG_MAIN_THREAD_TASK_THRESHOLD = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(50));\n\nexport function reset(): void {\n warningsPerEvent.clear();\n eventsPerWarning.clear();\n allEventsStack.length = 0;\n jsInvokeStack.length = 0;\n taskReflowEvents.length = 0;\n}\n\nfunction storeWarning(event: Types.TraceEvents.TraceEventData, warning: Warning): void {\n const existingWarnings = Platform.MapUtilities.getWithDefault(warningsPerEvent, event, () => []);\n existingWarnings.push(warning);\n warningsPerEvent.set(event, existingWarnings);\n\n const existingEvents = Platform.MapUtilities.getWithDefault(eventsPerWarning, warning, () => []);\n existingEvents.push(event);\n eventsPerWarning.set(warning, existingEvents);\n}\n\nexport function handleEvent(event: Types.TraceEvents.TraceEventData): void {\n processForcedReflowWarning(event);\n if (event.name === Types.TraceEvents.KnownEventName.RunTask) {\n const {duration} = Helpers.Timing.eventTimingsMicroSeconds(event);\n if (duration > LONG_MAIN_THREAD_TASK_THRESHOLD) {\n storeWarning(event, 'LONG_TASK');\n }\n return;\n }\n\n if (Types.TraceEvents.isTraceEventFireIdleCallback(event)) {\n const {duration} = Helpers.Timing.eventTimingsMilliSeconds(event);\n if (duration > event.args.data.allottedMilliseconds) {\n storeWarning(event, 'IDLE_CALLBACK_OVER_TIME');\n }\n return;\n }\n}\n\n/**\n * Reflows* are added a warning to if:\n * 1. They are forced/sync, meaning they are invoked by JS and finish\n * during the Script execution.\n * 2. Their duration exceeds a threshold.\n * - *Reflow: The style recalculation and layout steps in a render task.\n */\nfunction processForcedReflowWarning(event: Types.TraceEvents.TraceEventData): void {\n // Update the event and the JS invocation stacks.\n accomodateEventInStack(event, allEventsStack);\n accomodateEventInStack(event, jsInvokeStack, /* pushEventToStack */ Types.TraceEvents.isJSInvocationEvent(event));\n if (jsInvokeStack.length) {\n // Current event falls inside a JS call.\n if (event.name === Types.TraceEvents.KnownEventName.Layout ||\n event.name === Types.TraceEvents.KnownEventName.RecalculateStyles ||\n event.name === Types.TraceEvents.KnownEventName.UpdateLayoutTree) {\n // A forced reflow happened. However we need to check if\n // the threshold is surpassed to add a warning. Accumulate the\n // event to check for this after the current Task is over.\n taskReflowEvents.push(event);\n return;\n }\n }\n if (allEventsStack.length === 1) {\n // We hit a new task. Check if the forced reflows in the previous\n // task exceeded the threshold and add a warning if so.\n const totalTime = taskReflowEvents.reduce((time, event) => time + (event.dur || 0), 0);\n if (totalTime >= FORCED_REFLOW_THRESHOLD) {\n taskReflowEvents.forEach(reflowEvent => storeWarning(reflowEvent, 'FORCED_REFLOW'));\n }\n taskReflowEvents.length = 0;\n }\n}\n\n/**\n * Updates a given trace event stack given a new event.\n */\nfunction accomodateEventInStack(\n event: Types.TraceEvents.TraceEventData, stack: Types.TraceEvents.TraceEventData[], pushEventToStack = true): void {\n let nextItem = stack.at(-1);\n while (nextItem && event.ts > nextItem.ts + (nextItem.dur || 0)) {\n stack.pop();\n nextItem = stack.at(-1);\n }\n if (!pushEventToStack) {\n return;\n }\n stack.push(event);\n}\n\nexport function deps(): TraceEventHandlerName[] {\n return ['UserInteractions'];\n}\n\nexport async function finalize(): Promise<void> {\n // These events do exist on the UserInteractionsHandler, but we also put\n // them into the WarningsHandler so that the warnings handler can be the\n // source of truth and the way to look up all warnings for a given event.\n // Otherwise, we would have to look up warnings across multiple handlers for\n // a given event, which will start to get messy very quickly.\n const longInteractions = userInteractionsHandlerData().interactionsOverThreshold;\n for (const interaction of longInteractions) {\n storeWarning(interaction, 'LONG_INTERACTION');\n }\n}\n\nexport function data(): WarningsData {\n return {\n perEvent: new Map(warningsPerEvent),\n perWarning: new Map(eventsPerWarning),\n };\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import * as Types from '../types/types.js';
2
+ export interface WorkersData {
3
+ workerSessionIdEvents: readonly Types.TraceEvents.TraceEventTracingSessionIdForWorker[];
4
+ workerIdByThread: Map<Types.TraceEvents.ThreadID, Types.TraceEvents.WorkerId>;
5
+ workerURLById: Map<Types.TraceEvents.WorkerId, string>;
6
+ }
7
+ export declare function initialize(): void;
8
+ export declare function reset(): void;
9
+ export declare function handleEvent(event: Types.TraceEvents.TraceEventData): void;
10
+ export declare function finalize(): Promise<void>;
11
+ export declare function data(): WorkersData;
@@ -0,0 +1,52 @@
1
+ // Copyright 2023 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 Types from '../types/types.js';
5
+ let handlerState = 1 /* HandlerState.UNINITIALIZED */;
6
+ const sessionIdEvents = [];
7
+ const workerIdByThread = new Map();
8
+ const workerURLById = new Map();
9
+ export function initialize() {
10
+ if (handlerState !== 1 /* HandlerState.UNINITIALIZED */) {
11
+ throw new Error('Workers Handler was not reset');
12
+ }
13
+ handlerState = 2 /* HandlerState.INITIALIZED */;
14
+ }
15
+ export function reset() {
16
+ sessionIdEvents.length = 0;
17
+ workerIdByThread.clear();
18
+ workerURLById.clear();
19
+ handlerState = 1 /* HandlerState.UNINITIALIZED */;
20
+ }
21
+ export function handleEvent(event) {
22
+ if (handlerState !== 2 /* HandlerState.INITIALIZED */) {
23
+ throw new Error('Workers Handler is not initialized');
24
+ }
25
+ if (Types.TraceEvents.isTraceEventTracingSessionIdForWorker(event)) {
26
+ sessionIdEvents.push(event);
27
+ }
28
+ }
29
+ export async function finalize() {
30
+ if (handlerState !== 2 /* HandlerState.INITIALIZED */) {
31
+ throw new Error('Handler is not initialized');
32
+ }
33
+ for (const sessionIdEvent of sessionIdEvents) {
34
+ if (!sessionIdEvent.args.data) {
35
+ continue;
36
+ }
37
+ workerIdByThread.set(sessionIdEvent.args.data.workerThreadId, sessionIdEvent.args.data.workerId);
38
+ workerURLById.set(sessionIdEvent.args.data.workerId, sessionIdEvent.args.data.url);
39
+ }
40
+ handlerState = 3 /* HandlerState.FINALIZED */;
41
+ }
42
+ export function data() {
43
+ if (handlerState !== 3 /* HandlerState.FINALIZED */) {
44
+ throw new Error('Workers Handler is not finalized');
45
+ }
46
+ return {
47
+ workerSessionIdEvents: [...sessionIdEvents],
48
+ workerIdByThread: new Map(workerIdByThread),
49
+ workerURLById: new Map(workerURLById),
50
+ };
51
+ }
52
+ //# sourceMappingURL=WorkersHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkersHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/WorkersHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAS3C,IAAI,YAAY,qCAA6B,CAAC;AAE9C,MAAM,eAAe,GAA4D,EAAE,CAAC;AACpF,MAAM,gBAAgB,GAAgE,IAAI,GAAG,EAAE,CAAC;AAChG,MAAM,aAAa,GAA4C,IAAI,GAAG,EAAE,CAAC;AAEzE,MAAM,UAAU,UAAU;IACxB,IAAI,YAAY,uCAA+B,EAAE;QAC/C,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;KAClD;IAED,YAAY,mCAA2B,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,KAAK;IACnB,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,gBAAgB,CAAC,KAAK,EAAE,CAAC;IACzB,aAAa,CAAC,KAAK,EAAE,CAAC;IACtB,YAAY,qCAA6B,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAuC;IACjE,IAAI,YAAY,qCAA6B,EAAE;QAC7C,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;KACvD;IACD,IAAI,KAAK,CAAC,WAAW,CAAC,qCAAqC,CAAC,KAAK,CAAC,EAAE;QAClE,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KAC7B;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ;IAC5B,IAAI,YAAY,qCAA6B,EAAE;QAC7C,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;KAC/C;IACD,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE;QAC5C,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE;YAC7B,SAAS;SACV;QACD,gBAAgB,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjG,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACpF;IACD,YAAY,iCAAyB,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,IAAI,YAAY,mCAA2B,EAAE;QAC3C,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;KACrD;IAED,OAAO;QACL,qBAAqB,EAAE,CAAC,GAAG,eAAe,CAAC;QAC3C,gBAAgB,EAAE,IAAI,GAAG,CAAC,gBAAgB,CAAC;QAC3C,aAAa,EAAE,IAAI,GAAG,CAAC,aAAa,CAAC;KACtC,CAAC;AACJ,CAAC","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.\n\nimport * as Types from '../types/types.js';\n\nimport {HandlerState} from './types.js';\n\nexport interface WorkersData {\n workerSessionIdEvents: readonly Types.TraceEvents.TraceEventTracingSessionIdForWorker[];\n workerIdByThread: Map<Types.TraceEvents.ThreadID, Types.TraceEvents.WorkerId>;\n workerURLById: Map<Types.TraceEvents.WorkerId, string>;\n}\nlet handlerState = HandlerState.UNINITIALIZED;\n\nconst sessionIdEvents: Types.TraceEvents.TraceEventTracingSessionIdForWorker[] = [];\nconst workerIdByThread: Map<Types.TraceEvents.ThreadID, Types.TraceEvents.WorkerId> = new Map();\nconst workerURLById: Map<Types.TraceEvents.WorkerId, string> = new Map();\n\nexport function initialize(): void {\n if (handlerState !== HandlerState.UNINITIALIZED) {\n throw new Error('Workers Handler was not reset');\n }\n\n handlerState = HandlerState.INITIALIZED;\n}\n\nexport function reset(): void {\n sessionIdEvents.length = 0;\n workerIdByThread.clear();\n workerURLById.clear();\n handlerState = HandlerState.UNINITIALIZED;\n}\n\nexport function handleEvent(event: Types.TraceEvents.TraceEventData): void {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Workers Handler is not initialized');\n }\n if (Types.TraceEvents.isTraceEventTracingSessionIdForWorker(event)) {\n sessionIdEvents.push(event);\n }\n}\n\nexport async function finalize(): Promise<void> {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Handler is not initialized');\n }\n for (const sessionIdEvent of sessionIdEvents) {\n if (!sessionIdEvent.args.data) {\n continue;\n }\n workerIdByThread.set(sessionIdEvent.args.data.workerThreadId, sessionIdEvent.args.data.workerId);\n workerURLById.set(sessionIdEvent.args.data.workerId, sessionIdEvent.args.data.url);\n }\n handlerState = HandlerState.FINALIZED;\n}\n\nexport function data(): WorkersData {\n if (handlerState !== HandlerState.FINALIZED) {\n throw new Error('Workers Handler is not finalized');\n }\n\n return {\n workerSessionIdEvents: [...sessionIdEvents],\n workerIdByThread: new Map(workerIdByThread),\n workerURLById: new Map(workerURLById),\n };\n}\n"]}
@@ -0,0 +1 @@
1
+ {"compilerOptions":{"composite":true,"outDir":".","baseUrl":".","rootDir":"../../../../../../../front_end/models/trace/handlers"},"files":["../../../../../../../front_end/models/trace/handlers/handlers.ts"],"references":[{"path":"./handlers-tsconfig.json"}]}
@@ -0,0 +1,44 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": true,
5
+ "composite": true,
6
+ "declaration": true,
7
+ "experimentalDecorators": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "inlineSources": true,
10
+ "lib": [
11
+ "esnext",
12
+ "dom",
13
+ "dom.iterable"
14
+ ],
15
+ "module": "esnext",
16
+ "noEmitOnError": true,
17
+ "noFallthroughCasesInSwitch": true,
18
+ "noImplicitOverride": true,
19
+ "noImplicitReturns": true,
20
+ "noUnusedLocals": false,
21
+ "outDir": ".",
22
+ "rootDir": "../../../../../../../front_end/models/trace/handlers",
23
+ "skipLibCheck": true,
24
+ "sourceMap": true,
25
+ "strict": true,
26
+ "target": "esnext",
27
+ "tsBuildInfoFile": "devtools_entrypoint-bundle-typescript-tsconfig.json.tsbuildinfo",
28
+ "typeRoots": [],
29
+ "useUnknownInCatchVariables": false
30
+ },
31
+ "files": [
32
+ "../../../../../../../front_end/models/trace/handlers/handlers.ts",
33
+ "../../../../../../../front_end/legacy/legacy-defs.d.ts",
34
+ "../../../../../../../front_end/global_typings/global_defs.d.ts",
35
+ "../../../../../../../front_end/global_typings/request_idle_callback.d.ts",
36
+ "../../../../../../../node_modules/@types/filesystem/index.d.ts",
37
+ "../../../../../../../node_modules/@webgpu/types/dist/index.d.ts"
38
+ ],
39
+ "references": [
40
+ {
41
+ "path": "./handlers-tsconfig.json"
42
+ }
43
+ ]
44
+ }
@@ -0,0 +1,79 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": true,
5
+ "composite": true,
6
+ "declaration": true,
7
+ "experimentalDecorators": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "inlineSources": true,
10
+ "lib": [
11
+ "esnext",
12
+ "dom",
13
+ "dom.iterable"
14
+ ],
15
+ "module": "esnext",
16
+ "noEmitOnError": true,
17
+ "noFallthroughCasesInSwitch": true,
18
+ "noImplicitOverride": true,
19
+ "noImplicitReturns": true,
20
+ "noUnusedLocals": false,
21
+ "outDir": ".",
22
+ "rootDir": "../../../../../../../front_end/models/trace/handlers",
23
+ "skipLibCheck": true,
24
+ "sourceMap": true,
25
+ "strict": true,
26
+ "target": "esnext",
27
+ "tsBuildInfoFile": "handlers-tsconfig.json.tsbuildinfo",
28
+ "typeRoots": [],
29
+ "useUnknownInCatchVariables": false
30
+ },
31
+ "files": [
32
+ "../../../../../../../front_end/models/trace/handlers/AnimationHandler.ts",
33
+ "../../../../../../../front_end/models/trace/handlers/AuctionWorkletsHandler.ts",
34
+ "../../../../../../../front_end/models/trace/handlers/FramesHandler.ts",
35
+ "../../../../../../../front_end/models/trace/handlers/GPUHandler.ts",
36
+ "../../../../../../../front_end/models/trace/handlers/InitiatorsHandler.ts",
37
+ "../../../../../../../front_end/models/trace/handlers/InvalidationsHandler.ts",
38
+ "../../../../../../../front_end/models/trace/handlers/LargestImagePaintHandler.ts",
39
+ "../../../../../../../front_end/models/trace/handlers/LargestTextPaintHandler.ts",
40
+ "../../../../../../../front_end/models/trace/handlers/LayerTreeHandler.ts",
41
+ "../../../../../../../front_end/models/trace/handlers/LayoutShiftsHandler.ts",
42
+ "../../../../../../../front_end/models/trace/handlers/MemoryHandler.ts",
43
+ "../../../../../../../front_end/models/trace/handlers/MetaHandler.ts",
44
+ "../../../../../../../front_end/models/trace/handlers/ModelHandlers.ts",
45
+ "../../../../../../../front_end/models/trace/handlers/NetworkRequestsHandler.ts",
46
+ "../../../../../../../front_end/models/trace/handlers/PageLoadMetricsHandler.ts",
47
+ "../../../../../../../front_end/models/trace/handlers/RendererHandler.ts",
48
+ "../../../../../../../front_end/models/trace/handlers/SamplesHandler.ts",
49
+ "../../../../../../../front_end/models/trace/handlers/ScreenshotsHandler.ts",
50
+ "../../../../../../../front_end/models/trace/handlers/Threads.ts",
51
+ "../../../../../../../front_end/models/trace/handlers/UserInteractionsHandler.ts",
52
+ "../../../../../../../front_end/models/trace/handlers/UserTimingsHandler.ts",
53
+ "../../../../../../../front_end/models/trace/handlers/WarningsHandler.ts",
54
+ "../../../../../../../front_end/models/trace/handlers/WorkersHandler.ts",
55
+ "../../../../../../../front_end/models/trace/handlers/types.ts",
56
+ "../../../../../../../front_end/legacy/legacy-defs.d.ts",
57
+ "../../../../../../../front_end/global_typings/global_defs.d.ts",
58
+ "../../../../../../../front_end/global_typings/request_idle_callback.d.ts",
59
+ "../../../../../../../node_modules/@types/filesystem/index.d.ts",
60
+ "../../../../../../../node_modules/@webgpu/types/dist/index.d.ts"
61
+ ],
62
+ "references": [
63
+ {
64
+ "path": "../../../core/platform/bundle-tsconfig.json"
65
+ },
66
+ {
67
+ "path": "../../../generated/generated-tsconfig.json"
68
+ },
69
+ {
70
+ "path": "../../cpu_profile/bundle-tsconfig.json"
71
+ },
72
+ {
73
+ "path": "../helpers/bundle-tsconfig.json"
74
+ },
75
+ {
76
+ "path": "../types/bundle-tsconfig.json"
77
+ }
78
+ ]
79
+ }
@@ -0,0 +1,3 @@
1
+ export * as ModelHandlers from './ModelHandlers.js';
2
+ export * as Threads from './Threads.js';
3
+ export * as Types from './types.js';
@@ -0,0 +1,7 @@
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
+ export * as ModelHandlers from './ModelHandlers.js';
5
+ export * as Threads from './Threads.js';
6
+ export * as Types from './types.js';
7
+ //# sourceMappingURL=handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/handlers.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,YAAY,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\nexport * as ModelHandlers from './ModelHandlers.js';\nexport * as Threads from './Threads.js';\nexport * as Types from './types.js';\n"]}
@@ -0,0 +1,45 @@
1
+ import type * as Types from './../types/types.js';
2
+ import * as ModelHandlers from './ModelHandlers.js';
3
+ export interface TraceEventHandler {
4
+ reset(): void;
5
+ initialize?(freshRecording?: boolean): void;
6
+ handleEvent(data: {}): void;
7
+ finalize?(): Promise<void>;
8
+ data(): unknown;
9
+ deps?(): TraceEventHandlerName[];
10
+ handleUserConfig?(config: Types.Configuration.Configuration): void;
11
+ }
12
+ export type TraceEventHandlerName = keyof typeof ModelHandlers;
13
+ export type EnabledHandlerDataWithMeta<T extends {
14
+ [key: string]: TraceEventHandler;
15
+ }> = {
16
+ Meta: Readonly<ReturnType<typeof ModelHandlers['Meta']['data']>>;
17
+ } & {
18
+ [K in keyof T]: Readonly<ReturnType<T[K]['data']>>;
19
+ };
20
+ export type HandlersWithMeta<T extends {
21
+ [key: string]: TraceEventHandler;
22
+ }> = {
23
+ Meta: typeof ModelHandlers.Meta;
24
+ } & {
25
+ [K in keyof T]: T[K];
26
+ };
27
+ export type TraceParseData = Readonly<EnabledHandlerDataWithMeta<typeof ModelHandlers>>;
28
+ /**
29
+ * Because you can run the trace engine with a subset of handlers enabled,
30
+ * there can be times when you need to confirm if the trace contains all
31
+ * handlers or not, because some parts of the engine expect to be given all
32
+ * the handlers.
33
+ */
34
+ export declare function handlerDataHasAllHandlers(data: Readonly<EnabledHandlerDataWithMeta<{}>>): data is TraceParseData;
35
+ type DeepWriteable<T> = {
36
+ -readonly [P in keyof T]: DeepWriteable<T[P]>;
37
+ };
38
+ export type TraceParseDataMutable = DeepWriteable<TraceParseData>;
39
+ export type Handlers = typeof ModelHandlers;
40
+ export declare const enum HandlerState {
41
+ UNINITIALIZED = 1,
42
+ INITIALIZED = 2,
43
+ FINALIZED = 3
44
+ }
45
+ export {};
@@ -0,0 +1,18 @@
1
+ import * as ModelHandlers from './ModelHandlers.js';
2
+ /**
3
+ * Because you can run the trace engine with a subset of handlers enabled,
4
+ * there can be times when you need to confirm if the trace contains all
5
+ * handlers or not, because some parts of the engine expect to be given all
6
+ * the handlers.
7
+ */
8
+ export function handlerDataHasAllHandlers(data) {
9
+ let isMissingHandler = false;
10
+ for (const handlerName of Object.keys(ModelHandlers)) {
11
+ if (handlerName in data === false) {
12
+ isMissingHandler = true;
13
+ break;
14
+ }
15
+ }
16
+ return !isMissingHandler;
17
+ }
18
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/types.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AA0DpD;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,IAA8C;IACtF,IAAI,gBAAgB,GAAG,KAAK,CAAC;IAC7B,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE;QACpD,IAAI,WAAW,IAAI,IAAI,KAAK,KAAK,EAAE;YACjC,gBAAgB,GAAG,IAAI,CAAC;YACxB,MAAM;SACP;KACF;IACD,OAAO,CAAC,gBAAgB,CAAC;AAC3B,CAAC","sourcesContent":["\n// 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.\nimport type * as Types from './../types/types.js';\nimport * as ModelHandlers from './ModelHandlers.js';\n\nexport interface TraceEventHandler {\n reset(): void;\n initialize?(freshRecording?: boolean): void;\n handleEvent(data: {}): void;\n finalize?(): Promise<void>;\n data(): unknown;\n deps?(): TraceEventHandlerName[];\n handleUserConfig?(config: Types.Configuration.Configuration): void;\n}\nexport type TraceEventHandlerName = keyof typeof ModelHandlers;\n\n// This type maps TraceEventHandler names to the return type of their data\n// function. So, for example, if we are given an object with a key of 'foo'\n// and a value which is a TraceHandler containing a data() function that\n// returns a string, this type will be { foo: string }.\n//\n// This allows us to model the behavior of the TraceProcessor in the model,\n// which takes an object with TraceEventHandlers as part of its config, and\n// which ultimately returns an object keyed off the names of the\n// TraceEventHandlers, and with values that are derived from each\n// TraceEventHandler's data function.\n//\n// So, concretely, we provide a TraceEventHandler for calculating the #time\n// bounds of a trace called TraceBounds, whose data() function returns a\n// TraceWindow. The HandlerData, therefore, would determine that the\n// TraceProcessor would contain a key called 'TraceBounds' whose value is\n// a TraceWindow.\nexport type EnabledHandlerDataWithMeta<T extends {[key: string]: TraceEventHandler}> = {\n // We allow the user to configure which handlers are created by passing them\n // in when constructing a model instance. However, we then ensure that the\n // Meta handler is added to that, as the Model relies on some of the data\n // from the Meta handler when creating the file. Therefore, this type\n // explicitly defines that the Meta data is present, before then extending it\n // with the index type to represent all the other handlers.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: Readonly<ReturnType<typeof ModelHandlers['Meta']['data']>>,\n}&{\n // For every key in the object, look up the TraceEventHandler's data function\n // and use its return type as the value for the object.\n [K in keyof T]: Readonly<ReturnType<T[K]['data']>>;\n};\n\nexport type HandlersWithMeta<T extends {[key: string]: TraceEventHandler}> = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: typeof ModelHandlers.Meta,\n}&{\n [K in keyof T]: T[K];\n};\n\n// Represents the final parsed data from all of the handlers. Note that because\n// we are currently in the middle of the migration of data engines, not all the\n// handlers are enabled. Therefore for now you should use the type defined in\n// models/trace/handlers/Migration.ts, `PartialTraceData`, which\n// represents the final parsed data for only the enabled handlers.\nexport type TraceParseData = Readonly<EnabledHandlerDataWithMeta<typeof ModelHandlers>>;\n\n/**\n * Because you can run the trace engine with a subset of handlers enabled,\n * there can be times when you need to confirm if the trace contains all\n * handlers or not, because some parts of the engine expect to be given all\n * the handlers.\n */\nexport function handlerDataHasAllHandlers(data: Readonly<EnabledHandlerDataWithMeta<{}>>): data is TraceParseData {\n let isMissingHandler = false;\n for (const handlerName of Object.keys(ModelHandlers)) {\n if (handlerName in data === false) {\n isMissingHandler = true;\n break;\n }\n }\n return !isMissingHandler;\n}\n\ntype DeepWriteable<T> = {\n -readonly[P in keyof T]: DeepWriteable<T[P]>\n};\nexport type TraceParseDataMutable = DeepWriteable<TraceParseData>;\n\nexport type Handlers = typeof ModelHandlers;\n\nexport const enum HandlerState {\n UNINITIALIZED = 1,\n INITIALIZED = 2,\n FINALIZED = 3,\n}\n"]}
@@ -0,0 +1,49 @@
1
+ import type * as Protocol from '../../../generated/protocol.js';
2
+ import type * as CPUProfile from '../../cpu_profile/cpu_profile.js';
3
+ import * as Types from '../types/types.js';
4
+ /**
5
+ * This is a helper that integrates CPU profiling data coming in the
6
+ * shape of samples, with trace events. Samples indicate what the JS
7
+ * stack trace looked at a given point in time, but they don't have
8
+ * duration. The SamplesIntegrator task is to make an approximation
9
+ * of what the duration of each JS call was, given the sample data and
10
+ * given the trace events profiled during that time. At the end of its
11
+ * execution, the SamplesIntegrator returns an array of ProfileCalls
12
+ * (under SamplesIntegrator::buildProfileCalls()), which
13
+ * represent JS calls, with a call frame and duration. These calls have
14
+ * the shape of a complete trace events and can be treated as flame
15
+ * chart entries in the timeline.
16
+ *
17
+ * The approach to build the profile calls consists in tracking the
18
+ * current stack as the following events happen (in order):
19
+ * 1. A sample was done.
20
+ * 2. A trace event started.
21
+ * 3. A trace event ended.
22
+ * Depending on the event and on the data that's coming with it the
23
+ * stack is updated by adding or removing JS calls to it and updating
24
+ * the duration of the calls in the tracking stack.
25
+ *
26
+ * note: Although this approach has been implemented since long ago, and
27
+ * is relatively efficent (adds a complexity over the trace parsing of
28
+ * O(n) where n is the number of samples) it has proven to be faulty.
29
+ * It might be worthwhile experimenting with improvements or with a
30
+ * completely different approach. Improving the approach is tracked in
31
+ * crbug.com/1417439
32
+ */
33
+ export declare class SamplesIntegrator {
34
+ #private;
35
+ constructor(profileModel: CPUProfile.CPUProfileDataModel.CPUProfileDataModel, pid: Types.TraceEvents.ProcessID, tid: Types.TraceEvents.ThreadID, configuration?: Types.Configuration.Configuration);
36
+ buildProfileCalls(traceEvents: Types.TraceEvents.TraceEventData[]): Types.TraceEvents.SyntheticProfileCall[];
37
+ /**
38
+ * Builds the initial calls with no duration from samples. Their
39
+ * purpose is to be merged with the trace event array being parsed so
40
+ * that they can be traversed in order with them and their duration
41
+ * can be updated as the SampleIntegrator callbacks are invoked.
42
+ */
43
+ callsFromProfileSamples(): Types.TraceEvents.SyntheticProfileCall[];
44
+ static framesAreEqual(frame1: Protocol.Runtime.CallFrame, frame2: Protocol.Runtime.CallFrame): boolean;
45
+ static showNativeName(name: string, runtimeCallStatsEnabled: boolean): boolean;
46
+ static nativeGroup(nativeName: string): 'Parse' | 'Compile' | null;
47
+ static isNativeRuntimeFrame(frame: Protocol.Runtime.CallFrame): boolean;
48
+ static filterStackFrames(stack: Types.TraceEvents.SyntheticProfileCall[], engineConfig: Types.Configuration.Configuration): void;
49
+ }