@paulirish/trace_engine 0.0.10 → 0.0.12
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/README.md +1 -1
- package/analyze-trace.mjs +1 -1
- package/core/platform/DevToolsPath.d.ts +4 -13
- package/core/platform/DevToolsPath.js +7 -4
- package/core/platform/DevToolsPath.js.map +1 -7
- package/core/platform/MimeType.d.ts +27 -0
- package/core/platform/MimeType.js +119 -86
- package/core/platform/MimeType.js.map +1 -7
- package/core/platform/Timing.d.ts +7 -0
- package/core/platform/Timing.js +7 -4
- package/core/platform/Timing.js.map +1 -7
- package/core/platform/UIString.d.ts +2 -5
- package/core/platform/UIString.js +5 -2
- package/core/platform/UIString.js.map +1 -7
- package/core/platform/UserVisibleError.js +19 -10
- package/core/platform/UserVisibleError.js.map +1 -7
- package/core/platform/array-utilities.d.ts +48 -10
- package/core/platform/array-utilities.js +160 -124
- package/core/platform/array-utilities.js.map +1 -7
- package/core/platform/brand.d.ts +14 -0
- package/core/platform/brand.js +5 -1
- package/core/platform/brand.js.map +1 -7
- package/core/platform/date-utilities.js +10 -6
- package/core/platform/date-utilities.js.map +1 -7
- package/core/platform/dom-utilities.d.ts +3 -1
- package/core/platform/dom-utilities.js +94 -83
- package/core/platform/dom-utilities.js.map +1 -7
- package/core/platform/keyboard-utilities.d.ts +2 -0
- package/core/platform/keyboard-utilities.js +15 -24
- package/core/platform/keyboard-utilities.js.map +1 -7
- package/core/platform/map-utilities.d.ts +4 -0
- package/core/platform/map-utilities.js +66 -60
- package/core/platform/map-utilities.js.map +1 -7
- package/core/platform/number-utilities.js +66 -55
- package/core/platform/number-utilities.js.map +1 -7
- package/core/platform/platform.d.ts +5 -1
- package/core/platform/platform.js +54 -37
- package/core/platform/platform.js.map +1 -7
- package/core/platform/promise-utilities.d.ts +10 -0
- package/core/platform/promise-utilities.js +16 -8
- package/core/platform/promise-utilities.js.map +1 -7
- package/core/platform/set-utilities.js +20 -17
- package/core/platform/set-utilities.js.map +1 -7
- package/core/platform/string-utilities.d.ts +32 -1
- package/core/platform/string-utilities.js +453 -379
- package/core/platform/string-utilities.js.map +1 -7
- package/core/platform/typescript-utilities.d.ts +5 -5
- package/core/platform/typescript-utilities.js +19 -7
- package/core/platform/typescript-utilities.js.map +1 -7
- package/generated/protocol.d.ts +2081 -347
- package/generated/protocol.js +5 -2230
- package/models/cpu_profile/CPUProfileDataModel.d.ts +77 -0
- package/models/cpu_profile/CPUProfileDataModel.js +492 -359
- package/models/cpu_profile/CPUProfileDataModel.js.map +1 -7
- package/models/cpu_profile/ProfileTreeModel.d.ts +29 -0
- package/models/cpu_profile/ProfileTreeModel.js +87 -82
- package/models/cpu_profile/ProfileTreeModel.js.map +1 -7
- package/models/cpu_profile/cpu_profile.d.ts +3 -0
- package/models/cpu_profile/cpu_profile.js +7 -7
- package/models/cpu_profile/cpu_profile.js.map +1 -7
- package/models/trace/EntriesFilter.d.ts +55 -0
- package/models/trace/EntriesFilter.js +227 -166
- package/models/trace/EntriesFilter.js.map +1 -7
- package/models/trace/LegacyTracingModel.js.map +1 -7
- package/models/trace/ModelImpl.d.ts +110 -0
- package/models/trace/ModelImpl.js +161 -102
- package/models/trace/ModelImpl.js.map +1 -7
- package/models/trace/Processor.d.ts +36 -0
- package/models/trace/Processor.js +197 -163
- package/models/trace/Processor.js.map +1 -7
- package/models/trace/TracingManager.js.map +1 -7
- package/models/trace/extras/FetchNodes.d.ts +46 -0
- package/models/trace/extras/FetchNodes.js +132 -91
- package/models/trace/extras/FetchNodes.js.map +1 -7
- package/models/trace/extras/FilmStrip.d.ts +19 -0
- package/models/trace/extras/FilmStrip.js +38 -31
- package/models/trace/extras/FilmStrip.js.map +1 -7
- package/models/trace/extras/MainThreadActivity.d.ts +2 -0
- package/models/trace/extras/MainThreadActivity.js +72 -56
- package/models/trace/extras/MainThreadActivity.js.map +1 -7
- package/models/trace/extras/Metadata.d.ts +2 -0
- package/models/trace/extras/Metadata.js +42 -26
- package/models/trace/extras/Metadata.js.map +1 -7
- package/models/trace/extras/extras.js.map +1 -7
- package/models/trace/handlers/AnimationHandler.d.ts +8 -0
- package/models/trace/handlers/AnimationHandler.js +22 -20
- package/models/trace/handlers/AnimationHandler.js.map +1 -7
- package/models/trace/handlers/AuctionWorkletsHandler.d.ts +8 -0
- package/models/trace/handlers/AuctionWorkletsHandler.js +143 -89
- package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -7
- package/models/trace/handlers/FramesHandler.d.ts +76 -0
- package/models/trace/handlers/FramesHandler.js +424 -355
- package/models/trace/handlers/FramesHandler.js.map +1 -7
- package/models/trace/handlers/GPUHandler.d.ts +11 -0
- package/models/trace/handlers/GPUHandler.js +41 -37
- package/models/trace/handlers/GPUHandler.js.map +1 -7
- package/models/trace/handlers/InitiatorsHandler.d.ts +10 -0
- package/models/trace/handlers/InitiatorsHandler.js +164 -113
- package/models/trace/handlers/InitiatorsHandler.js.map +1 -7
- package/models/trace/handlers/InvalidationsHandler.d.ts +10 -0
- package/models/trace/handlers/InvalidationsHandler.js +101 -79
- package/models/trace/handlers/InvalidationsHandler.js.map +1 -7
- package/models/trace/handlers/LargestImagePaintHandler.d.ts +5 -0
- package/models/trace/handlers/LargestImagePaintHandler.js +32 -12
- package/models/trace/handlers/LargestImagePaintHandler.js.map +1 -7
- package/models/trace/handlers/LargestTextPaintHandler.d.ts +5 -0
- package/models/trace/handlers/LargestTextPaintHandler.js +20 -12
- package/models/trace/handlers/LargestTextPaintHandler.js.map +1 -7
- package/models/trace/handlers/LayerTreeHandler.d.ts +13 -0
- package/models/trace/handlers/LayerTreeHandler.js +96 -70
- package/models/trace/handlers/LayerTreeHandler.js.map +1 -7
- package/models/trace/handlers/LayoutShiftsHandler.d.ts +44 -0
- package/models/trace/handlers/LayoutShiftsHandler.js +304 -227
- package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -7
- package/models/trace/handlers/MemoryHandler.d.ts +7 -0
- package/models/trace/handlers/MemoryHandler.js +14 -11
- package/models/trace/handlers/MemoryHandler.js.map +1 -7
- package/models/trace/handlers/MetaHandler.d.ts +37 -0
- package/models/trace/handlers/MetaHandler.js +314 -226
- package/models/trace/handlers/MetaHandler.js.map +1 -7
- package/models/trace/handlers/ModelHandlers.d.ts +21 -0
- package/models/trace/handlers/ModelHandlers.js +25 -22
- package/models/trace/handlers/ModelHandlers.js.map +1 -7
- package/models/trace/handlers/NetworkRequestsHandler.d.ts +17 -0
- package/models/trace/handlers/NetworkRequestsHandler.js +342 -218
- package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -7
- package/models/trace/handlers/PageLoadMetricsHandler.d.ts +67 -0
- package/models/trace/handlers/PageLoadMetricsHandler.js +357 -284
- package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -7
- package/models/trace/handlers/RendererHandler.d.ts +101 -0
- package/models/trace/handlers/RendererHandler.js +295 -191
- package/models/trace/handlers/RendererHandler.js.map +1 -7
- package/models/trace/handlers/SamplesHandler.d.ts +46 -0
- package/models/trace/handlers/SamplesHandler.js +195 -158
- package/models/trace/handlers/SamplesHandler.js.map +1 -7
- package/models/trace/handlers/ScreenshotsHandler.d.ts +7 -0
- package/models/trace/handlers/ScreenshotsHandler.js +63 -41
- package/models/trace/handlers/ScreenshotsHandler.js.map +1 -7
- package/models/trace/handlers/Threads.d.ts +33 -0
- package/models/trace/handlers/Threads.js +85 -67
- package/models/trace/handlers/Threads.js.map +1 -7
- package/models/trace/handlers/UserInteractionsHandler.d.ts +57 -0
- package/models/trace/handlers/UserInteractionsHandler.js +240 -141
- package/models/trace/handlers/UserInteractionsHandler.js.map +1 -7
- package/models/trace/handlers/UserTimingsHandler.d.ts +28 -0
- package/models/trace/handlers/UserTimingsHandler.js +91 -80
- package/models/trace/handlers/UserTimingsHandler.js.map +1 -7
- package/models/trace/handlers/WarningsHandler.d.ts +14 -0
- package/models/trace/handlers/WarningsHandler.js +100 -62
- package/models/trace/handlers/WarningsHandler.js.map +1 -7
- package/models/trace/handlers/WorkersHandler.d.ts +11 -0
- package/models/trace/handlers/WorkersHandler.js +40 -38
- package/models/trace/handlers/WorkersHandler.js.map +1 -7
- package/models/trace/handlers/handlers.d.ts +3 -0
- package/models/trace/handlers/handlers.js +7 -4
- package/models/trace/handlers/handlers.js.map +1 -7
- package/models/trace/handlers/types.d.ts +45 -0
- package/models/trace/handlers/types.js +15 -15
- package/models/trace/handlers/types.js.map +1 -7
- package/models/trace/helpers/SamplesIntegrator.d.ts +49 -0
- package/models/trace/helpers/SamplesIntegrator.js +381 -204
- package/models/trace/helpers/SamplesIntegrator.js.map +1 -7
- package/models/trace/helpers/Timing.d.ts +26 -0
- package/models/trace/helpers/Timing.js +131 -110
- package/models/trace/helpers/Timing.js.map +1 -7
- package/models/trace/helpers/Trace.d.ts +37 -0
- package/models/trace/helpers/Trace.js +200 -166
- package/models/trace/helpers/Trace.js.map +1 -7
- package/models/trace/helpers/TreeHelpers.d.ts +90 -0
- package/models/trace/helpers/TreeHelpers.js +203 -100
- package/models/trace/helpers/TreeHelpers.js.map +1 -7
- package/models/trace/helpers/helpers.d.ts +4 -0
- package/models/trace/helpers/helpers.js +8 -5
- package/models/trace/helpers/helpers.js.map +1 -7
- package/models/trace/root-causes/LayoutShift.d.ts +119 -0
- package/models/trace/root-causes/LayoutShift.js +470 -323
- package/models/trace/root-causes/LayoutShift.js.map +1 -7
- package/models/trace/root-causes/RootCauses.d.ts +14 -0
- package/models/trace/root-causes/RootCauses.js +9 -6
- package/models/trace/root-causes/RootCauses.js.map +1 -7
- package/models/trace/root-causes/root-causes.d.ts +1 -0
- package/models/trace/root-causes/root-causes.js +5 -2
- package/models/trace/root-causes/root-causes.js.map +1 -7
- package/models/trace/trace.d.ts +11 -0
- package/models/trace/trace.js +17 -23
- package/models/trace/trace.js.map +1 -7
- package/models/trace/types/Configuration.d.ts +33 -0
- package/models/trace/types/Configuration.js +25 -14
- package/models/trace/types/Configuration.js.map +1 -7
- package/models/trace/types/File.d.ts +23 -0
- package/models/trace/types/File.js +5 -6
- package/models/trace/types/File.js.map +1 -7
- package/models/trace/types/Timing.d.ts +25 -0
- package/models/trace/types/Timing.js +10 -11
- package/models/trace/types/Timing.js.map +1 -7
- package/models/trace/types/TraceEvents.d.ts +1571 -0
- package/models/trace/types/TraceEvents.js +174 -381
- package/models/trace/types/TraceEvents.js.map +1 -7
- package/models/trace/types/types.d.ts +4 -0
- package/models/trace/types/types.js +8 -5
- package/models/trace/types/types.js.map +1 -7
- package/package.json +1 -1
- package/TracingManager.js +0 -0
- package/core/platform/devtools_entrypoint-bundle-tsconfig-tsconfig.json +0 -40
- package/core/platform/platform.js.compressed +0 -0
- package/core/platform/platform.js.hash +0 -1
- package/core/platform/platform.prebundle.d.ts +0 -15
- package/core/platform/platform.prebundle.js +0 -50
- package/core/platform/platform.prebundle.js.map +0 -1
- package/core/platform/platform.prebundle.ts +0 -64
- package/extras/extras.js +0 -0
- package/models/trace/SDKServices.js +0 -104
- package/models/trace/SDKServices.js.map +0 -7
- package/models/trace/TraceProcessor.js +0 -133
- package/models/trace/TraceProcessor.js.map +0 -7
- package/models/trace/TreeManipulator.js +0 -85
- package/models/trace/TreeManipulator.js.map +0 -7
- package/models/trace/devtools_entrypoint-legacy-typescript-tsconfig.json +0 -43
- package/models/trace/frames/TimelineFrameModel.js +0 -392
- package/models/trace/frames/TimelineFrameModel.js.map +0 -7
- package/models/trace/frames/bundle-tsconfig.json +0 -1
- package/models/trace/frames/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -43
- package/models/trace/frames/frames-tsconfig.json +0 -58
- package/models/trace/frames/frames.js +0 -5
- package/models/trace/frames/frames.js.map +0 -7
- package/models/trace/handlers/Migration.js +0 -27
- package/models/trace/handlers/Migration.js.map +0 -7
- package/models/trace/handlers/UberFramesHandler.js +0 -293
- package/models/trace/handlers/UberFramesHandler.js.map +0 -7
- package/models/trace/legacy-tsconfig.json +0 -1
- package/models/trace/sdk_services/DOMNodeLookup.js +0 -41
- package/models/trace/sdk_services/DOMNodeLookup.js.map +0 -7
- package/models/trace/sdk_services/LayoutShifts.js +0 -68
- package/models/trace/sdk_services/LayoutShifts.js.map +0 -7
- package/models/trace/sdk_services/bundle-tsconfig.json +0 -1
- package/models/trace/sdk_services/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -41
- package/models/trace/sdk_services/sdk_services-tsconfig.json +0 -57
- package/models/trace/sdk_services/sdk_services.js +0 -7
- package/models/trace/sdk_services/sdk_services.js.map +0 -7
- package/models/trace/trace-legacy.js +0 -16
- package/models/trace/trace-legacy.js.map +0 -7
- package/models/trace/worker/Processor.js +0 -143
- package/models/trace/worker/Processor.js.map +0 -7
- package/models/trace/worker/Types.js +0 -1
- package/models/trace/worker/Types.js.map +0 -7
- package/models/trace/worker/bundle-tsconfig.json +0 -1
- package/models/trace/worker/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -41
- package/models/trace/worker/devtools_entrypoint-worker_entrypoint-typescript-tsconfig.json +0 -41
- package/models/trace/worker/processor-tsconfig.json +0 -45
- package/models/trace/worker/worker.js +0 -7
- package/models/trace/worker/worker.js.map +0 -7
- package/models/trace/worker/worker_entrypoint-tsconfig.json +0 -1
- package/models/trace/worker/worker_entrypoint.js +0 -36
- package/models/trace/worker/worker_entrypoint.js.map +0 -7
- package/trace.mjs +0 -6980
- package/trace.mjs.map +0 -8
|
@@ -1,220 +1,397 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// Copyright 2023 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
import * as Types from '../types/types.js';
|
|
5
|
+
import { millisecondsToMicroseconds } from './Timing.js';
|
|
6
|
+
import { makeProfileCall, mergeEventsInOrder } from './Trace.js';
|
|
7
|
+
/**
|
|
8
|
+
* This is a helper that integrates CPU profiling data coming in the
|
|
9
|
+
* shape of samples, with trace events. Samples indicate what the JS
|
|
10
|
+
* stack trace looked at a given point in time, but they don't have
|
|
11
|
+
* duration. The SamplesIntegrator task is to make an approximation
|
|
12
|
+
* of what the duration of each JS call was, given the sample data and
|
|
13
|
+
* given the trace events profiled during that time. At the end of its
|
|
14
|
+
* execution, the SamplesIntegrator returns an array of ProfileCalls
|
|
15
|
+
* (under SamplesIntegrator::buildProfileCalls()), which
|
|
16
|
+
* represent JS calls, with a call frame and duration. These calls have
|
|
17
|
+
* the shape of a complete trace events and can be treated as flame
|
|
18
|
+
* chart entries in the timeline.
|
|
19
|
+
*
|
|
20
|
+
* The approach to build the profile calls consists in tracking the
|
|
21
|
+
* current stack as the following events happen (in order):
|
|
22
|
+
* 1. A sample was done.
|
|
23
|
+
* 2. A trace event started.
|
|
24
|
+
* 3. A trace event ended.
|
|
25
|
+
* Depending on the event and on the data that's coming with it the
|
|
26
|
+
* stack is updated by adding or removing JS calls to it and updating
|
|
27
|
+
* the duration of the calls in the tracking stack.
|
|
28
|
+
*
|
|
29
|
+
* note: Although this approach has been implemented since long ago, and
|
|
30
|
+
* is relatively efficent (adds a complexity over the trace parsing of
|
|
31
|
+
* O(n) where n is the number of samples) it has proven to be faulty.
|
|
32
|
+
* It might be worthwhile experimenting with improvements or with a
|
|
33
|
+
* completely different approach. Improving the approach is tracked in
|
|
34
|
+
* crbug.com/1417439
|
|
35
|
+
*/
|
|
4
36
|
export class SamplesIntegrator {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The result of runing the samples integrator. Holds the JS calls
|
|
39
|
+
* with their approximated duration after integrating samples into the
|
|
40
|
+
* trace event tree.
|
|
41
|
+
*/
|
|
42
|
+
#constructedProfileCalls = [];
|
|
43
|
+
/**
|
|
44
|
+
* tracks the state of the JS stack at each point in time to update
|
|
45
|
+
* the profile call durations as new events arrive. This doesn't only
|
|
46
|
+
* happen with new profile calls (in which case we would compare the
|
|
47
|
+
* stack in them) but also with trace events (in which case we would
|
|
48
|
+
* update the duration of the events we are tracking at the moment).
|
|
49
|
+
*/
|
|
50
|
+
#currentJSStack = [];
|
|
51
|
+
/**
|
|
52
|
+
* Process holding the CPU profile and trace events.
|
|
53
|
+
*/
|
|
54
|
+
#processId;
|
|
55
|
+
/**
|
|
56
|
+
* Thread holding the CPU profile and trace events.
|
|
57
|
+
*/
|
|
58
|
+
#threadId;
|
|
59
|
+
/**
|
|
60
|
+
* Tracks the depth of the JS stack at the moment a trace event starts
|
|
61
|
+
* or ends. It is assumed that for the duration of a trace event, the
|
|
62
|
+
* JS stack's depth cannot decrease, since JS calls that started
|
|
63
|
+
* before a trace event cannot end during the trace event. So as trace
|
|
64
|
+
* events arrive, we store the "locked" amount of JS frames that were
|
|
65
|
+
* in the stack before the event came.
|
|
66
|
+
*/
|
|
67
|
+
#lockedJsStackDepth = [];
|
|
68
|
+
/**
|
|
69
|
+
* Used to keep track when samples should be integrated even if they
|
|
70
|
+
* are not children of invocation trace events. This is useful in
|
|
71
|
+
* cases where we can be missing the start of JS invocation events if
|
|
72
|
+
* we start tracing half-way through.
|
|
73
|
+
*/
|
|
74
|
+
#fakeJSInvocation = false;
|
|
75
|
+
/**
|
|
76
|
+
* The parsed CPU profile, holding the tree hierarchy of JS frames and
|
|
77
|
+
* the sample data.
|
|
78
|
+
*/
|
|
79
|
+
#profileModel;
|
|
80
|
+
/**
|
|
81
|
+
* Because GC nodes don't have a stack, we artificially add a stack to
|
|
82
|
+
* them which corresponds to that of the previous sample. This map
|
|
83
|
+
* tracks which node is used for the stack of a GC call.
|
|
84
|
+
* Note that GC samples are not shown in the flamechart, however they
|
|
85
|
+
* are used during the construction of for profile calls, as we can
|
|
86
|
+
* infer information about the duration of the executed code when a
|
|
87
|
+
* GC node is sampled.
|
|
88
|
+
*/
|
|
89
|
+
#nodeForGC = new Map();
|
|
90
|
+
#engineConfig;
|
|
91
|
+
constructor(profileModel, pid, tid, configuration) {
|
|
92
|
+
this.#profileModel = profileModel;
|
|
93
|
+
this.#threadId = tid;
|
|
94
|
+
this.#processId = pid;
|
|
95
|
+
this.#engineConfig = configuration || Types.Configuration.DEFAULT;
|
|
58
96
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const call = makeProfileCall(node, timestamp, this.#processId, this.#threadId);
|
|
109
|
-
calls.push(call);
|
|
110
|
-
if (node.id === this.#profileModel.gcNode?.id && prevNode) {
|
|
111
|
-
this.#nodeForGC.set(call, prevNode);
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
prevNode = node;
|
|
115
|
-
}
|
|
116
|
-
return calls;
|
|
117
|
-
}
|
|
118
|
-
#getStackTraceFromProfileCall(profileCall) {
|
|
119
|
-
let node = this.#profileModel.nodeById(profileCall.nodeId);
|
|
120
|
-
const isGarbageCollection = node?.id === this.#profileModel.gcNode?.id;
|
|
121
|
-
if (isGarbageCollection) {
|
|
122
|
-
node = this.#nodeForGC.get(profileCall) || null;
|
|
97
|
+
buildProfileCalls(traceEvents) {
|
|
98
|
+
const mergedEvents = mergeEventsInOrder(traceEvents, this.callsFromProfileSamples());
|
|
99
|
+
const stack = [];
|
|
100
|
+
for (let i = 0; i < mergedEvents.length; i++) {
|
|
101
|
+
const event = mergedEvents[i];
|
|
102
|
+
// Because instant trace events have no duration, they don't provide
|
|
103
|
+
// useful information for possible changes in the duration of calls
|
|
104
|
+
// in the JS stack.
|
|
105
|
+
if (event.ph === "I" /* Types.TraceEvents.Phase.INSTANT */) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (stack.length === 0) {
|
|
109
|
+
if (Types.TraceEvents.isProfileCall(event)) {
|
|
110
|
+
this.#onProfileCall(event);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
stack.push(event);
|
|
114
|
+
this.#onTraceEventStart(event);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const parentEvent = stack.at(-1);
|
|
118
|
+
if (parentEvent === undefined) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const begin = event.ts;
|
|
122
|
+
const parentBegin = parentEvent.ts;
|
|
123
|
+
const parentDuration = parentEvent.dur || 0;
|
|
124
|
+
const parentEnd = parentBegin + parentDuration;
|
|
125
|
+
const startsAfterParent = begin >= parentEnd;
|
|
126
|
+
if (startsAfterParent) {
|
|
127
|
+
this.#onTraceEventEnd(parentEvent);
|
|
128
|
+
stack.pop();
|
|
129
|
+
i--;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (Types.TraceEvents.isProfileCall(event)) {
|
|
133
|
+
this.#onProfileCall(event, parentEvent);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
this.#onTraceEventStart(event);
|
|
137
|
+
stack.push(event);
|
|
138
|
+
}
|
|
139
|
+
while (stack.length) {
|
|
140
|
+
const last = stack.pop();
|
|
141
|
+
if (last) {
|
|
142
|
+
this.#onTraceEventEnd(last);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return this.#constructedProfileCalls;
|
|
123
146
|
}
|
|
124
|
-
|
|
125
|
-
|
|
147
|
+
#onTraceEventStart(event) {
|
|
148
|
+
// Top level events cannot be nested into JS frames so we reset
|
|
149
|
+
// the stack when we find one.
|
|
150
|
+
if (event.name === "RunMicrotasks" /* Types.TraceEvents.KnownEventName.RunMicrotasks */ ||
|
|
151
|
+
event.name === "RunTask" /* Types.TraceEvents.KnownEventName.RunTask */) {
|
|
152
|
+
this.#lockedJsStackDepth = [];
|
|
153
|
+
this.#truncateJSStack(0, event.ts);
|
|
154
|
+
this.#fakeJSInvocation = false;
|
|
155
|
+
}
|
|
156
|
+
if (this.#fakeJSInvocation) {
|
|
157
|
+
this.#truncateJSStack(this.#lockedJsStackDepth.pop() || 0, event.ts);
|
|
158
|
+
this.#fakeJSInvocation = false;
|
|
159
|
+
}
|
|
160
|
+
this.#extractStackTrace(event);
|
|
161
|
+
// Keep track of the call frames in the stack before the event
|
|
162
|
+
// happened. For the duration of this event, these frames cannot
|
|
163
|
+
// change (none can be terminated before this event finishes).
|
|
164
|
+
//
|
|
165
|
+
// Also, every frame that is opened after this event, is considered
|
|
166
|
+
// to be a descendant of the event. So once the event finishes, the
|
|
167
|
+
// frames that were opened after it, need to be closed (see
|
|
168
|
+
// onEndEvent).
|
|
169
|
+
//
|
|
170
|
+
// TODO(crbug.com/1417439):
|
|
171
|
+
// The assumption that every frame opened after an event is a
|
|
172
|
+
// descendant of the event is incorrect. For example, a JS call that
|
|
173
|
+
// parents a trace event might have been sampled after the event was
|
|
174
|
+
// dispatched. In this case the JS call would be discarded if this
|
|
175
|
+
// event isn't an invocation event, otherwise the call will be
|
|
176
|
+
// considered a child of the event. In both cases, the result would
|
|
177
|
+
// be incorrect.
|
|
178
|
+
this.#lockedJsStackDepth.push(this.#currentJSStack.length);
|
|
126
179
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
180
|
+
#onProfileCall(event, parent) {
|
|
181
|
+
if ((parent && Types.TraceEvents.isJSInvocationEvent(parent)) || this.#fakeJSInvocation) {
|
|
182
|
+
this.#extractStackTrace(event);
|
|
183
|
+
}
|
|
184
|
+
else if (Types.TraceEvents.isProfileCall(event) && this.#currentJSStack.length === 0) {
|
|
185
|
+
// Force JS Samples to show up even if we are not inside a JS
|
|
186
|
+
// invocation event, because we can be missing the start of JS
|
|
187
|
+
// invocation events if we start tracing half-way through. Pretend
|
|
188
|
+
// we have a top-level JS invocation event.
|
|
189
|
+
this.#fakeJSInvocation = true;
|
|
190
|
+
const stackDepthBefore = this.#currentJSStack.length;
|
|
191
|
+
this.#extractStackTrace(event);
|
|
192
|
+
this.#lockedJsStackDepth.push(stackDepthBefore);
|
|
193
|
+
}
|
|
131
194
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
195
|
+
#onTraceEventEnd(event) {
|
|
196
|
+
// Because the event has ended, any frames that happened after
|
|
197
|
+
// this event are terminated. Frames that are ancestors to this
|
|
198
|
+
// event are extended to cover its ending.
|
|
199
|
+
const endTime = Types.Timing.MicroSeconds(event.ts + (event.dur || 0));
|
|
200
|
+
this.#truncateJSStack(this.#lockedJsStackDepth.pop() || 0, endTime);
|
|
135
201
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
202
|
+
/**
|
|
203
|
+
* Builds the initial calls with no duration from samples. Their
|
|
204
|
+
* purpose is to be merged with the trace event array being parsed so
|
|
205
|
+
* that they can be traversed in order with them and their duration
|
|
206
|
+
* can be updated as the SampleIntegrator callbacks are invoked.
|
|
207
|
+
*/
|
|
208
|
+
callsFromProfileSamples() {
|
|
209
|
+
const samples = this.#profileModel.samples;
|
|
210
|
+
const timestamps = this.#profileModel.timestamps;
|
|
211
|
+
if (!samples) {
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
const calls = [];
|
|
215
|
+
let prevNode;
|
|
216
|
+
for (let i = 0; i < samples.length; i++) {
|
|
217
|
+
const node = this.#profileModel.nodeByIndex(i);
|
|
218
|
+
const timestamp = millisecondsToMicroseconds(Types.Timing.MilliSeconds(timestamps[i]));
|
|
219
|
+
if (!node) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const call = makeProfileCall(node, timestamp, this.#processId, this.#threadId);
|
|
223
|
+
calls.push(call);
|
|
224
|
+
if (node.id === this.#profileModel.gcNode?.id && prevNode) {
|
|
225
|
+
// GC samples have no stack, so we just put GC node on top of the
|
|
226
|
+
// last recorded sample. Cache the previous sample for future
|
|
227
|
+
// reference.
|
|
228
|
+
this.#nodeForGC.set(call, prevNode);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
prevNode = node;
|
|
232
|
+
}
|
|
233
|
+
return calls;
|
|
151
234
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
235
|
+
#getStackTraceFromProfileCall(profileCall) {
|
|
236
|
+
let node = this.#profileModel.nodeById(profileCall.nodeId);
|
|
237
|
+
const isGarbageCollection = node?.id === this.#profileModel.gcNode?.id;
|
|
238
|
+
if (isGarbageCollection) {
|
|
239
|
+
// Because GC don't have a stack, we use the stack of the previous
|
|
240
|
+
// sample.
|
|
241
|
+
node = this.#nodeForGC.get(profileCall) || null;
|
|
242
|
+
}
|
|
243
|
+
if (!node) {
|
|
244
|
+
return [];
|
|
245
|
+
}
|
|
246
|
+
// `node.depth` is 0 based, so to set the size of the array we need
|
|
247
|
+
// to add 1 to its value.
|
|
248
|
+
const callFrames = new Array(node.depth + 1 + Number(isGarbageCollection));
|
|
249
|
+
// Add the stack trace in reverse order (bottom first).
|
|
250
|
+
let i = callFrames.length - 1;
|
|
251
|
+
if (isGarbageCollection) {
|
|
252
|
+
// Place the garbage collection call frame on top of the stack.
|
|
253
|
+
callFrames[i--] = profileCall;
|
|
254
|
+
}
|
|
255
|
+
while (node) {
|
|
256
|
+
callFrames[i--] = makeProfileCall(node, profileCall.ts, this.#processId, this.#threadId);
|
|
257
|
+
node = node.parent;
|
|
258
|
+
}
|
|
259
|
+
return callFrames;
|
|
160
260
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
261
|
+
/**
|
|
262
|
+
* Update tracked stack using this event's call stack.
|
|
263
|
+
*/
|
|
264
|
+
#extractStackTrace(event) {
|
|
265
|
+
const stackTrace = Types.TraceEvents.isProfileCall(event) ? this.#getStackTraceFromProfileCall(event) : this.#currentJSStack;
|
|
266
|
+
SamplesIntegrator.filterStackFrames(stackTrace, this.#engineConfig);
|
|
267
|
+
const endTime = event.ts + (event.dur || 0);
|
|
268
|
+
const minFrames = Math.min(stackTrace.length, this.#currentJSStack.length);
|
|
269
|
+
let i;
|
|
270
|
+
// Merge a sample's stack frames with the stack frames we have
|
|
271
|
+
// so far if we detect they are equivalent.
|
|
272
|
+
// Graphically
|
|
273
|
+
// This:
|
|
274
|
+
// Current stack trace Sample
|
|
275
|
+
// [-------A------] [A]
|
|
276
|
+
// [-------B------] [B]
|
|
277
|
+
// [-------C------] [C]
|
|
278
|
+
// ^ t = x1 ^ t = x2
|
|
279
|
+
// Becomes this:
|
|
280
|
+
// New stack trace after merge
|
|
281
|
+
// [--------A-------]
|
|
282
|
+
// [--------B-------]
|
|
283
|
+
// [--------C-------]
|
|
284
|
+
// ^ t = x2
|
|
285
|
+
for (i = this.#lockedJsStackDepth.at(-1) || 0; i < minFrames; ++i) {
|
|
286
|
+
const newFrame = stackTrace[i].callFrame;
|
|
287
|
+
const oldFrame = this.#currentJSStack[i].callFrame;
|
|
288
|
+
if (!SamplesIntegrator.framesAreEqual(newFrame, oldFrame)) {
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
// Scoot the right edge of this callFrame to the right
|
|
292
|
+
this.#currentJSStack[i].dur =
|
|
293
|
+
Types.Timing.MicroSeconds(Math.max(this.#currentJSStack[i].dur || 0, endTime - this.#currentJSStack[i].ts));
|
|
294
|
+
}
|
|
295
|
+
// If there are call frames in the sample that differ with the stack
|
|
296
|
+
// we have, update the stack, but keeping the common frames in place
|
|
297
|
+
// Graphically
|
|
298
|
+
// This:
|
|
299
|
+
// Current stack trace Sample
|
|
300
|
+
// [-------A------] [A]
|
|
301
|
+
// [-------B------] [B]
|
|
302
|
+
// [-------C------] [C]
|
|
303
|
+
// [-------D------] [E]
|
|
304
|
+
// ^ t = x1 ^ t = x2
|
|
305
|
+
// Becomes this:
|
|
306
|
+
// New stack trace after merge
|
|
307
|
+
// [--------A-------]
|
|
308
|
+
// [--------B-------]
|
|
309
|
+
// [--------C-------]
|
|
310
|
+
// [E]
|
|
311
|
+
// ^ t = x2
|
|
312
|
+
this.#truncateJSStack(i, event.ts);
|
|
313
|
+
for (; i < stackTrace.length; ++i) {
|
|
314
|
+
const call = stackTrace[i];
|
|
315
|
+
if (call.nodeId === this.#profileModel.programNode?.id || call.nodeId === this.#profileModel.root?.id ||
|
|
316
|
+
call.nodeId === this.#profileModel.idleNode?.id || call.nodeId === this.#profileModel.gcNode?.id) {
|
|
317
|
+
// Skip (root), (program) and (idle) frames, since this are not
|
|
318
|
+
// relevant for web profiling and we don't want to show them in
|
|
319
|
+
// the timeline.
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
this.#currentJSStack.push(call);
|
|
323
|
+
this.#constructedProfileCalls.push(call);
|
|
324
|
+
}
|
|
169
325
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
326
|
+
/**
|
|
327
|
+
* When a call stack that differs from the one we are tracking has
|
|
328
|
+
* been detected in the samples, the latter is "truncated" by
|
|
329
|
+
* setting the ending time of its call frames and removing the top
|
|
330
|
+
* call frames that aren't shared with the new call stack. This way,
|
|
331
|
+
* we can update the tracked stack with the new call frames on top.
|
|
332
|
+
* @param depth the amount of call frames from bottom to top that
|
|
333
|
+
* should be kept in the tracking stack trace. AKA amount of shared
|
|
334
|
+
* call frames between two stacks.
|
|
335
|
+
* @param time the new end of the call frames in the stack.
|
|
336
|
+
*/
|
|
337
|
+
#truncateJSStack(depth, time) {
|
|
338
|
+
if (this.#lockedJsStackDepth.length) {
|
|
339
|
+
const lockedDepth = this.#lockedJsStackDepth.at(-1);
|
|
340
|
+
if (lockedDepth && depth < lockedDepth) {
|
|
341
|
+
console.error(`Child stack is shallower (${depth}) than the parent stack (${lockedDepth}) at ${time}`);
|
|
342
|
+
depth = lockedDepth;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (this.#currentJSStack.length < depth) {
|
|
346
|
+
console.error(`Trying to truncate higher than the current stack size at ${time}`);
|
|
347
|
+
depth = this.#currentJSStack.length;
|
|
348
|
+
}
|
|
349
|
+
for (let k = 0; k < this.#currentJSStack.length; ++k) {
|
|
350
|
+
this.#currentJSStack[k].dur = Types.Timing.MicroSeconds(Math.max(time - this.#currentJSStack[k].ts, 0));
|
|
351
|
+
}
|
|
352
|
+
this.#currentJSStack.length = depth;
|
|
173
353
|
}
|
|
174
|
-
|
|
175
|
-
|
|
354
|
+
static framesAreEqual(frame1, frame2) {
|
|
355
|
+
return frame1.scriptId === frame2.scriptId && frame1.functionName === frame2.functionName &&
|
|
356
|
+
frame1.lineNumber === frame2.lineNumber;
|
|
176
357
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
static framesAreEqual(frame1, frame2) {
|
|
180
|
-
return frame1.scriptId === frame2.scriptId && frame1.functionName === frame2.functionName && frame1.lineNumber === frame2.lineNumber;
|
|
181
|
-
}
|
|
182
|
-
static showNativeName(name, runtimeCallStatsEnabled) {
|
|
183
|
-
return runtimeCallStatsEnabled && Boolean(SamplesIntegrator.nativeGroup(name));
|
|
184
|
-
}
|
|
185
|
-
static nativeGroup(nativeName) {
|
|
186
|
-
if (nativeName.startsWith("Parse")) {
|
|
187
|
-
return "Parse";
|
|
358
|
+
static showNativeName(name, runtimeCallStatsEnabled) {
|
|
359
|
+
return runtimeCallStatsEnabled && Boolean(SamplesIntegrator.nativeGroup(name));
|
|
188
360
|
}
|
|
189
|
-
|
|
190
|
-
|
|
361
|
+
static nativeGroup(nativeName) {
|
|
362
|
+
if (nativeName.startsWith('Parse')) {
|
|
363
|
+
return 'Parse';
|
|
364
|
+
}
|
|
365
|
+
if (nativeName.startsWith('Compile') || nativeName.startsWith('Recompile')) {
|
|
366
|
+
return 'Compile';
|
|
367
|
+
}
|
|
368
|
+
return null;
|
|
191
369
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
static isNativeRuntimeFrame(frame) {
|
|
195
|
-
return frame.url === "native V8Runtime";
|
|
196
|
-
}
|
|
197
|
-
static filterStackFrames(stack, engineConfig) {
|
|
198
|
-
const showAllEvents = engineConfig.experiments.timelineShowAllEvents;
|
|
199
|
-
if (showAllEvents) {
|
|
200
|
-
return;
|
|
370
|
+
static isNativeRuntimeFrame(frame) {
|
|
371
|
+
return frame.url === 'native V8Runtime';
|
|
201
372
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
373
|
+
static filterStackFrames(stack, engineConfig) {
|
|
374
|
+
const showAllEvents = engineConfig.experiments.timelineShowAllEvents;
|
|
375
|
+
if (showAllEvents) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
let previousNativeFrameName = null;
|
|
379
|
+
let j = 0;
|
|
380
|
+
for (let i = 0; i < stack.length; ++i) {
|
|
381
|
+
const frame = stack[i].callFrame;
|
|
382
|
+
const nativeRuntimeFrame = SamplesIntegrator.isNativeRuntimeFrame(frame);
|
|
383
|
+
if (nativeRuntimeFrame &&
|
|
384
|
+
!SamplesIntegrator.showNativeName(frame.functionName, engineConfig.experiments.timelineV8RuntimeCallStats)) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
const nativeFrameName = nativeRuntimeFrame ? SamplesIntegrator.nativeGroup(frame.functionName) : null;
|
|
388
|
+
if (previousNativeFrameName && previousNativeFrameName === nativeFrameName) {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
previousNativeFrameName = nativeFrameName;
|
|
392
|
+
stack[j++] = stack[i];
|
|
393
|
+
}
|
|
394
|
+
stack.length = j;
|
|
216
395
|
}
|
|
217
|
-
stack.length = j;
|
|
218
|
-
}
|
|
219
396
|
}
|
|
220
|
-
//# sourceMappingURL=SamplesIntegrator.js.map
|
|
397
|
+
//# sourceMappingURL=SamplesIntegrator.js.map
|