forked from ChromeDevTools/devtools-frontend
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathTimelinePanel.ts
More file actions
3117 lines (2775 loc) · 126 KB
/
Copy pathTimelinePanel.ts
File metadata and controls
3117 lines (2775 loc) · 126 KB
1
2
3
4
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
58
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/*
* Copyright (C) 2012 Google Inc. All rights reserved.
* Copyright (C) 2012 Intel Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import '../../ui/legacy/legacy.js';
import * as Common from '../../core/common/common.js';
import * as Host from '../../core/host/host.js';
import * as i18n from '../../core/i18n/i18n.js';
import * as Platform from '../../core/platform/platform.js';
import * as Root from '../../core/root/root.js';
import * as SDK from '../../core/sdk/sdk.js';
import type * as Protocol from '../../generated/protocol.js';
import * as CrUXManager from '../../models/crux-manager/crux-manager.js';
import * as Trace from '../../models/trace/trace.js';
import * as Workspace from '../../models/workspace/workspace.js';
import * as TraceBounds from '../../services/trace_bounds/trace_bounds.js';
import * as Adorners from '../../ui/components/adorners/adorners.js';
import type * as Buttons from '../../ui/components/buttons/buttons.js';
import * as Dialogs from '../../ui/components/dialogs/dialogs.js';
import * as LegacyWrapper from '../../ui/components/legacy_wrapper/legacy_wrapper.js';
import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
import * as UI from '../../ui/legacy/legacy.js';
import * as ThemeSupport from '../../ui/legacy/theme_support/theme_support.js';
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
import * as MobileThrottling from '../mobile_throttling/mobile_throttling.js';
import {ActiveFilters} from './ActiveFilters.js';
import * as AnnotationHelpers from './AnnotationHelpers.js';
import {TraceLoadEvent} from './BenchmarkEvents.js';
import * as TimelineComponents from './components/components.js';
import * as TimelineInsights from './components/insights/insights.js';
import {Tracker} from './FreshRecording.js';
import {IsolateSelector} from './IsolateSelector.js';
import {AnnotationModifiedEvent, ModificationsManager} from './ModificationsManager.js';
import * as Overlays from './overlays/overlays.js';
import {ReactNativeTimelineLandingPage} from './ReactNativeTimelineLandingPage.js';
import {cpuprofileJsonGenerator, traceJsonGenerator} from './SaveFileFormatter.js';
import {type Client, TimelineController} from './TimelineController.js';
import {Tab} from './TimelineDetailsView.js';
import type {TimelineFlameChartDataProvider} from './TimelineFlameChartDataProvider.js';
import {Events as TimelineFlameChartViewEvents, TimelineFlameChartView} from './TimelineFlameChartView.js';
import {TimelineHistoryManager} from './TimelineHistoryManager.js';
import {TimelineLoader} from './TimelineLoader.js';
import {TimelineMiniMap} from './TimelineMiniMap.js';
import timelinePanelStyles from './timelinePanel.css.js';
import {
rangeForSelection,
selectionFromEvent,
selectionIsRange,
selectionsEqual,
type TimelineSelection,
} from './TimelineSelection.js';
import timelineStatusDialogStyles from './timelineStatusDialog.css.js';
import {TimelineUIUtils} from './TimelineUIUtils.js';
import {UIDevtoolsController} from './UIDevtoolsController.js';
import {UIDevtoolsUtils} from './UIDevtoolsUtils.js';
import * as Utils from './utils/utils.js';
const UIStrings = {
/**
*@description Text that appears when user drag and drop something (for example, a file) in Timeline Panel of the Performance panel
*/
dropTimelineFileOrUrlHere: 'Drop timeline file or URL here',
/**
*@description Title of disable capture jsprofile setting in timeline panel of the performance panel
*/
disableJavascriptSamples: 'Disable JavaScript samples',
/**
*@description Title of capture layers and pictures setting in timeline panel of the performance panel
*/
enableAdvancedPaint: 'Enable advanced paint instrumentation (slow)',
/**
*@description Title of CSS selector stats setting in timeline panel of the performance panel
*/
enableSelectorStats: 'Enable CSS selector stats (slow)',
/**
*@description Title of show screenshots setting in timeline panel of the performance panel
*/
screenshots: 'Screenshots',
/**
*@description Text for the memory of the page
*/
memory: 'Memory',
/**
*@description Text to clear content
*/
clear: 'Clear',
/**
*@description A label for a button that fixes something.
*/
fixMe: 'Fix me',
/**
*@description Tooltip text that appears when hovering over the largeicon load button
*/
loadProfile: 'Load profile…',
/**
*@description Tooltip text that appears when hovering over the largeicon download button
*/
saveProfile: 'Save profile…',
/**
*@description An option to save trace with annotations that appears in the menu of the toolbar download button. This is the expected default option, therefore it does not mention annotations.
*/
saveTraceWithAnnotationsMenuOption: 'Save trace',
/**
*@description An option to save trace without annotations that appears in the menu of the toolbar download button
*/
saveTraceWithoutAnnotationsMenuOption: 'Save trace without annotations',
/**
*@description Text to take screenshots
*/
captureScreenshots: 'Capture screenshots',
/**
*@description Text in Timeline Panel of the Performance panel
*/
showMemoryTimeline: 'Show memory timeline',
/**
*@description Tooltip text that appears when hovering over the largeicon settings gear in show settings pane setting in timeline panel of the performance panel
*/
captureSettings: 'Capture settings',
/**
*@description Text in Timeline Panel of the Performance panel
*/
disablesJavascriptSampling: 'Disables JavaScript sampling, reduces overhead when running against mobile devices',
/**
*@description Text in Timeline Panel of the Performance panel
*/
capturesAdvancedPaint: 'Captures advanced paint instrumentation, introduces significant performance overhead',
/**
*@description Text in Timeline Panel of the Performance panel
*/
capturesSelectorStats: 'Captures CSS selector statistics',
/**
*@description Text in Timeline Panel of the Performance panel
*/
network: 'Network:',
/**
*@description Text in Timeline Panel of the Performance panel
*/
cpu: 'CPU:',
/**
*@description Title of the 'Network conditions' tool in the bottom drawer
*/
networkConditions: 'Network conditions',
/**
*@description Text in Timeline Panel of the Performance panel
*@example {wrong format} PH1
*@example {ERROR_FILE_NOT_FOUND} PH2
*/
failedToSaveTimelineSS: 'Failed to save timeline: {PH1} ({PH2})',
/**
*@description Text in Timeline Panel of the Performance panel
*/
CpuThrottlingIsEnabled: '- CPU throttling is enabled',
/**
*@description Text in Timeline Panel of the Performance panel
*/
NetworkThrottlingIsEnabled: '- Network throttling is enabled',
/**
*@description Text in Timeline Panel of the Performance panel
*/
SignificantOverheadDueToPaint: '- Significant overhead due to paint instrumentation',
/**
*@description Text in Timeline Panel of the Performance panel
*/
SelectorStatsEnabled: '- Selector stats is enabled',
/**
*@description Text in Timeline Panel of the Performance panel
*/
JavascriptSamplingIsDisabled: '- JavaScript sampling is disabled',
/**
*@description Text in Timeline Panel of the Performance panel
*/
stoppingTimeline: 'Stopping timeline…',
/**
*@description Text in Timeline Panel of the Performance panel
*/
received: 'Received',
/**
*@description Text in Timeline Panel of the Performance panel
*/
processed: 'Processed',
/**
*@description Text to close something
*/
close: 'Close',
/**
*@description Text to download the trace file after an error
*/
downloadAfterError: 'Download trace',
/**
*@description Status text to indicate the recording has failed in the Performance panel
*/
recordingFailed: 'Recording failed',
/**
* @description Text to indicate the progress of a profile. Informs the user that we are currently
* creating a peformance profile.
*/
profiling: 'Profiling…',
/**
*@description Text in Timeline Panel of the Performance panel
*/
bufferUsage: 'Buffer usage',
/**
*@description Text in Timeline Panel of the Performance panel
*/
loadingProfile: 'Loading profile…',
/**
*@description Text in Timeline Panel of the Performance panel
*/
processingProfile: 'Processing profile…',
/**
*@description Text in Timeline Panel of the Performance panel
*/
initializingProfiler: 'Initializing profiler…',
/**
*@description Text for the status of something
*/
status: 'Status',
/**
*@description Text that refers to the time
*/
time: 'Time',
/**
*@description Text for the description of something
*/
description: 'Description',
/**
*@description Text of an item that stops the running task
*/
stop: 'Stop',
/**
*
* @description Text for exporting basic traces
*/
exportNormalTraces: 'Basic performance traces',
/**
*
* @description Text for exporting enhanced traces
*/
exportEnhancedTraces: 'Enhanced performance traces',
/**
*@description Tooltip description for a checkbox that toggles the visibility of data added by extensions of this panel (Performance).
*/
showDataAddedByExtensions: 'Show data added by extensions of the Performance panel',
/**
Label for a checkbox that toggles the visibility of data added by extensions of this panel (Performance).
*/
showCustomtracks: 'Show custom tracks',
/**
* @description Tooltip for the the sidebar toggle in the Performance panel. Command to open/show the sidebar.
*/
showSidebar: 'Show sidebar',
/**
* @description Tooltip for the the sidebar toggle in the Performance panel. Command to close the sidebar.
*/
hideSidebar: 'Hide sidebar',
/**
* @description Screen reader announcement when the sidebar is shown in the Performance panel.
*/
sidebarShown: 'Performance sidebar shown',
/**
* @description Screen reader announcement when the sidebar is hidden in the Performance panel.
*/
sidebarHidden: 'Performance sidebar hidden',
/**
* @description Screen reader announcement when the user clears their selection
*/
selectionCleared: 'Selection cleared',
/**
* @description Screen reader announcement when the user selects a frame.
*/
frameSelected: 'Frame selected',
/**
* @description Screen reader announcement when the user selects a trace event.
* @example {Paint} PH1
*/
eventSelected: 'Event {PH1} selected',
/**
*@description Text of a hyperlink to documentation.
*/
learnMore: 'Learn more',
/**
* @description Tooltip text for a button that takes the user back to the default view which shows performance metrics that are live.
*/
backToLiveMetrics: 'Go back to the live metrics page',
/**
* @description Description of the Timeline up/down scroll action that appears in the Performance panel shortcuts dialog.
*/
timelineScrollUpDown: 'Move up/down',
/**
* @description Description of the Timeline left/right panning action that appears in the Performance panel shortcuts dialog.
*/
timelinePanLeftRight: 'Move left/right',
/**
* @description Description of the Timeline in/out zoom action that appears in the Performance panel shortcuts dialog.
*/
timelineZoomInOut: 'Zoom in/out',
/**
* @description Description of the Timeline fast in/out zoom action that appears in the Performance panel shortcuts dialog.
*/
timelineFastZoomInOut: 'Fast zoom in/out',
/**
* @description Title for the Dim 3rd Parties checkbox.
*/
dimThirdParties: 'Dim 3rd parties',
/**
* @description Description for the Dim 3rd Parties checkbox tooltip describing how 3rd parties are classified.
*/
thirdPartiesByThirdPartyWeb: '3rd parties classified by third-party-web',
} as const;
const str_ = i18n.i18n.registerUIStrings('panels/timeline/TimelinePanel.ts', UIStrings);
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
let timelinePanelInstance: TimelinePanel|undefined;
let isNode: boolean;
let isReactNative: boolean;
/**
* Represents the states that the timeline panel can be in.
* If you need to change the panel's view, use the {@see #changeView} method.
* Note that we do not represent the "Loading/Processing" view here. The
* StatusPane is managed in the code that handles file import/recording, and
* when it is visible it is rendered on top of the UI so obscures what is behind
* it. When it completes, we will set the view mode to the trace that has been
* loaded.
*/
type ViewMode = {
mode: 'LANDING_PAGE',
}|{
mode: 'VIEWING_TRACE',
traceIndex: number,
}|{
mode: 'STATUS_PANE_OVERLAY',
};
export class TimelinePanel extends UI.Panel.Panel implements Client, TimelineModeViewDelegate {
private readonly dropTarget: UI.DropTarget.DropTarget;
private readonly recordingOptionUIControls: UI.Toolbar.ToolbarItem[];
private state: State;
private recordingPageReload: boolean;
private readonly millisecondsToRecordAfterLoadEvent: number;
private readonly toggleRecordAction: UI.ActionRegistration.Action;
// Null for React Native entrypoints, see https://docs.google.com/document/d/1_mtLIHEd9bFQN4xWBSVDR357GaRo56khB1aOxgWDeu4/edit?tab=t.0 for context.
private readonly recordReloadAction: UI.ActionRegistration.Action | null;
readonly #historyManager: TimelineHistoryManager;
private disableCaptureJSProfileSetting: Common.Settings.Setting<boolean>;
private readonly captureLayersAndPicturesSetting: Common.Settings.Setting<boolean>;
private readonly captureSelectorStatsSetting: Common.Settings.Setting<boolean>;
readonly #thirdPartyTracksSetting: Common.Settings.Setting<boolean>;
private showScreenshotsSetting: Common.Settings.Setting<boolean>;
// Null for React Native entrypoints, see https://docs.google.com/document/d/1_mtLIHEd9bFQN4xWBSVDR357GaRo56khB1aOxgWDeu4/edit?tab=t.0 for context.
private showMemorySetting: Common.Settings.Setting<boolean> | null;
private readonly panelToolbar: UI.Toolbar.Toolbar;
private readonly panelRightToolbar: UI.Toolbar.Toolbar;
private readonly timelinePane: UI.Widget.VBox;
readonly #minimapComponent = new TimelineMiniMap();
#viewMode: ViewMode = {mode: 'LANDING_PAGE'};
readonly #dimThirdPartiesSetting: Common.Settings.Setting<boolean>|null = null;
#thirdPartyCheckbox: UI.Toolbar.ToolbarSettingCheckbox|null = null;
/**
* We get given any filters for a new trace when it is recorded/imported.
* Because the user can then use the dropdown to navigate to another trace,
* we store the filters by the trace index, so if the user then navigates back
* to a previous trace we can reinstate the filters from this map.
*/
#exclusiveFilterPerTrace = new Map<number, Trace.Extras.TraceFilter.TraceFilter>();
/**
* This widget holds the timeline sidebar which shows Insights & Annotations,
* and the main UI which shows the timeline
*/
readonly #splitWidget = new UI.SplitWidget.SplitWidget(
true, // isVertical
false, // secondIsSidebar
'timeline-panel-sidebar-state', // settingName (to persist the open/closed state for the user)
TimelineComponents.Sidebar.DEFAULT_SIDEBAR_WIDTH_PX,
);
private readonly statusPaneContainer: HTMLElement;
private readonly flameChart: TimelineFlameChartView;
private readonly searchableViewInternal: UI.SearchableView.SearchableView;
private showSettingsPaneButton!: UI.Toolbar.ToolbarSettingToggle;
private showSettingsPaneSetting!: Common.Settings.Setting<boolean>;
private settingsPane?: HTMLElement;
private controller!: TimelineController|null;
private cpuProfiler!: SDK.CPUProfilerModel.CPUProfilerModel|null;
private clearButton!: UI.Toolbar.ToolbarButton;
private loadButton!: UI.Toolbar.ToolbarButton;
private saveButton!: UI.Toolbar.ToolbarButton|UI.Toolbar.ToolbarMenuButton;
private homeButton?: UI.Toolbar.ToolbarButton;
private statusPane!: StatusPane|null;
private landingPage!: UI.Widget.Widget;
private loader?: TimelineLoader;
private showScreenshotsToolbarCheckbox?: UI.Toolbar.ToolbarItem;
private showMemoryToolbarCheckbox?: UI.Toolbar.ToolbarItem;
private networkThrottlingSelect?: MobileThrottling.ThrottlingManager.NetworkThrottlingSelectorWrapper;
private cpuThrottlingSelect?: MobileThrottling.ThrottlingManager.CPUThrottlingSelectorWrapper;
private fileSelectorElement?: HTMLInputElement;
private selection: TimelineSelection|null = null;
private traceLoadStart!: Trace.Types.Timing.Milli|null;
private primaryPageTargetPromiseCallback = (_target: SDK.Target.Target): void => {};
// Note: this is technically unused, but we need it to define the promiseCallback function above.
private primaryPageTargetPromise = new Promise<SDK.Target.Target>(res => {
this.primaryPageTargetPromiseCallback = res;
});
#traceEngineModel: Trace.TraceModel.Model;
#sourceMapsResolver: Utils.SourceMapsResolver.SourceMapsResolver|null = null;
#entityMapper: Utils.EntityMapper.EntityMapper|null = null;
#onSourceMapsNodeNamesResolvedBound = this.#onSourceMapsNodeNamesResolved.bind(this);
#sidebarToggleButton = this.#splitWidget.createShowHideSidebarButton(
i18nString(UIStrings.showSidebar),
i18nString(UIStrings.hideSidebar),
// These are used to announce to screen-readers and not shown visibly.
i18nString(UIStrings.sidebarShown),
i18nString(UIStrings.sidebarHidden),
'timeline.sidebar', // jslog context
);
#sideBar = new TimelineComponents.Sidebar.SidebarWidget();
/**
* Rather than auto-pop the sidebar every time the user records a trace,
* which could get annoying, we instead persist the state of the sidebar
* visibility to a setting so it's restored across sessions.
* However, sometimes we have to automatically hide the sidebar, like when a
* trace recording is happening, or the user is on the landing page. In those
* times, we toggle this flag to true. Then, when we enter the VIEWING_TRACE
* mode, we check this flag and pop the sidebar open if it's set to true.
* Longer term a better fix here would be to divide the 3 UI screens
* (status pane, landing page, trace view) into distinct components /
* widgets, to avoid this complexity.
*/
#restoreSidebarVisibilityOnTraceLoad = false;
/**
* Used to track an aria announcement that we need to alert for
* screen-readers. We track these because we debounce announcements to not
* overwhelm.
*/
#pendingAriaMessage: string|null = null;
#eventToRelatedInsights: TimelineComponents.RelatedInsightChips.EventToRelatedInsightsMap = new Map();
#shortcutsDialog: Dialogs.ShortcutDialog.ShortcutDialog = new Dialogs.ShortcutDialog.ShortcutDialog();
/**
* Track if the user has opened the shortcuts dialog before. We do this so that the
* very first time the performance panel is open after the shortcuts dialog ships, we can
* automatically pop it open to aid discovery.
*/
#userHadShortcutsDialogOpenedOnce = Common.Settings.Settings.instance().createSetting<boolean>(
'timeline.user-had-shortcuts-dialog-opened-once', false);
/**
* Navigation radio buttons located in the shortcuts dialog.
*/
#navigationRadioButtons = document.createElement('form');
#modernNavRadioButton =
UI.UIUtils.createRadioButton('flamechart-selected-navigation', 'Modern', 'timeline.select-modern-navigation');
#classicNavRadioButton =
UI.UIUtils.createRadioButton('flamechart-selected-navigation', 'Classic', 'timeline.select-classic-navigation');
#onMainEntryHovered: (event: Common.EventTarget.EventTargetEvent<number>) => void;
constructor(traceModel?: Trace.TraceModel.Model) {
super('timeline');
this.registerRequiredCSS(timelinePanelStyles);
const adornerContent = document.createElement('span');
adornerContent.innerHTML = `<div style="
font-size: 12px;
transform: scale(1.25);
color: transparent;
background: linear-gradient(90deg,CLICK255 0 0 / 100%) 0%, rgb(255 154 0 / 100%) 10%, rgb(208 222 33 / 100%) 20%, rgb(79 220 74 / 100%) 30%, rgb(63 218 216 / 100%) 40%, rgb(47 201 226 / 100%) 50%, rgb(28 127 238 / 100%) 60%, rgb(95 21 242 / 100%) 70%, rgb(186 12 248 / 100%) 80%, rgb(251 7 217 / 100%) 90%, rgb(255 0 0 / 100%) 100%);
-webkit-background-clip: text;
">💫</div>`;
const adorner = new Adorners.Adorner.Adorner();
adorner.classList.add('fix-perf-icon');
adorner.data = {
name: i18nString(UIStrings.fixMe),
content: adornerContent,
};
this.#traceEngineModel = traceModel || this.#instantiateNewModel();
this.#listenForProcessingProgress();
this.element.addEventListener('contextmenu', this.contextMenu.bind(this), false);
this.dropTarget = new UI.DropTarget.DropTarget(
this.element, [UI.DropTarget.Type.File, UI.DropTarget.Type.URI],
i18nString(UIStrings.dropTimelineFileOrUrlHere), this.handleDrop.bind(this));
this.recordingOptionUIControls = [];
this.state = State.IDLE;
this.recordingPageReload = false;
this.millisecondsToRecordAfterLoadEvent = 5000;
this.toggleRecordAction = UI.ActionRegistry.ActionRegistry.instance().getAction('timeline.toggle-recording');
// See https://docs.google.com/document/d/1_mtLIHEd9bFQN4xWBSVDR357GaRo56khB1aOxgWDeu4/edit?tab=t.0 for context.
this.recordReloadAction = isReactNative ? null : UI.ActionRegistry.ActionRegistry.instance().getAction('timeline.record-reload');
this.#historyManager = new TimelineHistoryManager(this.#minimapComponent, isNode);
this.traceLoadStart = null;
this.disableCaptureJSProfileSetting = Common.Settings.Settings.instance().createSetting(
'timeline-disable-js-sampling', false, Common.Settings.SettingStorageType.SESSION);
this.disableCaptureJSProfileSetting.setTitle(i18nString(UIStrings.disableJavascriptSamples));
this.captureLayersAndPicturesSetting = Common.Settings.Settings.instance().createSetting(
'timeline-capture-layers-and-pictures', false, Common.Settings.SettingStorageType.SESSION);
this.captureLayersAndPicturesSetting.setTitle(i18nString(UIStrings.enableAdvancedPaint));
this.captureSelectorStatsSetting = Common.Settings.Settings.instance().createSetting(
'timeline-capture-selector-stats', false, Common.Settings.SettingStorageType.SESSION);
this.captureSelectorStatsSetting.setTitle(i18nString(UIStrings.enableSelectorStats));
this.showScreenshotsSetting =
Common.Settings.Settings.instance().createSetting('timeline-show-screenshots', isNode || isReactNative ? false : true);
this.showScreenshotsSetting.setTitle(i18nString(UIStrings.screenshots));
this.showScreenshotsSetting.addChangeListener(this.updateMiniMap, this);
// See https://docs.google.com/document/d/1_mtLIHEd9bFQN4xWBSVDR357GaRo56khB1aOxgWDeu4/edit?tab=t.0 for context.
if (isReactNative) {
this.showMemorySetting = null;
} else {
this.showMemorySetting = Common.Settings.Settings.instance().createSetting('timeline-show-memory', false);
this.showMemorySetting.setTitle(i18nString(UIStrings.memory));
this.showMemorySetting.addChangeListener(this.onMemoryModeChanged, this);
}
// [RN] Used to scope down available features for React Native targets
// See https://docs.google.com/document/d/1_mtLIHEd9bFQN4xWBSVDR357GaRo56khB1aOxgWDeu4/edit?tab=t.0 for context.
if (!isReactNative) {
this.#dimThirdPartiesSetting = Common.Settings.Settings.instance().createSetting(
'timeline-dim-third-parties', false, Common.Settings.SettingStorageType.SESSION);
this.#dimThirdPartiesSetting.setTitle(i18nString(UIStrings.dimThirdParties));
this.#dimThirdPartiesSetting.addChangeListener(this.onDimThirdPartiesChanged, this);
}
this.#thirdPartyTracksSetting = TimelinePanel.extensionDataVisibilitySetting();
this.#thirdPartyTracksSetting.addChangeListener(this.#extensionDataVisibilityChanged, this);
this.#thirdPartyTracksSetting.setTitle(i18nString(UIStrings.showCustomtracks));
const timelineToolbarContainer = this.element.createChild('div', 'timeline-toolbar-container');
timelineToolbarContainer.setAttribute('jslog', `${VisualLogging.toolbar()}`);
timelineToolbarContainer.role = 'toolbar';
this.panelToolbar = timelineToolbarContainer.createChild('devtools-toolbar', 'timeline-main-toolbar');
this.panelToolbar.role = 'presentation';
this.panelToolbar.wrappable = true;
this.panelRightToolbar = timelineToolbarContainer.createChild('devtools-toolbar');
this.panelRightToolbar.role = 'presentation';
if (!isNode) {
this.createSettingsPane();
this.updateShowSettingsToolbarButton();
}
this.timelinePane = new UI.Widget.VBox();
const topPaneElement = this.timelinePane.element.createChild('div', 'hbox');
topPaneElement.id = 'timeline-overview-panel';
this.#minimapComponent.show(topPaneElement);
this.#minimapComponent.addEventListener(PerfUI.TimelineOverviewPane.Events.OVERVIEW_PANE_MOUSE_MOVE, event => {
this.flameChart.addTimestampMarkerOverlay(event.data.timeInMicroSeconds);
});
this.#minimapComponent.addEventListener(PerfUI.TimelineOverviewPane.Events.OVERVIEW_PANE_MOUSE_LEAVE, async () => {
await this.flameChart.removeTimestampMarkerOverlay();
});
this.statusPaneContainer = this.timelinePane.element.createChild('div', 'status-pane-container fill');
this.createFileSelector();
SDK.TargetManager.TargetManager.instance().addModelListener(
SDK.ResourceTreeModel.ResourceTreeModel, SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
this.flameChart = new TimelineFlameChartView(this);
this.element.addEventListener(
'toggle-popover', event => this.flameChart.togglePopover((event as CustomEvent).detail));
this.#onMainEntryHovered = this.#onEntryHovered.bind(this, this.flameChart.getMainDataProvider());
this.flameChart.getMainFlameChart().addEventListener(
PerfUI.FlameChart.Events.ENTRY_HOVERED, this.#onMainEntryHovered);
this.flameChart.addEventListener(TimelineFlameChartViewEvents.ENTRY_LABEL_ANNOTATION_CLICKED, event => {
const selection = selectionFromEvent(event.data.entry);
this.select(selection);
});
this.searchableViewInternal = new UI.SearchableView.SearchableView(this.flameChart, null);
this.searchableViewInternal.setMinimumSize(0, 100);
this.searchableViewInternal.setMinimalSearchQuerySize(2); // At 1 it can introduce a bit of jank.
this.searchableViewInternal.element.classList.add('searchable-view');
this.searchableViewInternal.show(this.timelinePane.element);
this.flameChart.show(this.searchableViewInternal.element);
this.flameChart.setSearchableView(this.searchableViewInternal);
this.searchableViewInternal.hideWidget();
this.#splitWidget.setMainWidget(this.timelinePane);
this.#splitWidget.setSidebarWidget(this.#sideBar);
this.#splitWidget.enableShowModeSaving();
this.#splitWidget.show(this.element);
// [RN] Set up callback for Performance Issue selection
this.#sideBar.setSelectTimelineEventCallback((event: Trace.Types.Events.Event) => {
const selection = selectionFromEvent(event);
this.flameChart.setSelectionAndReveal(selection);
this.flameChart.updatePerfIssueFlameChartDimmer(event);
});
this.flameChart.overlays().addEventListener(Overlays.Overlays.TimeRangeMouseOverEvent.eventName, event => {
const {overlay} = event as Overlays.Overlays.TimeRangeMouseOverEvent;
const overlayBounds = Overlays.Overlays.traceWindowContainingOverlays([overlay]);
if (!overlayBounds) {
return;
}
this.#minimapComponent.highlightBounds(overlayBounds, /* withBracket */ false);
});
this.flameChart.overlays().addEventListener(Overlays.Overlays.TimeRangeMouseOutEvent.eventName, () => {
this.#minimapComponent.clearBoundsHighlight();
});
this.#sideBar.element.addEventListener(TimelineInsights.SidebarInsight.InsightDeactivated.eventName, () => {
this.#setActiveInsight(null);
});
this.#sideBar.element.addEventListener(TimelineInsights.SidebarInsight.InsightActivated.eventName, event => {
const {model, insightSetKey} = event;
this.#setActiveInsight({model, insightSetKey});
// Open the summary panel for the 3p insight.
if (model.insightKey === Trace.Insights.Types.InsightKeys.THIRD_PARTIES) {
void window.scheduler.postTask(() => {
this.#openSummaryTab();
}, {priority: 'background'});
}
});
this.#sideBar.element.addEventListener(TimelineInsights.SidebarInsight.InsightProvideOverlays.eventName, event => {
const {overlays, options} = event;
void window.scheduler.postTask(() => {
this.flameChart.setOverlays(overlays, options);
const overlaysBounds = Overlays.Overlays.traceWindowContainingOverlays(overlays);
if (overlaysBounds) {
this.#minimapComponent.highlightBounds(overlaysBounds, /* withBracket */ true);
} else {
this.#minimapComponent.clearBoundsHighlight();
}
}, {priority: 'user-visible'});
});
this.#sideBar.contentElement.addEventListener(TimelineInsights.EventRef.EventReferenceClick.eventName, event => {
this.select(selectionFromEvent(event.event));
});
this.#sideBar.element.addEventListener(TimelineComponents.Sidebar.RemoveAnnotation.eventName, event => {
const {removedAnnotation} = (event as TimelineComponents.Sidebar.RemoveAnnotation);
ModificationsManager.activeManager()?.removeAnnotation(removedAnnotation);
});
this.#sideBar.element.addEventListener(TimelineComponents.Sidebar.RevealAnnotation.eventName, event => {
this.flameChart.revealAnnotation(event.annotation);
});
this.#sideBar.element.addEventListener(TimelineInsights.SidebarInsight.InsightSetHovered.eventName, event => {
if (event.bounds) {
this.#minimapComponent.highlightBounds(event.bounds, /* withBracket */ true);
} else {
this.#minimapComponent.clearBoundsHighlight();
}
});
this.#sideBar.element.addEventListener(TimelineInsights.SidebarInsight.InsightSetZoom.eventName, event => {
TraceBounds.TraceBounds.BoundsManager.instance().setTimelineVisibleWindow(
event.bounds, {ignoreMiniMapBounds: true, shouldAnimate: true});
});
this.onMemoryModeChanged();
this.populateToolbar();
// The viewMode is set by default to the landing page, so we don't call
// `#changeView` here and can instead directly call showLandingPage();
this.#showLandingPage();
this.updateTimelineControls();
if (isReactNative) {
SDK.TargetManager.TargetManager.instance().observeModels(
SDK.ReactNativeApplicationModel.ReactNativeApplicationModel,
{
modelAdded: (model: SDK.ReactNativeApplicationModel.ReactNativeApplicationModel) => {
model.addEventListener(
SDK.ReactNativeApplicationModel.Events.TRACE_REQUESTED, () => this.rnPrepareForTraceCapturedInBackground());
},
modelRemoved: (_model: SDK.ReactNativeApplicationModel.ReactNativeApplicationModel) => {},
},
);
}
SDK.TargetManager.TargetManager.instance().addEventListener(
SDK.TargetManager.Events.SUSPEND_STATE_CHANGED, this.onSuspendStateChanged, this);
const profilerModels = SDK.TargetManager.TargetManager.instance().models(SDK.CPUProfilerModel.CPUProfilerModel);
for (const model of profilerModels) {
for (const message of model.registeredConsoleProfileMessages) {
this.consoleProfileFinished(message);
}
}
SDK.TargetManager.TargetManager.instance().observeModels(
SDK.CPUProfilerModel.CPUProfilerModel,
{
modelAdded: (model: SDK.CPUProfilerModel.CPUProfilerModel) => {
model.addEventListener(
SDK.CPUProfilerModel.Events.CONSOLE_PROFILE_FINISHED, event => this.consoleProfileFinished(event.data));
},
modelRemoved: (_model: SDK.CPUProfilerModel.CPUProfilerModel) => {
},
},
);
SDK.TargetManager.TargetManager.instance().observeTargets({
targetAdded: (target: SDK.Target.Target) => {
if (target !== SDK.TargetManager.TargetManager.instance().primaryPageTarget()) {
return;
}
this.primaryPageTargetPromiseCallback(target);
},
targetRemoved: (_: SDK.Target.Target) => {},
});
}
private async rnPrepareForTraceCapturedInBackground(): Promise<void> {
this.setUIControlsEnabled(false);
if (this.statusPane) {
this.statusPane.finish();
this.statusPane.updateStatus(i18nString(UIStrings.stoppingTimeline));
this.statusPane.updateProgressBar(i18nString(UIStrings.received), 0);
}
this.setState(State.STOP_PENDING);
const rootTarget = SDK.TargetManager.TargetManager.instance().rootTarget();
if (!rootTarget) {
throw new Error('Could not load root target.');
}
const primaryPageTarget = SDK.TargetManager.TargetManager.instance().primaryPageTarget();
if (!primaryPageTarget) {
throw new Error('Could not load primary page target.');
}
this.controller = new TimelineController(rootTarget, primaryPageTarget, this);
await this.controller.rnPrepareForTraceCapturedInBackground();
this.setUIControlsEnabled(true);
}
#setActiveInsight(insight: TimelineComponents.Sidebar.ActiveInsight|null): void {
// When an insight is selected, ensure that the 3P checkbox is disabled
// to avoid dimming interference.
if (insight && !Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.REACT_NATIVE_SPECIFIC_UI)) {
this.#splitWidget.showBoth();
}
this.#sideBar.setActiveInsight(insight);
this.flameChart.setActiveInsight(insight);
if (insight) {
const selectedInsight = new SelectedInsight(insight);
UI.Context.Context.instance().setFlavor(SelectedInsight, selectedInsight);
} else {
UI.Context.Context.instance().setFlavor(SelectedInsight, null);
}
}
/**
* This "disables" the 3P checkbox in the toolbar.
* Disabling here does a couple of things:
* 1) makes the checkbox dimmed and unclickable
* 2) gives the checkbox UI an indeterminate state
*/
set3PCheckboxDisabled(disabled: boolean): void {
if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.TIMELINE_DIM_UNRELATED_EVENTS)) {
this.#thirdPartyCheckbox?.applyEnabledState(!disabled);
this.#thirdPartyCheckbox?.setIndeterminate(disabled);
}
}
static instance(opts: {
forceNew: boolean|null,
isNode: boolean,
traceModel?: Trace.TraceModel.Model,
}|undefined = {forceNew: null, isNode: false}): TimelinePanel {
const {forceNew, isNode: isNodeMode} = opts;
isNode = isNodeMode;
// [RN] Used to scope down available features for React Native targets
isReactNative = Root.Runtime.experiments.isEnabled(
Root.Runtime.ExperimentName.REACT_NATIVE_SPECIFIC_UI,
);
if (!timelinePanelInstance || forceNew) {
timelinePanelInstance = new TimelinePanel(opts.traceModel);
}
return timelinePanelInstance;
}
static removeInstance(): void {
// TODO(crbug.com/358583420): Simplify attached data management
// so that we don't have to maintain all of these singletons.
Utils.SourceMapsResolver.SourceMapsResolver.clearResolvedNodeNames();
Trace.Helpers.SyntheticEvents.SyntheticEventsManager.reset();
TraceBounds.TraceBounds.BoundsManager.removeInstance();
ModificationsManager.reset();
ActiveFilters.removeInstance();
timelinePanelInstance = undefined;
}
#instantiateNewModel(): Trace.TraceModel.Model {
const config = Trace.Types.Configuration.defaults();
config.showAllEvents = Root.Runtime.experiments.isEnabled('timeline-show-all-events');
config.includeRuntimeCallStats = Root.Runtime.experiments.isEnabled('timeline-v8-runtime-call-stats');
config.debugMode = Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.TIMELINE_DEBUG_MODE);
return Trace.TraceModel.Model.createWithAllHandlers(config);
}
static extensionDataVisibilitySetting(): Common.Settings.Setting<boolean> {
// Calling this multiple times doesn't recreate the setting.
// Instead, after the second call, the cached setting is returned.
return Common.Settings.Settings.instance().createSetting('timeline-show-extension-data', true);
}
override searchableView(): UI.SearchableView.SearchableView|null {
return this.searchableViewInternal;
}
override wasShown(): void {
super.wasShown();
UI.Context.Context.instance().setFlavor(TimelinePanel, this);
// Record the performance tool load time.
Host.userMetrics.panelLoaded('timeline', 'DevTools.Launch.Timeline');
const cruxManager = CrUXManager.CrUXManager.instance();
cruxManager.addEventListener(CrUXManager.Events.FIELD_DATA_CHANGED, this.#onFieldDataChanged, this);
this.#onFieldDataChanged();
}
override willHide(): void {
UI.Context.Context.instance().setFlavor(TimelinePanel, null);
this.#historyManager.cancelIfShowing();
const cruxManager = CrUXManager.CrUXManager.instance();
cruxManager.removeEventListener(CrUXManager.Events.FIELD_DATA_CHANGED, this.#onFieldDataChanged, this);
}
#onFieldDataChanged(): void {
const recs = Utils.Helpers.getThrottlingRecommendations();
this.cpuThrottlingSelect?.updateRecommendedOption(recs.cpuOption);
this.networkThrottlingSelect?.updateRecommendedConditions(recs.networkConditions);
}
loadFromEvents(events: Trace.Types.Events.Event[]): void {
if (this.state !== State.IDLE) {
return;
}
this.prepareToLoadTimeline();
this.loader = TimelineLoader.loadFromEvents(events, this);
}
getFlameChart(): TimelineFlameChartView {
return this.flameChart;
}
getMinimap(): TimelineMiniMap {
return this.#minimapComponent;
}
/**
* Determine if two view modes are equivalent. Useful because if {@see
* #changeView} gets called and the new mode is identical to the current,
* we can bail without doing any UI updates.
*/
#viewModesEquivalent(m1: ViewMode, m2: ViewMode): boolean {
if (m1.mode === 'LANDING_PAGE' && m2.mode === 'LANDING_PAGE') {
return true;
}
if (m1.mode === 'STATUS_PANE_OVERLAY' && m2.mode === 'STATUS_PANE_OVERLAY') {
return true;
}
// VIEWING_TRACE views are only equivalent if their traceIndex is the same.
if (m1.mode === 'VIEWING_TRACE' && m2.mode === 'VIEWING_TRACE' && m1.traceIndex === m2.traceIndex) {
return true;
}
return false;
}
#uninstallSourceMapsResolver(): void {
if (this.#sourceMapsResolver) {
// this set of NodeNames is cached by PIDs, so we clear it so we don't
// use incorrect names from another trace that might happen to share
// PID/TIDs.
Utils.SourceMapsResolver.SourceMapsResolver.clearResolvedNodeNames();
this.#sourceMapsResolver.removeEventListener(
Utils.SourceMapsResolver.SourceMappingsUpdated.eventName, this.#onSourceMapsNodeNamesResolvedBound);
this.#sourceMapsResolver.uninstall();
this.#sourceMapsResolver = null;
}
}
#removeStatusPane(): void {
if (this.statusPane) {
this.statusPane.remove();
}
this.statusPane = null;
}
#changeView(newMode: ViewMode): void {
if (this.#viewModesEquivalent(this.#viewMode, newMode)) {
return;
}
if (this.#viewMode.mode === 'VIEWING_TRACE') {
// If the current / about to be "old" view was viewing a trace
// we also uninstall any source maps resolver for the trace that was active.
// If the user swaps back to this trace via the history dropdown, this will be reinstated.
this.#uninstallSourceMapsResolver();
// Store any modifications (e.g. annotations) that the user has created
// on the current trace before we move away to a new view.
this.#saveModificationsForActiveTrace();
}
this.#viewMode = newMode;
this.updateTimelineControls();
/**
* Note that the TimelinePanel UI is really rendered in two distinct layers.
* 1. status-pane-container: this is what renders both the StatusPane
* loading modal AND the landing page.
* What is important to note is that this renders ON TOP of the
* SearchableView widget, which is what holds the FlameChartView.
*
* 2. SearchableView: this is the container that renders
* TimelineFlameChartView and the rest of the flame chart code.
*
* What this layering means is that when we swap to the LANDING_PAGE or
* STATUS_PANE_OVERLAY view, we don't actually need to reset the
* SearchableView that is rendered behind it, because it won't be visible
* and will be hidden behind the StatusPane/Landing Page.
*
* So the only time we update this SearchableView is when the user goes to
* view a trace. That is why in the switch() statement below you won't see
* any code that resets the SearchableView because we don't need to. We do
* mark it as hidden, but mainly so the user can't accidentally use Cmd-F
* to search a hidden view.
*/
switch (newMode.mode) {
case 'LANDING_PAGE': {
this.#removeStatusPane();
this.#showLandingPage();
// Whilst we don't reset this, we hide it, mainly so the user cannot
// hit Ctrl/Cmd-F and try to search when it isn't visible.
this.searchableViewInternal.hideWidget();
return;
}
case 'VIEWING_TRACE': {
this.#hideLandingPage();
this.#setModelForActiveTrace();
this.#removeStatusPane();
this.#showSidebarIfRequired();
this.flameChart.dimThirdPartiesIfRequired();
return;
}
case 'STATUS_PANE_OVERLAY': {