@paulirish/trace_engine 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analyze-trace.mjs +1 -1
- package/core/platform/DevToolsPath.d.ts +23 -0
- package/core/platform/DevToolsPath.js +7 -0
- package/core/platform/DevToolsPath.js.map +1 -0
- package/core/platform/MimeType.d.ts +27 -0
- package/core/platform/MimeType.js +137 -0
- package/core/platform/MimeType.js.map +1 -0
- package/core/platform/Timing.d.ts +7 -0
- package/core/platform/Timing.js +13 -0
- package/core/platform/Timing.js.map +1 -0
- package/core/platform/UIString.d.ts +3 -0
- package/core/platform/UIString.js +5 -0
- package/core/platform/UIString.js.map +1 -0
- package/core/platform/UserVisibleError.d.ts +12 -0
- package/core/platform/UserVisibleError.js +23 -0
- package/core/platform/UserVisibleError.js.map +1 -0
- package/core/platform/array-utilities.d.ts +66 -0
- package/core/platform/array-utilities.js +199 -0
- package/core/platform/array-utilities.js.map +1 -0
- package/core/platform/brand.d.ts +14 -0
- package/core/platform/brand.js +5 -0
- package/core/platform/brand.js.map +1 -0
- package/core/platform/bundle-tsconfig.json +1 -0
- package/core/platform/date-utilities.d.ts +2 -0
- package/core/platform/date-utilities.js +14 -0
- package/core/platform/date-utilities.js.map +1 -0
- package/core/platform/dcheck-tsconfig.json +8 -0
- package/core/platform/dcheck.d.ts +4 -0
- package/core/platform/dcheck.js +5 -0
- package/core/platform/devtools_entrypoint-bundle-tsconfig-tsconfig.json +40 -0
- package/core/platform/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
- package/core/platform/dom-utilities.d.ts +8 -0
- package/core/platform/dom-utilities.js +109 -0
- package/core/platform/dom-utilities.js.map +1 -0
- package/core/platform/keyboard-utilities.d.ts +17 -0
- package/core/platform/keyboard-utilities.js +22 -0
- package/core/platform/keyboard-utilities.js.map +1 -0
- package/core/platform/map-utilities.d.ts +18 -0
- package/core/platform/map-utilities.js +76 -0
- package/core/platform/map-utilities.js.map +1 -0
- package/core/platform/number-utilities.d.ts +15 -0
- package/core/platform/number-utilities.js +82 -0
- package/core/platform/number-utilities.js.map +1 -0
- package/core/platform/platform-tsconfig.json +59 -0
- package/core/platform/platform.d.ts +19 -0
- package/core/platform/platform.js +54 -0
- package/core/platform/platform.js.compressed +0 -0
- package/core/platform/platform.js.hash +1 -0
- package/core/platform/platform.js.map +1 -0
- package/core/platform/platform.prebundle.d.ts +15 -0
- package/core/platform/platform.prebundle.js +50 -0
- package/core/platform/platform.prebundle.js.map +1 -0
- package/core/platform/platform.prebundle.ts +64 -0
- package/core/platform/promise-utilities.d.ts +10 -0
- package/core/platform/promise-utilities.js +18 -0
- package/core/platform/promise-utilities.js.map +1 -0
- package/core/platform/set-utilities.d.ts +2 -0
- package/core/platform/set-utilities.js +23 -0
- package/core/platform/set-utilities.js.map +1 -0
- package/core/platform/string-utilities.d.ts +71 -0
- package/core/platform/string-utilities.js +513 -0
- package/core/platform/string-utilities.js.map +1 -0
- package/core/platform/typescript-utilities.d.ts +56 -0
- package/core/platform/typescript-utilities.js +25 -0
- package/core/platform/typescript-utilities.js.map +1 -0
- package/generated/protocol.d.ts +17923 -0
- package/generated/protocol.js +5 -0
- package/models/cpu_profile/CPUProfileDataModel.d.ts +77 -0
- package/models/cpu_profile/CPUProfileDataModel.js +508 -0
- package/models/cpu_profile/CPUProfileDataModel.js.map +1 -0
- package/models/cpu_profile/ProfileTreeModel.d.ts +29 -0
- package/models/cpu_profile/ProfileTreeModel.js +95 -0
- package/models/cpu_profile/ProfileTreeModel.js.map +1 -0
- package/models/cpu_profile/bundle-tsconfig.json +1 -0
- package/models/cpu_profile/cpu_profile-tsconfig.json +51 -0
- package/models/cpu_profile/cpu_profile.d.ts +3 -0
- package/models/cpu_profile/cpu_profile.js +7 -0
- package/models/cpu_profile/cpu_profile.js.map +1 -0
- package/models/cpu_profile/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
- package/models/trace/EntriesFilter.d.ts +55 -0
- package/models/trace/EntriesFilter.js +243 -0
- package/models/trace/EntriesFilter.js.map +1 -0
- package/models/trace/LegacyTracingModel.d.ts +1 -0
- package/models/trace/LegacyTracingModel.js +1 -0
- package/models/trace/LegacyTracingModel.js.map +1 -0
- package/models/trace/ModelImpl.d.ts +110 -0
- package/models/trace/ModelImpl.js +175 -0
- package/models/trace/ModelImpl.js.map +1 -0
- package/models/trace/Processor.d.ts +36 -0
- package/models/trace/Processor.js +213 -0
- package/models/trace/Processor.js.map +1 -0
- package/models/trace/SDKServices.js +104 -0
- package/models/trace/SDKServices.js.map +7 -0
- package/models/trace/TraceProcessor.js +133 -0
- package/models/trace/TraceProcessor.js.map +7 -0
- package/models/trace/TracingManager.d.ts +1 -0
- package/models/trace/TracingManager.js +1 -0
- package/models/trace/TracingManager.js.map +1 -0
- package/models/trace/TreeManipulator.js +85 -0
- package/models/trace/TreeManipulator.js.map +7 -0
- package/models/trace/bundle-tsconfig.json +1 -0
- package/models/trace/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
- package/models/trace/devtools_entrypoint-legacy-typescript-tsconfig.json +43 -0
- package/models/trace/extras/FetchNodes.d.ts +46 -0
- package/models/trace/extras/FetchNodes.js +145 -0
- package/models/trace/extras/FetchNodes.js.map +1 -0
- package/models/trace/extras/FilmStrip.d.ts +19 -0
- package/models/trace/extras/FilmStrip.js +44 -0
- package/models/trace/extras/FilmStrip.js.map +1 -0
- package/models/trace/extras/MainThreadActivity.d.ts +2 -0
- package/models/trace/extras/MainThreadActivity.js +77 -0
- package/models/trace/extras/MainThreadActivity.js.map +1 -0
- package/models/trace/extras/Metadata.d.ts +2 -0
- package/models/trace/extras/Metadata.js +44 -0
- package/models/trace/extras/Metadata.js.map +1 -0
- package/models/trace/extras/bundle-tsconfig.json +1 -0
- package/models/trace/extras/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
- package/models/trace/extras/extras-tsconfig.json +59 -0
- package/models/trace/extras/extras.d.ts +1 -0
- package/models/trace/extras/extras.js +1 -0
- package/models/trace/extras/extras.js.map +1 -0
- package/models/trace/frames/TimelineFrameModel.js +392 -0
- package/models/trace/frames/TimelineFrameModel.js.map +7 -0
- package/models/trace/frames/bundle-tsconfig.json +1 -0
- package/models/trace/frames/devtools_entrypoint-bundle-typescript-tsconfig.json +43 -0
- package/models/trace/frames/frames-tsconfig.json +58 -0
- package/models/trace/frames/frames.js +5 -0
- package/models/trace/frames/frames.js.map +7 -0
- package/models/trace/handlers/AnimationHandler.d.ts +8 -0
- package/models/trace/handlers/AnimationHandler.js +32 -0
- package/models/trace/handlers/AnimationHandler.js.map +1 -0
- package/models/trace/handlers/AuctionWorkletsHandler.d.ts +8 -0
- package/models/trace/handlers/AuctionWorkletsHandler.js +160 -0
- package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -0
- package/models/trace/handlers/FramesHandler.d.ts +76 -0
- package/models/trace/handlers/FramesHandler.js +457 -0
- package/models/trace/handlers/FramesHandler.js.map +1 -0
- package/models/trace/handlers/GPUHandler.d.ts +11 -0
- package/models/trace/handlers/GPUHandler.js +54 -0
- package/models/trace/handlers/GPUHandler.js.map +1 -0
- package/models/trace/handlers/InitiatorsHandler.d.ts +10 -0
- package/models/trace/handlers/InitiatorsHandler.js +184 -0
- package/models/trace/handlers/InitiatorsHandler.js.map +1 -0
- package/models/trace/handlers/InvalidationsHandler.d.ts +10 -0
- package/models/trace/handlers/InvalidationsHandler.js +120 -0
- package/models/trace/handlers/InvalidationsHandler.js.map +1 -0
- package/models/trace/handlers/LargestImagePaintHandler.d.ts +5 -0
- package/models/trace/handlers/LargestImagePaintHandler.js +38 -0
- package/models/trace/handlers/LargestImagePaintHandler.js.map +1 -0
- package/models/trace/handlers/LargestTextPaintHandler.d.ts +5 -0
- package/models/trace/handlers/LargestTextPaintHandler.js +26 -0
- package/models/trace/handlers/LargestTextPaintHandler.js.map +1 -0
- package/models/trace/handlers/LayerTreeHandler.d.ts +13 -0
- package/models/trace/handlers/LayerTreeHandler.js +116 -0
- package/models/trace/handlers/LayerTreeHandler.js.map +1 -0
- package/models/trace/handlers/LayoutShiftsHandler.d.ts +44 -0
- package/models/trace/handlers/LayoutShiftsHandler.js +347 -0
- package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -0
- package/models/trace/handlers/MemoryHandler.d.ts +7 -0
- package/models/trace/handlers/MemoryHandler.js +20 -0
- package/models/trace/handlers/MemoryHandler.js.map +1 -0
- package/models/trace/handlers/MetaHandler.d.ts +37 -0
- package/models/trace/handlers/MetaHandler.js +338 -0
- package/models/trace/handlers/MetaHandler.js.map +1 -0
- package/models/trace/handlers/Migration.js +27 -0
- package/models/trace/handlers/Migration.js.map +7 -0
- package/models/trace/handlers/ModelHandlers.d.ts +21 -0
- package/models/trace/handlers/ModelHandlers.js +25 -0
- package/models/trace/handlers/ModelHandlers.js.map +1 -0
- package/models/trace/handlers/NetworkRequestsHandler.d.ts +17 -0
- package/models/trace/handlers/NetworkRequestsHandler.js +361 -0
- package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -0
- package/models/trace/handlers/PageLoadMetricsHandler.d.ts +67 -0
- package/models/trace/handlers/PageLoadMetricsHandler.js +407 -0
- package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -0
- package/models/trace/handlers/RendererHandler.d.ts +101 -0
- package/models/trace/handlers/RendererHandler.js +325 -0
- package/models/trace/handlers/RendererHandler.js.map +1 -0
- package/models/trace/handlers/SamplesHandler.d.ts +46 -0
- package/models/trace/handlers/SamplesHandler.js +215 -0
- package/models/trace/handlers/SamplesHandler.js.map +1 -0
- package/models/trace/handlers/ScreenshotsHandler.d.ts +7 -0
- package/models/trace/handlers/ScreenshotsHandler.js +79 -0
- package/models/trace/handlers/ScreenshotsHandler.js.map +1 -0
- package/models/trace/handlers/Threads.d.ts +33 -0
- package/models/trace/handlers/Threads.js +95 -0
- package/models/trace/handlers/Threads.js.map +1 -0
- package/models/trace/handlers/UberFramesHandler.js +293 -0
- package/models/trace/handlers/UberFramesHandler.js.map +7 -0
- package/models/trace/handlers/UserInteractionsHandler.d.ts +57 -0
- package/models/trace/handlers/UserInteractionsHandler.js +267 -0
- package/models/trace/handlers/UserInteractionsHandler.js.map +1 -0
- package/models/trace/handlers/UserTimingsHandler.d.ts +28 -0
- package/models/trace/handlers/UserTimingsHandler.js +108 -0
- package/models/trace/handlers/UserTimingsHandler.js.map +1 -0
- package/models/trace/handlers/WarningsHandler.d.ts +14 -0
- package/models/trace/handlers/WarningsHandler.js +125 -0
- package/models/trace/handlers/WarningsHandler.js.map +1 -0
- package/models/trace/handlers/WorkersHandler.d.ts +11 -0
- package/models/trace/handlers/WorkersHandler.js +52 -0
- package/models/trace/handlers/WorkersHandler.js.map +1 -0
- package/models/trace/handlers/bundle-tsconfig.json +1 -0
- package/models/trace/handlers/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
- package/models/trace/handlers/handlers-tsconfig.json +79 -0
- package/models/trace/handlers/handlers.d.ts +3 -0
- package/models/trace/handlers/handlers.js +7 -0
- package/models/trace/handlers/handlers.js.map +1 -0
- package/models/trace/handlers/types.d.ts +45 -0
- package/models/trace/handlers/types.js +18 -0
- package/models/trace/handlers/types.js.map +1 -0
- package/models/trace/helpers/SamplesIntegrator.d.ts +49 -0
- package/models/trace/helpers/SamplesIntegrator.js +397 -0
- package/models/trace/helpers/SamplesIntegrator.js.map +1 -0
- package/models/trace/helpers/Timing.d.ts +26 -0
- package/models/trace/helpers/Timing.js +162 -0
- package/models/trace/helpers/Timing.js.map +1 -0
- package/models/trace/helpers/Trace.d.ts +37 -0
- package/models/trace/helpers/Trace.js +230 -0
- package/models/trace/helpers/Trace.js.map +1 -0
- package/models/trace/helpers/TreeHelpers.d.ts +90 -0
- package/models/trace/helpers/TreeHelpers.js +222 -0
- package/models/trace/helpers/TreeHelpers.js.map +1 -0
- package/models/trace/helpers/bundle-tsconfig.json +1 -0
- package/models/trace/helpers/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
- package/models/trace/helpers/helpers-tsconfig.json +59 -0
- package/models/trace/helpers/helpers.d.ts +4 -0
- package/models/trace/helpers/helpers.js +8 -0
- package/models/trace/helpers/helpers.js.map +1 -0
- package/models/trace/legacy-tsconfig.json +1 -0
- package/models/trace/root-causes/LayoutShift.d.ts +119 -0
- package/models/trace/root-causes/LayoutShift.js +517 -0
- package/models/trace/root-causes/LayoutShift.js.map +1 -0
- package/models/trace/root-causes/RootCauses.d.ts +14 -0
- package/models/trace/root-causes/RootCauses.js +11 -0
- package/models/trace/root-causes/RootCauses.js.map +1 -0
- package/models/trace/root-causes/bundle-tsconfig.json +1 -0
- package/models/trace/root-causes/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
- package/models/trace/root-causes/root-causes-tsconfig.json +57 -0
- package/models/trace/root-causes/root-causes.d.ts +1 -0
- package/models/trace/root-causes/root-causes.js +5 -0
- package/models/trace/root-causes/root-causes.js.map +1 -0
- package/models/trace/sdk_services/DOMNodeLookup.js +41 -0
- package/models/trace/sdk_services/DOMNodeLookup.js.map +7 -0
- package/models/trace/sdk_services/LayoutShifts.js +68 -0
- package/models/trace/sdk_services/LayoutShifts.js.map +7 -0
- package/models/trace/sdk_services/bundle-tsconfig.json +1 -0
- package/models/trace/sdk_services/devtools_entrypoint-bundle-typescript-tsconfig.json +41 -0
- package/models/trace/sdk_services/sdk_services-tsconfig.json +57 -0
- package/models/trace/sdk_services/sdk_services.js +7 -0
- package/models/trace/sdk_services/sdk_services.js.map +7 -0
- package/models/trace/trace-legacy.js +16 -0
- package/models/trace/trace-legacy.js.map +7 -0
- package/models/trace/trace-tsconfig.json +69 -0
- package/models/trace/trace.d.ts +11 -0
- package/models/trace/trace.js +17 -0
- package/models/trace/trace.js.map +1 -0
- package/models/trace/types/Configuration.d.ts +33 -0
- package/models/trace/types/Configuration.js +29 -0
- package/models/trace/types/Configuration.js.map +1 -0
- package/models/trace/types/File.d.ts +23 -0
- package/models/trace/types/File.js +5 -0
- package/models/trace/types/File.js.map +1 -0
- package/models/trace/types/Timing.d.ts +25 -0
- package/models/trace/types/Timing.js +16 -0
- package/models/trace/types/Timing.js.map +1 -0
- package/models/trace/types/TraceEvents.d.ts +1571 -0
- package/models/trace/types/TraceEvents.js +388 -0
- package/models/trace/types/TraceEvents.js.map +1 -0
- package/models/trace/types/bundle-tsconfig.json +1 -0
- package/models/trace/types/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
- package/models/trace/types/types-tsconfig.json +47 -0
- package/models/trace/types/types.d.ts +4 -0
- package/models/trace/types/types.js +8 -0
- package/models/trace/types/types.js.map +1 -0
- package/models/trace/worker/Processor.js +143 -0
- package/models/trace/worker/Processor.js.map +7 -0
- package/models/trace/worker/Types.js +1 -0
- package/models/trace/worker/Types.js.map +7 -0
- package/models/trace/worker/bundle-tsconfig.json +1 -0
- package/models/trace/worker/devtools_entrypoint-bundle-typescript-tsconfig.json +41 -0
- package/models/trace/worker/devtools_entrypoint-worker_entrypoint-typescript-tsconfig.json +41 -0
- package/models/trace/worker/processor-tsconfig.json +45 -0
- package/models/trace/worker/worker.js +7 -0
- package/models/trace/worker/worker.js.map +7 -0
- package/models/trace/worker/worker_entrypoint-tsconfig.json +1 -0
- package/models/trace/worker/worker_entrypoint.js +36 -0
- package/models/trace/worker/worker_entrypoint.js.map +7 -0
- package/package.json +2 -2
- package/TracingManager.js +0 -0
- package/extras/extras.js +0 -0
- package/trace.mjs +0 -6980
- package/trace.mjs.map +0 -8
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as Types from '../types/types.js';
|
|
2
|
+
export declare const LONG_INTERACTION_THRESHOLD: Types.Timing.MicroSeconds;
|
|
3
|
+
export interface UserInteractionsData {
|
|
4
|
+
/** All the user events we found in the trace */
|
|
5
|
+
allEvents: readonly Types.TraceEvents.TraceEventEventTiming[];
|
|
6
|
+
/** All the interaction events we found in the trace that had an
|
|
7
|
+
* interactionId and a duration > 0
|
|
8
|
+
**/
|
|
9
|
+
interactionEvents: readonly Types.TraceEvents.SyntheticInteractionPair[];
|
|
10
|
+
/** If the user rapidly generates interaction events (think typing into a
|
|
11
|
+
* text box), in the UI we only really want to show the user the longest
|
|
12
|
+
* interaction in that set.
|
|
13
|
+
* For example picture interactions like this:
|
|
14
|
+
* ===[interaction A]==========
|
|
15
|
+
* =[interaction B]======
|
|
16
|
+
* =[interaction C]=
|
|
17
|
+
*
|
|
18
|
+
* These events all end at the same time, and so in this instance we only want
|
|
19
|
+
* to show the first interaction A on the timeline, as that is the longest one
|
|
20
|
+
* and the one the developer should be focusing on. So this array of events is
|
|
21
|
+
* all the interaction events filtered down, removing any nested interactions
|
|
22
|
+
* entirely.
|
|
23
|
+
**/
|
|
24
|
+
interactionEventsWithNoNesting: readonly Types.TraceEvents.SyntheticInteractionPair[];
|
|
25
|
+
longestInteractionEvent: Readonly<Types.TraceEvents.SyntheticInteractionPair> | null;
|
|
26
|
+
interactionsOverThreshold: Readonly<Set<Types.TraceEvents.SyntheticInteractionPair>>;
|
|
27
|
+
}
|
|
28
|
+
export declare function reset(): void;
|
|
29
|
+
export declare function handleEvent(event: Types.TraceEvents.TraceEventData): void;
|
|
30
|
+
export type InteractionCategory = 'KEYBOARD' | 'POINTER' | 'OTHER';
|
|
31
|
+
export declare function categoryOfInteraction(interaction: Types.TraceEvents.SyntheticInteractionPair): InteractionCategory;
|
|
32
|
+
/**
|
|
33
|
+
* We define a set of interactions as nested where:
|
|
34
|
+
* 1. Their end times align.
|
|
35
|
+
* 2. The longest interaction's start time is earlier than all other
|
|
36
|
+
* interactions with the same end time.
|
|
37
|
+
* 3. The interactions are of the same category [each interaction is either
|
|
38
|
+
* categorised as keyboard, or pointer.]
|
|
39
|
+
*
|
|
40
|
+
* =============A=[pointerup]=
|
|
41
|
+
* ====B=[pointerdown]=
|
|
42
|
+
* ===C=[pointerdown]==
|
|
43
|
+
* ===D=[pointerup]===
|
|
44
|
+
*
|
|
45
|
+
* In this example, B, C and D are all nested and therefore should not be
|
|
46
|
+
* returned from this function.
|
|
47
|
+
*
|
|
48
|
+
* However, in this example we would only consider B nested (under A) and D
|
|
49
|
+
* nested (under C). A and C both stay because they are of different types.
|
|
50
|
+
* ========A=[keydown]====
|
|
51
|
+
* =======B=[keyup]=====
|
|
52
|
+
* ====C=[pointerdown]=
|
|
53
|
+
* =D=[pointerup]=
|
|
54
|
+
**/
|
|
55
|
+
export declare function removeNestedInteractions(interactions: readonly Types.TraceEvents.SyntheticInteractionPair[]): readonly Types.TraceEvents.SyntheticInteractionPair[];
|
|
56
|
+
export declare function finalize(): Promise<void>;
|
|
57
|
+
export declare function data(): UserInteractionsData;
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// Copyright 2022 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
import * as Helpers from '../helpers/helpers.js';
|
|
5
|
+
import * as Types from '../types/types.js';
|
|
6
|
+
// This handler serves two purposes. It generates a list of events that are
|
|
7
|
+
// used to show user clicks in the timeline. It is also used to gather
|
|
8
|
+
// EventTimings into Interactions, which we use to show interactions and
|
|
9
|
+
// highlight long interactions to the user, along with INP.
|
|
10
|
+
// We don't need to know which process / thread these events occurred in,
|
|
11
|
+
// because they are effectively global, so we just track all that we find.
|
|
12
|
+
const allEvents = [];
|
|
13
|
+
export const LONG_INTERACTION_THRESHOLD = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(200));
|
|
14
|
+
let longestInteractionEvent = null;
|
|
15
|
+
const interactionEvents = [];
|
|
16
|
+
const interactionEventsWithNoNesting = [];
|
|
17
|
+
const eventTimingEndEventsById = new Map();
|
|
18
|
+
const eventTimingStartEventsForInteractions = [];
|
|
19
|
+
let handlerState = 1 /* HandlerState.UNINITIALIZED */;
|
|
20
|
+
export function reset() {
|
|
21
|
+
allEvents.length = 0;
|
|
22
|
+
interactionEvents.length = 0;
|
|
23
|
+
eventTimingStartEventsForInteractions.length = 0;
|
|
24
|
+
eventTimingEndEventsById.clear();
|
|
25
|
+
interactionEventsWithNoNesting.length = 0;
|
|
26
|
+
longestInteractionEvent = null;
|
|
27
|
+
handlerState = 2 /* HandlerState.INITIALIZED */;
|
|
28
|
+
}
|
|
29
|
+
export function handleEvent(event) {
|
|
30
|
+
if (handlerState !== 2 /* HandlerState.INITIALIZED */) {
|
|
31
|
+
throw new Error('Handler is not initialized');
|
|
32
|
+
}
|
|
33
|
+
if (!Types.TraceEvents.isTraceEventEventTiming(event)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (Types.TraceEvents.isTraceEventEventTimingEnd(event)) {
|
|
37
|
+
// Store the end event; for each start event that is an interaction, we need the matching end event to calculate the duration correctly.
|
|
38
|
+
eventTimingEndEventsById.set(event.id, event);
|
|
39
|
+
}
|
|
40
|
+
allEvents.push(event);
|
|
41
|
+
// From this point on we want to find events that represent interactions.
|
|
42
|
+
// These events are always start events - those are the ones that contain all
|
|
43
|
+
// the metadata about the interaction.
|
|
44
|
+
if (!event.args.data || !Types.TraceEvents.isTraceEventEventTimingStart(event)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const { duration, interactionId } = event.args.data;
|
|
48
|
+
// We exclude events for the sake of interactions if:
|
|
49
|
+
// 1. They have no duration.
|
|
50
|
+
// 2. They have no interactionId
|
|
51
|
+
// 3. They have an interactionId of 0: this indicates that it's not an
|
|
52
|
+
// interaction that we care about because it hasn't had its own interactionId
|
|
53
|
+
// set (0 is the default on the backend).
|
|
54
|
+
// See: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/responsiveness_metrics.cc;l=133;drc=40c209a9c365ebb9f16fb99dfe78c7fe768b9594
|
|
55
|
+
if (duration < 1 || interactionId === undefined || interactionId === 0) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// Store the start event. In the finalize() function we will pair this with
|
|
59
|
+
// its end event and create the synthetic interaction event.
|
|
60
|
+
eventTimingStartEventsForInteractions.push(event);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* See https://web.dev/better-responsiveness-metric/#interaction-types for the
|
|
64
|
+
* table that defines these sets.
|
|
65
|
+
**/
|
|
66
|
+
const pointerEventTypes = new Set([
|
|
67
|
+
'pointerdown',
|
|
68
|
+
'touchstart',
|
|
69
|
+
'pointerup',
|
|
70
|
+
'touchend',
|
|
71
|
+
'mousedown',
|
|
72
|
+
'mouseup',
|
|
73
|
+
'click',
|
|
74
|
+
]);
|
|
75
|
+
const keyboardEventTypes = new Set([
|
|
76
|
+
'keydown',
|
|
77
|
+
'keypress',
|
|
78
|
+
'keyup',
|
|
79
|
+
]);
|
|
80
|
+
export function categoryOfInteraction(interaction) {
|
|
81
|
+
if (pointerEventTypes.has(interaction.type)) {
|
|
82
|
+
return 'POINTER';
|
|
83
|
+
}
|
|
84
|
+
if (keyboardEventTypes.has(interaction.type)) {
|
|
85
|
+
return 'KEYBOARD';
|
|
86
|
+
}
|
|
87
|
+
return 'OTHER';
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* We define a set of interactions as nested where:
|
|
91
|
+
* 1. Their end times align.
|
|
92
|
+
* 2. The longest interaction's start time is earlier than all other
|
|
93
|
+
* interactions with the same end time.
|
|
94
|
+
* 3. The interactions are of the same category [each interaction is either
|
|
95
|
+
* categorised as keyboard, or pointer.]
|
|
96
|
+
*
|
|
97
|
+
* =============A=[pointerup]=
|
|
98
|
+
* ====B=[pointerdown]=
|
|
99
|
+
* ===C=[pointerdown]==
|
|
100
|
+
* ===D=[pointerup]===
|
|
101
|
+
*
|
|
102
|
+
* In this example, B, C and D are all nested and therefore should not be
|
|
103
|
+
* returned from this function.
|
|
104
|
+
*
|
|
105
|
+
* However, in this example we would only consider B nested (under A) and D
|
|
106
|
+
* nested (under C). A and C both stay because they are of different types.
|
|
107
|
+
* ========A=[keydown]====
|
|
108
|
+
* =======B=[keyup]=====
|
|
109
|
+
* ====C=[pointerdown]=
|
|
110
|
+
* =D=[pointerup]=
|
|
111
|
+
**/
|
|
112
|
+
export function removeNestedInteractions(interactions) {
|
|
113
|
+
/**
|
|
114
|
+
* Because we nest events only that are in the same category, we store the
|
|
115
|
+
* longest event for a given end time by category.
|
|
116
|
+
**/
|
|
117
|
+
const earliestEventForEndTimePerCategory = {
|
|
118
|
+
POINTER: new Map(),
|
|
119
|
+
KEYBOARD: new Map(),
|
|
120
|
+
OTHER: new Map(),
|
|
121
|
+
};
|
|
122
|
+
function storeEventIfEarliestForCategoryAndEndTime(interaction) {
|
|
123
|
+
const category = categoryOfInteraction(interaction);
|
|
124
|
+
const earliestEventForEndTime = earliestEventForEndTimePerCategory[category];
|
|
125
|
+
const endTime = Types.Timing.MicroSeconds(interaction.ts + interaction.dur);
|
|
126
|
+
const earliestCurrentEvent = earliestEventForEndTime.get(endTime);
|
|
127
|
+
if (!earliestCurrentEvent) {
|
|
128
|
+
earliestEventForEndTime.set(endTime, interaction);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (interaction.ts < earliestCurrentEvent.ts) {
|
|
132
|
+
earliestEventForEndTime.set(endTime, interaction);
|
|
133
|
+
}
|
|
134
|
+
else if (interaction.ts === earliestCurrentEvent.ts &&
|
|
135
|
+
interaction.interactionId === earliestCurrentEvent.interactionId) {
|
|
136
|
+
// We have seen in traces that the same interaction can have multiple
|
|
137
|
+
// events (e.g. a 'click' and a 'pointerdown'). Often only one of these
|
|
138
|
+
// events will have an event handler bound to it which caused delay on
|
|
139
|
+
// the main thread, and the others will not. This leads to a situation
|
|
140
|
+
// where if we pick one of the events that had no event handler, its
|
|
141
|
+
// processing time (processingEnd - processingStart) will be 0, but if we
|
|
142
|
+
// had picked the event that had the slow event handler, we would show
|
|
143
|
+
// correctly the main thread delay due to the event handler.
|
|
144
|
+
// So, if we find events with the same interactionId and the same
|
|
145
|
+
// begin/end times, we pick the one with the largest (processingEnd -
|
|
146
|
+
// processingStart) time in order to make sure we find the event with the
|
|
147
|
+
// worst main thread delay, as that is the one the user should care
|
|
148
|
+
// about.
|
|
149
|
+
const currentEventProcessingTime = earliestCurrentEvent.processingEnd - earliestCurrentEvent.processingStart;
|
|
150
|
+
const newEventProcessingTime = interaction.processingEnd - interaction.processingStart;
|
|
151
|
+
// Use the new interaction if it has a longer processing time than the existing one.
|
|
152
|
+
if (newEventProcessingTime > currentEventProcessingTime) {
|
|
153
|
+
earliestEventForEndTime.set(endTime, interaction);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Maximize the processing time based on the "children" interactions.
|
|
157
|
+
// We pick the earliest start processing time, and the latest end
|
|
158
|
+
// processing time to avoid under-reporting.
|
|
159
|
+
if (interaction.processingStart < earliestCurrentEvent.processingStart) {
|
|
160
|
+
earliestCurrentEvent.processingStart = interaction.processingStart;
|
|
161
|
+
writeSyntheticTimespans(earliestCurrentEvent);
|
|
162
|
+
}
|
|
163
|
+
if (interaction.processingEnd > earliestCurrentEvent.processingEnd) {
|
|
164
|
+
earliestCurrentEvent.processingEnd = interaction.processingEnd;
|
|
165
|
+
writeSyntheticTimespans(earliestCurrentEvent);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
for (const interaction of interactions) {
|
|
169
|
+
storeEventIfEarliestForCategoryAndEndTime(interaction);
|
|
170
|
+
}
|
|
171
|
+
// Combine all the events that we have kept from all the per-category event
|
|
172
|
+
// maps back into an array and sort them by timestamp.
|
|
173
|
+
const keptEvents = Object.values(earliestEventForEndTimePerCategory)
|
|
174
|
+
.flatMap(eventsByEndTime => Array.from(eventsByEndTime.values()));
|
|
175
|
+
keptEvents.sort((eventA, eventB) => {
|
|
176
|
+
return eventA.ts - eventB.ts;
|
|
177
|
+
});
|
|
178
|
+
return keptEvents;
|
|
179
|
+
}
|
|
180
|
+
function writeSyntheticTimespans(event) {
|
|
181
|
+
const startEvent = event.args.data.beginEvent;
|
|
182
|
+
const endEvent = event.args.data.endEvent;
|
|
183
|
+
event.inputDelay = Types.Timing.MicroSeconds(event.processingStart - startEvent.ts);
|
|
184
|
+
event.mainThreadHandling = Types.Timing.MicroSeconds(event.processingEnd - event.processingStart);
|
|
185
|
+
event.presentationDelay = Types.Timing.MicroSeconds(endEvent.ts - event.processingEnd);
|
|
186
|
+
}
|
|
187
|
+
export async function finalize() {
|
|
188
|
+
// For each interaction start event, find the async end event by the ID, and then create the Synthetic Interaction event.
|
|
189
|
+
for (const interactionStartEvent of eventTimingStartEventsForInteractions) {
|
|
190
|
+
const endEvent = eventTimingEndEventsById.get(interactionStartEvent.id);
|
|
191
|
+
if (!endEvent) {
|
|
192
|
+
// If we cannot find an end event, bail and drop this event.
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (!interactionStartEvent.args.data?.type || !interactionStartEvent.args.data?.interactionId) {
|
|
196
|
+
// A valid interaction event that we care about has to have a type (e.g.
|
|
197
|
+
// pointerdown, keyup).
|
|
198
|
+
//
|
|
199
|
+
// We also need to ensure it has an interactionId. We already checked
|
|
200
|
+
// this in the handleEvent() function, but we do it here also to satisfy
|
|
201
|
+
// TypeScript.
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
// In the future we will add microsecond timestamps to the trace events,
|
|
205
|
+
// but until then we can use the millisecond precision values that are in
|
|
206
|
+
// the trace event. To adjust them to be relative to the event.ts and the
|
|
207
|
+
// trace timestamps, for both processingStart and processingEnd we subtract
|
|
208
|
+
// the event timestamp (NOT event.ts, but the timeStamp millisecond value
|
|
209
|
+
// emitted in args.data), and then add that value to the event.ts. This
|
|
210
|
+
// will give us a processingStart and processingEnd time in microseconds
|
|
211
|
+
// that is relative to event.ts, and can be used when drawing boxes.
|
|
212
|
+
// There is some inaccuracy here as we are converting milliseconds to microseconds, but it is good enough until the backend emits more accurate numbers.
|
|
213
|
+
const processingStartRelativeToTraceTime = Types.Timing.MicroSeconds(Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.processingStart) -
|
|
214
|
+
Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.timeStamp) +
|
|
215
|
+
interactionStartEvent.ts);
|
|
216
|
+
const processingEndRelativeToTraceTime = Types.Timing.MicroSeconds((Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.processingEnd) -
|
|
217
|
+
Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.timeStamp)) +
|
|
218
|
+
interactionStartEvent.ts);
|
|
219
|
+
const interactionEvent = {
|
|
220
|
+
// Use the start event to define the common fields.
|
|
221
|
+
cat: interactionStartEvent.cat,
|
|
222
|
+
name: interactionStartEvent.name,
|
|
223
|
+
pid: interactionStartEvent.pid,
|
|
224
|
+
tid: interactionStartEvent.tid,
|
|
225
|
+
ph: interactionStartEvent.ph,
|
|
226
|
+
processingStart: processingStartRelativeToTraceTime,
|
|
227
|
+
processingEnd: processingEndRelativeToTraceTime,
|
|
228
|
+
// These will be set in writeSyntheticTimespans()
|
|
229
|
+
inputDelay: Types.Timing.MicroSeconds(-1),
|
|
230
|
+
mainThreadHandling: Types.Timing.MicroSeconds(-1),
|
|
231
|
+
presentationDelay: Types.Timing.MicroSeconds(-1),
|
|
232
|
+
args: {
|
|
233
|
+
data: {
|
|
234
|
+
beginEvent: interactionStartEvent,
|
|
235
|
+
endEvent: endEvent,
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
ts: interactionStartEvent.ts,
|
|
239
|
+
dur: Types.Timing.MicroSeconds(endEvent.ts - interactionStartEvent.ts),
|
|
240
|
+
type: interactionStartEvent.args.data.type,
|
|
241
|
+
interactionId: interactionStartEvent.args.data.interactionId,
|
|
242
|
+
};
|
|
243
|
+
writeSyntheticTimespans(interactionEvent);
|
|
244
|
+
interactionEvents.push(interactionEvent);
|
|
245
|
+
}
|
|
246
|
+
handlerState = 3 /* HandlerState.FINALIZED */;
|
|
247
|
+
interactionEventsWithNoNesting.push(...removeNestedInteractions(interactionEvents));
|
|
248
|
+
// Pick the longest interactions from the set that were not nested, as we
|
|
249
|
+
// know those are the set of the largest interactions.
|
|
250
|
+
for (const interactionEvent of interactionEventsWithNoNesting) {
|
|
251
|
+
if (!longestInteractionEvent || longestInteractionEvent.dur < interactionEvent.dur) {
|
|
252
|
+
longestInteractionEvent = interactionEvent;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
export function data() {
|
|
257
|
+
return {
|
|
258
|
+
allEvents: [...allEvents],
|
|
259
|
+
interactionEvents: [...interactionEvents],
|
|
260
|
+
interactionEventsWithNoNesting: [...interactionEventsWithNoNesting],
|
|
261
|
+
longestInteractionEvent,
|
|
262
|
+
interactionsOverThreshold: new Set(interactionEvents.filter(event => {
|
|
263
|
+
return event.dur > LONG_INTERACTION_THRESHOLD;
|
|
264
|
+
})),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=UserInteractionsHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserInteractionsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/UserInteractionsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAI3C,2EAA2E;AAC3E,sEAAsE;AACtE,wEAAwE;AACxE,2DAA2D;AAE3D,yEAAyE;AACzE,0EAA0E;AAC1E,MAAM,SAAS,GAA8C,EAAE,CAAC;AAEhE,MAAM,CAAC,MAAM,0BAA0B,GAAG,OAAO,CAAC,MAAM,CAAC,0BAA0B,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;AA8BpH,IAAI,uBAAuB,GAAoD,IAAI,CAAC;AAEpF,MAAM,iBAAiB,GAAiD,EAAE,CAAC;AAC3E,MAAM,8BAA8B,GAAiD,EAAE,CAAC;AACxF,MAAM,wBAAwB,GAAG,IAAI,GAAG,EAAsD,CAAC;AAC/F,MAAM,qCA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AC,GAAG,8BAA8B,CAAC;QACnE,uBAAuB;QACvB,yBAAyB,EAAE,IAAI,GAAG,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YAClE,OAAO,KAAK,CAAC,GAAG,GAAG,0BAA0B,CAAC;QAChD,CAAC,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2022 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {HandlerState} from './types.js';\n\n// This handler serves two purposes. It generates a list of events that are\n// used to show user clicks in the timeline. It is also used to gather\n// EventTimings into Interactions, which we use to show interactions and\n// highlight long interactions to the user, along with INP.\n\n// We don't need to know which process / thread these events occurred in,\n// because they are effectively global, so we just track all that we find.\nconst allEvents: Types.TraceEvents.TraceEventEventTiming[] = [];\n\nexport const LONG_INTERACTION_THRESHOLD = Helpers.Timing.millisecondsToMicroseconds(Types.Timing.MilliSeconds(200));\n\nexport interface UserInteractionsData {\n /** All the user events we found in the trace */\n allEvents: readonly Types.TraceEvents.TraceEventEventTiming[];\n /** All the interaction events we found in the trace that had an\n * interactionId and a duration > 0\n **/\n interactionEvents: readonly Types.TraceEvents.SyntheticInteractionPair[];\n /** If the user rapidly generates interaction events (think typing into a\n * text box), in the UI we only really want to show the user the longest\n * interaction in that set.\n * For example picture interactions like this:\n * ===[interaction A]==========\n * =[interaction B]======\n * =[interaction C]=\n *\n * These events all end at the same time, and so in this instance we only want\n * to show the first interaction A on the timeline, as that is the longest one\n * and the one the developer should be focusing on. So this array of events is\n * all the interaction events filtered down, removing any nested interactions\n * entirely.\n **/\n interactionEventsWithNoNesting: readonly Types.TraceEvents.SyntheticInteractionPair[];\n // The longest duration interaction event. Can be null if the trace has no interaction events.\n longestInteractionEvent: Readonly<Types.TraceEvents.SyntheticInteractionPair>|null;\n // All interactions that went over the interaction threshold (200ms, see https://web.dev/inp/)\n interactionsOverThreshold: Readonly<Set<Types.TraceEvents.SyntheticInteractionPair>>;\n}\n\nlet longestInteractionEvent: Types.TraceEvents.SyntheticInteractionPair|null = null;\n\nconst interactionEvents: Types.TraceEvents.SyntheticInteractionPair[] = [];\nconst interactionEventsWithNoNesting: Types.TraceEvents.SyntheticInteractionPair[] = [];\nconst eventTimingEndEventsById = new Map<string, Types.TraceEvents.TraceEventEventTimingEnd>();\nconst eventTimingStartEventsForInteractions: Types.TraceEvents.TraceEventEventTimingBegin[] = [];\nlet handlerState = HandlerState.UNINITIALIZED;\n\nexport function reset(): void {\n allEvents.length = 0;\n interactionEvents.length = 0;\n eventTimingStartEventsForInteractions.length = 0;\n eventTimingEndEventsById.clear();\n interactionEventsWithNoNesting.length = 0;\n longestInteractionEvent = null;\n handlerState = HandlerState.INITIALIZED;\n}\n\nexport function handleEvent(event: Types.TraceEvents.TraceEventData): void {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('Handler is not initialized');\n }\n\n if (!Types.TraceEvents.isTraceEventEventTiming(event)) {\n return;\n }\n\n if (Types.TraceEvents.isTraceEventEventTimingEnd(event)) {\n // Store the end event; for each start event that is an interaction, we need the matching end event to calculate the duration correctly.\n eventTimingEndEventsById.set(event.id, event);\n }\n\n allEvents.push(event);\n\n // From this point on we want to find events that represent interactions.\n // These events are always start events - those are the ones that contain all\n // the metadata about the interaction.\n if (!event.args.data || !Types.TraceEvents.isTraceEventEventTimingStart(event)) {\n return;\n }\n const {duration, interactionId} = event.args.data;\n // We exclude events for the sake of interactions if:\n // 1. They have no duration.\n // 2. They have no interactionId\n // 3. They have an interactionId of 0: this indicates that it's not an\n // interaction that we care about because it hasn't had its own interactionId\n // set (0 is the default on the backend).\n // See: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/timing/responsiveness_metrics.cc;l=133;drc=40c209a9c365ebb9f16fb99dfe78c7fe768b9594\n\n if (duration < 1 || interactionId === undefined || interactionId === 0) {\n return;\n }\n\n // Store the start event. In the finalize() function we will pair this with\n // its end event and create the synthetic interaction event.\n eventTimingStartEventsForInteractions.push(event);\n}\n\n/**\n * See https://web.dev/better-responsiveness-metric/#interaction-types for the\n * table that defines these sets.\n **/\nconst pointerEventTypes = new Set([\n 'pointerdown',\n 'touchstart',\n 'pointerup',\n 'touchend',\n 'mousedown',\n 'mouseup',\n 'click',\n]);\n\nconst keyboardEventTypes = new Set([\n 'keydown',\n 'keypress',\n 'keyup',\n]);\n\nexport type InteractionCategory = 'KEYBOARD'|'POINTER'|'OTHER';\nexport function categoryOfInteraction(interaction: Types.TraceEvents.SyntheticInteractionPair): InteractionCategory {\n if (pointerEventTypes.has(interaction.type)) {\n return 'POINTER';\n }\n if (keyboardEventTypes.has(interaction.type)) {\n return 'KEYBOARD';\n }\n\n return 'OTHER';\n}\n\n/**\n * We define a set of interactions as nested where:\n * 1. Their end times align.\n * 2. The longest interaction's start time is earlier than all other\n * interactions with the same end time.\n * 3. The interactions are of the same category [each interaction is either\n * categorised as keyboard, or pointer.]\n *\n * =============A=[pointerup]=\n * ====B=[pointerdown]=\n * ===C=[pointerdown]==\n * ===D=[pointerup]===\n *\n * In this example, B, C and D are all nested and therefore should not be\n * returned from this function.\n *\n * However, in this example we would only consider B nested (under A) and D\n * nested (under C). A and C both stay because they are of different types.\n * ========A=[keydown]====\n * =======B=[keyup]=====\n * ====C=[pointerdown]=\n * =D=[pointerup]=\n **/\nexport function removeNestedInteractions(interactions: readonly Types.TraceEvents.SyntheticInteractionPair[]):\n readonly Types.TraceEvents.SyntheticInteractionPair[] {\n /**\n * Because we nest events only that are in the same category, we store the\n * longest event for a given end time by category.\n **/\n const earliestEventForEndTimePerCategory:\n Record<InteractionCategory, Map<Types.Timing.MicroSeconds, Types.TraceEvents.SyntheticInteractionPair>> = {\n POINTER: new Map(),\n KEYBOARD: new Map(),\n OTHER: new Map(),\n };\n\n function storeEventIfEarliestForCategoryAndEndTime(interaction: Types.TraceEvents.SyntheticInteractionPair): void {\n const category = categoryOfInteraction(interaction);\n const earliestEventForEndTime = earliestEventForEndTimePerCategory[category];\n const endTime = Types.Timing.MicroSeconds(interaction.ts + interaction.dur);\n\n const earliestCurrentEvent = earliestEventForEndTime.get(endTime);\n if (!earliestCurrentEvent) {\n earliestEventForEndTime.set(endTime, interaction);\n return;\n }\n if (interaction.ts < earliestCurrentEvent.ts) {\n earliestEventForEndTime.set(endTime, interaction);\n } else if (\n interaction.ts === earliestCurrentEvent.ts &&\n interaction.interactionId === earliestCurrentEvent.interactionId) {\n // We have seen in traces that the same interaction can have multiple\n // events (e.g. a 'click' and a 'pointerdown'). Often only one of these\n // events will have an event handler bound to it which caused delay on\n // the main thread, and the others will not. This leads to a situation\n // where if we pick one of the events that had no event handler, its\n // processing time (processingEnd - processingStart) will be 0, but if we\n // had picked the event that had the slow event handler, we would show\n // correctly the main thread delay due to the event handler.\n // So, if we find events with the same interactionId and the same\n // begin/end times, we pick the one with the largest (processingEnd -\n // processingStart) time in order to make sure we find the event with the\n // worst main thread delay, as that is the one the user should care\n // about.\n const currentEventProcessingTime = earliestCurrentEvent.processingEnd - earliestCurrentEvent.processingStart;\n const newEventProcessingTime = interaction.processingEnd - interaction.processingStart;\n\n // Use the new interaction if it has a longer processing time than the existing one.\n if (newEventProcessingTime > currentEventProcessingTime) {\n earliestEventForEndTime.set(endTime, interaction);\n }\n }\n\n // Maximize the processing time based on the \"children\" interactions.\n // We pick the earliest start processing time, and the latest end\n // processing time to avoid under-reporting.\n if (interaction.processingStart < earliestCurrentEvent.processingStart) {\n earliestCurrentEvent.processingStart = interaction.processingStart;\n writeSyntheticTimespans(earliestCurrentEvent);\n }\n if (interaction.processingEnd > earliestCurrentEvent.processingEnd) {\n earliestCurrentEvent.processingEnd = interaction.processingEnd;\n writeSyntheticTimespans(earliestCurrentEvent);\n }\n }\n\n for (const interaction of interactions) {\n storeEventIfEarliestForCategoryAndEndTime(interaction);\n }\n\n // Combine all the events that we have kept from all the per-category event\n // maps back into an array and sort them by timestamp.\n const keptEvents = Object.values(earliestEventForEndTimePerCategory)\n .flatMap(eventsByEndTime => Array.from(eventsByEndTime.values()));\n keptEvents.sort((eventA, eventB) => {\n return eventA.ts - eventB.ts;\n });\n return keptEvents;\n}\n\nfunction writeSyntheticTimespans(event: Types.TraceEvents.SyntheticInteractionPair): void {\n const startEvent = event.args.data.beginEvent;\n const endEvent = event.args.data.endEvent;\n\n event.inputDelay = Types.Timing.MicroSeconds(event.processingStart - startEvent.ts);\n event.mainThreadHandling = Types.Timing.MicroSeconds(event.processingEnd - event.processingStart);\n event.presentationDelay = Types.Timing.MicroSeconds(endEvent.ts - event.processingEnd);\n}\n\nexport async function finalize(): Promise<void> {\n // For each interaction start event, find the async end event by the ID, and then create the Synthetic Interaction event.\n for (const interactionStartEvent of eventTimingStartEventsForInteractions) {\n const endEvent = eventTimingEndEventsById.get(interactionStartEvent.id);\n if (!endEvent) {\n // If we cannot find an end event, bail and drop this event.\n continue;\n }\n if (!interactionStartEvent.args.data?.type || !interactionStartEvent.args.data?.interactionId) {\n // A valid interaction event that we care about has to have a type (e.g.\n // pointerdown, keyup).\n //\n // We also need to ensure it has an interactionId. We already checked\n // this in the handleEvent() function, but we do it here also to satisfy\n // TypeScript.\n continue;\n }\n\n // In the future we will add microsecond timestamps to the trace events,\n // but until then we can use the millisecond precision values that are in\n // the trace event. To adjust them to be relative to the event.ts and the\n // trace timestamps, for both processingStart and processingEnd we subtract\n // the event timestamp (NOT event.ts, but the timeStamp millisecond value\n // emitted in args.data), and then add that value to the event.ts. This\n // will give us a processingStart and processingEnd time in microseconds\n // that is relative to event.ts, and can be used when drawing boxes.\n // There is some inaccuracy here as we are converting milliseconds to microseconds, but it is good enough until the backend emits more accurate numbers.\n const processingStartRelativeToTraceTime = Types.Timing.MicroSeconds(\n Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.processingStart) -\n Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.timeStamp) +\n interactionStartEvent.ts,\n );\n\n const processingEndRelativeToTraceTime = Types.Timing.MicroSeconds(\n (Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.processingEnd) -\n Helpers.Timing.millisecondsToMicroseconds(interactionStartEvent.args.data.timeStamp)) +\n interactionStartEvent.ts);\n\n const interactionEvent: Types.TraceEvents.SyntheticInteractionPair = {\n // Use the start event to define the common fields.\n cat: interactionStartEvent.cat,\n name: interactionStartEvent.name,\n pid: interactionStartEvent.pid,\n tid: interactionStartEvent.tid,\n ph: interactionStartEvent.ph,\n processingStart: processingStartRelativeToTraceTime,\n processingEnd: processingEndRelativeToTraceTime,\n // These will be set in writeSyntheticTimespans()\n inputDelay: Types.Timing.MicroSeconds(-1),\n mainThreadHandling: Types.Timing.MicroSeconds(-1),\n presentationDelay: Types.Timing.MicroSeconds(-1),\n args: {\n data: {\n beginEvent: interactionStartEvent,\n endEvent: endEvent,\n },\n },\n ts: interactionStartEvent.ts,\n dur: Types.Timing.MicroSeconds(endEvent.ts - interactionStartEvent.ts),\n type: interactionStartEvent.args.data.type,\n interactionId: interactionStartEvent.args.data.interactionId,\n };\n writeSyntheticTimespans(interactionEvent);\n\n interactionEvents.push(interactionEvent);\n }\n\n handlerState = HandlerState.FINALIZED;\n interactionEventsWithNoNesting.push(...removeNestedInteractions(interactionEvents));\n\n // Pick the longest interactions from the set that were not nested, as we\n // know those are the set of the largest interactions.\n for (const interactionEvent of interactionEventsWithNoNesting) {\n if (!longestInteractionEvent || longestInteractionEvent.dur < interactionEvent.dur) {\n longestInteractionEvent = interactionEvent;\n }\n }\n}\n\nexport function data(): UserInteractionsData {\n return {\n allEvents: [...allEvents],\n interactionEvents: [...interactionEvents],\n interactionEventsWithNoNesting: [...interactionEventsWithNoNesting],\n longestInteractionEvent,\n interactionsOverThreshold: new Set(interactionEvents.filter(event => {\n return event.dur > LONG_INTERACTION_THRESHOLD;\n })),\n };\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as Types from '../types/types.js';
|
|
2
|
+
export interface UserTimingsData {
|
|
3
|
+
/**
|
|
4
|
+
* Events triggered with the performance.measure() API.
|
|
5
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure
|
|
6
|
+
*/
|
|
7
|
+
performanceMeasures: readonly Types.TraceEvents.SyntheticUserTimingPair[];
|
|
8
|
+
/**
|
|
9
|
+
* Events triggered with the performance.mark() API.
|
|
10
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark
|
|
11
|
+
*/
|
|
12
|
+
performanceMarks: readonly Types.TraceEvents.TraceEventPerformanceMark[];
|
|
13
|
+
/**
|
|
14
|
+
* Events triggered with the console.time(), console.timeEnd() and
|
|
15
|
+
* console.timeLog() API.
|
|
16
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/console/time
|
|
17
|
+
*/
|
|
18
|
+
consoleTimings: readonly Types.TraceEvents.SyntheticConsoleTimingPair[];
|
|
19
|
+
/**
|
|
20
|
+
* Events triggered with the console.timeStamp() API
|
|
21
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/console/timeStamp
|
|
22
|
+
*/
|
|
23
|
+
timestampEvents: readonly Types.TraceEvents.TraceEventTimeStamp[];
|
|
24
|
+
}
|
|
25
|
+
export declare function reset(): void;
|
|
26
|
+
export declare function handleEvent(event: Types.TraceEvents.TraceEventData): void;
|
|
27
|
+
export declare function finalize(): Promise<void>;
|
|
28
|
+
export declare function data(): UserTimingsData;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Copyright 2022 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
import * as Helpers from '../helpers/helpers.js';
|
|
5
|
+
import * as Types from '../types/types.js';
|
|
6
|
+
/**
|
|
7
|
+
* IMPORTANT!
|
|
8
|
+
* See UserTimings.md in this directory for some handy documentation on
|
|
9
|
+
* UserTimings and the trace events we parse currently.
|
|
10
|
+
**/
|
|
11
|
+
let syntheticEvents = [];
|
|
12
|
+
const performanceMeasureEvents = [];
|
|
13
|
+
const performanceMarkEvents = [];
|
|
14
|
+
const consoleTimings = [];
|
|
15
|
+
const timestampEvents = [];
|
|
16
|
+
let handlerState = 1 /* HandlerState.UNINITIALIZED */;
|
|
17
|
+
export function reset() {
|
|
18
|
+
syntheticEvents.length = 0;
|
|
19
|
+
performanceMeasureEvents.length = 0;
|
|
20
|
+
performanceMarkEvents.length = 0;
|
|
21
|
+
consoleTimings.length = 0;
|
|
22
|
+
timestampEvents.length = 0;
|
|
23
|
+
handlerState = 2 /* HandlerState.INITIALIZED */;
|
|
24
|
+
}
|
|
25
|
+
const resourceTimingNames = [
|
|
26
|
+
'workerStart',
|
|
27
|
+
'redirectStart',
|
|
28
|
+
'redirectEnd',
|
|
29
|
+
'fetchStart',
|
|
30
|
+
'domainLookupStart',
|
|
31
|
+
'domainLookupEnd',
|
|
32
|
+
'connectStart',
|
|
33
|
+
'connectEnd',
|
|
34
|
+
'secureConnectionStart',
|
|
35
|
+
'requestStart',
|
|
36
|
+
'responseStart',
|
|
37
|
+
'responseEnd',
|
|
38
|
+
];
|
|
39
|
+
const navTimingNames = [
|
|
40
|
+
'navigationStart',
|
|
41
|
+
'unloadEventStart',
|
|
42
|
+
'unloadEventEnd',
|
|
43
|
+
'redirectStart',
|
|
44
|
+
'redirectEnd',
|
|
45
|
+
'fetchStart',
|
|
46
|
+
'commitNavigationEnd',
|
|
47
|
+
'domainLookupStart',
|
|
48
|
+
'domainLookupEnd',
|
|
49
|
+
'connectStart',
|
|
50
|
+
'connectEnd',
|
|
51
|
+
'secureConnectionStart',
|
|
52
|
+
'requestStart',
|
|
53
|
+
'responseStart',
|
|
54
|
+
'responseEnd',
|
|
55
|
+
'domLoading',
|
|
56
|
+
'domInteractive',
|
|
57
|
+
'domContentLoadedEventStart',
|
|
58
|
+
'domContentLoadedEventEnd',
|
|
59
|
+
'domComplete',
|
|
60
|
+
'loadEventStart',
|
|
61
|
+
'loadEventEnd',
|
|
62
|
+
];
|
|
63
|
+
export function handleEvent(event) {
|
|
64
|
+
if (handlerState !== 2 /* HandlerState.INITIALIZED */) {
|
|
65
|
+
throw new Error('UserTimings handler is not initialized');
|
|
66
|
+
}
|
|
67
|
+
// These are events dispatched under the blink.user_timing category
|
|
68
|
+
// but that the user didn't add. Filter them out so that they do not
|
|
69
|
+
// Appear in the timings track (they still appear in the main thread
|
|
70
|
+
// flame chart).
|
|
71
|
+
const ignoredNames = [...resourceTimingNames, ...navTimingNames];
|
|
72
|
+
if (ignoredNames.includes(event.name)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (Types.TraceEvents.isTraceEventPerformanceMeasure(event)) {
|
|
76
|
+
performanceMeasureEvents.push(event);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (Types.TraceEvents.isTraceEventPerformanceMark(event)) {
|
|
80
|
+
performanceMarkEvents.push(event);
|
|
81
|
+
}
|
|
82
|
+
if (Types.TraceEvents.isTraceEventConsoleTime(event)) {
|
|
83
|
+
consoleTimings.push(event);
|
|
84
|
+
}
|
|
85
|
+
if (Types.TraceEvents.isTraceEventTimeStamp(event)) {
|
|
86
|
+
timestampEvents.push(event);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export async function finalize() {
|
|
90
|
+
if (handlerState !== 2 /* HandlerState.INITIALIZED */) {
|
|
91
|
+
throw new Error('UserTimings handler is not initialized');
|
|
92
|
+
}
|
|
93
|
+
const asyncEvents = [...performanceMeasureEvents, ...consoleTimings];
|
|
94
|
+
syntheticEvents = Helpers.Trace.createMatchedSortedSyntheticEvents(asyncEvents);
|
|
95
|
+
handlerState = 3 /* HandlerState.FINALIZED */;
|
|
96
|
+
}
|
|
97
|
+
export function data() {
|
|
98
|
+
if (handlerState !== 3 /* HandlerState.FINALIZED */) {
|
|
99
|
+
throw new Error('UserTimings handler is not finalized');
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
performanceMeasures: syntheticEvents.filter(e => e.cat === 'blink.user_timing'),
|
|
103
|
+
consoleTimings: syntheticEvents.filter(e => e.cat === 'blink.console'),
|
|
104
|
+
performanceMarks: [...performanceMarkEvents],
|
|
105
|
+
timestampEvents: [...timestampEvents],
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=UserTimingsHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserTimingsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/UserTimingsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAI3C;;;;IAII;AACJ,IAAI,eAAe,GAAsF,EAAE,CAAC;AAC5G,MAAM,wBAAwB,GAAqD,EAAE,CAAC;AACtF,MAAM,qBAAqB,GAAkD,EAAE,CAAC;AAEhF,MAAM,cAAc,GAAgG,EAAE,CAAC;AAEvH,MAAM,eAAe,GAA4C,EAAE,CAAC;AAyBpE,IAAI,YAAY,qCAA6B,CAAC;AAE9C,MAAM,UAAU,KAAK;IACnB,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,wBAAwB,CAAC,MAAM,GAAG,CAAC,CAAC;IACpC,qBAAqB,CAAC,MAAM,GAAG,CAAC,CAAC;IACjC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1B,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,YAAY,mCAA2B,CAAC;AAC1C,CAAC;AAED,MAAM,mBAAmB,GAAG;IAC1B,aAAa;IACb,eAAe;IACf,aAAa;IACb,YAAY;IACZ,mBAAmB;IACnB,iBAAiB;IACjB,cAAc;IACd,YAAY;IACZ,uBAAuB;IACvB,cAAc;IACd,eAAe;IACf,aAAa;CACd,CAAC;AACF,MAAM,cAAc,GAAG;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,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC3D;IAED,MAAM,WAAW,GAAG,CAAC,GAAG,wBAAwB,EAAE,GAAG,cAAc,CAAC,CAAC;IACrE,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,kCAAkC,CAAC,WAAW,CAAC,CAAC;IAChF,YAAY,iCAAyB,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,IAAI,YAAY,mCAA2B,EAAE;QAC3C,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;KACzD;IAED,OAAO;QACL,mBAAmB,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,mBAAmB,CAC/B;QAC/C,cAAc,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,eAAe,CACnB;QAClD,gBAAgB,EAAE,CAAC,GAAG,qBAAqB,CAAC;QAC5C,eAAe,EAAE,CAAC,GAAG,eAAe,CAAC;KACtC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2022 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {HandlerState} from './types.js';\n\n/**\n * IMPORTANT!\n * See UserTimings.md in this directory for some handy documentation on\n * UserTimings and the trace events we parse currently.\n **/\nlet syntheticEvents: Types.TraceEvents.SyntheticEventPair<Types.TraceEvents.TraceEventPairableAsync>[] = [];\nconst performanceMeasureEvents: Types.TraceEvents.TraceEventPerformanceMeasure[] = [];\nconst performanceMarkEvents: Types.TraceEvents.TraceEventPerformanceMark[] = [];\n\nconst consoleTimings: (Types.TraceEvents.TraceEventConsoleTimeBegin|Types.TraceEvents.TraceEventConsoleTimeEnd)[] = [];\n\nconst timestampEvents: Types.TraceEvents.TraceEventTimeStamp[] = [];\n\nexport interface UserTimingsData {\n /**\n * Events triggered with the performance.measure() API.\n * https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure\n */\n performanceMeasures: readonly Types.TraceEvents.SyntheticUserTimingPair[];\n /**\n * Events triggered with the performance.mark() API.\n * https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark\n */\n performanceMarks: readonly Types.TraceEvents.TraceEventPerformanceMark[];\n /**\n * Events triggered with the console.time(), console.timeEnd() and\n * console.timeLog() API.\n * https://developer.mozilla.org/en-US/docs/Web/API/console/time\n */\n consoleTimings: readonly Types.TraceEvents.SyntheticConsoleTimingPair[];\n /**\n * Events triggered with the console.timeStamp() API\n * https://developer.mozilla.org/en-US/docs/Web/API/console/timeStamp\n */\n timestampEvents: readonly Types.TraceEvents.TraceEventTimeStamp[];\n}\nlet handlerState = HandlerState.UNINITIALIZED;\n\nexport function reset(): void {\n syntheticEvents.length = 0;\n performanceMeasureEvents.length = 0;\n performanceMarkEvents.length = 0;\n consoleTimings.length = 0;\n timestampEvents.length = 0;\n handlerState = HandlerState.INITIALIZED;\n}\n\nconst resourceTimingNames = [\n 'workerStart',\n 'redirectStart',\n 'redirectEnd',\n 'fetchStart',\n 'domainLookupStart',\n 'domainLookupEnd',\n 'connectStart',\n 'connectEnd',\n 'secureConnectionStart',\n 'requestStart',\n 'responseStart',\n 'responseEnd',\n];\nconst navTimingNames = [\n 'navigationStart',\n 'unloadEventStart',\n 'unloadEventEnd',\n 'redirectStart',\n 'redirectEnd',\n 'fetchStart',\n 'commitNavigationEnd',\n 'domainLookupStart',\n 'domainLookupEnd',\n 'connectStart',\n 'connectEnd',\n 'secureConnectionStart',\n 'requestStart',\n 'responseStart',\n 'responseEnd',\n 'domLoading',\n 'domInteractive',\n 'domContentLoadedEventStart',\n 'domContentLoadedEventEnd',\n 'domComplete',\n 'loadEventStart',\n 'loadEventEnd',\n];\n\nexport function handleEvent(event: Types.TraceEvents.TraceEventData): void {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('UserTimings handler is not initialized');\n }\n\n // These are events dispatched under the blink.user_timing category\n // but that the user didn't add. Filter them out so that they do not\n // Appear in the timings track (they still appear in the main thread\n // flame chart).\n const ignoredNames = [...resourceTimingNames, ...navTimingNames];\n if (ignoredNames.includes(event.name)) {\n return;\n }\n\n if (Types.TraceEvents.isTraceEventPerformanceMeasure(event)) {\n performanceMeasureEvents.push(event);\n return;\n }\n if (Types.TraceEvents.isTraceEventPerformanceMark(event)) {\n performanceMarkEvents.push(event);\n }\n if (Types.TraceEvents.isTraceEventConsoleTime(event)) {\n consoleTimings.push(event);\n }\n if (Types.TraceEvents.isTraceEventTimeStamp(event)) {\n timestampEvents.push(event);\n }\n}\n\nexport async function finalize(): Promise<void> {\n if (handlerState !== HandlerState.INITIALIZED) {\n throw new Error('UserTimings handler is not initialized');\n }\n\n const asyncEvents = [...performanceMeasureEvents, ...consoleTimings];\n syntheticEvents = Helpers.Trace.createMatchedSortedSyntheticEvents(asyncEvents);\n handlerState = HandlerState.FINALIZED;\n}\n\nexport function data(): UserTimingsData {\n if (handlerState !== HandlerState.FINALIZED) {\n throw new Error('UserTimings handler is not finalized');\n }\n\n return {\n performanceMeasures: syntheticEvents.filter(e => e.cat === 'blink.user_timing') as\n Types.TraceEvents.SyntheticUserTimingPair[],\n consoleTimings: syntheticEvents.filter(e => e.cat === 'blink.console') as\n Types.TraceEvents.SyntheticConsoleTimingPair[],\n performanceMarks: [...performanceMarkEvents],\n timestampEvents: [...timestampEvents],\n };\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as Types from '../types/types.js';
|
|
2
|
+
import { type TraceEventHandlerName } from './types.js';
|
|
3
|
+
export interface WarningsData {
|
|
4
|
+
perEvent: Map<Types.TraceEvents.TraceEventData, Warning[]>;
|
|
5
|
+
perWarning: Map<Warning, Types.TraceEvents.TraceEventData[]>;
|
|
6
|
+
}
|
|
7
|
+
export type Warning = 'LONG_TASK' | 'IDLE_CALLBACK_OVER_TIME' | 'FORCED_REFLOW' | 'LONG_INTERACTION';
|
|
8
|
+
export declare const FORCED_REFLOW_THRESHOLD: Types.Timing.MicroSeconds;
|
|
9
|
+
export declare const LONG_MAIN_THREAD_TASK_THRESHOLD: Types.Timing.MicroSeconds;
|
|
10
|
+
export declare function reset(): void;
|
|
11
|
+
export declare function handleEvent(event: Types.TraceEvents.TraceEventData): void;
|
|
12
|
+
export declare function deps(): TraceEventHandlerName[];
|
|
13
|
+
export declare function finalize(): Promise<void>;
|
|
14
|
+
export declare function data(): WarningsData;
|