Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | // 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 Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 5 | import * as Common from '../common/common.js'; |
| 6 | import * as PerfUI from '../perf_ui/perf_ui.js'; |
Jack Franklin | 1cb3421 | 2020-03-09 09:28:12 | [diff] [blame] | 7 | import * as Platform from '../platform/platform.js'; |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 8 | import * as SDK from '../sdk/sdk.js'; |
| 9 | import * as TimelineModel from '../timeline_model/timeline_model.js'; |
| 10 | import * as UI from '../ui/ui.js'; |
| 11 | |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 12 | import {CountersGraph} from './CountersGraph.js'; |
Tim van der Lippe | fced1b9 | 2020-02-17 12:33:50 | [diff] [blame] | 13 | import {Events as PerformanceModelEvents, PerformanceModel, Window} from './PerformanceModel.js'; // eslint-disable-line no-unused-vars |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 14 | import {TimelineDetailsView} from './TimelineDetailsView.js'; |
| 15 | import {TimelineRegExp} from './TimelineFilters.js'; |
| 16 | import {Events as TimelineFlameChartDataProviderEvents, TimelineFlameChartDataProvider} from './TimelineFlameChartDataProvider.js'; |
| 17 | import {TimelineFlameChartNetworkDataProvider} from './TimelineFlameChartNetworkDataProvider.js'; |
| 18 | import {TimelineModeViewDelegate, TimelineSelection} from './TimelinePanel.js'; // eslint-disable-line no-unused-vars |
| 19 | import {AggregatedTimelineTreeView} from './TimelineTreeView.js'; |
Tim van der Lippe | fced1b9 | 2020-02-17 12:33:50 | [diff] [blame] | 20 | import {TimelineMarkerStyle, TimelineUIUtils} from './TimelineUIUtils.js'; // eslint-disable-line no-unused-vars |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 21 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 22 | /** |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 23 | * @implements {PerfUI.FlameChart.FlameChartDelegate} |
| 24 | * @implements {UI.SearchableView.Searchable} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 25 | * @unrestricted |
| 26 | */ |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 27 | export class TimelineFlameChartView extends UI.Widget.VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 28 | /** |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 29 | * @param {!TimelineModeViewDelegate} delegate |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 30 | */ |
Alexei Filippov | 35f97d6 | 2018-04-28 01:02:31 | [diff] [blame] | 31 | constructor(delegate) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 32 | super(); |
| 33 | this.element.classList.add('timeline-flamechart'); |
| 34 | this._delegate = delegate; |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 35 | /** @type {?PerformanceModel} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 36 | this._model = null; |
| 37 | /** @type {!Array<number>|undefined} */ |
| 38 | this._searchResults; |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 39 | /** @type {!Array<!Common.EventTarget.EventDescriptor>} */ |
| 40 | this._eventListeners = []; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 41 | |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame^] | 42 | this._showMemoryGraphSetting = Common.Settings.Settings.instance().createSetting('timelineShowMemory', false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 43 | |
| 44 | // Create main and network flamecharts. |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 45 | this._networkSplitWidget = new UI.SplitWidget.SplitWidget(false, false, 'timelineFlamechartMainView', 150); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 46 | |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 47 | const mainViewGroupExpansionSetting = |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame^] | 48 | Common.Settings.Settings.instance().createSetting('timelineFlamechartMainViewGroupExpansion', {}); |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 49 | this._mainDataProvider = new TimelineFlameChartDataProvider(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 50 | this._mainDataProvider.addEventListener( |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 51 | TimelineFlameChartDataProviderEvents.DataChanged, () => this._mainFlameChart.scheduleUpdate()); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 52 | this._mainFlameChart = |
| 53 | new PerfUI.FlameChart.FlameChart(this._mainDataProvider, this, mainViewGroupExpansionSetting); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 54 | this._mainFlameChart.alwaysShowVerticalScroll(); |
| 55 | this._mainFlameChart.enableRuler(false); |
| 56 | |
| 57 | this._networkFlameChartGroupExpansionSetting = |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame^] | 58 | Common.Settings.Settings.instance().createSetting('timelineFlamechartNetworkViewGroupExpansion', {}); |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 59 | this._networkDataProvider = new TimelineFlameChartNetworkDataProvider(); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 60 | this._networkFlameChart = |
| 61 | new PerfUI.FlameChart.FlameChart(this._networkDataProvider, this, this._networkFlameChartGroupExpansionSetting); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 62 | this._networkFlameChart.alwaysShowVerticalScroll(); |
| 63 | this._networkFlameChart.disableRangeSelection(); |
| 64 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 65 | this._networkPane = new UI.Widget.VBox(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 66 | 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 Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 76 | this._chartSplitWidget = new UI.SplitWidget.SplitWidget(false, true, 'timelineCountersSplitViewState'); |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 77 | this._countersView = new CountersGraph(this._delegate); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 78 | 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 Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 85 | this._detailsSplitWidget = new UI.SplitWidget.SplitWidget(false, true, 'timelinePanelDetailsSplitViewState'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 86 | this._detailsSplitWidget.element.classList.add('timeline-details-split'); |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 87 | this._detailsView = new TimelineDetailsView(delegate); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 88 | 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 Liao | 712bbc2 | 2019-10-15 19:21:51 | [diff] [blame] | 96 | this._mainFlameChart.addEventListener(PerfUI.FlameChart.Events.EntryInvoked, this._onMainEntrySelected, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 97 | this._networkFlameChart.addEventListener(PerfUI.FlameChart.Events.EntrySelected, this._onNetworkEntrySelected, this); |
Michael Liao | 712bbc2 | 2019-10-15 19:21:51 | [diff] [blame] | 98 | this._networkFlameChart.addEventListener(PerfUI.FlameChart.Events.EntryInvoked, this._onNetworkEntrySelected, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 99 | 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 Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 105 | this._mainDataProvider.setEventColorMapping(TimelineUIUtils.eventColor); |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame^] | 106 | this._groupBySetting = Common.Settings.Settings.instance().createSetting( |
| 107 | 'timelineTreeGroupBy', AggregatedTimelineTreeView.GroupBy.None); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 108 | this._groupBySetting.addChangeListener(this._updateColorMapper, this); |
| 109 | this._updateColorMapper(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | _updateColorMapper() { |
| 113 | /** @type {!Map<string, string>} */ |
| 114 | this._urlToColorCache = new Map(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 115 | if (!this._model) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 116 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 117 | } |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 118 | this._mainDataProvider.setEventColorMapping(TimelineUIUtils.eventColor); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 119 | this._mainFlameChart.update(); |
| 120 | } |
| 121 | |
| 122 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 123 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 124 | */ |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 125 | _onWindowChanged(event) { |
Tim van der Lippe | fced1b9 | 2020-02-17 12:33:50 | [diff] [blame] | 126 | const window = /** @type {!Window} */ (event.data.window); |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 127 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /** |
| 135 | * @override |
| 136 | * @param {number} windowStartTime |
| 137 | * @param {number} windowEndTime |
| 138 | * @param {boolean} animate |
| 139 | */ |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 140 | windowChanged(windowStartTime, windowEndTime, animate) { |
| 141 | this._model.setWindow({left: windowStartTime, right: windowEndTime}, animate); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /** |
| 145 | * @override |
| 146 | * @param {number} startTime |
| 147 | * @param {number} endTime |
| 148 | */ |
| 149 | updateRangeSelection(startTime, endTime) { |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 150 | this._delegate.select(TimelineSelection.fromRange(startTime, endTime)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /** |
| 154 | * @override |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 155 | * @param {!PerfUI.FlameChart.FlameChart} flameChart |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 156 | * @param {?PerfUI.FlameChart.Group} group |
| 157 | */ |
| 158 | updateSelectedGroup(flameChart, group) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 159 | if (flameChart !== this._mainFlameChart) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 160 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 161 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 162 | const track = group ? this._mainDataProvider.groupTrack(group) : null; |
| 163 | this._selectedTrack = track; |
| 164 | this._updateTrack(); |
| 165 | } |
| 166 | |
| 167 | /** |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 168 | * @param {?PerformanceModel} model |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 169 | */ |
| 170 | setModel(model) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 171 | if (model === this._model) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 172 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 173 | } |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 174 | Common.EventTarget.EventTarget.removeEventListeners(this._eventListeners); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 175 | this._model = model; |
| 176 | this._selectedTrack = null; |
Alexei Filippov | d68f5f7 | 2018-04-26 00:52:00 | [diff] [blame] | 177 | this._mainDataProvider.setModel(this._model); |
| 178 | this._networkDataProvider.setModel(this._model); |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 179 | if (this._model) { |
| 180 | this._eventListeners = [ |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 181 | this._model.addEventListener(PerformanceModelEvents.WindowChanged, this._onWindowChanged, this), |
| 182 | this._model.addEventListener(PerformanceModelEvents.ExtensionDataAdded, this._appendExtensionData, this) |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 183 | ]; |
| 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 190 | 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 217 | if (!this._model) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 218 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 219 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 220 | const extensions = this._model.extensionInfo(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 221 | while (this._nextExtensionIndex < extensions.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 222 | this._mainDataProvider.appendExtensionEvents(extensions[this._nextExtensionIndex++]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 223 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 224 | this._mainFlameChart.scheduleUpdate(); |
| 225 | } |
| 226 | |
| 227 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 228 | * @param {!Common.EventTarget.EventTargetEvent} commonEvent |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 229 | */ |
| 230 | _onEntryHighlighted(commonEvent) { |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 231 | SDK.OverlayModel.OverlayModel.hideDOMNodeHighlight(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 232 | const entryIndex = /** @type {number} */ (commonEvent.data); |
| 233 | const event = this._mainDataProvider.eventByIndex(entryIndex); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 234 | if (!event) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 235 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 236 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 237 | const target = this._model && this._model.timelineModel().targetByEvent(event); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 238 | if (!target) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 239 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 240 | } |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 241 | const timelineData = TimelineModel.TimelineModel.TimelineData.forEvent(event); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 242 | const backendNodeId = timelineData.backendNodeId; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 243 | if (!backendNodeId) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 244 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 245 | } |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 246 | new SDK.DOMModel.DeferredDOMNode(target, backendNodeId).highlight(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 250 | * @param {?SDK.TracingModel.Event} event |
| 251 | */ |
| 252 | highlightEvent(event) { |
| 253 | const entryIndex = |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 254 | event ? this._mainDataProvider.entryIndexForSelection(TimelineSelection.fromTraceEvent(event)) : -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 255 | if (entryIndex >= 0) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 256 | this._mainFlameChart.highlightEntry(entryIndex); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 257 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 258 | this._mainFlameChart.hideHighlight(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 259 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /** |
| 263 | * @override |
| 264 | */ |
| 265 | willHide() { |
| 266 | this._networkFlameChartGroupExpansionSetting.removeChangeListener(this.resizeToPreferredHeights, this); |
| 267 | this._showMemoryGraphSetting.removeChangeListener(this._updateCountersGraphToggle, this); |
Paul Lewis | 2ddc631 | 2020-01-23 13:20:12 | [diff] [blame] | 268 | self.Bindings.blackboxManager.removeChangeListener(this._boundRefresh); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /** |
| 272 | * @override |
| 273 | */ |
| 274 | wasShown() { |
| 275 | this._networkFlameChartGroupExpansionSetting.addChangeListener(this.resizeToPreferredHeights, this); |
| 276 | this._showMemoryGraphSetting.addChangeListener(this._updateCountersGraphToggle, this); |
Paul Lewis | 2ddc631 | 2020-01-23 13:20:12 | [diff] [blame] | 277 | self.Bindings.blackboxManager.addChangeListener(this._boundRefresh); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 278 | if (this._needsResizeToPreferredHeights) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 279 | this.resizeToPreferredHeights(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 280 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 281 | this._mainFlameChart.scheduleUpdate(); |
| 282 | this._networkFlameChart.scheduleUpdate(); |
| 283 | } |
| 284 | |
| 285 | _updateCountersGraphToggle() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 286 | if (this._showMemoryGraphSetting.get()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 287 | this._chartSplitWidget.showBoth(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 288 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 289 | this._chartSplitWidget.hideSidebar(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 290 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /** |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 294 | * @param {?TimelineSelection} selection |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 295 | */ |
| 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 301 | if (this._detailsView) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 302 | this._detailsView.setSelection(selection); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 303 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /** |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 307 | * @param {!PerfUI.FlameChart.FlameChartDataProvider} dataProvider |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 308 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 309 | */ |
| 310 | _onEntrySelected(dataProvider, event) { |
| 311 | const entryIndex = /** @type{number} */ (event.data); |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 312 | if (Root.Runtime.experiments.isEnabled('timelineEventInitiators') && dataProvider === this._mainDataProvider) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 313 | if (this._mainDataProvider.buildFlowForInitiator(entryIndex)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 314 | this._mainFlameChart.scheduleUpdate(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 315 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 316 | } |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 317 | this._delegate.select( |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 318 | /** @type {!TimelineFlameChartNetworkDataProvider} */ (dataProvider).createSelection(entryIndex)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 319 | } |
| 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 Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 335 | * @param {!UI.SearchableView.SearchableView} searchableView |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 336 | */ |
| 337 | setSearchableView(searchableView) { |
| 338 | this._searchableView = searchableView; |
| 339 | } |
| 340 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 341 | // UI.SearchableView.Searchable implementation |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 342 | |
| 343 | /** |
| 344 | * @override |
| 345 | */ |
| 346 | jumpToNextSearchResult() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 347 | if (!this._searchResults || !this._searchResults.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 348 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 349 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 350 | const index = typeof this._selectedSearchResult !== 'undefined' ? |
| 351 | this._searchResults.indexOf(this._selectedSearchResult) : |
| 352 | -1; |
Jack Franklin | 1cb3421 | 2020-03-09 09:28:12 | [diff] [blame] | 353 | this._selectSearchResult(Platform.NumberUtilities.mod(index + 1, this._searchResults.length)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /** |
| 357 | * @override |
| 358 | */ |
| 359 | jumpToPreviousSearchResult() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 360 | if (!this._searchResults || !this._searchResults.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 361 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 362 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 363 | const index = |
| 364 | typeof this._selectedSearchResult !== 'undefined' ? this._searchResults.indexOf(this._selectedSearchResult) : 0; |
Jack Franklin | 1cb3421 | 2020-03-09 09:28:12 | [diff] [blame] | 365 | this._selectSearchResult(Platform.NumberUtilities.mod(index - 1, this._searchResults.length)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 366 | } |
| 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 401 | if (!this._searchRegex || !this._model) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 402 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 403 | } |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 404 | const regExpFilter = new TimelineRegExp(this._searchRegex); |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 405 | const window = this._model.window(); |
| 406 | this._searchResults = this._mainDataProvider.search(window.left, window.right, regExpFilter); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 407 | this._searchableView.updateSearchMatchesCount(this._searchResults.length); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 408 | if (!shouldJump || !this._searchResults.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 409 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 410 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 411 | let selectedIndex = this._searchResults.indexOf(oldSelectedSearchResult); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 412 | if (selectedIndex === -1) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 413 | selectedIndex = jumpBackwards ? this._searchResults.length - 1 : 0; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 414 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 415 | this._selectSearchResult(selectedIndex); |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * @override |
| 420 | */ |
| 421 | searchCanceled() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 422 | if (typeof this._selectedSearchResult !== 'undefined') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 423 | this._delegate.select(null); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 424 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 425 | 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 Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 440 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 441 | |
| 442 | /** |
| 443 | * @unrestricted |
| 444 | */ |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 445 | export class Selection { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 446 | /** |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 447 | * @param {!TimelineSelection} selection |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 448 | * @param {number} entryIndex |
| 449 | */ |
| 450 | constructor(selection, entryIndex) { |
| 451 | this.timelineSelection = selection; |
| 452 | this.entryIndex = entryIndex; |
| 453 | } |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 454 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 455 | |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 456 | export const FlameChartStyle = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 457 | textColor: '#333' |
| 458 | }; |
| 459 | |
| 460 | /** |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 461 | * @implements {PerfUI.FlameChart.FlameChartMarker} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 462 | * @unrestricted |
| 463 | */ |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 464 | export class TimelineFlameChartMarker { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 465 | /** |
| 466 | * @param {number} startTime |
| 467 | * @param {number} startOffset |
Tim van der Lippe | fced1b9 | 2020-02-17 12:33:50 | [diff] [blame] | 468 | * @param {!TimelineMarkerStyle} style |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 469 | */ |
| 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 Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 494 | * @return {?string} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 495 | */ |
| 496 | title() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 497 | if (this._style.lowPriority) { |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 498 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 499 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 500 | const startTime = Number.millisToString(this._startOffset); |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 501 | return ls`${this._style.title} at ${startTime}`; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 502 | } |
| 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 514 | if (this._style.lowPriority && pixelsPerMillisecond < lowPriorityVisibilityThresholdInPixelsPerMs) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 515 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 516 | } |
Alexei Filippov | 8ee6638 | 2018-11-30 01:53:56 | [diff] [blame] | 517 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 518 | context.save(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 519 | 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 Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 524 | context.moveTo(x, 0); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 525 | context.setLineDash(this._style.dashStyle); |
| 526 | context.lineTo(x, context.canvas.height); |
| 527 | context.stroke(); |
| 528 | } |
| 529 | context.restore(); |
| 530 | } |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 531 | } |
Tim van der Lippe | 907156a | 2020-01-07 17:01:53 | [diff] [blame] | 532 | |
Tim van der Lippe | 907156a | 2020-01-07 17:01:53 | [diff] [blame] | 533 | /** @enum {string} */ |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 534 | export const ColorBy = { |
Rob Paveza | 96705c6 | 2020-01-08 01:37:48 | [diff] [blame] | 535 | URL: 'URL', |
| 536 | }; |