-
Notifications
You must be signed in to change notification settings - Fork 450
/
TimelineUIUtils.ts
2673 lines (2452 loc) · 109 KB
/
TimelineUIUtils.ts
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) 2013 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 * as Common from '../../core/common/common.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 Bindings from '../../models/bindings/bindings.js';
import * as TimelineModel from '../../models/timeline_model/timeline_model.js';
import * as TraceEngine from '../../models/trace/trace.js';
import * as ModificationsManager from '../../services/modifications_manager/modifications_manager.js';
import * as TraceBounds from '../../services/trace_bounds/trace_bounds.js';
import * as CodeHighlighter from '../../ui/components/code_highlighter/code_highlighter.js';
// eslint-disable-next-line rulesdir/es_modules_import
import codeHighlighterStyles from '../../ui/components/code_highlighter/codeHighlighter.css.js';
import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
// eslint-disable-next-line rulesdir/es_modules_import
import imagePreviewStyles from '../../ui/legacy/components/utils/imagePreview.css.js';
import * as LegacyComponents from '../../ui/legacy/components/utils/utils.js';
// eslint-disable-next-line rulesdir/es_modules_import
import inspectorCommonStyles from '../../ui/legacy/inspectorCommon.css.js';
import * as UI from '../../ui/legacy/legacy.js';
import * as ThemeSupport from '../../ui/legacy/theme_support/theme_support.js';
import {CLSRect} from './CLSLinkifier.js';
import * as TimelineComponents from './components/components.js';
import {
type CategoryPalette,
getCategoryStyles,
getEventStyle,
type TimelineCategory,
TimelineRecordStyle,
visibleTypes,
} from './EventUICategory.js';
import * as Extensions from './extensions/extensions.js';
import {Tracker} from './FreshRecording.js';
import {titleForInteractionEvent} from './InteractionsTrackAppender.js';
import {SourceMapsResolver} from './SourceMapsResolver.js';
import {targetForEvent} from './TargetForEvent.js';
import {TimelinePanel} from './TimelinePanel.js';
import {TimelineSelection} from './TimelineSelection.js';
const UIStrings = {
/**
*@description Text that only contain a placeholder
*@example {100ms (at 200ms)} PH1
*/
emptyPlaceholder: '{PH1}', // eslint-disable-line rulesdir/l10n_no_locked_or_placeholder_only_phrase
/**
*@description Text that refers to updated priority of network request
*/
initialPriority: 'Initial Priority',
/**
*@description Text for timestamps of items
*/
timestamp: 'Timestamp',
/**
*@description Text shown next to the interaction event's ID in the detail view.
*/
interactionID: 'ID',
/**
*@description Text shown next to the interaction event's input delay time in the detail view.
*/
inputDelay: 'Input delay',
/**
*@description Text shown next to the interaction event's thread processing duration in the detail view.
*/
processingDuration: 'Processing duration',
/**
*@description Text shown next to the interaction event's presentation delay time in the detail view.
*/
presentationDelay: 'Presentation delay',
/**
*@description Text shown when the user has selected an event that represents script compiliation.
*/
compile: 'Compile',
/**
*@description Text shown when the user selects an event that represents script parsing.
*/
parse: 'Parse',
/**
*@description Text with two placeholders separated by a colon
*@example {Node removed} PH1
*@example {div#id1} PH2
*/
sS: '{PH1}: {PH2}',
/**
*@description Details text used to show the amount of data collected.
*@example {30 MB} PH1
*/
sCollected: '{PH1} collected',
/**
*@description Text used to show a URL to a script and the relevant line numbers.
*@example {https://example.com/foo.js} PH1
*@example {2} PH2
*@example {4} PH3
*/
sSs: '{PH1} [{PH2}…{PH3}]',
/**
*@description Text used to show a URL to a script and the starting line
* number - used when there is no end line number available.
*@example {https://example.com/foo.js} PH1
*@example {2} PH2
*/
sSSquareBrackets: '{PH1} [{PH2}…]',
/**
*@description Text that is usually a hyperlink to more documentation
*/
learnMore: 'Learn more',
/**
*@description Text referring to the status of the browser's compilation cache.
*/
compilationCacheStatus: 'Compilation cache status',
/**
*@description Text referring to the size of the browser's compiliation cache.
*/
compilationCacheSize: 'Compilation cache size',
/**
*@description Text in Timeline UIUtils of the Performance panel. "Compilation
* cache" refers to the code cache described at
* https://v8.dev/blog/code-caching-for-devs . This label is followed by the
* type of code cache data used, either "normal" or "full" as described in the
* linked article.
*/
compilationCacheKind: 'Compilation cache kind',
/**
*@description Text used to inform the user that the script they are looking
* at was loaded from the browser's cache.
*/
scriptLoadedFromCache: 'script loaded from cache',
/**
*@description Text to inform the user that the script they are looking at
* was unable to be loaded from the browser's cache.
*/
failedToLoadScriptFromCache: 'failed to load script from cache',
/**
*@description Text to inform the user that the script they are looking at was not eligible to be loaded from the browser's cache.
*/
scriptNotEligibleToBeLoadedFromCache: 'script not eligible',
/**
*@description Text for the total time of something
*/
totalTime: 'Total Time',
/**
*@description Time of a single activity, as opposed to the total time
*/
selfTime: 'Self Time',
/**
*@description Label in the summary view in the Performance panel for a number which indicates how much managed memory has been reclaimed by performing Garbage Collection
*/
collected: 'Collected',
/**
*@description Text for a programming function
*/
function: 'Function',
/**
*@description Text for referring to the ID of a timer.
*/
timerId: 'Timer ID',
/**
*@description Text for referring to a timer that has timed-out and therefore is being removed.
*/
timeout: 'Timeout',
/**
*@description Text used to indicate that a timer is repeating (e.g. every X seconds) rather than a one off.
*/
repeats: 'Repeats',
/**
*@description Text for referring to the ID of a callback function installed by an event.
*/
callbackId: 'Callback ID',
/**
*@description Text that refers to the network request method
*/
requestMethod: 'Request Method',
/**
*@description Text to show the priority of an item
*/
priority: 'Priority',
/**
*@description Text used when referring to the data sent in a network request that is encoded as a particular file format.
*/
encodedData: 'Encoded Data',
/**
*@description Text used to refer to the data sent in a network request that has been decoded.
*/
decodedBody: 'Decoded Body',
/**
*@description Text for a module, the programming concept
*/
module: 'Module',
/**
*@description Label for a group of JavaScript files
*/
script: 'Script',
/**
*@description Text used to tell a user that a compilation trace event was streamed.
*/
streamed: 'Streamed',
/**
*@description Text to indicate if a compilation event was eager.
*/
eagerCompile: 'Compiling all functions eagerly',
/**
*@description Text to refer to the URL associated with a given event.
*/
url: 'Url',
/**
*@description Text to indicate to the user the size of the cache (as a filesize - e.g. 5mb).
*/
producedCacheSize: 'Produced Cache Size',
/**
*@description Text to indicate to the user the amount of the cache (as a filesize - e.g. 5mb) that has been used.
*/
consumedCacheSize: 'Consumed Cache Size',
/**
*@description Title for a group of cities
*/
location: 'Location',
/**
*@description Text used to show a coordinate pair (e.g. (3, 2)).
*@example {2} PH1
*@example {2} PH2
*/
sSCurlyBrackets: '({PH1}, {PH2})',
/**
*@description Text used to indicate to the user they are looking at the physical dimensions of a shape that was drawn by the browser.
*/
dimensions: 'Dimensions',
/**
*@description Text used to show the user the dimensions of a shape and indicate its area (e.g. 3x2).
*@example {2} PH1
*@example {2} PH2
*/
sSDimensions: '{PH1} × {PH2}',
/**
*@description Related node label in Timeline UIUtils of the Performance panel
*/
layerRoot: 'Layer Root',
/**
*@description Related node label in Timeline UIUtils of the Performance panel
*/
ownerElement: 'Owner Element',
/**
*@description Text used to show the user the URL of the image they are viewing.
*/
imageUrl: 'Image URL',
/**
*@description Text used to show the user that the URL they are viewing is loading a CSS stylesheet.
*/
stylesheetUrl: 'Stylesheet URL',
/**
*@description Text used next to a number to show the user how many elements were affected.
*/
elementsAffected: 'Elements Affected',
/**
*@description Text used next to a number to show the user how many nodes required the browser to update and re-layout the page.
*/
nodesThatNeedLayout: 'Nodes That Need Layout',
/**
*@description Text used to show the amount in a subset - e.g. "2 of 10".
*@example {2} PH1
*@example {10} PH2
*/
sOfS: '{PH1} of {PH2}',
/**
*@description Related node label in Timeline UIUtils of the Performance panel
*/
layoutRoot: 'Layout root',
/**
*@description Text used when viewing an event that can have a custom message attached.
*/
message: 'Message',
/**
*@description Text used to tell the user they are viewing an event that has a function embedded in it, which is referred to as the "callback function".
*/
callbackFunction: 'Callback Function',
/**
*@description The current state of an item
*/
state: 'State',
/**
*@description Text used to show the relevant range of a file - e.g. "lines 2-10".
*/
range: 'Range',
/**
*@description Text used to refer to the amount of time some event or code was given to complete within.
*/
allottedTime: 'Allotted Time',
/**
*@description Text used to tell a user that a particular event or function was automatically run by a timeout.
*/
invokedByTimeout: 'Invoked by Timeout',
/**
*@description Text that refers to some types
*/
type: 'Type',
/**
*@description Text for the size of something
*/
size: 'Size',
/**
*@description Text for the details of something
*/
details: 'Details',
/**
*@description Title in Timeline for Cumulative Layout Shifts
*/
cumulativeLayoutShifts: 'Cumulative Layout Shifts',
/**
*@description Text for the link to the evolved CLS website
*/
evolvedClsLink: 'evolved',
/**
*@description Warning in Timeline that CLS can cause a poor user experience. It contains a link to inform developers about the recent changes to how CLS is measured. The new CLS metric is said to have evolved from the previous version.
*@example {Link to web.dev/metrics} PH1
*@example {Link to web.dev/evolving-cls which will always have the text 'evolved'} PH2
*/
sCLSInformation: '{PH1} can result in poor user experiences. It has recently {PH2}.',
/**
*@description Text to indicate an item is a warning
*/
warning: 'Warning',
/**
*@description Title for the Timeline CLS Score
*/
score: 'Score',
/**
*@description Text in Timeline for the cumulative CLS score
*/
cumulativeScore: 'Cumulative Score',
/**
*@description Text in Timeline for the current CLS score
*/
currentClusterScore: 'Current Cluster Score',
/**
*@description Text in Timeline for the current CLS cluster
*/
currentClusterId: 'Current Cluster ID',
/**
*@description Text in Timeline for whether input happened recently
*/
hadRecentInput: 'Had recent input',
/**
*@description Text in Timeline indicating that input has happened recently
*/
yes: 'Yes',
/**
*@description Text in Timeline indicating that input has not happened recently
*/
no: 'No',
/**
*@description Label for Cumulative Layout records, indicating where they moved from
*/
movedFrom: 'Moved from',
/**
*@description Label for Cumulative Layout records, indicating where they moved to
*/
movedTo: 'Moved to',
/**
*@description Text that indicates a particular HTML element or node is related to what the user is viewing.
*/
relatedNode: 'Related Node',
/**
*@description Text for previewing items
*/
preview: 'Preview',
/**
*@description Text used to refer to the total time summed up across multiple events.
*/
aggregatedTime: 'Aggregated Time',
/**
*@description Text to indicate to the user they are viewing an event representing a network request.
*/
networkRequest: 'Network request',
/**
*@description Text used to indicate if a network request was loaded from the cache.
*/
loadFromCache: 'load from cache',
/**
*@description Text used to indicate if a network request was transferred over the network (rather than being loaded from the cache.)
*/
networkTransfer: 'network transfer',
/**
*@description Text used to show the total time a network request spent loading a resource.
*@example {1ms} PH1
*@example {network transfer} PH2
*@example {1ms} PH3
*/
SSSResourceLoading: ' ({PH1} {PH2} + {PH3} resource loading)',
/**
*@description Text for the duration of something
*/
duration: 'Duration',
/**
*@description Text used to show the mime-type of the data transferred with a network request (e.g. "application/json").
*/
mimeType: 'Mime Type',
/**
*@description Text used to show the user that a request was served from the browser's in-memory cache.
*/
FromMemoryCache: ' (from memory cache)',
/**
*@description Text used to show the user that a request was served from the browser's file cache.
*/
FromCache: ' (from cache)',
/**
*@description Label for a network request indicating that it was a HTTP2 server push instead of a regular network request, in the Performance panel
*/
FromPush: ' (from push)',
/**
*@description Text used to show a user that a request was served from an installed, active service worker.
*/
FromServiceWorker: ' (from `service worker`)',
/**
*@description Text for the stack trace of the initiator of something. The Initiator is the event or factor that directly triggered or precipitated a subsequent action.
*/
initiatorStackTrace: 'Initiator Stack Trace',
/**
*@description Text for the event initiated by another one
*/
initiatedBy: 'Initiated by',
/**
*@description Text for the event that is an initiator for another one
*/
initiatorFor: 'Initiator for',
/**
*@description Text for the underlying data behing a specific flamechart selection. Trace events are the browser instrumentation that are emitted as JSON objects.
*/
traceEvent: 'Trace Event',
/**
*@description Call site stack label in Timeline UIUtils of the Performance panel
*/
timerInstalled: 'Timer Installed',
/**
*@description Call site stack label in Timeline UIUtils of the Performance panel
*/
animationFrameRequested: 'Animation Frame Requested',
/**
*@description Call site stack label in Timeline UIUtils of the Performance panel
*/
idleCallbackRequested: 'Idle Callback Requested',
/**
*@description Stack label in Timeline UIUtils of the Performance panel
*/
recalculationForced: 'Recalculation Forced',
/**
*@description Call site stack label in Timeline UIUtils of the Performance panel
*/
firstLayoutInvalidation: 'First Layout Invalidation',
/**
*@description Stack label in Timeline UIUtils of the Performance panel
*/
layoutForced: 'Layout Forced',
/**
*@description Text for the execution stack trace
*/
stackTrace: 'Stack Trace',
/**
*@description Text used to show any invalidations for a particular event that caused the browser to have to do more work to update the page.
*/
invalidations: 'Invalidations',
/**
* @description Text in Timeline UIUtils of the Performance panel. Phrase is followed by a number of milliseconds.
* Some events or tasks might have been only started, but have not ended yet. Such events or tasks are considered
* "pending".
*/
pendingFor: 'Pending for',
/**
*@description Noun label for a stack trace which indicates the first time some condition was invalidated.
*/
firstInvalidated: 'First Invalidated',
/**
*@description Title of the paint profiler, old name of the performance pane
*/
paintProfiler: 'Paint Profiler',
/**
*@description Text in Timeline Flame Chart View of the Performance panel
*@example {Frame} PH1
*@example {10ms} PH2
*/
sAtS: '{PH1} at {PH2}',
/**
*@description Text used next to a time to indicate that the particular event took that much time itself. In context this might look like "3ms blink.console (self)"
*@example {blink.console} PH1
*/
sSelf: '{PH1} (self)',
/**
*@description Text used next to a time to indicate that the event's children took that much time. In context this might look like "3ms blink.console (children)"
*@example {blink.console} PH1
*/
sChildren: '{PH1} (children)',
/**
*@description Text used to show the user how much time the browser spent on rendering (drawing the page onto the screen).
*/
timeSpentInRendering: 'Time spent in rendering',
/**
*@description Text for a rendering frame
*/
frame: 'Frame',
/**
*@description Text used to refer to the duration of an event at a given offset - e.g. "2ms at 10ms" which can be read as "2ms starting after 10ms".
*@example {10ms} PH1
*@example {10ms} PH2
*/
sAtSParentheses: '{PH1} (at {PH2})',
/**
*@description Text of a DOM element in Timeline UIUtils of the Performance panel
*/
UnknownNode: '[ unknown node ]',
/**
*@description Text used to refer to a particular element and the file it was referred to in.
*@example {node} PH1
*@example {app.js} PH2
*/
invalidationWithCallFrame: '{PH1} at {PH2}',
/**
*@description Text indicating that something is outside of the Performace Panel Timeline Minimap range
*/
outsideBreadcrumbRange: '(outside of the breadcrumb range)',
/**
*@description Text indicating that something is hidden from the Performace Panel Timeline
*/
entryIsHidden: '(entry is hidden)',
/**
* @description Title of a row in the details view for a `Recalculate Styles` event that contains more info about selector stats tracing.
*/
selectorStatsTitle: 'Selector Stats',
/**
* @description Info text that explains to the user how to enable selector stats tracing.
* @example {Setting Name} PH1
*/
sSelectorStatsInfo: 'Select "{PH1}" to collect detailed CSS selector matching statistics.',
};
const str_ = i18n.i18n.registerUIStrings('panels/timeline/TimelineUIUtils.ts', UIStrings);
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
let eventDispatchDesciptors: EventDispatchTypeDescriptor[];
let colorGenerator: Common.Color.Generator;
const requestPreviewElements = new WeakMap<TraceEngine.Types.TraceEvents.SyntheticNetworkRequest, HTMLImageElement>();
type LinkifyLocationOptions = {
scriptId: Protocol.Runtime.ScriptId|null,
url: string,
lineNumber: number,
columnNumber?: number,
isFreshRecording?: boolean, target: SDK.Target.Target|null, linkifier: LegacyComponents.Linkifier.Linkifier,
};
export class TimelineUIUtils {
static frameDisplayName(frame: Protocol.Runtime.CallFrame): string {
if (!TimelineModel.TimelineJSProfile.TimelineJSProfileProcessor.isNativeRuntimeFrame(frame)) {
return UI.UIUtils.beautifyFunctionName(frame.functionName);
}
const nativeGroup = TimelineModel.TimelineJSProfile.TimelineJSProfileProcessor.nativeGroup(frame.functionName);
switch (nativeGroup) {
case TimelineModel.TimelineJSProfile.TimelineJSProfileProcessor.NativeGroups.Compile:
return i18nString(UIStrings.compile);
case TimelineModel.TimelineJSProfile.TimelineJSProfileProcessor.NativeGroups.Parse:
return i18nString(UIStrings.parse);
}
return frame.functionName;
}
static testContentMatching(
traceEvent: TraceEngine.Types.TraceEvents.TraceEventData, regExp: RegExp,
traceParsedData?: TraceEngine.Handlers.Types.TraceParseData): boolean {
const title = TimelineUIUtils.eventStyle(traceEvent).title;
const tokens = [title];
if (TraceEngine.Types.TraceEvents.isProfileCall(traceEvent)) {
// In the future this case will not be possible - wherever we call this
// function we will be able to pass in the data from the new engine. But
// currently this is called in a variety of places including from the
// legacy model which does not have a reference to the new engine's data.
// So if we are missing the data, we just fallback to the name from the
// callFrame.
if (!traceParsedData || !traceParsedData.Samples) {
tokens.push(traceEvent.callFrame.functionName);
} else {
tokens.push(
TraceEngine.Handlers.ModelHandlers.Samples.getProfileCallFunctionName(traceParsedData.Samples, traceEvent));
}
}
if (traceParsedData) {
const url = TraceEngine.Extras.URLForEntry.get(traceParsedData, traceEvent);
if (url) {
tokens.push(url);
}
}
// This works for both legacy and new engine events.
appendObjectProperties(traceEvent.args as ContentObject, 2);
const result = tokens.join('|').match(regExp);
return result ? result.length > 0 : false;
interface ContentObject {
[x: string]: number|string|ContentObject;
}
function appendObjectProperties(object: ContentObject, depth: number): void {
if (!depth) {
return;
}
for (const key in object) {
const value = object[key];
if (typeof value === 'string') {
tokens.push(value);
} else if (typeof value === 'number') {
tokens.push(String(value));
} else if (typeof value === 'object' && value !== null) {
appendObjectProperties(value, depth - 1);
}
}
}
}
static eventStyle(event: TraceEngine.Types.TraceEvents.TraceEventData): TimelineRecordStyle {
if (TraceEngine.Helpers.Trace.eventHasCategory(event, TraceEngine.Types.TraceEvents.Categories.Console) ||
TraceEngine.Helpers.Trace.eventHasCategory(event, TraceEngine.Types.TraceEvents.Categories.UserTiming)) {
return new TimelineRecordStyle(event.name, getCategoryStyles()['scripting']);
}
if (TraceEngine.Types.TraceEvents.isProfileCall(event)) {
if (event.callFrame.functionName === '(idle)') {
return new TimelineRecordStyle(event.name, getCategoryStyles().idle);
}
}
const defaultStyles = new TimelineRecordStyle(event.name, getCategoryStyles().other);
return getEventStyle(event.name as TraceEngine.Types.TraceEvents.KnownEventName) || defaultStyles;
}
static eventColor(event: TraceEngine.Types.TraceEvents.TraceEventData): string {
if (TraceEngine.Types.TraceEvents.isProfileCall(event)) {
const frame = event.callFrame;
if (TimelineUIUtils.isUserFrame(frame)) {
return TimelineUIUtils.colorForId(frame.url);
}
}
if (TraceEngine.Types.Extensions.isSyntheticExtensionEntry(event)) {
return Extensions.ExtensionUI.extensionEntryColor(event);
}
let parsedColor = TimelineUIUtils.eventStyle(event).category.getComputedColorValue();
// This event is considered idle time but still rendered as a scripting event here
// to connect the StreamingCompileScriptParsing events it belongs to.
if (event.name === TraceEngine.Types.TraceEvents.KnownEventName.StreamingCompileScriptWaiting) {
parsedColor = getCategoryStyles().scripting.getComputedColorValue();
if (!parsedColor) {
throw new Error('Unable to parse color from getCategoryStyles().scripting.color');
}
}
return parsedColor;
}
static eventTitle(event: TraceEngine.Types.TraceEvents.TraceEventData): string {
// Profile call events do not have a args.data property, thus, we
// need to check for profile calls in the beginning of this
// function.
if (TraceEngine.Types.TraceEvents.isProfileCall(event)) {
const maybeResolvedName = SourceMapsResolver.resolvedNodeNameForEntry(event);
const displayName = maybeResolvedName || TimelineUIUtils.frameDisplayName(event.callFrame);
return displayName;
}
if (event.name === 'EventTiming' && TraceEngine.Types.TraceEvents.isSyntheticInteractionEvent(event)) {
return titleForInteractionEvent(event);
}
const title = TimelineUIUtils.eventStyle(event).title;
if (TraceEngine.Helpers.Trace.eventHasCategory(event, TraceEngine.Types.TraceEvents.Categories.Console)) {
return title;
}
if (TraceEngine.Types.TraceEvents.isTraceEventTimeStamp(event)) {
return i18nString(UIStrings.sS, {PH1: title, PH2: event.args.data.message});
}
if (TraceEngine.Types.TraceEvents.isTraceEventAnimation(event) && event.args.data.name) {
return i18nString(UIStrings.sS, {PH1: title, PH2: event.args.data.name});
}
if (TraceEngine.Types.TraceEvents.isTraceEventDispatch(event)) {
return i18nString(UIStrings.sS, {PH1: title, PH2: event.args.data.type});
}
return title;
}
static isUserFrame(frame: Protocol.Runtime.CallFrame): boolean {
return frame.scriptId !== '0' && !(frame.url && frame.url.startsWith('native '));
}
static syntheticNetworkRequestCategory(request: TraceEngine.Types.TraceEvents.SyntheticNetworkRequest):
NetworkCategory {
switch (request.args.data.mimeType) {
case 'text/html':
return NetworkCategory.HTML;
case 'application/javascript':
case 'application/x-javascript':
case 'text/javascript':
return NetworkCategory.Script;
case 'text/css':
return NetworkCategory.Style;
case 'audio/ogg':
case 'image/gif':
case 'image/jpeg':
case 'image/png':
case 'image/svg+xml':
case 'image/webp':
case 'image/x-icon':
case 'font/opentype':
case 'font/woff2':
case 'font/ttf':
case 'application/font-woff':
return NetworkCategory.Media;
default:
return NetworkCategory.Other;
}
}
static networkCategoryColor(category: NetworkCategory): string {
let cssVarName = '--app-color-system';
switch (category) {
case NetworkCategory.HTML:
cssVarName = '--app-color-loading';
break;
case NetworkCategory.Script:
cssVarName = '--app-color-scripting';
break;
case NetworkCategory.Style:
cssVarName = '--app-color-rendering';
break;
case NetworkCategory.Media:
cssVarName = '--app-color-painting';
break;
default:
cssVarName = '--app-color-system';
break;
}
return ThemeSupport.ThemeSupport.instance().getComputedValue(cssVarName);
}
static async buildDetailsTextForTraceEvent(
event: TraceEngine.Types.TraceEvents.TraceEventData,
traceParsedData: TraceEngine.Handlers.Types.TraceParseData): Promise<string|null> {
let detailsText;
// TODO(40287735): update this code with type-safe data checks.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const unsafeEventArgs = event.args as Record<string, any>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const unsafeEventData = event.args?.data as Record<string, any>;
switch (event.name) {
case TraceEngine.Types.TraceEvents.KnownEventName.GC:
case TraceEngine.Types.TraceEvents.KnownEventName.MajorGC:
case TraceEngine.Types.TraceEvents.KnownEventName.MinorGC: {
const delta = unsafeEventArgs['usedHeapSizeBefore'] - unsafeEventArgs['usedHeapSizeAfter'];
detailsText = i18nString(UIStrings.sCollected, {PH1: Platform.NumberUtilities.bytesToString(delta)});
break;
}
case TraceEngine.Types.TraceEvents.KnownEventName.FunctionCall: {
const {lineNumber, columnNumber} = TraceEngine.Helpers.Trace.getZeroIndexedLineAndColumnForEvent(event);
if (lineNumber !== undefined && columnNumber !== undefined) {
detailsText = unsafeEventData.url + ':' + (lineNumber + 1) + ':' + (columnNumber + 1);
}
break;
}
case TraceEngine.Types.TraceEvents.KnownEventName.EventDispatch:
detailsText = unsafeEventData ? unsafeEventData['type'] : null;
break;
case TraceEngine.Types.TraceEvents.KnownEventName.Paint: {
const width = TimelineUIUtils.quadWidth(unsafeEventData.clip);
const height = TimelineUIUtils.quadHeight(unsafeEventData.clip);
if (width && height) {
detailsText = i18nString(UIStrings.sSDimensions, {PH1: width, PH2: height});
}
break;
}
case TraceEngine.Types.TraceEvents.KnownEventName.ParseHTML: {
const startLine = unsafeEventArgs['beginData']['startLine'];
const endLine = unsafeEventArgs['endData'] && unsafeEventArgs['endData']['endLine'];
const url = Bindings.ResourceUtils.displayNameForURL(unsafeEventArgs['beginData']['url']);
if (endLine >= 0) {
detailsText = i18nString(UIStrings.sSs, {PH1: url, PH2: startLine + 1, PH3: endLine + 1});
} else {
detailsText = i18nString(UIStrings.sSSquareBrackets, {PH1: url, PH2: startLine + 1});
}
break;
}
case TraceEngine.Types.TraceEvents.KnownEventName.CompileModule:
case TraceEngine.Types.TraceEvents.KnownEventName.CacheModule:
detailsText = Bindings.ResourceUtils.displayNameForURL(unsafeEventArgs['fileName']);
break;
case TraceEngine.Types.TraceEvents.KnownEventName.CompileScript:
case TraceEngine.Types.TraceEvents.KnownEventName.CacheScript:
case TraceEngine.Types.TraceEvents.KnownEventName.EvaluateScript: {
const {lineNumber} = TraceEngine.Helpers.Trace.getZeroIndexedLineAndColumnForEvent(event);
const url = unsafeEventData && unsafeEventData['url'];
if (url) {
detailsText = Bindings.ResourceUtils.displayNameForURL(url) + ':' + ((lineNumber || 0) + 1);
}
break;
}
case TraceEngine.Types.TraceEvents.KnownEventName.WasmCompiledModule:
case TraceEngine.Types.TraceEvents.KnownEventName.WasmModuleCacheHit: {
const url = unsafeEventArgs['url'];
if (url) {
detailsText = Bindings.ResourceUtils.displayNameForURL(url);
}
break;
}
case TraceEngine.Types.TraceEvents.KnownEventName.StreamingCompileScript:
case TraceEngine.Types.TraceEvents.KnownEventName.BackgroundDeserialize:
case TraceEngine.Types.TraceEvents.KnownEventName.XHRReadyStateChange:
case TraceEngine.Types.TraceEvents.KnownEventName.XHRLoad: {
const url = unsafeEventData['url'];
if (url) {
detailsText = Bindings.ResourceUtils.displayNameForURL(url);
}
break;
}
case TraceEngine.Types.TraceEvents.KnownEventName.TimeStamp:
detailsText = unsafeEventData['message'];
break;
case TraceEngine.Types.TraceEvents.KnownEventName.WebSocketCreate:
case TraceEngine.Types.TraceEvents.KnownEventName.WebSocketSendHandshakeRequest:
case TraceEngine.Types.TraceEvents.KnownEventName.WebSocketReceiveHandshakeResponse:
case TraceEngine.Types.TraceEvents.KnownEventName.WebSocketDestroy:
case TraceEngine.Types.TraceEvents.KnownEventName.ResourceWillSendRequest:
case TraceEngine.Types.TraceEvents.KnownEventName.ResourceSendRequest:
case TraceEngine.Types.TraceEvents.KnownEventName.ResourceReceivedData:
case TraceEngine.Types.TraceEvents.KnownEventName.ResourceReceiveResponse:
case TraceEngine.Types.TraceEvents.KnownEventName.ResourceFinish:
case TraceEngine.Types.TraceEvents.KnownEventName.PaintImage:
case TraceEngine.Types.TraceEvents.KnownEventName.DecodeImage:
case TraceEngine.Types.TraceEvents.KnownEventName.DecodeLazyPixelRef: {
const url = TraceEngine.Extras.URLForEntry.get(traceParsedData, event);
if (url) {
detailsText = Bindings.ResourceUtils.displayNameForURL(url);
}
break;
}
case TraceEngine.Types.TraceEvents.KnownEventName.EmbedderCallback:
detailsText = unsafeEventData['callbackName'];
break;
case TraceEngine.Types.TraceEvents.KnownEventName.Animation:
detailsText = unsafeEventData && unsafeEventData['name'];
break;
case TraceEngine.Types.TraceEvents.KnownEventName.AsyncTask:
detailsText = unsafeEventData ? unsafeEventData['name'] : null;
break;
default:
if (TraceEngine.Helpers.Trace.eventHasCategory(event, TraceEngine.Types.TraceEvents.Categories.Console)) {
detailsText = null;
} else {
detailsText = linkifyTopCallFrameAsText();
}
break;
}
return detailsText;
function linkifyTopCallFrameAsText(): string|null {
const frame = TraceEngine.Helpers.Trace.getZeroIndexedStackTraceForEvent(event)?.at(0) ?? null;
if (!frame) {
return null;
}
return frame.url + ':' + (frame.lineNumber + 1) + ':' + (frame.columnNumber + 1);
}
}
static async buildDetailsNodeForTraceEvent(
event: TraceEngine.Types.TraceEvents.TraceEventData, target: SDK.Target.Target|null,
linkifier: LegacyComponents.Linkifier.Linkifier, isFreshRecording = false,
traceParsedData: TraceEngine.Handlers.Types.TraceParseData): Promise<Node|null> {
let details: HTMLElement|HTMLSpanElement|(Element | null)|Text|null = null;
let detailsText;
// TODO(40287735): update this code with type-safe data checks.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const unsafeEventArgs = event.args as Record<string, any>;
// TODO(40287735): update this code with type-safe data checks.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const unsafeEventData = event.args?.data as Record<string, any>;
switch (event.name) {
case TraceEngine.Types.TraceEvents.KnownEventName.GC:
case TraceEngine.Types.TraceEvents.KnownEventName.MajorGC:
case TraceEngine.Types.TraceEvents.KnownEventName.MinorGC:
case TraceEngine.Types.TraceEvents.KnownEventName.EventDispatch:
case TraceEngine.Types.TraceEvents.KnownEventName.Paint:
case TraceEngine.Types.TraceEvents.KnownEventName.Animation:
case TraceEngine.Types.TraceEvents.KnownEventName.EmbedderCallback:
case TraceEngine.Types.TraceEvents.KnownEventName.ParseHTML:
case TraceEngine.Types.TraceEvents.KnownEventName.WasmStreamFromResponseCallback:
case TraceEngine.Types.TraceEvents.KnownEventName.WasmCompiledModule:
case TraceEngine.Types.TraceEvents.KnownEventName.WasmModuleCacheHit:
case TraceEngine.Types.TraceEvents.KnownEventName.WasmCachedModule:
case TraceEngine.Types.TraceEvents.KnownEventName.WasmModuleCacheInvalid:
case TraceEngine.Types.TraceEvents.KnownEventName.WebSocketCreate:
case TraceEngine.Types.TraceEvents.KnownEventName.WebSocketSendHandshakeRequest:
case TraceEngine.Types.TraceEvents.KnownEventName.WebSocketReceiveHandshakeResponse:
case TraceEngine.Types.TraceEvents.KnownEventName.WebSocketDestroy: {
detailsText = await TimelineUIUtils.buildDetailsTextForTraceEvent(event, traceParsedData);
break;
}
case TraceEngine.Types.TraceEvents.KnownEventName.PaintImage:
case TraceEngine.Types.TraceEvents.KnownEventName.DecodeImage:
case TraceEngine.Types.TraceEvents.KnownEventName.DecodeLazyPixelRef:
case TraceEngine.Types.TraceEvents.KnownEventName.XHRReadyStateChange:
case TraceEngine.Types.TraceEvents.KnownEventName.XHRLoad:
case TraceEngine.Types.TraceEvents.KnownEventName.ResourceWillSendRequest:
case TraceEngine.Types.TraceEvents.KnownEventName.ResourceSendRequest:
case TraceEngine.Types.TraceEvents.KnownEventName.ResourceReceivedData:
case TraceEngine.Types.TraceEvents.KnownEventName.ResourceReceiveResponse:
case TraceEngine.Types.TraceEvents.KnownEventName.ResourceFinish: {
const url = TraceEngine.Extras.URLForEntry.get(traceParsedData, event);
if (url) {
const options = {
tabStop: true,
showColumnNumber: false,
inlineFrameIndex: 0,
};
details = LegacyComponents.Linkifier.Linkifier.linkifyURL(url, options);
}
break;
}
case TraceEngine.Types.TraceEvents.KnownEventName.FunctionCall: {
details = document.createElement('span');
// FunctionCall events have an args.data that could be a CallFrame, if all the details are present, so we check for that.
if (TraceEngine.Types.TraceEvents.isTraceEventFunctionCall(event) && event.args.data &&
TraceEngine.Types.TraceEvents.objectIsTraceEventCallFrame(event.args.data)) {
UI.UIUtils.createTextChild(
details,
TimelineUIUtils.frameDisplayName(
{...event.args.data, scriptId: String(event.args.data.scriptId) as Protocol.Runtime.ScriptId}));
}
const {lineNumber, columnNumber} = TraceEngine.Helpers.Trace.getZeroIndexedLineAndColumnForEvent(event);
const location = this.linkifyLocation({
scriptId: unsafeEventData['scriptId'],
url: unsafeEventData['url'],
lineNumber: lineNumber || 0,
columnNumber: columnNumber,
target,
isFreshRecording,
linkifier,
});
if (location) {
UI.UIUtils.createTextChild(details, ' @ ');
details.appendChild(location);
}
break;
}
case TraceEngine.Types.TraceEvents.KnownEventName.CompileModule:
case TraceEngine.Types.TraceEvents.KnownEventName.CacheModule: {
details = this.linkifyLocation({
scriptId: null,
url: unsafeEventArgs['fileName'],
lineNumber: 0,
columnNumber: 0,
target,