@paulirish/trace_engine 0.0.35 → 0.0.36

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 (75) hide show
  1. package/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
  2. package/README.md +0 -1
  3. package/generated/protocol.d.ts +5 -1
  4. package/models/trace/Processor.d.ts +1 -0
  5. package/models/trace/Processor.js +2 -6
  6. package/models/trace/Processor.js.map +1 -1
  7. package/models/trace/handlers/AnimationHandler.js +0 -5
  8. package/models/trace/handlers/AnimationHandler.js.map +1 -1
  9. package/models/trace/handlers/ExtensionTraceDataHandler.d.ts +1 -1
  10. package/models/trace/handlers/ExtensionTraceDataHandler.js +0 -9
  11. package/models/trace/handlers/ExtensionTraceDataHandler.js.map +1 -1
  12. package/models/trace/handlers/FramesHandler.d.ts +1 -2
  13. package/models/trace/handlers/FramesHandler.js +0 -11
  14. package/models/trace/handlers/FramesHandler.js.map +1 -1
  15. package/models/trace/handlers/GPUHandler.d.ts +1 -2
  16. package/models/trace/handlers/GPUHandler.js +0 -18
  17. package/models/trace/handlers/GPUHandler.js.map +1 -1
  18. package/models/trace/handlers/ImagePaintingHandler.d.ts +1 -0
  19. package/models/trace/handlers/ImagePaintingHandler.js +2 -0
  20. package/models/trace/handlers/ImagePaintingHandler.js.map +1 -1
  21. package/models/trace/handlers/InitiatorsHandler.d.ts +0 -1
  22. package/models/trace/handlers/InitiatorsHandler.js +0 -12
  23. package/models/trace/handlers/InitiatorsHandler.js.map +1 -1
  24. package/models/trace/handlers/InvalidationsHandler.d.ts +0 -1
  25. package/models/trace/handlers/InvalidationsHandler.js +0 -12
  26. package/models/trace/handlers/InvalidationsHandler.js.map +1 -1
  27. package/models/trace/handlers/LargestImagePaintHandler.d.ts +2 -1
  28. package/models/trace/handlers/LargestImagePaintHandler.js +2 -0
  29. package/models/trace/handlers/LargestImagePaintHandler.js.map +1 -1
  30. package/models/trace/handlers/LargestTextPaintHandler.d.ts +1 -0
  31. package/models/trace/handlers/LargestTextPaintHandler.js +2 -0
  32. package/models/trace/handlers/LargestTextPaintHandler.js.map +1 -1
  33. package/models/trace/handlers/LayerTreeHandler.d.ts +1 -2
  34. package/models/trace/handlers/LayerTreeHandler.js +0 -12
  35. package/models/trace/handlers/LayerTreeHandler.js.map +1 -1
  36. package/models/trace/handlers/LayoutShiftsHandler.d.ts +1 -2
  37. package/models/trace/handlers/LayoutShiftsHandler.js +0 -15
  38. package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
  39. package/models/trace/handlers/MemoryHandler.d.ts +1 -0
  40. package/models/trace/handlers/MemoryHandler.js +2 -0
  41. package/models/trace/handlers/MemoryHandler.js.map +1 -1
  42. package/models/trace/handlers/MetaHandler.d.ts +0 -1
  43. package/models/trace/handlers/MetaHandler.js +0 -18
  44. package/models/trace/handlers/MetaHandler.js.map +1 -1
  45. package/models/trace/handlers/NetworkRequestsHandler.d.ts +1 -2
  46. package/models/trace/handlers/NetworkRequestsHandler.js +0 -15
  47. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
  48. package/models/trace/handlers/PageFramesHandler.d.ts +1 -0
  49. package/models/trace/handlers/PageFramesHandler.js +2 -0
  50. package/models/trace/handlers/PageFramesHandler.js.map +1 -1
  51. package/models/trace/handlers/RendererHandler.d.ts +1 -2
  52. package/models/trace/handlers/RendererHandler.js +0 -18
  53. package/models/trace/handlers/RendererHandler.js.map +1 -1
  54. package/models/trace/handlers/SamplesHandler.d.ts +0 -1
  55. package/models/trace/handlers/SamplesHandler.js +0 -18
  56. package/models/trace/handlers/SamplesHandler.js.map +1 -1
  57. package/models/trace/handlers/SelectorStatsHandler.d.ts +1 -0
  58. package/models/trace/handlers/SelectorStatsHandler.js +2 -0
  59. package/models/trace/handlers/SelectorStatsHandler.js.map +1 -1
  60. package/models/trace/handlers/ServerTimingsHandler.d.ts +1 -2
  61. package/models/trace/handlers/ServerTimingsHandler.js +0 -12
  62. package/models/trace/handlers/ServerTimingsHandler.js.map +1 -1
  63. package/models/trace/handlers/UserInteractionsHandler.d.ts +2 -2
  64. package/models/trace/handlers/UserInteractionsHandler.js +13 -21
  65. package/models/trace/handlers/UserInteractionsHandler.js.map +1 -1
  66. package/models/trace/handlers/UserTimingsHandler.js +0 -12
  67. package/models/trace/handlers/UserTimingsHandler.js.map +1 -1
  68. package/models/trace/handlers/WorkersHandler.d.ts +0 -1
  69. package/models/trace/handlers/WorkersHandler.js +0 -18
  70. package/models/trace/handlers/WorkersHandler.js.map +1 -1
  71. package/models/trace/handlers/types.d.ts +1 -7
  72. package/models/trace/handlers/types.js.map +1 -1
  73. package/models/trace/types/TraceEvents.d.ts +20 -14
  74. package/models/trace/types/TraceEvents.js.map +1 -1
  75. package/package.json +1 -1
@@ -2,7 +2,6 @@
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
4
  import * as Types from '../types/types.js';
5
- let handlerState = 1 /* HandlerState.UNINITIALIZED */;
6
5
  const invalidationsForEvent = new Map();
7
6
  const invalidationCountForEvent = new Map();
8
7
  let lastRecalcStyleEvent = null;
@@ -10,7 +9,6 @@ let lastRecalcStyleEvent = null;
10
9
  let hasPainted = false;
11
10
  const allInvalidationTrackingEvents = [];
12
11
  export function reset() {
13
- handlerState = 1 /* HandlerState.UNINITIALIZED */;
14
12
  invalidationsForEvent.clear();
15
13
  lastRecalcStyleEvent = null;
16
14
  allInvalidationTrackingEvents.length = 0;
@@ -21,12 +19,6 @@ let maxInvalidationsPerEvent = null;
21
19
  export function handleUserConfig(userConfig) {
22
20
  maxInvalidationsPerEvent = userConfig.maxInvalidationEventsPerEvent;
23
21
  }
24
- export function initialize() {
25
- if (handlerState !== 1 /* HandlerState.UNINITIALIZED */) {
26
- throw new Error('InvalidationsHandler was not reset before being initialized');
27
- }
28
- handlerState = 2 /* HandlerState.INITIALIZED */;
29
- }
30
22
  function addInvalidationToEvent(event, invalidation) {
31
23
  const existingInvalidations = invalidationsForEvent.get(event) || [];
32
24
  existingInvalidations.push(invalidation);
@@ -105,10 +97,6 @@ export function handleEvent(event) {
105
97
  }
106
98
  }
107
99
  export async function finalize() {
108
- if (handlerState !== 2 /* HandlerState.INITIALIZED */) {
109
- throw new Error('InvalidationsHandler is not initialized');
110
- }
111
- handlerState = 3 /* HandlerState.FINALIZED */;
112
100
  }
113
101
  export function data() {
114
102
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"InvalidationsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/InvalidationsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAI3C,IAAI,YAAY,qCAA6B,CAAC;AAE9C,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAgE,CAAC;AACtG,MAAM,yBAAyB,GAAG,IAAI,GAAG,EAA8B,CAAC;AAExE,IAAI,oBAAoB,GAAuC,IAAI,CAAC;AAEpE,sEAAsE;AACtE,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB,MAAM,6BAA6B,GAAkD,EAAE,CAAC;AAExF,MAAM,UAAU,KAAK;IACnB,YAAY,qCAA6B,CAAC;IAC1C,qBAAqB,CAAC,KAAK,EAAE,CAAC;IAC9B,oBAAoB,GAAG,IAAI,CAAC;IAC5B,6BAA6B,CAAC,MAAM,GAAG,CAAC,CAAC;IACzC,UAAU,GAAG,KAAK,CAAC;IACnB,wBAAwB,GAAG,IAAI,CAAC;AAClC,CAAC;AAED,IAAI,wBAAwB,GAAgB,IAAI,CAAC;AACjD,MAAM,UAAU,gBAAgB,CAAC,UAA6C;IAC5E,wBAAwB,GAAG,UAAU,CAAC,6BAA6B,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,IAAI,YAAY,uCAA+B,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjF,CAAC;IAED,YAAY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,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACjC,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;QAC/C,KAAK,MAAM,YAAY,IAAI,6BAA6B,EAAE,CAAC;YACzD,wEAAwE;YACxE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,4BAA4B,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC7D,SAAS;YACX,CAAC;YAED,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;gBACjD,sBAAsB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ;IAC5B,IAAI,YAAY,qCAA6B,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,YAAY,iCAAyB,CAAC;AACxC,CAAC;AAOD,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,qBAAqB;QACrB,yBAAyB;KAC1B,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\nlet handlerState = HandlerState.UNINITIALIZED;\n\nconst invalidationsForEvent = new Map<Types.Events.Event, Types.Events.InvalidationTrackingEvent[]>();\nconst invalidationCountForEvent = new Map<Types.Events.Event, number>();\n\nlet lastRecalcStyleEvent: Types.Events.UpdateLayoutTree|null = null;\n\n// Used to track paints so we track invalidations correctly per paint.\nlet hasPainted = false;\n\nconst allInvalidationTrackingEvents: Array<Types.Events.InvalidationTrackingEvent> = [];\n\nexport function reset(): void {\n handlerState = HandlerState.UNINITIALIZED;\n invalidationsForEvent.clear();\n lastRecalcStyleEvent = null;\n allInvalidationTrackingEvents.length = 0;\n hasPainted = false;\n maxInvalidationsPerEvent = null;\n}\n\nlet maxInvalidationsPerEvent: number|null = null;\nexport function handleUserConfig(userConfig: Types.Configuration.Configuration): void {\n maxInvalidationsPerEvent = userConfig.maxInvalidationEventsPerEvent;\n}\n\nexport function initialize(): void {\n if (handlerState !== HandlerState.UNINITIALIZED) {\n throw new Error('InvalidationsHandler was not reset before being initialized');\n }\n\n handlerState = HandlerState.INITIALIZED;\n}\n\nfunction addInvalidationToEvent(event: Types.Events.Event, invalidation: Types.Events.InvalidationTrackingEvent): void {\n const existingInvalidations = invalidationsForEvent.get(event) || [];\n existingInvalidations.push(invalidation);\n\n if (maxInvalidationsPerEvent !== null && existingInvalidations.length > maxInvalidationsPerEvent) {\n existingInvalidations.shift();\n }\n invalidationsForEvent.set(event, existingInvalidations);\n\n const count = invalidationCountForEvent.get(event) ?? 0;\n invalidationCountForEvent.set(event, count + 1);\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n // Special case: if we have been configured to not store any invalidations,\n // we take that as a sign that we don't even want to gather any invalidations\n // data at all and early exit.\n if (maxInvalidationsPerEvent === 0) {\n return;\n }\n\n if (Types.Events.isUpdateLayoutTree(event)) {\n lastRecalcStyleEvent = event;\n\n // Associate any prior invalidations with this recalc event.\n for (const invalidation of allInvalidationTrackingEvents) {\n if (Types.Events.isLayoutInvalidationTracking(invalidation)) {\n // LayoutInvalidation events cannot be associated with a LayoutTree\n // event.\n continue;\n }\n\n const recalcFrameId = lastRecalcStyleEvent.args.beginData?.frame;\n\n if (recalcFrameId && invalidation.args.data.frame === recalcFrameId) {\n addInvalidationToEvent(event, invalidation);\n }\n }\n return;\n }\n\n if (Types.Events.isInvalidationTracking(event)) {\n if (hasPainted) {\n // If we have painted, then we can clear out the list of all existing\n // invalidations, as we cannot associate them across frames.\n allInvalidationTrackingEvents.length = 0;\n lastRecalcStyleEvent = null;\n hasPainted = false;\n }\n\n // Style invalidation events can occur before and during recalc styles. When we get a recalc style event (aka UpdateLayoutTree), we check and associate any prior invalidations with it.\n // But any invalidations that occur during a UpdateLayoutTree\n // event would be reported in trace events after. So each time we get an\n // invalidation that might be due to a style recalc, we check if the\n // timings overlap and if so associate them.\n if (lastRecalcStyleEvent &&\n (Types.Events.isScheduleStyleInvalidationTracking(event) ||\n Types.Events.isStyleRecalcInvalidationTracking(event) ||\n Types.Events.isStyleInvalidatorInvalidationTracking(event))) {\n const recalcEndTime = lastRecalcStyleEvent.ts + (lastRecalcStyleEvent.dur || 0);\n if (event.ts >= lastRecalcStyleEvent.ts && event.ts <= recalcEndTime &&\n lastRecalcStyleEvent.args.beginData?.frame === event.args.data.frame) {\n addInvalidationToEvent(lastRecalcStyleEvent, event);\n }\n }\n\n allInvalidationTrackingEvents.push(event);\n return;\n }\n\n if (Types.Events.isPaint(event)) {\n // Used to ensure that we do not create relationships across frames.\n hasPainted = true;\n return;\n }\n\n if (Types.Events.isLayout(event)) {\n const layoutFrame = event.args.beginData.frame;\n for (const invalidation of allInvalidationTrackingEvents) {\n // The only invalidations that cause a Layout are LayoutInvalidations :)\n if (!Types.Events.isLayoutInvalidationTracking(invalidation)) {\n continue;\n }\n\n if (invalidation.args.data.frame === layoutFrame) {\n addInvalidationToEvent(event, invalidation);\n }\n }\n }\n}\n\nexport async function finalize(): Promise<void> {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('InvalidationsHandler is not initialized');\n }\n\n handlerState = HandlerState.FINALIZED;\n}\n\ninterface InvalidationsData {\n invalidationsForEvent: Map<Types.Events.Event, Types.Events.InvalidationTrackingEvent[]>;\n invalidationCountForEvent: Map<Types.Events.Event, number>;\n}\n\nexport function data(): InvalidationsData {\n return {\n invalidationsForEvent,\n invalidationCountForEvent,\n };\n}\n"]}
1
+ {"version":3,"file":"InvalidationsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/InvalidationsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO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\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\nconst invalidationsForEvent = new Map<Types.Events.Event, Types.Events.InvalidationTrackingEvent[]>();\nconst invalidationCountForEvent = new Map<Types.Events.Event, number>();\n\nlet lastRecalcStyleEvent: Types.Events.UpdateLayoutTree|null = null;\n\n// Used to track paints so we track invalidations correctly per paint.\nlet hasPainted = false;\n\nconst allInvalidationTrackingEvents: Array<Types.Events.InvalidationTrackingEvent> = [];\n\nexport function reset(): void {\n invalidationsForEvent.clear();\n lastRecalcStyleEvent = null;\n allInvalidationTrackingEvents.length = 0;\n hasPainted = false;\n maxInvalidationsPerEvent = null;\n}\n\nlet maxInvalidationsPerEvent: number|null = null;\nexport function handleUserConfig(userConfig: Types.Configuration.Configuration): void {\n maxInvalidationsPerEvent = userConfig.maxInvalidationEventsPerEvent;\n}\n\nfunction addInvalidationToEvent(event: Types.Events.Event, invalidation: Types.Events.InvalidationTrackingEvent): void {\n const existingInvalidations = invalidationsForEvent.get(event) || [];\n existingInvalidations.push(invalidation);\n\n if (maxInvalidationsPerEvent !== null && existingInvalidations.length > maxInvalidationsPerEvent) {\n existingInvalidations.shift();\n }\n invalidationsForEvent.set(event, existingInvalidations);\n\n const count = invalidationCountForEvent.get(event) ?? 0;\n invalidationCountForEvent.set(event, count + 1);\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n // Special case: if we have been configured to not store any invalidations,\n // we take that as a sign that we don't even want to gather any invalidations\n // data at all and early exit.\n if (maxInvalidationsPerEvent === 0) {\n return;\n }\n\n if (Types.Events.isUpdateLayoutTree(event)) {\n lastRecalcStyleEvent = event;\n\n // Associate any prior invalidations with this recalc event.\n for (const invalidation of allInvalidationTrackingEvents) {\n if (Types.Events.isLayoutInvalidationTracking(invalidation)) {\n // LayoutInvalidation events cannot be associated with a LayoutTree\n // event.\n continue;\n }\n\n const recalcFrameId = lastRecalcStyleEvent.args.beginData?.frame;\n\n if (recalcFrameId && invalidation.args.data.frame === recalcFrameId) {\n addInvalidationToEvent(event, invalidation);\n }\n }\n return;\n }\n\n if (Types.Events.isInvalidationTracking(event)) {\n if (hasPainted) {\n // If we have painted, then we can clear out the list of all existing\n // invalidations, as we cannot associate them across frames.\n allInvalidationTrackingEvents.length = 0;\n lastRecalcStyleEvent = null;\n hasPainted = false;\n }\n\n // Style invalidation events can occur before and during recalc styles. When we get a recalc style event (aka UpdateLayoutTree), we check and associate any prior invalidations with it.\n // But any invalidations that occur during a UpdateLayoutTree\n // event would be reported in trace events after. So each time we get an\n // invalidation that might be due to a style recalc, we check if the\n // timings overlap and if so associate them.\n if (lastRecalcStyleEvent &&\n (Types.Events.isScheduleStyleInvalidationTracking(event) ||\n Types.Events.isStyleRecalcInvalidationTracking(event) ||\n Types.Events.isStyleInvalidatorInvalidationTracking(event))) {\n const recalcEndTime = lastRecalcStyleEvent.ts + (lastRecalcStyleEvent.dur || 0);\n if (event.ts >= lastRecalcStyleEvent.ts && event.ts <= recalcEndTime &&\n lastRecalcStyleEvent.args.beginData?.frame === event.args.data.frame) {\n addInvalidationToEvent(lastRecalcStyleEvent, event);\n }\n }\n\n allInvalidationTrackingEvents.push(event);\n return;\n }\n\n if (Types.Events.isPaint(event)) {\n // Used to ensure that we do not create relationships across frames.\n hasPainted = true;\n return;\n }\n\n if (Types.Events.isLayout(event)) {\n const layoutFrame = event.args.beginData.frame;\n for (const invalidation of allInvalidationTrackingEvents) {\n // The only invalidations that cause a Layout are LayoutInvalidations :)\n if (!Types.Events.isLayoutInvalidationTracking(invalidation)) {\n continue;\n }\n\n if (invalidation.args.data.frame === layoutFrame) {\n addInvalidationToEvent(event, invalidation);\n }\n }\n }\n}\n\nexport async function finalize(): Promise<void> {\n}\n\ninterface InvalidationsData {\n invalidationsForEvent: Map<Types.Events.Event, Types.Events.InvalidationTrackingEvent[]>;\n invalidationCountForEvent: Map<Types.Events.Event, number>;\n}\n\nexport function data(): InvalidationsData {\n return {\n invalidationsForEvent,\n invalidationCountForEvent,\n };\n}\n"]}
@@ -1,5 +1,6 @@
1
- import * as Types from '../types/types.js';
2
1
  import type * as Protocol from '../../../generated/protocol.js';
2
+ import * as Types from '../types/types.js';
3
3
  export declare function reset(): void;
4
4
  export declare function handleEvent(event: Types.Events.Event): void;
5
+ export declare function finalize(): Promise<void>;
5
6
  export declare function data(): Map<Protocol.DOM.BackendNodeId, Types.Events.LargestImagePaintCandidate>;
@@ -32,6 +32,8 @@ export function handleEvent(event) {
32
32
  }
33
33
  imageByDOMNodeId.set(event.args.data.DOMNodeId, event);
34
34
  }
35
+ export async function finalize() {
36
+ }
35
37
  export function data() {
36
38
  return imageByDOMNodeId;
37
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LargestImagePaintHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/LargestImagePaintHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C;;;;;;;;;;;;;;;;IAgBI;AACJ,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAuE,CAAC;AAExG,MAAM,UAAU,KAAK;IACnB,gBAAgB,CAAC,KAAK,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAyB;IACnD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,4BAA4B,CAAC,KAAK,CAAC,EAAE,CAAC;QACtD,OAAO;IACT,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACrB,OAAO;IACT,CAAC;IAED,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,gBAAgB,CAAC;AAC1B,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 Types from '../types/types.js';\nimport type * as Protocol from '../../../generated/protocol.js';\n/**\n * If the LCP resource was an image, and that image was fetched over the\n * network, we want to be able to find the network request in order to construct\n * the critical path for an LCP image.\n * Within the trace file there are `LargestImagePaint::Candidate` events.\n * Within their data object, they contain a `DOMNodeId` property, which maps to\n * the DOM Node ID for that image.\n *\n * This id maps exactly to the `data.nodeId` property that a\n * `LargestContentfulPaint::Candidate` will have. So, when we find an image\n * paint candidate, we can store it, keying it on the node ID.\n * Then, when it comes to finding the network request for an LCP image, we can\n *\n * use the nodeId from the LCP candidate to find the image candidate. That image\n * candidate also contains a `imageUrl` property, which will have the full URL\n * to the image.\n **/\nconst imageByDOMNodeId = new Map<Protocol.DOM.BackendNodeId, Types.Events.LargestImagePaintCandidate>();\n\nexport function reset(): void {\n imageByDOMNodeId.clear();\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (!Types.Events.isLargestImagePaintCandidate(event)) {\n return;\n }\n\n if (!event.args.data) {\n return;\n }\n\n imageByDOMNodeId.set(event.args.data.DOMNodeId, event);\n}\n\nexport function data(): Map<Protocol.DOM.BackendNodeId, Types.Events.LargestImagePaintCandidate> {\n return imageByDOMNodeId;\n}\n"]}
1
+ {"version":3,"file":"LargestImagePaintHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/LargestImagePaintHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAG7B,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C;;;;;;;;;;;;;;;;IAgBI;AACJ,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAuE,CAAC;AAExG,MAAM,UAAU,KAAK;IACnB,gBAAgB,CAAC,KAAK,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAyB;IACnD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,4BAA4B,CAAC,KAAK,CAAC,EAAE,CAAC;QACtD,OAAO;IACT,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACrB,OAAO;IACT,CAAC;IAED,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ;AAC9B,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,gBAAgB,CAAC;AAC1B,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 type * as Protocol from '../../../generated/protocol.js';\nimport * as Types from '../types/types.js';\n\n/**\n * If the LCP resource was an image, and that image was fetched over the\n * network, we want to be able to find the network request in order to construct\n * the critical path for an LCP image.\n * Within the trace file there are `LargestImagePaint::Candidate` events.\n * Within their data object, they contain a `DOMNodeId` property, which maps to\n * the DOM Node ID for that image.\n *\n * This id maps exactly to the `data.nodeId` property that a\n * `LargestContentfulPaint::Candidate` will have. So, when we find an image\n * paint candidate, we can store it, keying it on the node ID.\n * Then, when it comes to finding the network request for an LCP image, we can\n *\n * use the nodeId from the LCP candidate to find the image candidate. That image\n * candidate also contains a `imageUrl` property, which will have the full URL\n * to the image.\n **/\nconst imageByDOMNodeId = new Map<Protocol.DOM.BackendNodeId, Types.Events.LargestImagePaintCandidate>();\n\nexport function reset(): void {\n imageByDOMNodeId.clear();\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (!Types.Events.isLargestImagePaintCandidate(event)) {\n return;\n }\n\n if (!event.args.data) {\n return;\n }\n\n imageByDOMNodeId.set(event.args.data.DOMNodeId, event);\n}\n\nexport async function finalize(): Promise<void> {\n}\n\nexport function data(): Map<Protocol.DOM.BackendNodeId, Types.Events.LargestImagePaintCandidate> {\n return imageByDOMNodeId;\n}\n"]}
@@ -2,4 +2,5 @@ import type * as Protocol from '../../../generated/protocol.js';
2
2
  import * as Types from '../types/types.js';
3
3
  export declare function reset(): void;
4
4
  export declare function handleEvent(event: Types.Events.Event): void;
5
+ export declare function finalize(): Promise<void>;
5
6
  export declare function data(): Map<Protocol.DOM.BackendNodeId, Types.Events.LargestTextPaintCandidate>;
@@ -20,6 +20,8 @@ export function handleEvent(event) {
20
20
  }
21
21
  textPaintByDOMNodeId.set(event.args.data.DOMNodeId, event);
22
22
  }
23
+ export async function finalize() {
24
+ }
23
25
  export function data() {
24
26
  return textPaintByDOMNodeId;
25
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LargestTextPaintHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/LargestTextPaintHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAG7B,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAC3C;;;;IAII;AACJ,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAsE,CAAC;AAE3G,MAAM,UAAU,KAAK;IACnB,oBAAoB,CAAC,KAAK,EAAE,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAyB;IACnD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,2BAA2B,CAAC,KAAK,CAAC,EAAE,CAAC;QACrD,OAAO;IACT,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACrB,OAAO;IACT,CAAC;IAED,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,oBAAoB,CAAC;AAC9B,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 type * as Protocol from '../../../generated/protocol.js';\nimport * as Types from '../types/types.js';\n/**\n * A trace file will contain all the text paints that were candidates for the\n * LargestTextPaint. If an LCP event is text, it will point to one of these\n * candidates, so we store them by their DOM Node ID.\n **/\nconst textPaintByDOMNodeId = new Map<Protocol.DOM.BackendNodeId, Types.Events.LargestTextPaintCandidate>();\n\nexport function reset(): void {\n textPaintByDOMNodeId.clear();\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (!Types.Events.isLargestTextPaintCandidate(event)) {\n return;\n }\n\n if (!event.args.data) {\n return;\n }\n\n textPaintByDOMNodeId.set(event.args.data.DOMNodeId, event);\n}\n\nexport function data(): Map<Protocol.DOM.BackendNodeId, Types.Events.LargestTextPaintCandidate> {\n return textPaintByDOMNodeId;\n}\n"]}
1
+ {"version":3,"file":"LargestTextPaintHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/LargestTextPaintHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAG7B,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAC3C;;;;IAII;AACJ,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAsE,CAAC;AAE3G,MAAM,UAAU,KAAK;IACnB,oBAAoB,CAAC,KAAK,EAAE,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAyB;IACnD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,2BAA2B,CAAC,KAAK,CAAC,EAAE,CAAC;QACrD,OAAO;IACT,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACrB,OAAO;IACT,CAAC;IAED,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ;AAC9B,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,oBAAoB,CAAC;AAC9B,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 type * as Protocol from '../../../generated/protocol.js';\nimport * as Types from '../types/types.js';\n/**\n * A trace file will contain all the text paints that were candidates for the\n * LargestTextPaint. If an LCP event is text, it will point to one of these\n * candidates, so we store them by their DOM Node ID.\n **/\nconst textPaintByDOMNodeId = new Map<Protocol.DOM.BackendNodeId, Types.Events.LargestTextPaintCandidate>();\n\nexport function reset(): void {\n textPaintByDOMNodeId.clear();\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (!Types.Events.isLargestTextPaintCandidate(event)) {\n return;\n }\n\n if (!event.args.data) {\n return;\n }\n\n textPaintByDOMNodeId.set(event.args.data.DOMNodeId, event);\n}\n\nexport async function finalize(): Promise<void> {\n}\n\nexport function data(): Map<Protocol.DOM.BackendNodeId, Types.Events.LargestTextPaintCandidate> {\n return textPaintByDOMNodeId;\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  import * as Types from '../types/types.js';
2
- import { type HandlerName } from './types.js';
2
+ import type { HandlerName } from './types.js';
3
3
  export declare function reset(): void;
4
- export declare function initialize(): void;
5
4
  export declare function handleEvent(event: Types.Events.Event): void;
6
5
  export declare function finalize(): Promise<void>;
7
6
  export interface LayerTreeData {
@@ -4,7 +4,6 @@
4
4
  import * as Helpers from '../helpers/helpers.js';
5
5
  import * as Types from '../types/types.js';
6
6
  import { data as metaHandlerData } from './MetaHandler.js';
7
- let handlerState = 1 /* HandlerState.UNINITIALIZED */;
8
7
  const paintEvents = [];
9
8
  const snapshotEvents = [];
10
9
  const paintToSnapshotMap = new Map();
@@ -13,7 +12,6 @@ let currentMainFrameLayerTreeId = null;
13
12
  const updateLayerEvents = [];
14
13
  const relevantEvents = [];
15
14
  export function reset() {
16
- handlerState = 1 /* HandlerState.UNINITIALIZED */;
17
15
  paintEvents.length = 0;
18
16
  snapshotEvents.length = 0;
19
17
  paintToSnapshotMap.clear();
@@ -22,12 +20,6 @@ export function reset() {
22
20
  updateLayerEvents.length = 0;
23
21
  relevantEvents.length = 0;
24
22
  }
25
- export function initialize() {
26
- if (handlerState !== 1 /* HandlerState.UNINITIALIZED */) {
27
- throw new Error('LayerTree Handler was not reset before being initialized');
28
- }
29
- handlerState = 2 /* HandlerState.INITIALIZED */;
30
- }
31
23
  export function handleEvent(event) {
32
24
  // We gather up the events here but do all the processing in finalize(). This
33
25
  // is because we need to have all the events before we process them, and we
@@ -39,9 +31,6 @@ export function handleEvent(event) {
39
31
  }
40
32
  }
41
33
  export async function finalize() {
42
- if (handlerState !== 2 /* HandlerState.INITIALIZED */) {
43
- throw new Error('LayerTree Handler is not initialized');
44
- }
45
34
  const metaData = metaHandlerData();
46
35
  Helpers.Trace.sortTraceEventsInPlace(relevantEvents);
47
36
  for (const event of relevantEvents) {
@@ -101,7 +90,6 @@ export async function finalize() {
101
90
  paintToSnapshotMap.set(paintEvent, event);
102
91
  }
103
92
  }
104
- handlerState = 3 /* HandlerState.FINALIZED */;
105
93
  }
106
94
  export function data() {
107
95
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"LayerTreeHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/LayerTreeHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,IAAI,IAAI,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAGzD,IAAI,YAAY,qCAA6B,CAAC;AAE9C,MAAM,WAAW,GAAyB,EAAE,CAAC;AAC7C,MAAM,cAAc,GAA2C,EAAE,CAAC;AAClE,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAA4D,CAAC;AAE/F,IAAI,mBAAmB,GAAuC,EAAE,CAAC;AAEjE,IAAI,2BAA2B,GAAgB,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,iBAAiB,CAAC,CAAC,CAAC,CAAC;gBACzC,IAAI,WAAW,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,IAAI,WAAW,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,EAAE,CAAC;oBACnE,6BAA6B,GAAG,WAAW,CAAC;oBAC5C,MAAM;gBACR,CAAC;YACH,CAAC;YACD,IAAI,CAAC,6BAA6B,EAAE,CAAC;gBACnC,qDAAqD;gBACrD,SAAS;YACX,CAAC;YACD,IAAI,6BAA6B,CAAC,IAAI,CAAC,WAAW,KAAK,2BAA2B,EAAE,CAAC;gBACnF,sEAAsE;gBACtE,SAAS;YACX,CAAC;YACD,MAAM,UAAU,GAAG,mBAAmB,CAAC,6BAA6B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACnF,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,6CAA6C;gBAC7C,SAAS;YACX,CAAC;YACD,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAE3B,6DAA6D;YAC7D,kBAAkB,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IAED,YAAY,iCAAyB,CAAC;AACxC,CAAC;AAQD,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,MAAM,EAAE,WAAW;QACnB,SAAS,EAAE,cAAc;QACzB,iBAAiB,EAAE,kBAAkB;KACtC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,CAAC,CAAC;AAClB,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 Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {data as metaHandlerData} from './MetaHandler.js';\nimport {type HandlerName, HandlerState} from './types.js';\n\nlet handlerState = HandlerState.UNINITIALIZED;\n\nconst paintEvents: Types.Events.Paint[] = [];\nconst snapshotEvents: Types.Events.DisplayItemListSnapshot[] = [];\nconst paintToSnapshotMap = new Map<Types.Events.Paint, Types.Events.DisplayItemListSnapshot>();\n\nlet lastPaintForLayerId: Record<number, Types.Events.Paint> = {};\n\nlet currentMainFrameLayerTreeId: number|null = null;\nconst updateLayerEvents: Types.Events.UpdateLayer[] = [];\n\ntype RelevantLayerTreeEvent =\n Types.Events.Paint|Types.Events.DisplayItemListSnapshot|Types.Events.UpdateLayer|Types.Events.SetLayerTreeId;\n\nconst relevantEvents: RelevantLayerTreeEvent[] = [];\nexport function reset(): void {\n handlerState = HandlerState.UNINITIALIZED;\n paintEvents.length = 0;\n snapshotEvents.length = 0;\n paintToSnapshotMap.clear();\n\n lastPaintForLayerId = {};\n currentMainFrameLayerTreeId = null;\n updateLayerEvents.length = 0;\n relevantEvents.length = 0;\n}\n\nexport function initialize(): void {\n if (handlerState !== HandlerState.UNINITIALIZED) {\n throw new Error('LayerTree Handler was not reset before being initialized');\n }\n\n handlerState = HandlerState.INITIALIZED;\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n // We gather up the events here but do all the processing in finalize(). This\n // is because we need to have all the events before we process them, and we\n // need the Meta handler to be finalized() so we can use its data as we need\n // the mainFrameId to know which Layer(s) to care about.\n if (Types.Events.isPaint(event) || Types.Events.isDisplayListItemListSnapshot(event) ||\n Types.Events.isUpdateLayer(event) || Types.Events.isSetLayerId(event)) {\n relevantEvents.push(event);\n }\n}\n\nexport async function finalize(): Promise<void> {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('LayerTree Handler is not initialized');\n }\n\n const metaData = metaHandlerData();\n Helpers.Trace.sortTraceEventsInPlace(relevantEvents);\n\n for (const event of relevantEvents) {\n if (Types.Events.isSetLayerId(event)) {\n if (metaData.mainFrameId !== event.args.data.frame) {\n // We only care about LayerId changes that affect the main frame.\n continue;\n }\n currentMainFrameLayerTreeId = event.args.data.layerTreeId;\n } else if (Types.Events.isUpdateLayer(event)) {\n // We don't do anything with this event, but we need to store it because\n // the information in it determines if we need to care about future\n // snapshot events - we need to know what the active layer is when we see a\n // snapshot.\n updateLayerEvents.push(event);\n } else if (Types.Events.isPaint(event)) {\n if (!event.args.data.layerId) {\n // Note that this check purposefully includes excluding an event with a layerId of 0.\n // 0 indicates that this paint was for a subframe - we do not want these\n // as we only care about paints for top level frames.\n continue;\n }\n paintEvents.push(event);\n lastPaintForLayerId[event.args.data.layerId] = event;\n continue;\n } else if (Types.Events.isDisplayListItemListSnapshot(event)) {\n // First we figure out which layer is active for this event's thread. To\n // do this we work backwards through the list of UpdateLayerEvents,\n // finding the first one (i.e. the most recent one) with the same pid and\n // tid.\n let lastUpdateLayerEventForThread: Types.Events.UpdateLayer|null = null;\n for (let i = updateLayerEvents.length - 1; i > -1; i--) {\n const updateEvent = updateLayerEvents[i];\n if (updateEvent.pid === event.pid && updateEvent.tid === event.tid) {\n lastUpdateLayerEventForThread = updateEvent;\n break;\n }\n }\n if (!lastUpdateLayerEventForThread) {\n // No active layer, so this snapshot is not relevant.\n continue;\n }\n if (lastUpdateLayerEventForThread.args.layerTreeId !== currentMainFrameLayerTreeId) {\n // Snapshot applies to a layer that is not the main frame, so discard.\n continue;\n }\n const paintEvent = lastPaintForLayerId[lastUpdateLayerEventForThread.args.layerId];\n if (!paintEvent) {\n // No paint event for this layer, so discard.\n continue;\n }\n snapshotEvents.push(event);\n\n // Store the relationship between the paint and the snapshot.\n paintToSnapshotMap.set(paintEvent, event);\n }\n }\n\n handlerState = HandlerState.FINALIZED;\n}\n\nexport interface LayerTreeData {\n paints: Types.Events.Paint[];\n snapshots: Types.Events.DisplayItemListSnapshot[];\n paintsToSnapshots: Map<Types.Events.Paint, Types.Events.DisplayItemListSnapshot>;\n}\n\nexport function data(): LayerTreeData {\n return {\n paints: paintEvents,\n snapshots: snapshotEvents,\n paintsToSnapshots: paintToSnapshotMap,\n };\n}\n\nexport function deps(): HandlerName[] {\n return ['Meta'];\n}\n"]}
1
+ {"version":3,"file":"LayerTreeHandler.js","s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AA6B,GAAkC,IAAI,CAAC;YACxE,KAAK,IAAI,CAAC,GAAG,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBACvD,MAAM,WAAW,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;gBACzC,IAAI,WAAW,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,IAAI,WAAW,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,EAAE,CAAC;oBACnE,6BAA6B,GAAG,WAAW,CAAC;oBAC5C,MAAM;gBACR,CAAC;YACH,CAAC;YACD,IAAI,CAAC,6BAA6B,EAAE,CAAC;gBACnC,qDAAqD;gBACrD,SAAS;YACX,CAAC;YACD,IAAI,6BAA6B,CAAC,IAAI,CAAC,WAAW,KAAK,2BAA2B,EAAE,CAAC;gBACnF,sEAAsE;gBACtE,SAAS;YACX,CAAC;YACD,MAAM,UAAU,GAAG,mBAAmB,CAAC,6BAA6B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACnF,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,6CAA6C;gBAC7C,SAAS;YACX,CAAC;YACD,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAE3B,6DAA6D;YAC7D,kBAAkB,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;AACH,CAAC;AAQD,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,MAAM,EAAE,WAAW;QACnB,SAAS,EAAE,cAAc;QACzB,iBAAiB,EAAE,kBAAkB;KACtC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,CAAC,CAAC;AAClB,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 Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {data as metaHandlerData} from './MetaHandler.js';\nimport type {HandlerName} from './types.js';\n\nconst paintEvents: Types.Events.Paint[] = [];\nconst snapshotEvents: Types.Events.DisplayItemListSnapshot[] = [];\nconst paintToSnapshotMap = new Map<Types.Events.Paint, Types.Events.DisplayItemListSnapshot>();\n\nlet lastPaintForLayerId: Record<number, Types.Events.Paint> = {};\n\nlet currentMainFrameLayerTreeId: number|null = null;\nconst updateLayerEvents: Types.Events.UpdateLayer[] = [];\n\ntype RelevantLayerTreeEvent =\n Types.Events.Paint|Types.Events.DisplayItemListSnapshot|Types.Events.UpdateLayer|Types.Events.SetLayerTreeId;\n\nconst relevantEvents: RelevantLayerTreeEvent[] = [];\nexport function reset(): void {\n paintEvents.length = 0;\n snapshotEvents.length = 0;\n paintToSnapshotMap.clear();\n\n lastPaintForLayerId = {};\n currentMainFrameLayerTreeId = null;\n updateLayerEvents.length = 0;\n relevantEvents.length = 0;\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n // We gather up the events here but do all the processing in finalize(). This\n // is because we need to have all the events before we process them, and we\n // need the Meta handler to be finalized() so we can use its data as we need\n // the mainFrameId to know which Layer(s) to care about.\n if (Types.Events.isPaint(event) || Types.Events.isDisplayListItemListSnapshot(event) ||\n Types.Events.isUpdateLayer(event) || Types.Events.isSetLayerId(event)) {\n relevantEvents.push(event);\n }\n}\n\nexport async function finalize(): Promise<void> {\n const metaData = metaHandlerData();\n Helpers.Trace.sortTraceEventsInPlace(relevantEvents);\n\n for (const event of relevantEvents) {\n if (Types.Events.isSetLayerId(event)) {\n if (metaData.mainFrameId !== event.args.data.frame) {\n // We only care about LayerId changes that affect the main frame.\n continue;\n }\n currentMainFrameLayerTreeId = event.args.data.layerTreeId;\n } else if (Types.Events.isUpdateLayer(event)) {\n // We don't do anything with this event, but we need to store it because\n // the information in it determines if we need to care about future\n // snapshot events - we need to know what the active layer is when we see a\n // snapshot.\n updateLayerEvents.push(event);\n } else if (Types.Events.isPaint(event)) {\n if (!event.args.data.layerId) {\n // Note that this check purposefully includes excluding an event with a layerId of 0.\n // 0 indicates that this paint was for a subframe - we do not want these\n // as we only care about paints for top level frames.\n continue;\n }\n paintEvents.push(event);\n lastPaintForLayerId[event.args.data.layerId] = event;\n continue;\n } else if (Types.Events.isDisplayListItemListSnapshot(event)) {\n // First we figure out which layer is active for this event's thread. To\n // do this we work backwards through the list of UpdateLayerEvents,\n // finding the first one (i.e. the most recent one) with the same pid and\n // tid.\n let lastUpdateLayerEventForThread: Types.Events.UpdateLayer|null = null;\n for (let i = updateLayerEvents.length - 1; i > -1; i--) {\n const updateEvent = updateLayerEvents[i];\n if (updateEvent.pid === event.pid && updateEvent.tid === event.tid) {\n lastUpdateLayerEventForThread = updateEvent;\n break;\n }\n }\n if (!lastUpdateLayerEventForThread) {\n // No active layer, so this snapshot is not relevant.\n continue;\n }\n if (lastUpdateLayerEventForThread.args.layerTreeId !== currentMainFrameLayerTreeId) {\n // Snapshot applies to a layer that is not the main frame, so discard.\n continue;\n }\n const paintEvent = lastPaintForLayerId[lastUpdateLayerEventForThread.args.layerId];\n if (!paintEvent) {\n // No paint event for this layer, so discard.\n continue;\n }\n snapshotEvents.push(event);\n\n // Store the relationship between the paint and the snapshot.\n paintToSnapshotMap.set(paintEvent, event);\n }\n }\n}\n\nexport interface LayerTreeData {\n paints: Types.Events.Paint[];\n snapshots: Types.Events.DisplayItemListSnapshot[];\n paintsToSnapshots: Map<Types.Events.Paint, Types.Events.DisplayItemListSnapshot>;\n}\n\nexport function data(): LayerTreeData {\n return {\n paints: paintEvents,\n snapshots: snapshotEvents,\n paintsToSnapshots: paintToSnapshotMap,\n };\n}\n\nexport function deps(): HandlerName[] {\n return ['Meta'];\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import type * as Protocol from '../../../generated/protocol.js';
2
2
  import * as Types from '../types/types.js';
3
3
  import { ScoreClassification } from './PageLoadMetricsHandler.js';
4
- import { type HandlerName } from './types.js';
4
+ import type { HandlerName } from './types.js';
5
5
  interface LayoutShifts {
6
6
  clusters: readonly Types.Events.SyntheticLayoutShiftCluster[];
7
7
  clustersByNavigationId: Map<Types.Events.NavigationId, Types.Events.SyntheticLayoutShiftCluster[]>;
@@ -25,7 +25,6 @@ type ScoreRecord = {
25
25
  ts: number;
26
26
  score: number;
27
27
  };
28
- export declare function initialize(): void;
29
28
  export declare function reset(): void;
30
29
  export declare function handleEvent(event: Types.Events.Event): void;
31
30
  export declare function finalize(): Promise<void>;
@@ -43,15 +43,7 @@ const clustersByNavigationId = new Map();
43
43
  // The complete timeline of LS score changes in a trace.
44
44
  // Includes drops to 0 when session windows end.
45
45
  const scoreRecords = [];
46
- let handlerState = 1 /* HandlerState.UNINITIALIZED */;
47
- export function initialize() {
48
- if (handlerState !== 1 /* HandlerState.UNINITIALIZED */) {
49
- throw new Error('LayoutShifts Handler was not reset');
50
- }
51
- handlerState = 2 /* HandlerState.INITIALIZED */;
52
- }
53
46
  export function reset() {
54
- handlerState = 1 /* HandlerState.UNINITIALIZED */;
55
47
  layoutShiftEvents.length = 0;
56
48
  layoutInvalidationEvents.length = 0;
57
49
  scheduleStyleInvalidationEvents.length = 0;
@@ -70,9 +62,6 @@ export function reset() {
70
62
  clustersByNavigationId.clear();
71
63
  }
72
64
  export function handleEvent(event) {
73
- if (handlerState !== 2 /* HandlerState.INITIALIZED */) {
74
- throw new Error('Handler is not initialized');
75
- }
76
65
  if (Types.Events.isLayoutShift(event) && !event.args.data?.had_recent_input) {
77
66
  layoutShiftEvents.push(event);
78
67
  return;
@@ -187,7 +176,6 @@ export async function finalize() {
187
176
  await buildLayoutShiftsClusters();
188
177
  buildScoreRecords();
189
178
  collectNodes();
190
- handlerState = 3 /* HandlerState.FINALIZED */;
191
179
  }
192
180
  async function buildLayoutShiftsClusters() {
193
181
  const { navigationsByFrameId, mainFrameId, traceBounds } = metaHandlerData();
@@ -399,9 +387,6 @@ async function buildLayoutShiftsClusters() {
399
387
  }
400
388
  }
401
389
  export function data() {
402
- if (handlerState !== 3 /* HandlerState.FINALIZED */) {
403
- throw new Error('Layout Shifts Handler is not finalized');
404
- }
405
390
  return {
406
391
  clusters,
407
392
  sessionMaxScore,
@@ -1 +1 @@
1
- {"version":3,"file":"LayoutShiftsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/LayoutShiftsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAE/D,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,IAAI,IAAI,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EAAC,IAAI,IAAI,sBAAsB,EAAC,MAAM,yBAAyB,CAAC;AAkDvE,4EAA4E;AAC5E,YAAY;AACZ,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,0BAA0B,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;AAE/G,8EAA8E;AAC9E,0DAA0D;AAC1D,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,0BAA0B,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;AAE/G,8EAA8E;AAC9E,+EAA+E;AAC/E,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,+EAA+E;AAC/E,UAAU;AACV,MAAM,iBAAiB,GAA+B,EAAE,CAAC;AAEzD,+EAA+E;AAC/E,qDAAqD;AACrD,MAAM,wBAAwB,GAA8C,EAAE,CAAC;AAC/E,MAAM,+BAA+B,GAAqD,EAAE,CAAC;AAC7F,MAAM,6BAA6B,GAAmD,EAAE,CAAC;AACzF,MAAM,qCAAqC,GAAmD,EAAE,CAAC;AACjG,MAAM,gB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AM,UAAU,IAAI;IAClB,IAAI,YAAY,mCAA2B,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO;QACL,QAAQ;QACR,eAAe;QACf,WAAW;QACX,cAAc;QACd,wBAAwB;QACxB,+BAA+B;QAC/B,6BAA6B,EAAE,EAAE;QACjC,qCAAqC;QACrC,gBAAgB;QAChB,wBAAwB;QACxB,yBAAyB;QACzB,YAAY;QACZ,4DAA4D;QAC5D,cAAc,EAAE,CAAC,GAAG,cAAc,CAAC;QACnC,sBAAsB,EAAE,IAAI,GAAG,CAAC,sBAAsB,CAAC;QACvD,gBAAgB;KACjB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,iCAAiC,CAAC,KAAa;IAC7D,IAAI,KAAK,wCAA2B,CAAC;IACrC,IAAI,KAAK,qDAA2C,EAAE,CAAC;QACrD,KAAK,oCAAyB,CAAC;IACjC,CAAC;IAED,IAAI,KAAK,wCAA6B,EAAE,CAAC;QACvC,KAAK,sCAA0B,CAAC;IAClC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Copyright 2022 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\nimport type * as Protocol from '../../../generated/protocol.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {data as metaHandlerData} from './MetaHandler.js';\nimport {ScoreClassification} from './PageLoadMetricsHandler.js';\nimport {data as screenshotsHandlerData} from './ScreenshotsHandler.js';\nimport {type HandlerName, HandlerState} from './types.js';\n\n// We start with a score of zero and step through all Layout Shift records from\n// all renderers. Each record not only tells us which renderer it is, but also\n// the unweighted and weighted scores. The unweighted score is the score we would\n// get if the renderer were the only one in the viewport. The weighted score, on\n// the other hand, accounts for how much of the viewport that particular render\n// takes up when the shift happened. An ad frame in the corner of the viewport\n// that shifts is considered less disruptive, therefore, than if it were taking\n// up the whole viewport.\n//\n// Next, we step through all the records from all renderers and add the weighted\n// score to a running total across all of the renderers. We create a new \"cluster\"\n// and reset the running total when:\n//\n// 1. We observe a outermost frame navigation, or\n// 2. When there's a gap between records of > 1s, or\n// 3. When there's more than 5 seconds of continuous layout shifting.\n//\n// Note that for it to be Cumulative Layout Shift in the sense described in the\n// documentation we would need to guarantee that we are tracking from navigation\n// to unload. However, we don't make any such guarantees here (since a developer\n// can record and stop when they please), so we support the cluster approach,\n// and we can give them a score, but it is effectively a \"session\" score, a\n// score for the given recording, and almost certainly not the\n// navigation-to-unload CLS score.\n\ninterface LayoutShifts {\n clusters: readonly Types.Events.SyntheticLayoutShiftCluster[];\n clustersByNavigationId: Map<Types.Events.NavigationId, Types.Events.SyntheticLayoutShiftCluster[]>;\n sessionMaxScore: number;\n // The session window which contains the SessionMaxScore\n clsWindowID: number;\n // We use these to calculate root causes for a given LayoutShift\n // TODO(crbug/41484172): should be readonly\n prePaintEvents: Types.Events.PrePaint[];\n paintImageEvents: Types.Events.PaintImage[];\n layoutInvalidationEvents: readonly Types.Events.LayoutInvalidationTracking[];\n scheduleStyleInvalidationEvents: readonly Types.Events.ScheduleStyleInvalidationTracking[];\n styleRecalcInvalidationEvents: readonly Types.Events.StyleRecalcInvalidationTracking[];\n renderFrameImplCreateChildFrameEvents: readonly Types.Events.RenderFrameImplCreateChildFrame[];\n domLoadingEvents: readonly Types.Events.DomLoading[];\n layoutImageUnsizedEvents: readonly Types.Events.LayoutImageUnsized[];\n beginRemoteFontLoadEvents: readonly Types.Events.BeginRemoteFontLoad[];\n scoreRecords: readonly ScoreRecord[];\n // TODO(crbug/41484172): should be readonly\n backendNodeIds: Protocol.DOM.BackendNodeId[];\n}\n\n// This represents the maximum #time we will allow a cluster to go before we\n// reset it.\nexport const MAX_CLUSTER_DURATION = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(5000));\n\n// This represents the maximum #time we will allow between layout shift events\n// before considering it to be the start of a new cluster.\nexport const MAX_SHIFT_TIME_DELTA = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(1000));\n\n// Layout shifts are reported globally to the developer, irrespective of which\n// frame they originated in. However, each process does have its own individual\n// CLS score, so we need to segment by process. This means Layout Shifts from\n// sites with one process (no subframes, or subframes from the same origin)\n// will be reported together. In the case of multiple renderers (frames across\n// different origins), we offer the developer the ability to switch renderer in\n// the UI.\nconst layoutShiftEvents: Types.Events.LayoutShift[] = [];\n\n// These events denote potential node resizings. We store them to link captured\n// layout shifts to the resizing of unsized elements.\nconst layoutInvalidationEvents: Types.Events.LayoutInvalidationTracking[] = [];\nconst scheduleStyleInvalidationEvents: Types.Events.ScheduleStyleInvalidationTracking[] = [];\nconst styleRecalcInvalidationEvents: Types.Events.StyleRecalcInvalidationTracking[] = [];\nconst renderFrameImplCreateChildFrameEvents: Types.Events.RenderFrameImplCreateChildFrame[] = [];\nconst domLoadingEvents: Types.Events.DomLoading[] = [];\nconst layoutImageUnsizedEvents: Types.Events.LayoutImageUnsized[] = [];\nconst beginRemoteFontLoadEvents: Types.Events.BeginRemoteFontLoad[] = [];\n\nconst backendNodeIds = new Set<Protocol.DOM.BackendNodeId>();\n\n// Layout shifts happen during PrePaint as part of the rendering lifecycle.\n// We determine if a LayoutInvalidation event is a potential root cause of a layout\n// shift if the next PrePaint after the LayoutInvalidation is the parent\n// node of such shift.\nconst prePaintEvents: Types.Events.PrePaint[] = [];\n\nconst paintImageEvents: Types.Events.PaintImage[] = [];\n\nlet sessionMaxScore = 0;\n\nlet clsWindowID = -1;\n\nconst clusters: Types.Events.SyntheticLayoutShiftCluster[] = [];\nconst clustersByNavigationId = new Map<Types.Events.NavigationId, Types.Events.SyntheticLayoutShiftCluster[]>();\n\n// Represents a point in time in which a LS score change\n// was recorded.\ntype ScoreRecord = {\n ts: number,\n score: number,\n};\n\n// The complete timeline of LS score changes in a trace.\n// Includes drops to 0 when session windows end.\nconst scoreRecords: ScoreRecord[] = [];\n\nlet handlerState = HandlerState.UNINITIALIZED;\n\nexport function initialize(): void {\n if (handlerState !== HandlerState.UNINITIALIZED) {\n throw new Error('LayoutShifts Handler was not reset');\n }\n handlerState = HandlerState.INITIALIZED;\n}\n\nexport function reset(): void {\n handlerState = HandlerState.UNINITIALIZED;\n layoutShiftEvents.length = 0;\n layoutInvalidationEvents.length = 0;\n scheduleStyleInvalidationEvents.length = 0;\n styleRecalcInvalidationEvents.length = 0;\n prePaintEvents.length = 0;\n paintImageEvents.length = 0;\n renderFrameImplCreateChildFrameEvents.length = 0;\n layoutImageUnsizedEvents.length = 0;\n domLoadingEvents.length = 0;\n beginRemoteFontLoadEvents.length = 0;\n backendNodeIds.clear();\n clusters.length = 0;\n sessionMaxScore = 0;\n scoreRecords.length = 0;\n clsWindowID = -1;\n clustersByNavigationId.clear();\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Handler is not initialized');\n }\n\n if (Types.Events.isLayoutShift(event) && !event.args.data?.had_recent_input) {\n layoutShiftEvents.push(event);\n return;\n }\n if (Types.Events.isLayoutInvalidationTracking(event)) {\n layoutInvalidationEvents.push(event);\n return;\n }\n if (Types.Events.isScheduleStyleInvalidationTracking(event)) {\n scheduleStyleInvalidationEvents.push(event);\n }\n if (Types.Events.isStyleRecalcInvalidationTracking(event)) {\n styleRecalcInvalidationEvents.push(event);\n }\n if (Types.Events.isPrePaint(event)) {\n prePaintEvents.push(event);\n return;\n }\n if (Types.Events.isRenderFrameImplCreateChildFrame(event)) {\n renderFrameImplCreateChildFrameEvents.push(event);\n }\n if (Types.Events.isDomLoading(event)) {\n domLoadingEvents.push(event);\n }\n if (Types.Events.isLayoutImageUnsized(event)) {\n layoutImageUnsizedEvents.push(event);\n }\n if (Types.Events.isBeginRemoteFontLoad(event)) {\n beginRemoteFontLoadEvents.push(event);\n }\n if (Types.Events.isPaintImage(event)) {\n paintImageEvents.push(event);\n }\n}\n\nfunction traceWindowFromTime(time: Types.Timing.MicroSeconds): Types.Timing.TraceWindowMicroSeconds {\n return {\n min: time,\n max: time,\n range: Types.Timing.MicroSeconds(0),\n };\n}\n\nfunction updateTraceWindowMax(\n traceWindow: Types.Timing.TraceWindowMicroSeconds, newMax: Types.Timing.MicroSeconds): void {\n traceWindow.max = newMax;\n traceWindow.range = Types.Timing.MicroSeconds(traceWindow.max - traceWindow.min);\n}\n\nfunction findScreenshots(timestamp: Types.Timing.MicroSeconds): Types.Events.LayoutShiftParsedData['screenshots'] {\n const screenshots = screenshotsHandlerData().all;\n const before = Helpers.Trace.findPreviousEventBeforeTimestamp(screenshots, timestamp);\n const after = before ? screenshots[screenshots.indexOf(before) + 1] : null;\n return {before, after};\n}\n\nfunction buildScoreRecords(): void {\n const {traceBounds} = metaHandlerData();\n scoreRecords.push({ts: traceBounds.min, score: 0});\n\n for (const cluster of clusters) {\n let clusterScore = 0;\n if (cluster.events[0].args.data) {\n scoreRecords.push({ts: cluster.clusterWindow.min, score: cluster.events[0].args.data.weighted_score_delta});\n }\n for (let i = 0; i < cluster.events.length; i++) {\n const event = cluster.events[i];\n if (!event.args.data) {\n continue;\n }\n clusterScore += event.args.data.weighted_score_delta;\n scoreRecords.push({ts: event.ts, score: clusterScore});\n }\n scoreRecords.push({ts: cluster.clusterWindow.max, score: 0});\n }\n}\n\n/**\n * Collects backend node ids coming from LayoutShift and LayoutInvalidation\n * events.\n */\nfunction collectNodes(): void {\n backendNodeIds.clear();\n\n // Collect the node ids present in the shifts.\n for (const layoutShift of layoutShiftEvents) {\n if (!layoutShift.args.data?.impacted_nodes) {\n continue;\n }\n for (const node of layoutShift.args.data.impacted_nodes) {\n backendNodeIds.add(node.node_id);\n }\n }\n\n // Collect the node ids present in LayoutInvalidation & scheduleStyleInvalidation events.\n for (const layoutInvalidation of layoutInvalidationEvents) {\n if (!layoutInvalidation.args.data?.nodeId) {\n continue;\n }\n backendNodeIds.add(layoutInvalidation.args.data.nodeId);\n }\n for (const scheduleStyleInvalidation of scheduleStyleInvalidationEvents) {\n if (!scheduleStyleInvalidation.args.data?.nodeId) {\n continue;\n }\n backendNodeIds.add(scheduleStyleInvalidation.args.data.nodeId);\n }\n}\n\nexport async function finalize(): Promise<void> {\n // Ensure the events are sorted by #time ascending.\n layoutShiftEvents.sort((a, b) => a.ts - b.ts);\n prePaintEvents.sort((a, b) => a.ts - b.ts);\n layoutInvalidationEvents.sort((a, b) => a.ts - b.ts);\n renderFrameImplCreateChildFrameEvents.sort((a, b) => a.ts - b.ts);\n domLoadingEvents.sort((a, b) => a.ts - b.ts);\n layoutImageUnsizedEvents.sort((a, b) => a.ts - b.ts);\n beginRemoteFontLoadEvents.sort((a, b) => a.ts - b.ts);\n paintImageEvents.sort((a, b) => a.ts - b.ts);\n\n // Each function transforms the data used by the next, as such the invoke order\n // is important.\n await buildLayoutShiftsClusters();\n buildScoreRecords();\n collectNodes();\n handlerState = HandlerState.FINALIZED;\n}\n\nasync function buildLayoutShiftsClusters(): Promise<void> {\n const {navigationsByFrameId, mainFrameId, traceBounds} = metaHandlerData();\n const navigations = navigationsByFrameId.get(mainFrameId) || [];\n if (layoutShiftEvents.length === 0) {\n return;\n }\n let firstShiftTime = layoutShiftEvents[0].ts;\n let lastShiftTime = layoutShiftEvents[0].ts;\n let lastShiftNavigation = null;\n // Now step through each and create clusters.\n // A cluster is equivalent to a session window (see https://web.dev/cls/#what-is-cls).\n // To make the line chart clear, we explicitly demark the limits of each session window\n // by starting the cumulative score of the window at the time of the first layout shift\n // and ending it (dropping the line back to 0) when the window ends according to the\n // thresholds (MAX_CLUSTER_DURATION, MAX_SHIFT_TIME_DELTA).\n for (const event of layoutShiftEvents) {\n // First detect if either the cluster duration or the #time between this and\n // the last shift has been exceeded.\n const clusterDurationExceeded = event.ts - firstShiftTime > MAX_CLUSTER_DURATION;\n const maxTimeDeltaSinceLastShiftExceeded = event.ts - lastShiftTime > MAX_SHIFT_TIME_DELTA;\n\n // Next take a look at navigations. If between this and the last shift we have navigated,\n // note it.\n const currentShiftNavigation = Platform.ArrayUtilities.nearestIndexFromEnd(navigations, nav => nav.ts < event.ts);\n const hasNavigated = lastShiftNavigation !== currentShiftNavigation && currentShiftNavigation !== null;\n\n // If any of the above criteria are met or if we don't have any cluster yet we should\n // start a new one.\n if (clusterDurationExceeded || maxTimeDeltaSinceLastShiftExceeded || hasNavigated || !clusters.length) {\n // The cluster starts #time should be the timestamp of the first layout shift in it.\n const clusterStartTime = event.ts;\n\n // If the last session window ended because the max delta time between shifts\n // was exceeded set the endtime to MAX_SHIFT_TIME_DELTA microseconds after the\n // last shift in the session.\n const endTimeByMaxSessionDuration = clusterDurationExceeded ? firstShiftTime + MAX_CLUSTER_DURATION : Infinity;\n\n // If the last session window ended because the max session duration was\n // surpassed, set the endtime so that the window length = MAX_CLUSTER_DURATION;\n const endTimeByMaxShiftGap = maxTimeDeltaSinceLastShiftExceeded ? lastShiftTime + MAX_SHIFT_TIME_DELTA : Infinity;\n\n // If there was a navigation during the last window, close it at the time\n // of the navigation.\n const endTimeByNavigation = hasNavigated ? navigations[currentShiftNavigation].ts : Infinity;\n\n // End the previous cluster at the time of the first of the criteria above that was met.\n const previousClusterEndTime = Math.min(endTimeByMaxSessionDuration, endTimeByMaxShiftGap, endTimeByNavigation);\n\n // If there is an existing cluster update its closing time.\n if (clusters.length > 0) {\n const currentCluster = clusters[clusters.length - 1];\n updateTraceWindowMax(currentCluster.clusterWindow, Types.Timing.MicroSeconds(previousClusterEndTime));\n }\n\n // If this cluster happened after a navigation, set the navigationId to\n // the current navigation. This lets us easily group clusters by\n // navigation.\n const navigationId = currentShiftNavigation === null ?\n Types.Events.NO_NAVIGATION :\n navigations[currentShiftNavigation].args.data?.navigationId;\n // TODO: `navigationId` is `string | undefined`, but the undefined portion\n // comes from `data.navigationId`. I don't think that is possible for this\n // event type. Can we make this typing stronger? In the meantime, we allow\n // `navigationId` to include undefined values.\n\n clusters.push({\n name: 'SyntheticLayoutShiftCluster',\n events: [],\n clusterWindow: traceWindowFromTime(clusterStartTime),\n clusterCumulativeScore: 0,\n scoreWindows: {\n good: traceWindowFromTime(clusterStartTime),\n },\n navigationId,\n // Set default Event so that this event is treated accordingly for the track appender.\n ts: event.ts,\n pid: event.pid,\n tid: event.tid,\n ph: Types.Events.Phase.COMPLETE,\n cat: '',\n dur: Types.Timing.MicroSeconds(-1), // This `cluster.dur` is updated below.\n });\n\n firstShiftTime = clusterStartTime;\n }\n\n // Given the above we should have a cluster available, so pick the most\n // recent one and append the shift, bump its score and window values accordingly.\n const currentCluster = clusters[clusters.length - 1];\n const timeFromNavigation = currentShiftNavigation !== null ?\n Types.Timing.MicroSeconds(event.ts - navigations[currentShiftNavigation].ts) :\n undefined;\n\n currentCluster.clusterCumulativeScore += event.args.data ? event.args.data.weighted_score_delta : 0;\n if (!event.args.data) {\n continue;\n }\n const shift =\n Helpers.SyntheticEvents.SyntheticEventsManager.registerSyntheticEvent<Types.Events.SyntheticLayoutShift>({\n rawSourceEvent: event,\n ...event,\n args: {\n frame: event.args.frame,\n data: {\n ...event.args.data,\n rawEvent: event,\n navigationId: currentCluster.navigationId ?? undefined,\n },\n },\n parsedData: {\n timeFromNavigation,\n screenshots: findScreenshots(event.ts),\n cumulativeWeightedScoreInWindow: currentCluster.clusterCumulativeScore,\n // The score of the session window is temporarily set to 0 just\n // to initialize it. Since we need to get the score of all shifts\n // in the session window to determine its value, its definite\n // value is set when stepping through the built clusters.\n sessionWindowData: {cumulativeWindowScore: 0, id: clusters.length},\n },\n });\n currentCluster.events.push(shift);\n updateTraceWindowMax(currentCluster.clusterWindow, event.ts);\n\n lastShiftTime = event.ts;\n lastShiftNavigation = currentShiftNavigation;\n }\n\n // Now step through each cluster and set up the times at which the value\n // goes from Good, to needs improvement, to Bad. Note that if there is a\n // large jump we may go from Good to Bad without ever creating a Needs\n // Improvement window at all.\n for (const cluster of clusters) {\n let weightedScore = 0;\n let windowID = -1;\n // If this is the last cluster update its window. The cluster duration is determined\n // by the minimum between: time to next navigation, trace end time, time to maximum\n // cluster duration and time to maximum gap between layout shifts.\n if (cluster === clusters[clusters.length - 1]) {\n const clusterEndByMaxDuration = MAX_CLUSTER_DURATION + cluster.clusterWindow.min;\n const clusterEndByMaxGap = cluster.clusterWindow.max + MAX_SHIFT_TIME_DELTA;\n const nextNavigationIndex =\n Platform.ArrayUtilities.nearestIndexFromBeginning(navigations, nav => nav.ts > cluster.clusterWindow.max);\n const nextNavigationTime = nextNavigationIndex ? navigations[nextNavigationIndex].ts : Infinity;\n const clusterEnd = Math.min(clusterEndByMaxDuration, clusterEndByMaxGap, traceBounds.max, nextNavigationTime);\n updateTraceWindowMax(cluster.clusterWindow, Types.Timing.MicroSeconds(clusterEnd));\n }\n\n let largestScore: number = 0;\n let worstShiftEvent: Types.Events.Event|null = null;\n\n for (const shift of cluster.events) {\n weightedScore += shift.args.data ? shift.args.data.weighted_score_delta : 0;\n windowID = shift.parsedData.sessionWindowData.id;\n const ts = shift.ts;\n // Update the the CLS score of this shift's session window now that\n // we have it.\n shift.parsedData.sessionWindowData.cumulativeWindowScore = cluster.clusterCumulativeScore;\n if (weightedScore < LayoutShiftsThreshold.NEEDS_IMPROVEMENT) {\n // Expand the Good window.\n updateTraceWindowMax(cluster.scoreWindows.good, ts);\n } else if (\n weightedScore >= LayoutShiftsThreshold.NEEDS_IMPROVEMENT && weightedScore < LayoutShiftsThreshold.BAD) {\n if (!cluster.scoreWindows.needsImprovement) {\n // Close the Good window, and open the needs improvement window.\n updateTraceWindowMax(cluster.scoreWindows.good, Types.Timing.MicroSeconds(ts - 1));\n cluster.scoreWindows.needsImprovement = traceWindowFromTime(ts);\n }\n\n // Expand the needs improvement window.\n updateTraceWindowMax(cluster.scoreWindows.needsImprovement, ts);\n } else if (weightedScore >= LayoutShiftsThreshold.BAD) {\n if (!cluster.scoreWindows.bad) {\n // We may jump from Good to Bad here, so update whichever window is open.\n if (cluster.scoreWindows.needsImprovement) {\n updateTraceWindowMax(cluster.scoreWindows.needsImprovement, Types.Timing.MicroSeconds(ts - 1));\n } else {\n updateTraceWindowMax(cluster.scoreWindows.good, Types.Timing.MicroSeconds(ts - 1));\n }\n\n cluster.scoreWindows.bad = traceWindowFromTime(shift.ts);\n }\n\n // Expand the Bad window.\n updateTraceWindowMax(cluster.scoreWindows.bad, ts);\n }\n\n // At this point the windows are set by the timestamps of the events, but the\n // next cluster begins at the timestamp of its first event. As such we now\n // need to expand the score window to the end of the cluster, and we do so\n // by using the Bad widow if it's there, or the NI window, or finally the\n // Good window.\n if (cluster.scoreWindows.bad) {\n updateTraceWindowMax(cluster.scoreWindows.bad, cluster.clusterWindow.max);\n } else if (cluster.scoreWindows.needsImprovement) {\n updateTraceWindowMax(cluster.scoreWindows.needsImprovement, cluster.clusterWindow.max);\n } else {\n updateTraceWindowMax(cluster.scoreWindows.good, cluster.clusterWindow.max);\n }\n\n // Find the worst layout shift of the cluster.\n const score = shift.args.data?.weighted_score_delta;\n if (score !== undefined && score > largestScore) {\n largestScore = score;\n worstShiftEvent = shift;\n }\n }\n // Update the cluster's worst layout shift.\n if (worstShiftEvent) {\n cluster.worstShiftEvent = worstShiftEvent;\n }\n\n // layout shifts are already sorted by time ascending.\n // Capture the time range of the cluster.\n cluster.ts = cluster.events[0].ts;\n const lastShiftTimings = Helpers.Timing.eventTimingsMicroSeconds(cluster.events[cluster.events.length - 1]);\n // Add MAX_SHIFT_TIME_DELTA, the section gap after the last layout shift. This marks the end of the cluster.\n cluster.dur = Types.Timing.MicroSeconds((lastShiftTimings.endTime - cluster.events[0].ts) + MAX_SHIFT_TIME_DELTA);\n\n if (weightedScore > sessionMaxScore) {\n clsWindowID = windowID;\n sessionMaxScore = weightedScore;\n }\n\n if (cluster.navigationId) {\n const clustersForId = Platform.MapUtilities.getWithDefault(clustersByNavigationId, cluster.navigationId, () => {\n return [];\n });\n clustersForId.push(cluster);\n }\n }\n}\n\nexport function data(): LayoutShifts {\n if (handlerState !== HandlerState.FINALIZED) {\n throw new Error('Layout Shifts Handler is not finalized');\n }\n\n return {\n clusters,\n sessionMaxScore,\n clsWindowID,\n prePaintEvents,\n layoutInvalidationEvents,\n scheduleStyleInvalidationEvents,\n styleRecalcInvalidationEvents: [],\n renderFrameImplCreateChildFrameEvents,\n domLoadingEvents,\n layoutImageUnsizedEvents,\n beginRemoteFontLoadEvents,\n scoreRecords,\n // TODO(crbug/41484172): change the type so no need to clone\n backendNodeIds: [...backendNodeIds],\n clustersByNavigationId: new Map(clustersByNavigationId),\n paintImageEvents,\n };\n}\n\nexport function deps(): HandlerName[] {\n return ['Screenshots', 'Meta'];\n}\n\nexport function scoreClassificationForLayoutShift(score: number): ScoreClassification {\n let state = ScoreClassification.GOOD;\n if (score >= LayoutShiftsThreshold.NEEDS_IMPROVEMENT) {\n state = ScoreClassification.OK;\n }\n\n if (score >= LayoutShiftsThreshold.BAD) {\n state = ScoreClassification.BAD;\n }\n\n return state;\n}\n\n// Based on https://web.dev/cls/\nexport const enum LayoutShiftsThreshold {\n GOOD = 0,\n NEEDS_IMPROVEMENT = 0.1,\n BAD = 0.25,\n}\n"]}
1
+ {"version":3,"file":"LayoutShiftsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/LayoutShiftsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAE/D,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,IAAI,IAAI,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EAAC,IAAI,IAAI,sBAAsB,EAAC,MAAM,yBAAyB,CAAC;AAkDvE,4EAA4E;AAC5E,YAAY;AACZ,MAAM,CAAC,MAAM,oBAA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AAO,CAAC,YAAY,EAAE,CAAC;YACzB,MAAM,aAAa,GAAG,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAC,sBAAsB,EAAE,OAAO,CAAC,YAAY,EAAE,GAAG,EAAE;gBAC5G,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;YACH,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,QAAQ;QACR,eAAe;QACf,WAAW;QACX,cAAc;QACd,wBAAwB;QACxB,+BAA+B;QAC/B,6BAA6B,EAAE,EAAE;QACjC,qCAAqC;QACrC,gBAAgB;QAChB,wBAAwB;QACxB,yBAAyB;QACzB,YAAY;QACZ,4DAA4D;QAC5D,cAAc,EAAE,CAAC,GAAG,cAAc,CAAC;QACnC,sBAAsB,EAAE,IAAI,GAAG,CAAC,sBAAsB,CAAC;QACvD,gBAAgB;KACjB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,iCAAiC,CAAC,KAAa;IAC7D,IAAI,KAAK,wCAA2B,CAAC;IACrC,IAAI,KAAK,qDAA2C,EAAE,CAAC;QACrD,KAAK,oCAAyB,CAAC;IACjC,CAAC;IAED,IAAI,KAAK,wCAA6B,EAAE,CAAC;QACvC,KAAK,sCAA0B,CAAC;IAClC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Copyright 2022 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\nimport type * as Protocol from '../../../generated/protocol.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {data as metaHandlerData} from './MetaHandler.js';\nimport {ScoreClassification} from './PageLoadMetricsHandler.js';\nimport {data as screenshotsHandlerData} from './ScreenshotsHandler.js';\nimport type {HandlerName} from './types.js';\n\n// We start with a score of zero and step through all Layout Shift records from\n// all renderers. Each record not only tells us which renderer it is, but also\n// the unweighted and weighted scores. The unweighted score is the score we would\n// get if the renderer were the only one in the viewport. The weighted score, on\n// the other hand, accounts for how much of the viewport that particular render\n// takes up when the shift happened. An ad frame in the corner of the viewport\n// that shifts is considered less disruptive, therefore, than if it were taking\n// up the whole viewport.\n//\n// Next, we step through all the records from all renderers and add the weighted\n// score to a running total across all of the renderers. We create a new \"cluster\"\n// and reset the running total when:\n//\n// 1. We observe a outermost frame navigation, or\n// 2. When there's a gap between records of > 1s, or\n// 3. When there's more than 5 seconds of continuous layout shifting.\n//\n// Note that for it to be Cumulative Layout Shift in the sense described in the\n// documentation we would need to guarantee that we are tracking from navigation\n// to unload. However, we don't make any such guarantees here (since a developer\n// can record and stop when they please), so we support the cluster approach,\n// and we can give them a score, but it is effectively a \"session\" score, a\n// score for the given recording, and almost certainly not the\n// navigation-to-unload CLS score.\n\ninterface LayoutShifts {\n clusters: readonly Types.Events.SyntheticLayoutShiftCluster[];\n clustersByNavigationId: Map<Types.Events.NavigationId, Types.Events.SyntheticLayoutShiftCluster[]>;\n sessionMaxScore: number;\n // The session window which contains the SessionMaxScore\n clsWindowID: number;\n // We use these to calculate root causes for a given LayoutShift\n // TODO(crbug/41484172): should be readonly\n prePaintEvents: Types.Events.PrePaint[];\n paintImageEvents: Types.Events.PaintImage[];\n layoutInvalidationEvents: readonly Types.Events.LayoutInvalidationTracking[];\n scheduleStyleInvalidationEvents: readonly Types.Events.ScheduleStyleInvalidationTracking[];\n styleRecalcInvalidationEvents: readonly Types.Events.StyleRecalcInvalidationTracking[];\n renderFrameImplCreateChildFrameEvents: readonly Types.Events.RenderFrameImplCreateChildFrame[];\n domLoadingEvents: readonly Types.Events.DomLoading[];\n layoutImageUnsizedEvents: readonly Types.Events.LayoutImageUnsized[];\n beginRemoteFontLoadEvents: readonly Types.Events.BeginRemoteFontLoad[];\n scoreRecords: readonly ScoreRecord[];\n // TODO(crbug/41484172): should be readonly\n backendNodeIds: Protocol.DOM.BackendNodeId[];\n}\n\n// This represents the maximum #time we will allow a cluster to go before we\n// reset it.\nexport const MAX_CLUSTER_DURATION = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(5000));\n\n// This represents the maximum #time we will allow between layout shift events\n// before considering it to be the start of a new cluster.\nexport const MAX_SHIFT_TIME_DELTA = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(1000));\n\n// Layout shifts are reported globally to the developer, irrespective of which\n// frame they originated in. However, each process does have its own individual\n// CLS score, so we need to segment by process. This means Layout Shifts from\n// sites with one process (no subframes, or subframes from the same origin)\n// will be reported together. In the case of multiple renderers (frames across\n// different origins), we offer the developer the ability to switch renderer in\n// the UI.\nconst layoutShiftEvents: Types.Events.LayoutShift[] = [];\n\n// These events denote potential node resizings. We store them to link captured\n// layout shifts to the resizing of unsized elements.\nconst layoutInvalidationEvents: Types.Events.LayoutInvalidationTracking[] = [];\nconst scheduleStyleInvalidationEvents: Types.Events.ScheduleStyleInvalidationTracking[] = [];\nconst styleRecalcInvalidationEvents: Types.Events.StyleRecalcInvalidationTracking[] = [];\nconst renderFrameImplCreateChildFrameEvents: Types.Events.RenderFrameImplCreateChildFrame[] = [];\nconst domLoadingEvents: Types.Events.DomLoading[] = [];\nconst layoutImageUnsizedEvents: Types.Events.LayoutImageUnsized[] = [];\nconst beginRemoteFontLoadEvents: Types.Events.BeginRemoteFontLoad[] = [];\n\nconst backendNodeIds = new Set<Protocol.DOM.BackendNodeId>();\n\n// Layout shifts happen during PrePaint as part of the rendering lifecycle.\n// We determine if a LayoutInvalidation event is a potential root cause of a layout\n// shift if the next PrePaint after the LayoutInvalidation is the parent\n// node of such shift.\nconst prePaintEvents: Types.Events.PrePaint[] = [];\n\nconst paintImageEvents: Types.Events.PaintImage[] = [];\n\nlet sessionMaxScore = 0;\n\nlet clsWindowID = -1;\n\nconst clusters: Types.Events.SyntheticLayoutShiftCluster[] = [];\nconst clustersByNavigationId = new Map<Types.Events.NavigationId, Types.Events.SyntheticLayoutShiftCluster[]>();\n\n// Represents a point in time in which a LS score change\n// was recorded.\ntype ScoreRecord = {\n ts: number,\n score: number,\n};\n\n// The complete timeline of LS score changes in a trace.\n// Includes drops to 0 when session windows end.\nconst scoreRecords: ScoreRecord[] = [];\n\nexport function reset(): void {\n layoutShiftEvents.length = 0;\n layoutInvalidationEvents.length = 0;\n scheduleStyleInvalidationEvents.length = 0;\n styleRecalcInvalidationEvents.length = 0;\n prePaintEvents.length = 0;\n paintImageEvents.length = 0;\n renderFrameImplCreateChildFrameEvents.length = 0;\n layoutImageUnsizedEvents.length = 0;\n domLoadingEvents.length = 0;\n beginRemoteFontLoadEvents.length = 0;\n backendNodeIds.clear();\n clusters.length = 0;\n sessionMaxScore = 0;\n scoreRecords.length = 0;\n clsWindowID = -1;\n clustersByNavigationId.clear();\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (Types.Events.isLayoutShift(event) && !event.args.data?.had_recent_input) {\n layoutShiftEvents.push(event);\n return;\n }\n if (Types.Events.isLayoutInvalidationTracking(event)) {\n layoutInvalidationEvents.push(event);\n return;\n }\n if (Types.Events.isScheduleStyleInvalidationTracking(event)) {\n scheduleStyleInvalidationEvents.push(event);\n }\n if (Types.Events.isStyleRecalcInvalidationTracking(event)) {\n styleRecalcInvalidationEvents.push(event);\n }\n if (Types.Events.isPrePaint(event)) {\n prePaintEvents.push(event);\n return;\n }\n if (Types.Events.isRenderFrameImplCreateChildFrame(event)) {\n renderFrameImplCreateChildFrameEvents.push(event);\n }\n if (Types.Events.isDomLoading(event)) {\n domLoadingEvents.push(event);\n }\n if (Types.Events.isLayoutImageUnsized(event)) {\n layoutImageUnsizedEvents.push(event);\n }\n if (Types.Events.isBeginRemoteFontLoad(event)) {\n beginRemoteFontLoadEvents.push(event);\n }\n if (Types.Events.isPaintImage(event)) {\n paintImageEvents.push(event);\n }\n}\n\nfunction traceWindowFromTime(time: Types.Timing.MicroSeconds): Types.Timing.TraceWindowMicroSeconds {\n return {\n min: time,\n max: time,\n range: Types.Timing.MicroSeconds(0),\n };\n}\n\nfunction updateTraceWindowMax(\n traceWindow: Types.Timing.TraceWindowMicroSeconds, newMax: Types.Timing.MicroSeconds): void {\n traceWindow.max = newMax;\n traceWindow.range = Types.Timing.MicroSeconds(traceWindow.max - traceWindow.min);\n}\n\nfunction findScreenshots(timestamp: Types.Timing.MicroSeconds): Types.Events.LayoutShiftParsedData['screenshots'] {\n const screenshots = screenshotsHandlerData().all;\n const before = Helpers.Trace.findPreviousEventBeforeTimestamp(screenshots, timestamp);\n const after = before ? screenshots[screenshots.indexOf(before) + 1] : null;\n return {before, after};\n}\n\nfunction buildScoreRecords(): void {\n const {traceBounds} = metaHandlerData();\n scoreRecords.push({ts: traceBounds.min, score: 0});\n\n for (const cluster of clusters) {\n let clusterScore = 0;\n if (cluster.events[0].args.data) {\n scoreRecords.push({ts: cluster.clusterWindow.min, score: cluster.events[0].args.data.weighted_score_delta});\n }\n for (let i = 0; i < cluster.events.length; i++) {\n const event = cluster.events[i];\n if (!event.args.data) {\n continue;\n }\n clusterScore += event.args.data.weighted_score_delta;\n scoreRecords.push({ts: event.ts, score: clusterScore});\n }\n scoreRecords.push({ts: cluster.clusterWindow.max, score: 0});\n }\n}\n\n/**\n * Collects backend node ids coming from LayoutShift and LayoutInvalidation\n * events.\n */\nfunction collectNodes(): void {\n backendNodeIds.clear();\n\n // Collect the node ids present in the shifts.\n for (const layoutShift of layoutShiftEvents) {\n if (!layoutShift.args.data?.impacted_nodes) {\n continue;\n }\n for (const node of layoutShift.args.data.impacted_nodes) {\n backendNodeIds.add(node.node_id);\n }\n }\n\n // Collect the node ids present in LayoutInvalidation & scheduleStyleInvalidation events.\n for (const layoutInvalidation of layoutInvalidationEvents) {\n if (!layoutInvalidation.args.data?.nodeId) {\n continue;\n }\n backendNodeIds.add(layoutInvalidation.args.data.nodeId);\n }\n for (const scheduleStyleInvalidation of scheduleStyleInvalidationEvents) {\n if (!scheduleStyleInvalidation.args.data?.nodeId) {\n continue;\n }\n backendNodeIds.add(scheduleStyleInvalidation.args.data.nodeId);\n }\n}\n\nexport async function finalize(): Promise<void> {\n // Ensure the events are sorted by #time ascending.\n layoutShiftEvents.sort((a, b) => a.ts - b.ts);\n prePaintEvents.sort((a, b) => a.ts - b.ts);\n layoutInvalidationEvents.sort((a, b) => a.ts - b.ts);\n renderFrameImplCreateChildFrameEvents.sort((a, b) => a.ts - b.ts);\n domLoadingEvents.sort((a, b) => a.ts - b.ts);\n layoutImageUnsizedEvents.sort((a, b) => a.ts - b.ts);\n beginRemoteFontLoadEvents.sort((a, b) => a.ts - b.ts);\n paintImageEvents.sort((a, b) => a.ts - b.ts);\n\n // Each function transforms the data used by the next, as such the invoke order\n // is important.\n await buildLayoutShiftsClusters();\n buildScoreRecords();\n collectNodes();\n}\n\nasync function buildLayoutShiftsClusters(): Promise<void> {\n const {navigationsByFrameId, mainFrameId, traceBounds} = metaHandlerData();\n const navigations = navigationsByFrameId.get(mainFrameId) || [];\n if (layoutShiftEvents.length === 0) {\n return;\n }\n let firstShiftTime = layoutShiftEvents[0].ts;\n let lastShiftTime = layoutShiftEvents[0].ts;\n let lastShiftNavigation = null;\n // Now step through each and create clusters.\n // A cluster is equivalent to a session window (see https://web.dev/cls/#what-is-cls).\n // To make the line chart clear, we explicitly demark the limits of each session window\n // by starting the cumulative score of the window at the time of the first layout shift\n // and ending it (dropping the line back to 0) when the window ends according to the\n // thresholds (MAX_CLUSTER_DURATION, MAX_SHIFT_TIME_DELTA).\n for (const event of layoutShiftEvents) {\n // First detect if either the cluster duration or the #time between this and\n // the last shift has been exceeded.\n const clusterDurationExceeded = event.ts - firstShiftTime > MAX_CLUSTER_DURATION;\n const maxTimeDeltaSinceLastShiftExceeded = event.ts - lastShiftTime > MAX_SHIFT_TIME_DELTA;\n\n // Next take a look at navigations. If between this and the last shift we have navigated,\n // note it.\n const currentShiftNavigation = Platform.ArrayUtilities.nearestIndexFromEnd(navigations, nav => nav.ts < event.ts);\n const hasNavigated = lastShiftNavigation !== currentShiftNavigation && currentShiftNavigation !== null;\n\n // If any of the above criteria are met or if we don't have any cluster yet we should\n // start a new one.\n if (clusterDurationExceeded || maxTimeDeltaSinceLastShiftExceeded || hasNavigated || !clusters.length) {\n // The cluster starts #time should be the timestamp of the first layout shift in it.\n const clusterStartTime = event.ts;\n\n // If the last session window ended because the max delta time between shifts\n // was exceeded set the endtime to MAX_SHIFT_TIME_DELTA microseconds after the\n // last shift in the session.\n const endTimeByMaxSessionDuration = clusterDurationExceeded ? firstShiftTime + MAX_CLUSTER_DURATION : Infinity;\n\n // If the last session window ended because the max session duration was\n // surpassed, set the endtime so that the window length = MAX_CLUSTER_DURATION;\n const endTimeByMaxShiftGap = maxTimeDeltaSinceLastShiftExceeded ? lastShiftTime + MAX_SHIFT_TIME_DELTA : Infinity;\n\n // If there was a navigation during the last window, close it at the time\n // of the navigation.\n const endTimeByNavigation = hasNavigated ? navigations[currentShiftNavigation].ts : Infinity;\n\n // End the previous cluster at the time of the first of the criteria above that was met.\n const previousClusterEndTime = Math.min(endTimeByMaxSessionDuration, endTimeByMaxShiftGap, endTimeByNavigation);\n\n // If there is an existing cluster update its closing time.\n if (clusters.length > 0) {\n const currentCluster = clusters[clusters.length - 1];\n updateTraceWindowMax(currentCluster.clusterWindow, Types.Timing.MicroSeconds(previousClusterEndTime));\n }\n\n // If this cluster happened after a navigation, set the navigationId to\n // the current navigation. This lets us easily group clusters by\n // navigation.\n const navigationId = currentShiftNavigation === null ?\n Types.Events.NO_NAVIGATION :\n navigations[currentShiftNavigation].args.data?.navigationId;\n // TODO: `navigationId` is `string | undefined`, but the undefined portion\n // comes from `data.navigationId`. I don't think that is possible for this\n // event type. Can we make this typing stronger? In the meantime, we allow\n // `navigationId` to include undefined values.\n\n clusters.push({\n name: 'SyntheticLayoutShiftCluster',\n events: [],\n clusterWindow: traceWindowFromTime(clusterStartTime),\n clusterCumulativeScore: 0,\n scoreWindows: {\n good: traceWindowFromTime(clusterStartTime),\n },\n navigationId,\n // Set default Event so that this event is treated accordingly for the track appender.\n ts: event.ts,\n pid: event.pid,\n tid: event.tid,\n ph: Types.Events.Phase.COMPLETE,\n cat: '',\n dur: Types.Timing.MicroSeconds(-1), // This `cluster.dur` is updated below.\n });\n\n firstShiftTime = clusterStartTime;\n }\n\n // Given the above we should have a cluster available, so pick the most\n // recent one and append the shift, bump its score and window values accordingly.\n const currentCluster = clusters[clusters.length - 1];\n const timeFromNavigation = currentShiftNavigation !== null ?\n Types.Timing.MicroSeconds(event.ts - navigations[currentShiftNavigation].ts) :\n undefined;\n\n currentCluster.clusterCumulativeScore += event.args.data ? event.args.data.weighted_score_delta : 0;\n if (!event.args.data) {\n continue;\n }\n const shift =\n Helpers.SyntheticEvents.SyntheticEventsManager.registerSyntheticEvent<Types.Events.SyntheticLayoutShift>({\n rawSourceEvent: event,\n ...event,\n args: {\n frame: event.args.frame,\n data: {\n ...event.args.data,\n rawEvent: event,\n navigationId: currentCluster.navigationId ?? undefined,\n },\n },\n parsedData: {\n timeFromNavigation,\n screenshots: findScreenshots(event.ts),\n cumulativeWeightedScoreInWindow: currentCluster.clusterCumulativeScore,\n // The score of the session window is temporarily set to 0 just\n // to initialize it. Since we need to get the score of all shifts\n // in the session window to determine its value, its definite\n // value is set when stepping through the built clusters.\n sessionWindowData: {cumulativeWindowScore: 0, id: clusters.length},\n },\n });\n currentCluster.events.push(shift);\n updateTraceWindowMax(currentCluster.clusterWindow, event.ts);\n\n lastShiftTime = event.ts;\n lastShiftNavigation = currentShiftNavigation;\n }\n\n // Now step through each cluster and set up the times at which the value\n // goes from Good, to needs improvement, to Bad. Note that if there is a\n // large jump we may go from Good to Bad without ever creating a Needs\n // Improvement window at all.\n for (const cluster of clusters) {\n let weightedScore = 0;\n let windowID = -1;\n // If this is the last cluster update its window. The cluster duration is determined\n // by the minimum between: time to next navigation, trace end time, time to maximum\n // cluster duration and time to maximum gap between layout shifts.\n if (cluster === clusters[clusters.length - 1]) {\n const clusterEndByMaxDuration = MAX_CLUSTER_DURATION + cluster.clusterWindow.min;\n const clusterEndByMaxGap = cluster.clusterWindow.max + MAX_SHIFT_TIME_DELTA;\n const nextNavigationIndex =\n Platform.ArrayUtilities.nearestIndexFromBeginning(navigations, nav => nav.ts > cluster.clusterWindow.max);\n const nextNavigationTime = nextNavigationIndex ? navigations[nextNavigationIndex].ts : Infinity;\n const clusterEnd = Math.min(clusterEndByMaxDuration, clusterEndByMaxGap, traceBounds.max, nextNavigationTime);\n updateTraceWindowMax(cluster.clusterWindow, Types.Timing.MicroSeconds(clusterEnd));\n }\n\n let largestScore: number = 0;\n let worstShiftEvent: Types.Events.Event|null = null;\n\n for (const shift of cluster.events) {\n weightedScore += shift.args.data ? shift.args.data.weighted_score_delta : 0;\n windowID = shift.parsedData.sessionWindowData.id;\n const ts = shift.ts;\n // Update the the CLS score of this shift's session window now that\n // we have it.\n shift.parsedData.sessionWindowData.cumulativeWindowScore = cluster.clusterCumulativeScore;\n if (weightedScore < LayoutShiftsThreshold.NEEDS_IMPROVEMENT) {\n // Expand the Good window.\n updateTraceWindowMax(cluster.scoreWindows.good, ts);\n } else if (\n weightedScore >= LayoutShiftsThreshold.NEEDS_IMPROVEMENT && weightedScore < LayoutShiftsThreshold.BAD) {\n if (!cluster.scoreWindows.needsImprovement) {\n // Close the Good window, and open the needs improvement window.\n updateTraceWindowMax(cluster.scoreWindows.good, Types.Timing.MicroSeconds(ts - 1));\n cluster.scoreWindows.needsImprovement = traceWindowFromTime(ts);\n }\n\n // Expand the needs improvement window.\n updateTraceWindowMax(cluster.scoreWindows.needsImprovement, ts);\n } else if (weightedScore >= LayoutShiftsThreshold.BAD) {\n if (!cluster.scoreWindows.bad) {\n // We may jump from Good to Bad here, so update whichever window is open.\n if (cluster.scoreWindows.needsImprovement) {\n updateTraceWindowMax(cluster.scoreWindows.needsImprovement, Types.Timing.MicroSeconds(ts - 1));\n } else {\n updateTraceWindowMax(cluster.scoreWindows.good, Types.Timing.MicroSeconds(ts - 1));\n }\n\n cluster.scoreWindows.bad = traceWindowFromTime(shift.ts);\n }\n\n // Expand the Bad window.\n updateTraceWindowMax(cluster.scoreWindows.bad, ts);\n }\n\n // At this point the windows are set by the timestamps of the events, but the\n // next cluster begins at the timestamp of its first event. As such we now\n // need to expand the score window to the end of the cluster, and we do so\n // by using the Bad widow if it's there, or the NI window, or finally the\n // Good window.\n if (cluster.scoreWindows.bad) {\n updateTraceWindowMax(cluster.scoreWindows.bad, cluster.clusterWindow.max);\n } else if (cluster.scoreWindows.needsImprovement) {\n updateTraceWindowMax(cluster.scoreWindows.needsImprovement, cluster.clusterWindow.max);\n } else {\n updateTraceWindowMax(cluster.scoreWindows.good, cluster.clusterWindow.max);\n }\n\n // Find the worst layout shift of the cluster.\n const score = shift.args.data?.weighted_score_delta;\n if (score !== undefined && score > largestScore) {\n largestScore = score;\n worstShiftEvent = shift;\n }\n }\n // Update the cluster's worst layout shift.\n if (worstShiftEvent) {\n cluster.worstShiftEvent = worstShiftEvent;\n }\n\n // layout shifts are already sorted by time ascending.\n // Capture the time range of the cluster.\n cluster.ts = cluster.events[0].ts;\n const lastShiftTimings = Helpers.Timing.eventTimingsMicroSeconds(cluster.events[cluster.events.length - 1]);\n // Add MAX_SHIFT_TIME_DELTA, the section gap after the last layout shift. This marks the end of the cluster.\n cluster.dur = Types.Timing.MicroSeconds((lastShiftTimings.endTime - cluster.events[0].ts) + MAX_SHIFT_TIME_DELTA);\n\n if (weightedScore > sessionMaxScore) {\n clsWindowID = windowID;\n sessionMaxScore = weightedScore;\n }\n\n if (cluster.navigationId) {\n const clustersForId = Platform.MapUtilities.getWithDefault(clustersByNavigationId, cluster.navigationId, () => {\n return [];\n });\n clustersForId.push(cluster);\n }\n }\n}\n\nexport function data(): LayoutShifts {\n return {\n clusters,\n sessionMaxScore,\n clsWindowID,\n prePaintEvents,\n layoutInvalidationEvents,\n scheduleStyleInvalidationEvents,\n styleRecalcInvalidationEvents: [],\n renderFrameImplCreateChildFrameEvents,\n domLoadingEvents,\n layoutImageUnsizedEvents,\n beginRemoteFontLoadEvents,\n scoreRecords,\n // TODO(crbug/41484172): change the type so no need to clone\n backendNodeIds: [...backendNodeIds],\n clustersByNavigationId: new Map(clustersByNavigationId),\n paintImageEvents,\n };\n}\n\nexport function deps(): HandlerName[] {\n return ['Screenshots', 'Meta'];\n}\n\nexport function scoreClassificationForLayoutShift(score: number): ScoreClassification {\n let state = ScoreClassification.GOOD;\n if (score >= LayoutShiftsThreshold.NEEDS_IMPROVEMENT) {\n state = ScoreClassification.OK;\n }\n\n if (score >= LayoutShiftsThreshold.BAD) {\n state = ScoreClassification.BAD;\n }\n\n return state;\n}\n\n// Based on https://web.dev/cls/\nexport const enum LayoutShiftsThreshold {\n GOOD = 0,\n NEEDS_IMPROVEMENT = 0.1,\n BAD = 0.25,\n}\n"]}
@@ -4,4 +4,5 @@ export interface MemoryData {
4
4
  }
5
5
  export declare function reset(): void;
6
6
  export declare function handleEvent(event: Types.Events.Event): void;
7
+ export declare function finalize(): Promise<void>;
7
8
  export declare function data(): MemoryData;
@@ -14,6 +14,8 @@ export function handleEvent(event) {
14
14
  updateCountersByProcess.set(event.pid, countersForProcess);
15
15
  }
16
16
  }
17
+ export async function finalize() {
18
+ }
17
19
  export function data() {
18
20
  return { updateCountersByProcess };
19
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/MemoryHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAC/D,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAM3C,MAAM,uBAAuB,GAA0C,IAAI,GAAG,EAAE,CAAC;AAEjF,MAAM,UAAU,KAAK;IACnB,uBAAuB,CAAC,KAAK,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAyB;IACnD,IAAI,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QACzC,MAAM,kBAAkB,GAAG,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAC,uBAAuB,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9G,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,uBAAuB,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,EAAC,uBAAuB,EAAC,CAAC;AACnC,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 Types from '../types/types.js';\n\nexport interface MemoryData {\n updateCountersByProcess: Map<Types.Events.ProcessID, Types.Events.UpdateCounters[]>;\n}\n\nconst updateCountersByProcess: MemoryData['updateCountersByProcess'] = new Map();\n\nexport function reset(): void {\n updateCountersByProcess.clear();\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (Types.Events.isUpdateCounters(event)) {\n const countersForProcess = Platform.MapUtilities.getWithDefault(updateCountersByProcess, event.pid, () => []);\n countersForProcess.push(event);\n updateCountersByProcess.set(event.pid, countersForProcess);\n }\n}\n\nexport function data(): MemoryData {\n return {updateCountersByProcess};\n}\n"]}
1
+ {"version":3,"file":"MemoryHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/MemoryHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAC/D,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAM3C,MAAM,uBAAuB,GAA0C,IAAI,GAAG,EAAE,CAAC;AAEjF,MAAM,UAAU,KAAK;IACnB,uBAAuB,CAAC,KAAK,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAyB;IACnD,IAAI,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QACzC,MAAM,kBAAkB,GAAG,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAC,uBAAuB,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9G,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,uBAAuB,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ;AAC9B,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,EAAC,uBAAuB,EAAC,CAAC;AACnC,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 Types from '../types/types.js';\n\nexport interface MemoryData {\n updateCountersByProcess: Map<Types.Events.ProcessID, Types.Events.UpdateCounters[]>;\n}\n\nconst updateCountersByProcess: MemoryData['updateCountersByProcess'] = new Map();\n\nexport function reset(): void {\n updateCountersByProcess.clear();\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (Types.Events.isUpdateCounters(event)) {\n const countersForProcess = Platform.MapUtilities.getWithDefault(updateCountersByProcess, event.pid, () => []);\n countersForProcess.push(event);\n updateCountersByProcess.set(event.pid, countersForProcess);\n }\n}\n\nexport async function finalize(): Promise<void> {\n}\n\nexport function data(): MemoryData {\n return {updateCountersByProcess};\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  import * as Types from '../types/types.js';
2
2
  export declare function reset(): void;
3
- export declare function initialize(): void;
4
3
  export declare function handleEvent(event: Types.Events.Event): void;
5
4
  export declare function finalize(): Promise<void>;
6
5
  export type MetaHandlerData = {
@@ -54,7 +54,6 @@ const eventPhasesOfInterestForTraceBounds = new Set([
54
54
  "X" /* Types.Events.Phase.COMPLETE */,
55
55
  "I" /* Types.Events.Phase.INSTANT */,
56
56
  ]);
57
- let handlerState = 1 /* HandlerState.UNINITIALIZED */;
58
57
  // Tracks if the trace is a generic trace, which here means that it did not come from athe DevTools Performance Panel recording.
59
58
  // We assume a trace is generic, and mark it as not generic if we see any of:
60
59
  // - TracingStartedInPage
@@ -86,13 +85,6 @@ export function reset() {
86
85
  traceBounds.range = Types.Timing.MicroSeconds(Number.POSITIVE_INFINITY);
87
86
  traceStartedTimeFromTracingStartedEvent = Types.Timing.MicroSeconds(-1);
88
87
  traceIsGeneric = true;
89
- handlerState = 1 /* HandlerState.UNINITIALIZED */;
90
- }
91
- export function initialize() {
92
- if (handlerState !== 1 /* HandlerState.UNINITIALIZED */) {
93
- throw new Error('Meta Handler was not reset');
94
- }
95
- handlerState = 2 /* HandlerState.INITIALIZED */;
96
88
  }
97
89
  function updateRendererProcessByFrame(event, frame) {
98
90
  const framesInProcessById = Platform.MapUtilities.getWithDefault(framesByProcessId, frame.processId, () => new Map());
@@ -119,9 +111,6 @@ function updateRendererProcessByFrame(event, frame) {
119
111
  });
120
112
  }
121
113
  export function handleEvent(event) {
122
- if (handlerState !== 2 /* HandlerState.INITIALIZED */) {
123
- throw new Error('Meta Handler is not initialized');
124
- }
125
114
  if (traceIsGeneric && CHROME_WEB_TRACE_EVENTS.has(event.name)) {
126
115
  traceIsGeneric = false;
127
116
  }
@@ -285,9 +274,6 @@ export function handleEvent(event) {
285
274
  }
286
275
  }
287
276
  export async function finalize() {
288
- if (handlerState !== 2 /* HandlerState.INITIALIZED */) {
289
- throw new Error('Handler is not initialized');
290
- }
291
277
  // We try to set the minimum time by finding the event with the smallest
292
278
  // timestamp. However, if we also got a timestamp from the
293
279
  // TracingStartedInBrowser event, we should always use that.
@@ -357,12 +343,8 @@ export async function finalize() {
357
343
  mainFrameURL = firstMainFrameNav.args.data.documentLoaderURL;
358
344
  }
359
345
  }
360
- handlerState = 3 /* HandlerState.FINALIZED */;
361
346
  }
362
347
  export function data() {
363
- if (handlerState !== 3 /* HandlerState.FINALIZED */) {
364
- throw new Error('Meta Handler is not finalized');
365
- }
366
348
  return {
367
349
  traceBounds: { ...traceBounds },
368
350
  browserProcessId,