blob: abcf9799623028ec8becd1e4daac89c5f2dbe337 [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371// Copyright 2016 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
Tim van der Lippecec9b762020-02-13 15:31:225import * as Common from '../common/common.js';
6import * as PerfUI from '../perf_ui/perf_ui.js';
Jack Franklin1cb34212020-03-09 09:28:127import * as Platform from '../platform/platform.js';
Tim van der Lippecec9b762020-02-13 15:31:228import * as SDK from '../sdk/sdk.js';
9import * as TimelineModel from '../timeline_model/timeline_model.js';
10import * as UI from '../ui/ui.js';
11
Paul Lewis897ad8b2020-01-15 16:49:1712import {CountersGraph} from './CountersGraph.js';
Tim van der Lippefced1b92020-02-17 12:33:5013import {Events as PerformanceModelEvents, PerformanceModel, Window} from './PerformanceModel.js'; // eslint-disable-line no-unused-vars
Paul Lewis897ad8b2020-01-15 16:49:1714import {TimelineDetailsView} from './TimelineDetailsView.js';
15import {TimelineRegExp} from './TimelineFilters.js';
16import {Events as TimelineFlameChartDataProviderEvents, TimelineFlameChartDataProvider} from './TimelineFlameChartDataProvider.js';
17import {TimelineFlameChartNetworkDataProvider} from './TimelineFlameChartNetworkDataProvider.js';
18import {TimelineModeViewDelegate, TimelineSelection} from './TimelinePanel.js'; // eslint-disable-line no-unused-vars
19import {AggregatedTimelineTreeView} from './TimelineTreeView.js';
Tim van der Lippefced1b92020-02-17 12:33:5020import {TimelineMarkerStyle, TimelineUIUtils} from './TimelineUIUtils.js'; // eslint-disable-line no-unused-vars
Paul Lewis897ad8b2020-01-15 16:49:1721
Blink Reformat4c46d092018-04-07 15:32:3722/**
Tim van der Lippecec9b762020-02-13 15:31:2223 * @implements {PerfUI.FlameChart.FlameChartDelegate}
24 * @implements {UI.SearchableView.Searchable}
Blink Reformat4c46d092018-04-07 15:32:3725 * @unrestricted
26 */
Tim van der Lippecec9b762020-02-13 15:31:2227export class TimelineFlameChartView extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3728 /**
Paul Lewis897ad8b2020-01-15 16:49:1729 * @param {!TimelineModeViewDelegate} delegate
Blink Reformat4c46d092018-04-07 15:32:3730 */
Alexei Filippov35f97d62018-04-28 01:02:3131 constructor(delegate) {
Blink Reformat4c46d092018-04-07 15:32:3732 super();
33 this.element.classList.add('timeline-flamechart');
34 this._delegate = delegate;
Paul Lewis897ad8b2020-01-15 16:49:1735 /** @type {?PerformanceModel} */
Blink Reformat4c46d092018-04-07 15:32:3736 this._model = null;
37 /** @type {!Array<number>|undefined} */
38 this._searchResults;
Alexei Filippov2578eb02018-04-11 08:15:0539 /** @type {!Array<!Common.EventTarget.EventDescriptor>} */
40 this._eventListeners = [];
Blink Reformat4c46d092018-04-07 15:32:3741
Paul Lewis2d7d65c2020-03-16 17:26:3042 this._showMemoryGraphSetting = Common.Settings.Settings.instance().createSetting('timelineShowMemory', false);
Blink Reformat4c46d092018-04-07 15:32:3743
44 // Create main and network flamecharts.
Tim van der Lippecec9b762020-02-13 15:31:2245 this._networkSplitWidget = new UI.SplitWidget.SplitWidget(false, false, 'timelineFlamechartMainView', 150);
Blink Reformat4c46d092018-04-07 15:32:3746
Paul Lewis6bcdb182020-01-23 11:08:0547 const mainViewGroupExpansionSetting =
Paul Lewis2d7d65c2020-03-16 17:26:3048 Common.Settings.Settings.instance().createSetting('timelineFlamechartMainViewGroupExpansion', {});
Paul Lewis897ad8b2020-01-15 16:49:1749 this._mainDataProvider = new TimelineFlameChartDataProvider();
Blink Reformat4c46d092018-04-07 15:32:3750 this._mainDataProvider.addEventListener(
Paul Lewis897ad8b2020-01-15 16:49:1751 TimelineFlameChartDataProviderEvents.DataChanged, () => this._mainFlameChart.scheduleUpdate());
Tim van der Lippecec9b762020-02-13 15:31:2252 this._mainFlameChart =
53 new PerfUI.FlameChart.FlameChart(this._mainDataProvider, this, mainViewGroupExpansionSetting);
Blink Reformat4c46d092018-04-07 15:32:3754 this._mainFlameChart.alwaysShowVerticalScroll();
55 this._mainFlameChart.enableRuler(false);
56
57 this._networkFlameChartGroupExpansionSetting =
Paul Lewis2d7d65c2020-03-16 17:26:3058 Common.Settings.Settings.instance().createSetting('timelineFlamechartNetworkViewGroupExpansion', {});
Paul Lewis897ad8b2020-01-15 16:49:1759 this._networkDataProvider = new TimelineFlameChartNetworkDataProvider();
Tim van der Lippecec9b762020-02-13 15:31:2260 this._networkFlameChart =
61 new PerfUI.FlameChart.FlameChart(this._networkDataProvider, this, this._networkFlameChartGroupExpansionSetting);
Blink Reformat4c46d092018-04-07 15:32:3762 this._networkFlameChart.alwaysShowVerticalScroll();
63 this._networkFlameChart.disableRangeSelection();
64
Tim van der Lippecec9b762020-02-13 15:31:2265 this._networkPane = new UI.Widget.VBox();
Blink Reformat4c46d092018-04-07 15:32:3766 this._networkPane.setMinimumSize(23, 23);
67 this._networkFlameChart.show(this._networkPane.element);
68 this._splitResizer = this._networkPane.element.createChild('div', 'timeline-flamechart-resizer');
69 this._networkSplitWidget.hideDefaultResizer(true);
70 this._networkSplitWidget.installResizer(this._splitResizer);
71
72 this._networkSplitWidget.setMainWidget(this._mainFlameChart);
73 this._networkSplitWidget.setSidebarWidget(this._networkPane);
74
75 // Create counters chart splitter.
Tim van der Lippecec9b762020-02-13 15:31:2276 this._chartSplitWidget = new UI.SplitWidget.SplitWidget(false, true, 'timelineCountersSplitViewState');
Paul Lewis897ad8b2020-01-15 16:49:1777 this._countersView = new CountersGraph(this._delegate);
Blink Reformat4c46d092018-04-07 15:32:3778 this._chartSplitWidget.setMainWidget(this._networkSplitWidget);
79 this._chartSplitWidget.setSidebarWidget(this._countersView);
80 this._chartSplitWidget.hideDefaultResizer();
81 this._chartSplitWidget.installResizer(/** @type {!Element} */ (this._countersView.resizerElement()));
82 this._updateCountersGraphToggle();
83
84 // Create top level properties splitter.
Tim van der Lippecec9b762020-02-13 15:31:2285 this._detailsSplitWidget = new UI.SplitWidget.SplitWidget(false, true, 'timelinePanelDetailsSplitViewState');
Blink Reformat4c46d092018-04-07 15:32:3786 this._detailsSplitWidget.element.classList.add('timeline-details-split');
Paul Lewis897ad8b2020-01-15 16:49:1787 this._detailsView = new TimelineDetailsView(delegate);
Blink Reformat4c46d092018-04-07 15:32:3788 this._detailsSplitWidget.installResizer(this._detailsView.headerElement());
89 this._detailsSplitWidget.setMainWidget(this._chartSplitWidget);
90 this._detailsSplitWidget.setSidebarWidget(this._detailsView);
91 this._detailsSplitWidget.show(this.element);
92
93 this._onMainEntrySelected = this._onEntrySelected.bind(this, this._mainDataProvider);
94 this._onNetworkEntrySelected = this._onEntrySelected.bind(this, this._networkDataProvider);
95 this._mainFlameChart.addEventListener(PerfUI.FlameChart.Events.EntrySelected, this._onMainEntrySelected, this);
Michael Liao712bbc22019-10-15 19:21:5196 this._mainFlameChart.addEventListener(PerfUI.FlameChart.Events.EntryInvoked, this._onMainEntrySelected, this);
Blink Reformat4c46d092018-04-07 15:32:3797 this._networkFlameChart.addEventListener(PerfUI.FlameChart.Events.EntrySelected, this._onNetworkEntrySelected, this);
Michael Liao712bbc22019-10-15 19:21:5198 this._networkFlameChart.addEventListener(PerfUI.FlameChart.Events.EntryInvoked, this._onNetworkEntrySelected, this);
Blink Reformat4c46d092018-04-07 15:32:3799 this._mainFlameChart.addEventListener(PerfUI.FlameChart.Events.EntryHighlighted, this._onEntryHighlighted, this);
100 this._nextExtensionIndex = 0;
101
102 this._boundRefresh = this._refresh.bind(this);
103 this._selectedTrack = null;
104
Paul Lewis897ad8b2020-01-15 16:49:17105 this._mainDataProvider.setEventColorMapping(TimelineUIUtils.eventColor);
Paul Lewis2d7d65c2020-03-16 17:26:30106 this._groupBySetting = Common.Settings.Settings.instance().createSetting(
107 'timelineTreeGroupBy', AggregatedTimelineTreeView.GroupBy.None);
Blink Reformat4c46d092018-04-07 15:32:37108 this._groupBySetting.addChangeListener(this._updateColorMapper, this);
109 this._updateColorMapper();
Blink Reformat4c46d092018-04-07 15:32:37110 }
111
112 _updateColorMapper() {
113 /** @type {!Map<string, string>} */
114 this._urlToColorCache = new Map();
Tim van der Lippe1d6e57a2019-09-30 11:55:34115 if (!this._model) {
Blink Reformat4c46d092018-04-07 15:32:37116 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34117 }
Paul Lewis897ad8b2020-01-15 16:49:17118 this._mainDataProvider.setEventColorMapping(TimelineUIUtils.eventColor);
Blink Reformat4c46d092018-04-07 15:32:37119 this._mainFlameChart.update();
120 }
121
122 /**
Tim van der Lippec02a97c2020-02-14 14:39:27123 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37124 */
Alexei Filippov2578eb02018-04-11 08:15:05125 _onWindowChanged(event) {
Tim van der Lippefced1b92020-02-17 12:33:50126 const window = /** @type {!Window} */ (event.data.window);
Alexei Filippov2578eb02018-04-11 08:15:05127 const animate = !!event.data.animate;
128 this._mainFlameChart.setWindowTimes(window.left, window.right, animate);
129 this._networkFlameChart.setWindowTimes(window.left, window.right, animate);
130 this._networkDataProvider.setWindowTimes(window.left, window.right);
131 this._updateSearchResults(false, false);
Blink Reformat4c46d092018-04-07 15:32:37132 }
133
134 /**
135 * @override
136 * @param {number} windowStartTime
137 * @param {number} windowEndTime
138 * @param {boolean} animate
139 */
Alexei Filippov2578eb02018-04-11 08:15:05140 windowChanged(windowStartTime, windowEndTime, animate) {
141 this._model.setWindow({left: windowStartTime, right: windowEndTime}, animate);
Blink Reformat4c46d092018-04-07 15:32:37142 }
143
144 /**
145 * @override
146 * @param {number} startTime
147 * @param {number} endTime
148 */
149 updateRangeSelection(startTime, endTime) {
Paul Lewis897ad8b2020-01-15 16:49:17150 this._delegate.select(TimelineSelection.fromRange(startTime, endTime));
Blink Reformat4c46d092018-04-07 15:32:37151 }
152
153 /**
154 * @override
Tim van der Lippecec9b762020-02-13 15:31:22155 * @param {!PerfUI.FlameChart.FlameChart} flameChart
Blink Reformat4c46d092018-04-07 15:32:37156 * @param {?PerfUI.FlameChart.Group} group
157 */
158 updateSelectedGroup(flameChart, group) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34159 if (flameChart !== this._mainFlameChart) {
Blink Reformat4c46d092018-04-07 15:32:37160 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34161 }
Blink Reformat4c46d092018-04-07 15:32:37162 const track = group ? this._mainDataProvider.groupTrack(group) : null;
163 this._selectedTrack = track;
164 this._updateTrack();
165 }
166
167 /**
Paul Lewis897ad8b2020-01-15 16:49:17168 * @param {?PerformanceModel} model
Blink Reformat4c46d092018-04-07 15:32:37169 */
170 setModel(model) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34171 if (model === this._model) {
Blink Reformat4c46d092018-04-07 15:32:37172 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34173 }
Tim van der Lippecec9b762020-02-13 15:31:22174 Common.EventTarget.EventTarget.removeEventListeners(this._eventListeners);
Blink Reformat4c46d092018-04-07 15:32:37175 this._model = model;
176 this._selectedTrack = null;
Alexei Filippovd68f5f72018-04-26 00:52:00177 this._mainDataProvider.setModel(this._model);
178 this._networkDataProvider.setModel(this._model);
Alexei Filippov2578eb02018-04-11 08:15:05179 if (this._model) {
180 this._eventListeners = [
Paul Lewis897ad8b2020-01-15 16:49:17181 this._model.addEventListener(PerformanceModelEvents.WindowChanged, this._onWindowChanged, this),
182 this._model.addEventListener(PerformanceModelEvents.ExtensionDataAdded, this._appendExtensionData, this)
Alexei Filippov2578eb02018-04-11 08:15:05183 ];
184 const window = model.window();
185 this._mainFlameChart.setWindowTimes(window.left, window.right);
186 this._networkFlameChart.setWindowTimes(window.left, window.right);
187 this._networkDataProvider.setWindowTimes(window.left, window.right);
188 this._updateSearchResults(false, false);
189 }
Blink Reformat4c46d092018-04-07 15:32:37190 this._updateColorMapper();
191 this._updateTrack();
192 this._nextExtensionIndex = 0;
193 this._appendExtensionData();
194 this._refresh();
195 }
196
197 _updateTrack() {
198 this._countersView.setModel(this._model, this._selectedTrack);
199 this._detailsView.setModel(this._model, this._selectedTrack);
200 }
201
202 _refresh() {
203 if (this._networkDataProvider.isEmpty()) {
204 this._mainFlameChart.enableRuler(true);
205 this._networkSplitWidget.hideSidebar();
206 } else {
207 this._mainFlameChart.enableRuler(false);
208 this._networkSplitWidget.showBoth();
209 this.resizeToPreferredHeights();
210 }
211 this._mainFlameChart.reset();
212 this._networkFlameChart.reset();
213 this._updateSearchResults(false, false);
214 }
215
216 _appendExtensionData() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34217 if (!this._model) {
Blink Reformat4c46d092018-04-07 15:32:37218 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34219 }
Blink Reformat4c46d092018-04-07 15:32:37220 const extensions = this._model.extensionInfo();
Tim van der Lippe1d6e57a2019-09-30 11:55:34221 while (this._nextExtensionIndex < extensions.length) {
Blink Reformat4c46d092018-04-07 15:32:37222 this._mainDataProvider.appendExtensionEvents(extensions[this._nextExtensionIndex++]);
Tim van der Lippe1d6e57a2019-09-30 11:55:34223 }
Blink Reformat4c46d092018-04-07 15:32:37224 this._mainFlameChart.scheduleUpdate();
225 }
226
227 /**
Tim van der Lippec02a97c2020-02-14 14:39:27228 * @param {!Common.EventTarget.EventTargetEvent} commonEvent
Blink Reformat4c46d092018-04-07 15:32:37229 */
230 _onEntryHighlighted(commonEvent) {
Tim van der Lippecec9b762020-02-13 15:31:22231 SDK.OverlayModel.OverlayModel.hideDOMNodeHighlight();
Blink Reformat4c46d092018-04-07 15:32:37232 const entryIndex = /** @type {number} */ (commonEvent.data);
233 const event = this._mainDataProvider.eventByIndex(entryIndex);
Tim van der Lippe1d6e57a2019-09-30 11:55:34234 if (!event) {
Blink Reformat4c46d092018-04-07 15:32:37235 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34236 }
Blink Reformat4c46d092018-04-07 15:32:37237 const target = this._model && this._model.timelineModel().targetByEvent(event);
Tim van der Lippe1d6e57a2019-09-30 11:55:34238 if (!target) {
Blink Reformat4c46d092018-04-07 15:32:37239 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34240 }
Tim van der Lippecec9b762020-02-13 15:31:22241 const timelineData = TimelineModel.TimelineModel.TimelineData.forEvent(event);
Blink Reformat4c46d092018-04-07 15:32:37242 const backendNodeId = timelineData.backendNodeId;
Tim van der Lippe1d6e57a2019-09-30 11:55:34243 if (!backendNodeId) {
Blink Reformat4c46d092018-04-07 15:32:37244 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34245 }
Tim van der Lippecec9b762020-02-13 15:31:22246 new SDK.DOMModel.DeferredDOMNode(target, backendNodeId).highlight();
Blink Reformat4c46d092018-04-07 15:32:37247 }
248
249 /**
Blink Reformat4c46d092018-04-07 15:32:37250 * @param {?SDK.TracingModel.Event} event
251 */
252 highlightEvent(event) {
253 const entryIndex =
Paul Lewis897ad8b2020-01-15 16:49:17254 event ? this._mainDataProvider.entryIndexForSelection(TimelineSelection.fromTraceEvent(event)) : -1;
Tim van der Lippe1d6e57a2019-09-30 11:55:34255 if (entryIndex >= 0) {
Blink Reformat4c46d092018-04-07 15:32:37256 this._mainFlameChart.highlightEntry(entryIndex);
Tim van der Lippe1d6e57a2019-09-30 11:55:34257 } else {
Blink Reformat4c46d092018-04-07 15:32:37258 this._mainFlameChart.hideHighlight();
Tim van der Lippe1d6e57a2019-09-30 11:55:34259 }
Blink Reformat4c46d092018-04-07 15:32:37260 }
261
262 /**
263 * @override
264 */
265 willHide() {
266 this._networkFlameChartGroupExpansionSetting.removeChangeListener(this.resizeToPreferredHeights, this);
267 this._showMemoryGraphSetting.removeChangeListener(this._updateCountersGraphToggle, this);
Paul Lewis2ddc6312020-01-23 13:20:12268 self.Bindings.blackboxManager.removeChangeListener(this._boundRefresh);
Blink Reformat4c46d092018-04-07 15:32:37269 }
270
271 /**
272 * @override
273 */
274 wasShown() {
275 this._networkFlameChartGroupExpansionSetting.addChangeListener(this.resizeToPreferredHeights, this);
276 this._showMemoryGraphSetting.addChangeListener(this._updateCountersGraphToggle, this);
Paul Lewis2ddc6312020-01-23 13:20:12277 self.Bindings.blackboxManager.addChangeListener(this._boundRefresh);
Tim van der Lippe1d6e57a2019-09-30 11:55:34278 if (this._needsResizeToPreferredHeights) {
Blink Reformat4c46d092018-04-07 15:32:37279 this.resizeToPreferredHeights();
Tim van der Lippe1d6e57a2019-09-30 11:55:34280 }
Blink Reformat4c46d092018-04-07 15:32:37281 this._mainFlameChart.scheduleUpdate();
282 this._networkFlameChart.scheduleUpdate();
283 }
284
285 _updateCountersGraphToggle() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34286 if (this._showMemoryGraphSetting.get()) {
Blink Reformat4c46d092018-04-07 15:32:37287 this._chartSplitWidget.showBoth();
Tim van der Lippe1d6e57a2019-09-30 11:55:34288 } else {
Blink Reformat4c46d092018-04-07 15:32:37289 this._chartSplitWidget.hideSidebar();
Tim van der Lippe1d6e57a2019-09-30 11:55:34290 }
Blink Reformat4c46d092018-04-07 15:32:37291 }
292
293 /**
Paul Lewis897ad8b2020-01-15 16:49:17294 * @param {?TimelineSelection} selection
Blink Reformat4c46d092018-04-07 15:32:37295 */
296 setSelection(selection) {
297 let index = this._mainDataProvider.entryIndexForSelection(selection);
298 this._mainFlameChart.setSelectedEntry(index);
299 index = this._networkDataProvider.entryIndexForSelection(selection);
300 this._networkFlameChart.setSelectedEntry(index);
Tim van der Lippe1d6e57a2019-09-30 11:55:34301 if (this._detailsView) {
Blink Reformat4c46d092018-04-07 15:32:37302 this._detailsView.setSelection(selection);
Tim van der Lippe1d6e57a2019-09-30 11:55:34303 }
Blink Reformat4c46d092018-04-07 15:32:37304 }
305
306 /**
Tim van der Lippecec9b762020-02-13 15:31:22307 * @param {!PerfUI.FlameChart.FlameChartDataProvider} dataProvider
Tim van der Lippec02a97c2020-02-14 14:39:27308 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37309 */
310 _onEntrySelected(dataProvider, event) {
311 const entryIndex = /** @type{number} */ (event.data);
Tim van der Lippe99e59b82019-09-30 20:00:59312 if (Root.Runtime.experiments.isEnabled('timelineEventInitiators') && dataProvider === this._mainDataProvider) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34313 if (this._mainDataProvider.buildFlowForInitiator(entryIndex)) {
Blink Reformat4c46d092018-04-07 15:32:37314 this._mainFlameChart.scheduleUpdate();
Tim van der Lippe1d6e57a2019-09-30 11:55:34315 }
Blink Reformat4c46d092018-04-07 15:32:37316 }
Tim van der Lippefd2b2ce2020-01-03 15:05:18317 this._delegate.select(
Paul Lewis897ad8b2020-01-15 16:49:17318 /** @type {!TimelineFlameChartNetworkDataProvider} */ (dataProvider).createSelection(entryIndex));
Blink Reformat4c46d092018-04-07 15:32:37319 }
320
321 resizeToPreferredHeights() {
322 if (!this.isShowing()) {
323 this._needsResizeToPreferredHeights = true;
324 return;
325 }
326 this._needsResizeToPreferredHeights = false;
327 this._networkPane.element.classList.toggle(
328 'timeline-network-resizer-disabled', !this._networkDataProvider.isExpanded());
329 this._networkSplitWidget.setSidebarSize(
330 this._networkDataProvider.preferredHeight() + this._splitResizer.clientHeight + PerfUI.FlameChart.HeaderHeight +
331 2);
332 }
333
334 /**
Tim van der Lippecec9b762020-02-13 15:31:22335 * @param {!UI.SearchableView.SearchableView} searchableView
Blink Reformat4c46d092018-04-07 15:32:37336 */
337 setSearchableView(searchableView) {
338 this._searchableView = searchableView;
339 }
340
Tim van der Lippecec9b762020-02-13 15:31:22341 // UI.SearchableView.Searchable implementation
Blink Reformat4c46d092018-04-07 15:32:37342
343 /**
344 * @override
345 */
346 jumpToNextSearchResult() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34347 if (!this._searchResults || !this._searchResults.length) {
Blink Reformat4c46d092018-04-07 15:32:37348 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34349 }
Blink Reformat4c46d092018-04-07 15:32:37350 const index = typeof this._selectedSearchResult !== 'undefined' ?
351 this._searchResults.indexOf(this._selectedSearchResult) :
352 -1;
Jack Franklin1cb34212020-03-09 09:28:12353 this._selectSearchResult(Platform.NumberUtilities.mod(index + 1, this._searchResults.length));
Blink Reformat4c46d092018-04-07 15:32:37354 }
355
356 /**
357 * @override
358 */
359 jumpToPreviousSearchResult() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34360 if (!this._searchResults || !this._searchResults.length) {
Blink Reformat4c46d092018-04-07 15:32:37361 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34362 }
Blink Reformat4c46d092018-04-07 15:32:37363 const index =
364 typeof this._selectedSearchResult !== 'undefined' ? this._searchResults.indexOf(this._selectedSearchResult) : 0;
Jack Franklin1cb34212020-03-09 09:28:12365 this._selectSearchResult(Platform.NumberUtilities.mod(index - 1, this._searchResults.length));
Blink Reformat4c46d092018-04-07 15:32:37366 }
367
368 /**
369 * @override
370 * @return {boolean}
371 */
372 supportsCaseSensitiveSearch() {
373 return true;
374 }
375
376 /**
377 * @override
378 * @return {boolean}
379 */
380 supportsRegexSearch() {
381 return true;
382 }
383
384 /**
385 * @param {number} index
386 */
387 _selectSearchResult(index) {
388 this._searchableView.updateCurrentMatchIndex(index);
389 this._selectedSearchResult = this._searchResults[index];
390 this._delegate.select(this._mainDataProvider.createSelection(this._selectedSearchResult));
391 }
392
393 /**
394 * @param {boolean} shouldJump
395 * @param {boolean=} jumpBackwards
396 */
397 _updateSearchResults(shouldJump, jumpBackwards) {
398 const oldSelectedSearchResult = this._selectedSearchResult;
399 delete this._selectedSearchResult;
400 this._searchResults = [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34401 if (!this._searchRegex || !this._model) {
Blink Reformat4c46d092018-04-07 15:32:37402 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34403 }
Paul Lewis897ad8b2020-01-15 16:49:17404 const regExpFilter = new TimelineRegExp(this._searchRegex);
Alexei Filippov2578eb02018-04-11 08:15:05405 const window = this._model.window();
406 this._searchResults = this._mainDataProvider.search(window.left, window.right, regExpFilter);
Blink Reformat4c46d092018-04-07 15:32:37407 this._searchableView.updateSearchMatchesCount(this._searchResults.length);
Tim van der Lippe1d6e57a2019-09-30 11:55:34408 if (!shouldJump || !this._searchResults.length) {
Blink Reformat4c46d092018-04-07 15:32:37409 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34410 }
Blink Reformat4c46d092018-04-07 15:32:37411 let selectedIndex = this._searchResults.indexOf(oldSelectedSearchResult);
Tim van der Lippe1d6e57a2019-09-30 11:55:34412 if (selectedIndex === -1) {
Blink Reformat4c46d092018-04-07 15:32:37413 selectedIndex = jumpBackwards ? this._searchResults.length - 1 : 0;
Tim van der Lippe1d6e57a2019-09-30 11:55:34414 }
Blink Reformat4c46d092018-04-07 15:32:37415 this._selectSearchResult(selectedIndex);
416 }
417
418 /**
419 * @override
420 */
421 searchCanceled() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34422 if (typeof this._selectedSearchResult !== 'undefined') {
Blink Reformat4c46d092018-04-07 15:32:37423 this._delegate.select(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:34424 }
Blink Reformat4c46d092018-04-07 15:32:37425 delete this._searchResults;
426 delete this._selectedSearchResult;
427 delete this._searchRegex;
428 }
429
430 /**
431 * @override
432 * @param {!UI.SearchableView.SearchConfig} searchConfig
433 * @param {boolean} shouldJump
434 * @param {boolean=} jumpBackwards
435 */
436 performSearch(searchConfig, shouldJump, jumpBackwards) {
437 this._searchRegex = searchConfig.toSearchRegex();
438 this._updateSearchResults(shouldJump, jumpBackwards);
439 }
Tim van der Lippe0176f6c2020-01-08 11:07:01440}
Blink Reformat4c46d092018-04-07 15:32:37441
442/**
443 * @unrestricted
444 */
Tim van der Lippe0176f6c2020-01-08 11:07:01445export class Selection {
Blink Reformat4c46d092018-04-07 15:32:37446 /**
Paul Lewis897ad8b2020-01-15 16:49:17447 * @param {!TimelineSelection} selection
Blink Reformat4c46d092018-04-07 15:32:37448 * @param {number} entryIndex
449 */
450 constructor(selection, entryIndex) {
451 this.timelineSelection = selection;
452 this.entryIndex = entryIndex;
453 }
Tim van der Lippe0176f6c2020-01-08 11:07:01454}
Blink Reformat4c46d092018-04-07 15:32:37455
Tim van der Lippe0176f6c2020-01-08 11:07:01456export const FlameChartStyle = {
Blink Reformat4c46d092018-04-07 15:32:37457 textColor: '#333'
458};
459
460/**
Tim van der Lippecec9b762020-02-13 15:31:22461 * @implements {PerfUI.FlameChart.FlameChartMarker}
Blink Reformat4c46d092018-04-07 15:32:37462 * @unrestricted
463 */
Tim van der Lippe0176f6c2020-01-08 11:07:01464export class TimelineFlameChartMarker {
Blink Reformat4c46d092018-04-07 15:32:37465 /**
466 * @param {number} startTime
467 * @param {number} startOffset
Tim van der Lippefced1b92020-02-17 12:33:50468 * @param {!TimelineMarkerStyle} style
Blink Reformat4c46d092018-04-07 15:32:37469 */
470 constructor(startTime, startOffset, style) {
471 this._startTime = startTime;
472 this._startOffset = startOffset;
473 this._style = style;
474 }
475
476 /**
477 * @override
478 * @return {number}
479 */
480 startTime() {
481 return this._startTime;
482 }
483
484 /**
485 * @override
486 * @return {string}
487 */
488 color() {
489 return this._style.color;
490 }
491
492 /**
493 * @override
Alexei Filippov72d792d2018-11-06 07:15:04494 * @return {?string}
Blink Reformat4c46d092018-04-07 15:32:37495 */
496 title() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34497 if (this._style.lowPriority) {
Alexei Filippov72d792d2018-11-06 07:15:04498 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34499 }
Blink Reformat4c46d092018-04-07 15:32:37500 const startTime = Number.millisToString(this._startOffset);
Alexei Filippov72d792d2018-11-06 07:15:04501 return ls`${this._style.title} at ${startTime}`;
Blink Reformat4c46d092018-04-07 15:32:37502 }
503
504 /**
505 * @override
506 * @param {!CanvasRenderingContext2D} context
507 * @param {number} x
508 * @param {number} height
509 * @param {number} pixelsPerMillisecond
510 */
511 draw(context, x, height, pixelsPerMillisecond) {
512 const lowPriorityVisibilityThresholdInPixelsPerMs = 4;
513
Tim van der Lippe1d6e57a2019-09-30 11:55:34514 if (this._style.lowPriority && pixelsPerMillisecond < lowPriorityVisibilityThresholdInPixelsPerMs) {
Blink Reformat4c46d092018-04-07 15:32:37515 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34516 }
Alexei Filippov8ee66382018-11-30 01:53:56517
Blink Reformat4c46d092018-04-07 15:32:37518 context.save();
Blink Reformat4c46d092018-04-07 15:32:37519 if (this._style.tall) {
520 context.strokeStyle = this._style.color;
521 context.lineWidth = this._style.lineWidth;
522 context.translate(this._style.lineWidth < 1 || (this._style.lineWidth & 1) ? 0.5 : 0, 0.5);
523 context.beginPath();
Alexei Filippov6c622e92018-11-10 02:13:59524 context.moveTo(x, 0);
Blink Reformat4c46d092018-04-07 15:32:37525 context.setLineDash(this._style.dashStyle);
526 context.lineTo(x, context.canvas.height);
527 context.stroke();
528 }
529 context.restore();
530 }
Tim van der Lippe0176f6c2020-01-08 11:07:01531}
Tim van der Lippe907156a2020-01-07 17:01:53532
Tim van der Lippe907156a2020-01-07 17:01:53533/** @enum {string} */
Paul Lewis897ad8b2020-01-15 16:49:17534export const ColorBy = {
Rob Paveza96705c62020-01-08 01:37:48535 URL: 'URL',
536};