Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 | * Copyright (C) 2012 Intel Inc. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: |
| 8 | * |
| 9 | * * Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * * Redistributions in binary form must reproduce the above |
| 12 | * copyright notice, this list of conditions and the following disclaimer |
| 13 | * in the documentation and/or other materials provided with the |
| 14 | * distribution. |
| 15 | * * Neither the name of Google Inc. nor the names of its |
| 16 | * contributors may be used to endorse or promote products derived from |
| 17 | * this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | */ |
| 31 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 32 | import * as Bindings from '../bindings/bindings.js'; |
| 33 | import * as Common from '../common/common.js'; |
| 34 | import * as Extensions from '../extensions/extensions.js'; |
| 35 | import * as Host from '../host/host.js'; |
| 36 | import * as MobileThrottling from '../mobile_throttling/mobile_throttling.js'; |
| 37 | import * as PerfUI from '../perf_ui/perf_ui.js'; |
| 38 | import * as ProtocolModule from '../protocol/protocol.js'; |
| 39 | import * as SDK from '../sdk/sdk.js'; |
| 40 | import * as TimelineModel from '../timeline_model/timeline_model.js'; |
| 41 | import * as UI from '../ui/ui.js'; |
| 42 | |
Tim van der Lippe | fced1b9 | 2020-02-17 12:33:50 | [diff] [blame] | 43 | import {Events, PerformanceModel, Window} from './PerformanceModel.js'; // eslint-disable-line no-unused-vars |
| 44 | import {Client, TimelineController} from './TimelineController.js'; // eslint-disable-line no-unused-vars |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 45 | import {TimelineEventOverview, TimelineEventOverviewCoverage, TimelineEventOverviewCPUActivity, TimelineEventOverviewFrames, TimelineEventOverviewInput, TimelineEventOverviewMemory, TimelineEventOverviewNetwork, TimelineEventOverviewResponsiveness, TimelineFilmStripOverview,} from './TimelineEventOverview.js'; // eslint-disable-line no-unused-vars |
| 46 | import {TimelineFlameChartView} from './TimelineFlameChartView.js'; |
| 47 | import {TimelineHistoryManager} from './TimelineHistoryManager.js'; |
| 48 | import {TimelineLoader} from './TimelineLoader.js'; |
| 49 | import {TimelineUIUtils} from './TimelineUIUtils.js'; |
| 50 | import {UIDevtoolsController} from './UIDevtoolsController.js'; |
| 51 | import {UIDevtoolsUtils} from './UIDevtoolsUtils.js'; |
| 52 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 53 | /** |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 54 | * @implements {Client} |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 55 | * @implements {TimelineModeViewDelegate} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 56 | * @unrestricted |
| 57 | */ |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 58 | export class TimelinePanel extends UI.Panel.Panel { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 59 | constructor() { |
| 60 | super('timeline'); |
| 61 | this.registerRequiredCSS('timeline/timelinePanel.css'); |
| 62 | this.element.addEventListener('contextmenu', this._contextMenu.bind(this), false); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 63 | this._dropTarget = new UI.DropTarget.DropTarget( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 64 | this.element, [UI.DropTarget.Type.File, UI.DropTarget.Type.URI], |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 65 | Common.UIString.UIString('Drop timeline file or URL here'), this._handleDrop.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 66 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 67 | /** @type {!Array<!UI.Toolbar.ToolbarItem>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 68 | this._recordingOptionUIControls = []; |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 69 | this._state = State.Idle; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 70 | this._recordingPageReload = false; |
| 71 | this._millisecondsToRecordAfterLoadEvent = 3000; |
| 72 | this._toggleRecordAction = |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 73 | /** @type {!UI.Action.Action }*/ (self.UI.actionRegistry.action('timeline.toggle-recording')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 74 | this._recordReloadAction = |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 75 | /** @type {!UI.Action.Action }*/ (self.UI.actionRegistry.action('timeline.record-reload')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 76 | |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 77 | this._historyManager = new TimelineHistoryManager(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 78 | |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 79 | /** @type {?PerformanceModel} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 80 | this._performanceModel = null; |
| 81 | |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 82 | this._viewModeSetting = self.Common.settings.createSetting('timelineViewMode', ViewMode.FlameChart); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 83 | |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 84 | this._disableCaptureJSProfileSetting = self.Common.settings.createSetting('timelineDisableJSSampling', false); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 85 | this._disableCaptureJSProfileSetting.setTitle(Common.UIString.UIString('Disable JavaScript samples')); |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 86 | this._captureLayersAndPicturesSetting = |
| 87 | self.Common.settings.createSetting('timelineCaptureLayersAndPictures', false); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 88 | this._captureLayersAndPicturesSetting.setTitle( |
| 89 | Common.UIString.UIString('Enable advanced paint instrumentation (slow)')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 90 | |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 91 | this._showScreenshotsSetting = self.Common.settings.createSetting('timelineShowScreenshots', true); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 92 | this._showScreenshotsSetting.setTitle(Common.UIString.UIString('Screenshots')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 93 | this._showScreenshotsSetting.addChangeListener(this._updateOverviewControls, this); |
| 94 | |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 95 | this._startCoverage = self.Common.settings.createSetting('timelineStartCoverage', false); |
Jan Scheffler | fc2f383 | 2019-09-24 14:03:32 | [diff] [blame] | 96 | this._startCoverage.setTitle(ls`Coverage`); |
| 97 | |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 98 | if (!Root.Runtime.experiments.isEnabled('recordCoverageWithPerformanceTracing')) { |
Jan Scheffler | fc2f383 | 2019-09-24 14:03:32 | [diff] [blame] | 99 | this._startCoverage.set(false); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 100 | } |
Jan Scheffler | fc2f383 | 2019-09-24 14:03:32 | [diff] [blame] | 101 | |
| 102 | |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 103 | this._showMemorySetting = self.Common.settings.createSetting('timelineShowMemory', false); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 104 | this._showMemorySetting.setTitle(Common.UIString.UIString('Memory')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 105 | this._showMemorySetting.addChangeListener(this._onModeChanged, this); |
| 106 | |
Erik Luo | 6355f4d | 2018-06-01 03:32:24 | [diff] [blame] | 107 | const timelineToolbarContainer = this.element.createChild('div', 'timeline-toolbar-container'); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 108 | this._panelToolbar = new UI.Toolbar.Toolbar('timeline-main-toolbar', timelineToolbarContainer); |
| 109 | this._panelRightToolbar = new UI.Toolbar.Toolbar('', timelineToolbarContainer); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 110 | this._createSettingsPane(); |
| 111 | this._updateShowSettingsToolbarButton(); |
| 112 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 113 | this._timelinePane = new UI.Widget.VBox(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 114 | this._timelinePane.show(this.element); |
| 115 | const topPaneElement = this._timelinePane.element.createChild('div', 'hbox'); |
| 116 | topPaneElement.id = 'timeline-overview-panel'; |
| 117 | |
| 118 | // Create top overview component. |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 119 | this._overviewPane = new PerfUI.TimelineOverviewPane.TimelineOverviewPane('timeline'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 120 | this._overviewPane.addEventListener( |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 121 | PerfUI.TimelineOverviewPane.Events.WindowChanged, this._onOverviewWindowChanged.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 122 | this._overviewPane.show(topPaneElement); |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 123 | /** @type {!Array<!TimelineEventOverview>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 124 | this._overviewControls = []; |
| 125 | |
| 126 | this._statusPaneContainer = this._timelinePane.element.createChild('div', 'status-pane-container fill'); |
| 127 | |
| 128 | this._createFileSelector(); |
| 129 | |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 130 | self.SDK.targetManager.addModelListener( |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 131 | SDK.ResourceTreeModel.ResourceTreeModel, SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 132 | |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 133 | this._flameChart = new TimelineFlameChartView(this); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 134 | this._searchableView = new UI.SearchableView.SearchableView(this._flameChart); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 135 | this._searchableView.setMinimumSize(0, 100); |
| 136 | this._searchableView.element.classList.add('searchable-view'); |
| 137 | this._searchableView.show(this._timelinePane.element); |
| 138 | this._flameChart.show(this._searchableView.element); |
| 139 | this._flameChart.setSearchableView(this._searchableView); |
Jack Lynch | d9a5b6e | 2020-02-24 20:35:19 | [diff] [blame] | 140 | this._searchableView.hideWidget(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 141 | |
| 142 | this._onModeChanged(); |
| 143 | this._populateToolbar(); |
| 144 | this._showLandingPage(); |
| 145 | this._updateTimelineControls(); |
| 146 | |
Paul Lewis | 396d0b9 | 2020-01-24 16:08:30 | [diff] [blame] | 147 | self.Extensions.extensionServer.addEventListener( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 148 | Extensions.ExtensionServer.Events.TraceProviderAdded, this._appendExtensionsToToolbar, this); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 149 | self.SDK.targetManager.addEventListener(SDK.SDKModel.Events.SuspendStateChanged, this._onSuspendStateChanged, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /** |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 153 | * @return {!TimelinePanel} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 154 | */ |
| 155 | static instance() { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 156 | return /** @type {!TimelinePanel} */ (self.runtime.sharedInstance(TimelinePanel)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @override |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 161 | * @return {?UI.SearchableView.SearchableView} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 162 | */ |
| 163 | searchableView() { |
| 164 | return this._searchableView; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * @override |
| 169 | */ |
| 170 | wasShown() { |
Paul Lewis | d990734 | 2020-01-24 13:49:47 | [diff] [blame] | 171 | self.UI.context.setFlavor(TimelinePanel, this); |
Alex Chiem | 1c99251 | 2020-01-15 19:38:23 | [diff] [blame] | 172 | // Record the performance tool load time. |
| 173 | Host.userMetrics.panelLoaded('timeline', 'DevTools.Launch.Timeline'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /** |
| 177 | * @override |
| 178 | */ |
| 179 | willHide() { |
Paul Lewis | d990734 | 2020-01-24 13:49:47 | [diff] [blame] | 180 | self.UI.context.setFlavor(TimelinePanel, null); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 181 | this._historyManager.cancelIfShowing(); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * @param {!Array.<!SDK.TracingManager.EventPayload>} events |
| 186 | */ |
| 187 | loadFromEvents(events) { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 188 | if (this._state !== State.Idle) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 189 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 190 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 191 | this._prepareToLoadTimeline(); |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 192 | this._loader = TimelineLoader.loadFromEvents(events, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 196 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 197 | */ |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 198 | _onOverviewWindowChanged(event) { |
| 199 | const left = event.data.startTime; |
| 200 | const right = event.data.endTime; |
| 201 | this._performanceModel.setWindow({left, right}, /* animate */ true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 205 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 206 | */ |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 207 | _onModelWindowChanged(event) { |
Tim van der Lippe | fced1b9 | 2020-02-17 12:33:50 | [diff] [blame] | 208 | const window = /** @type {!Window} */ (event.data.window); |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 209 | this._overviewPane.setWindowTimes(window.left, window.right); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /** |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 213 | * @param {!State} state |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 214 | */ |
| 215 | _setState(state) { |
| 216 | this._state = state; |
| 217 | this._updateTimelineControls(); |
| 218 | } |
| 219 | |
| 220 | /** |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 221 | * @param {!Common.Settings.Setting} setting |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 222 | * @param {string} tooltip |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 223 | * @return {!UI.Toolbar.ToolbarItem} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 224 | */ |
| 225 | _createSettingCheckbox(setting, tooltip) { |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 226 | const checkboxItem = new UI.Toolbar.ToolbarSettingCheckbox(setting, tooltip); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 227 | this._recordingOptionUIControls.push(checkboxItem); |
| 228 | return checkboxItem; |
| 229 | } |
| 230 | |
| 231 | _populateToolbar() { |
| 232 | // Record |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 233 | this._panelToolbar.appendToolbarItem(UI.Toolbar.Toolbar.createActionButton(this._toggleRecordAction)); |
| 234 | this._panelToolbar.appendToolbarItem(UI.Toolbar.Toolbar.createActionButton(this._recordReloadAction)); |
| 235 | this._clearButton = new UI.Toolbar.ToolbarButton(Common.UIString.UIString('Clear'), 'largeicon-clear'); |
| 236 | this._clearButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, () => this._onClearButton()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 237 | this._panelToolbar.appendToolbarItem(this._clearButton); |
| 238 | |
| 239 | // Load / Save |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame^] | 240 | this._loadButton = new UI.Toolbar.ToolbarButton(Common.UIString.UIString('Load profile…'), 'largeicon-load'); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 241 | this._loadButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, () => this._selectFileToLoad()); |
Ella Ge | d09f6c8 | 2020-02-18 16:34:10 | [diff] [blame] | 242 | this._saveButton = |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame^] | 243 | new UI.Toolbar.ToolbarButton(Common.UIString.UIString('Save profile…'), 'largeicon-download'); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 244 | this._saveButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, () => this._saveToFile()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 245 | this._panelToolbar.appendSeparator(); |
| 246 | this._panelToolbar.appendToolbarItem(this._loadButton); |
| 247 | this._panelToolbar.appendToolbarItem(this._saveButton); |
| 248 | |
| 249 | // History |
| 250 | this._panelToolbar.appendSeparator(); |
| 251 | this._panelToolbar.appendToolbarItem(this._historyManager.button()); |
| 252 | this._panelToolbar.appendSeparator(); |
| 253 | |
| 254 | // View |
| 255 | this._panelToolbar.appendSeparator(); |
| 256 | this._showScreenshotsToolbarCheckbox = |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 257 | this._createSettingCheckbox(this._showScreenshotsSetting, Common.UIString.UIString('Capture screenshots')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 258 | this._panelToolbar.appendToolbarItem(this._showScreenshotsToolbarCheckbox); |
| 259 | |
| 260 | this._showMemoryToolbarCheckbox = |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 261 | this._createSettingCheckbox(this._showMemorySetting, Common.UIString.UIString('Show memory timeline')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 262 | this._panelToolbar.appendToolbarItem(this._showMemoryToolbarCheckbox); |
| 263 | |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 264 | if (Root.Runtime.experiments.isEnabled('recordCoverageWithPerformanceTracing')) { |
Jan Scheffler | fc2f383 | 2019-09-24 14:03:32 | [diff] [blame] | 265 | this._startCoverageCheckbox = |
| 266 | this._createSettingCheckbox(this._startCoverage, ls`Record coverage with performance trace`); |
| 267 | this._panelToolbar.appendToolbarItem(this._startCoverageCheckbox); |
| 268 | } |
| 269 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 270 | // GC |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 271 | this._panelToolbar.appendToolbarItem(UI.Toolbar.Toolbar.createActionButtonForId('components.collect-garbage')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 272 | |
| 273 | // Settings |
Erik Luo | 6355f4d | 2018-06-01 03:32:24 | [diff] [blame] | 274 | this._panelRightToolbar.appendSeparator(); |
| 275 | this._panelRightToolbar.appendToolbarItem(this._showSettingsPaneButton); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | _createSettingsPane() { |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 279 | this._showSettingsPaneSetting = self.Common.settings.createSetting('timelineShowSettingsToolbar', false); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 280 | this._showSettingsPaneButton = new UI.Toolbar.ToolbarSettingToggle( |
| 281 | this._showSettingsPaneSetting, 'largeicon-settings-gear', Common.UIString.UIString('Capture settings')); |
Paul Lewis | 5a922e7 | 2020-01-24 11:58:08 | [diff] [blame] | 282 | self.SDK.multitargetNetworkManager.addEventListener( |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 283 | SDK.NetworkManager.MultitargetNetworkManager.Events.ConditionsChanged, this._updateShowSettingsToolbarButton, |
| 284 | this); |
| 285 | MobileThrottling.ThrottlingManager.throttlingManager().addEventListener( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 286 | MobileThrottling.ThrottlingManager.Events.RateChanged, this._updateShowSettingsToolbarButton, this); |
| 287 | this._disableCaptureJSProfileSetting.addChangeListener(this._updateShowSettingsToolbarButton, this); |
| 288 | this._captureLayersAndPicturesSetting.addChangeListener(this._updateShowSettingsToolbarButton, this); |
| 289 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 290 | this._settingsPane = new UI.Widget.HBox(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 291 | this._settingsPane.element.classList.add('timeline-settings-pane'); |
| 292 | this._settingsPane.show(this.element); |
| 293 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 294 | const captureToolbar = new UI.Toolbar.Toolbar('', this._settingsPane.element); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 295 | captureToolbar.element.classList.add('flex-auto'); |
| 296 | captureToolbar.makeVertical(); |
| 297 | captureToolbar.appendToolbarItem(this._createSettingCheckbox( |
| 298 | this._disableCaptureJSProfileSetting, |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 299 | Common.UIString.UIString( |
| 300 | 'Disables JavaScript sampling, reduces overhead when running against mobile devices'))); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 301 | captureToolbar.appendToolbarItem(this._createSettingCheckbox( |
| 302 | this._captureLayersAndPicturesSetting, |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 303 | Common.UIString.UIString( |
| 304 | 'Captures advanced paint instrumentation, introduces significant performance overhead'))); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 305 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 306 | const throttlingPane = new UI.Widget.VBox(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 307 | throttlingPane.element.classList.add('flex-auto'); |
| 308 | throttlingPane.show(this._settingsPane.element); |
| 309 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 310 | const networkThrottlingToolbar = new UI.Toolbar.Toolbar('', throttlingPane.element); |
| 311 | networkThrottlingToolbar.appendText(Common.UIString.UIString('Network:')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 312 | this._networkThrottlingSelect = this._createNetworkConditionsSelect(); |
| 313 | networkThrottlingToolbar.appendToolbarItem(this._networkThrottlingSelect); |
| 314 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 315 | const cpuThrottlingToolbar = new UI.Toolbar.Toolbar('', throttlingPane.element); |
| 316 | cpuThrottlingToolbar.appendText(Common.UIString.UIString('CPU:')); |
| 317 | this._cpuThrottlingSelect = MobileThrottling.ThrottlingManager.throttlingManager().createCPUThrottlingSelector(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 318 | cpuThrottlingToolbar.appendToolbarItem(this._cpuThrottlingSelect); |
| 319 | |
| 320 | this._showSettingsPaneSetting.addChangeListener(this._updateSettingsPaneVisibility.bind(this)); |
| 321 | this._updateSettingsPaneVisibility(); |
| 322 | } |
| 323 | |
| 324 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 325 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 326 | */ |
| 327 | _appendExtensionsToToolbar(event) { |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 328 | const provider = /** @type {!Extensions.ExtensionTraceProvider.ExtensionTraceProvider} */ (event.data); |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 329 | const setting = TimelinePanel._settingForTraceProvider(provider); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 330 | const checkbox = this._createSettingCheckbox(setting, provider.longDisplayName()); |
| 331 | this._panelToolbar.appendToolbarItem(checkbox); |
| 332 | } |
| 333 | |
| 334 | /** |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 335 | * @param {!Extensions.ExtensionTraceProvider.ExtensionTraceProvider} traceProvider |
| 336 | * @return {!Common.Settings.Setting<boolean>} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 337 | */ |
| 338 | static _settingForTraceProvider(traceProvider) { |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 339 | let setting = traceProvider[traceProviderSettingSymbol]; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 340 | if (!setting) { |
| 341 | const providerId = traceProvider.persistentIdentifier(); |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 342 | setting = self.Common.settings.createSetting(providerId, false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 343 | setting.setTitle(traceProvider.shortDisplayName()); |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 344 | traceProvider[traceProviderSettingSymbol] = setting; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 345 | } |
| 346 | return setting; |
| 347 | } |
| 348 | |
| 349 | /** |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 350 | * @return {!UI.Toolbar.ToolbarComboBox} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 351 | */ |
| 352 | _createNetworkConditionsSelect() { |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 353 | const toolbarItem = new UI.Toolbar.ToolbarComboBox(null, ls`Network conditions`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 354 | toolbarItem.setMaxWidth(140); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 355 | MobileThrottling.ThrottlingManager.throttlingManager().decorateSelectWithNetworkThrottling( |
| 356 | toolbarItem.selectElement()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 357 | return toolbarItem; |
| 358 | } |
| 359 | |
| 360 | _prepareToLoadTimeline() { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 361 | console.assert(this._state === State.Idle); |
| 362 | this._setState(State.Loading); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 363 | if (this._performanceModel) { |
| 364 | this._performanceModel.dispose(); |
| 365 | this._performanceModel = null; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | _createFileSelector() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 370 | if (this._fileSelectorElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 371 | this._fileSelectorElement.remove(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 372 | } |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 373 | this._fileSelectorElement = UI.UIUtils.createFileSelectorElement(this._loadFromFile.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 374 | this._timelinePane.element.appendChild(this._fileSelectorElement); |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * @param {!Event} event |
| 379 | */ |
| 380 | _contextMenu(event) { |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 381 | const contextMenu = new UI.ContextMenu.ContextMenu(event); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 382 | contextMenu.appendItemsAtLocation('timelineMenu'); |
| 383 | contextMenu.show(); |
| 384 | } |
| 385 | |
Tim van der Lippe | ffa7862 | 2019-09-16 12:07:12 | [diff] [blame] | 386 | /** |
| 387 | * @suppress {deprecated} |
| 388 | */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 389 | async _saveToFile() { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 390 | if (this._state !== State.Idle) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 391 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 392 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 393 | const performanceModel = this._performanceModel; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 394 | if (!performanceModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 395 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 396 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 397 | |
| 398 | const now = new Date(); |
| 399 | const fileName = 'Profile-' + now.toISO8601Compact() + '.json'; |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 400 | const stream = new Bindings.FileUtils.FileOutputStream(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 401 | |
| 402 | const accepted = await stream.open(fileName); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 403 | if (!accepted) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 404 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 405 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 406 | |
| 407 | const error = await performanceModel.save(stream); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 408 | if (!error) { |
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 | } |
Paul Lewis | 04ccecc | 2020-01-22 17:15:14 | [diff] [blame] | 411 | self.Common.console.error( |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 412 | Common.UIString.UIString('Failed to save timeline: %s (%s, %s)', error.message, error.name, error.code)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | async _showHistory() { |
| 416 | const model = await this._historyManager.showHistoryDropDown(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 417 | if (model && model !== this._performanceModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 418 | this._setModel(model); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 419 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /** |
| 423 | * @param {number} direction |
| 424 | * @return {boolean} |
| 425 | */ |
| 426 | _navigateHistory(direction) { |
| 427 | const model = this._historyManager.navigate(direction); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 428 | if (model && model !== this._performanceModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 429 | this._setModel(model); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 430 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 431 | return true; |
| 432 | } |
| 433 | |
| 434 | _selectFileToLoad() { |
| 435 | this._fileSelectorElement.click(); |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * @param {!File} file |
| 440 | */ |
| 441 | _loadFromFile(file) { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 442 | if (this._state !== State.Idle) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 443 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 444 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 445 | this._prepareToLoadTimeline(); |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 446 | this._loader = TimelineLoader.loadFromFile(file, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 447 | this._createFileSelector(); |
| 448 | } |
| 449 | |
| 450 | /** |
| 451 | * @param {string} url |
| 452 | */ |
| 453 | _loadFromURL(url) { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 454 | if (this._state !== State.Idle) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 455 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 456 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 457 | this._prepareToLoadTimeline(); |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 458 | this._loader = TimelineLoader.loadFromURL(url, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | _updateOverviewControls() { |
| 462 | this._overviewControls = []; |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 463 | this._overviewControls.push(new TimelineEventOverviewResponsiveness()); |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 464 | if (Root.Runtime.experiments.isEnabled('inputEventsOnTimelineOverview')) { |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 465 | this._overviewControls.push(new TimelineEventOverviewInput()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 466 | } |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 467 | this._overviewControls.push(new TimelineEventOverviewFrames()); |
| 468 | this._overviewControls.push(new TimelineEventOverviewCPUActivity()); |
| 469 | this._overviewControls.push(new TimelineEventOverviewNetwork()); |
Alexei Filippov | eddfd84 | 2018-04-28 01:01:13 | [diff] [blame] | 470 | if (this._showScreenshotsSetting.get() && this._performanceModel && |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 471 | this._performanceModel.filmStripModel().frames().length) { |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 472 | this._overviewControls.push(new TimelineFilmStripOverview()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 473 | } |
| 474 | if (this._showMemorySetting.get()) { |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 475 | this._overviewControls.push(new TimelineEventOverviewMemory()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 476 | } |
| 477 | if (this._startCoverage.get()) { |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 478 | this._overviewControls.push(new TimelineEventOverviewCoverage()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 479 | } |
| 480 | for (const control of this._overviewControls) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 481 | control.setModel(this._performanceModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 482 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 483 | this._overviewPane.setOverviewControls(this._overviewControls); |
| 484 | } |
| 485 | |
| 486 | _onModeChanged() { |
| 487 | this._updateOverviewControls(); |
| 488 | this.doResize(); |
| 489 | this.select(null); |
| 490 | } |
| 491 | |
| 492 | _updateSettingsPaneVisibility() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 493 | if (this._showSettingsPaneSetting.get()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 494 | this._settingsPane.showWidget(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 495 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 496 | this._settingsPane.hideWidget(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 497 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | _updateShowSettingsToolbarButton() { |
| 501 | const messages = []; |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 502 | if (MobileThrottling.ThrottlingManager.throttlingManager().cpuThrottlingRate() !== 1) { |
| 503 | messages.push(Common.UIString.UIString('- CPU throttling is enabled')); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 504 | } |
Paul Lewis | 5a922e7 | 2020-01-24 11:58:08 | [diff] [blame] | 505 | if (self.SDK.multitargetNetworkManager.isThrottling()) { |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 506 | messages.push(Common.UIString.UIString('- Network throttling is enabled')); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 507 | } |
| 508 | if (this._captureLayersAndPicturesSetting.get()) { |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 509 | messages.push(Common.UIString.UIString('- Significant overhead due to paint instrumentation')); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 510 | } |
| 511 | if (this._disableCaptureJSProfileSetting.get()) { |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 512 | messages.push(Common.UIString.UIString('- JavaScript sampling is disabled')); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 513 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 514 | |
| 515 | this._showSettingsPaneButton.setDefaultWithRedColor(messages.length); |
| 516 | this._showSettingsPaneButton.setToggleWithRedColor(messages.length); |
| 517 | |
| 518 | if (messages.length) { |
| 519 | const tooltipElement = createElement('div'); |
| 520 | messages.forEach(message => { |
| 521 | tooltipElement.createChild('div').textContent = message; |
| 522 | }); |
| 523 | this._showSettingsPaneButton.setTitle(tooltipElement); |
| 524 | } else { |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 525 | this._showSettingsPaneButton.setTitle(Common.UIString.UIString('Capture settings')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * @param {boolean} enabled |
| 531 | */ |
| 532 | _setUIControlsEnabled(enabled) { |
| 533 | this._recordingOptionUIControls.forEach(control => control.setEnabled(enabled)); |
| 534 | } |
| 535 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 536 | async _startRecording() { |
| 537 | console.assert(!this._statusPane, 'Status pane is already opened.'); |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 538 | this._setState(State.StartPending); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 539 | |
| 540 | const recordingOptions = { |
| 541 | enableJSSampling: !this._disableCaptureJSProfileSetting.get(), |
| 542 | capturePictures: this._captureLayersAndPicturesSetting.get(), |
Jan Scheffler | fc2f383 | 2019-09-24 14:03:32 | [diff] [blame] | 543 | captureFilmStrip: this._showScreenshotsSetting.get(), |
| 544 | startCoverage: this._startCoverage.get() |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 545 | }; |
| 546 | |
Jan Scheffler | fc2f383 | 2019-09-24 14:03:32 | [diff] [blame] | 547 | if (recordingOptions.startCoverage) { |
Paul Lewis | 5099369 | 2020-01-23 15:22:26 | [diff] [blame] | 548 | await self.UI.viewManager.showView('coverage') |
| 549 | .then(() => self.UI.viewManager.view('coverage').widget()) |
Jan Scheffler | fc2f383 | 2019-09-24 14:03:32 | [diff] [blame] | 550 | .then(widget => widget.ensureRecordingStarted()); |
| 551 | } |
| 552 | |
| 553 | this._showRecordingStarted(); |
| 554 | |
Paul Lewis | 396d0b9 | 2020-01-24 16:08:30 | [diff] [blame] | 555 | const enabledTraceProviders = self.Extensions.extensionServer.traceProviders().filter( |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 556 | provider => TimelinePanel._settingForTraceProvider(provider).get()); |
Jan Scheffler | fc2f383 | 2019-09-24 14:03:32 | [diff] [blame] | 557 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 558 | const mainTarget = /** @type {!SDK.SDKModel.Target} */ (self.SDK.targetManager.mainTarget()); |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 559 | if (UIDevtoolsUtils.isUiDevTools()) { |
| 560 | this._controller = new UIDevtoolsController(mainTarget, this); |
Yang Guo | 1225402 | 2019-10-01 19:20:44 | [diff] [blame] | 561 | } else { |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 562 | this._controller = new TimelineController(mainTarget, this); |
Yang Guo | 1225402 | 2019-10-01 19:20:44 | [diff] [blame] | 563 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 564 | this._setUIControlsEnabled(false); |
| 565 | this._hideLandingPage(); |
Sigurd Schneider | 6eecdaa | 2019-08-20 07:47:10 | [diff] [blame] | 566 | const response = await this._controller.startRecording(recordingOptions, enabledTraceProviders); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 567 | if (response[ProtocolModule.InspectorBackend.ProtocolError]) { |
| 568 | this._recordingFailed(response[ProtocolModule.InspectorBackend.ProtocolError]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 569 | } else { |
Sigurd Schneider | 6eecdaa | 2019-08-20 07:47:10 | [diff] [blame] | 570 | this._recordingStarted(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 571 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | async _stopRecording() { |
| 575 | if (this._statusPane) { |
| 576 | this._statusPane.finish(); |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame^] | 577 | this._statusPane.updateStatus(Common.UIString.UIString('Stopping timeline…')); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 578 | this._statusPane.updateProgressBar(Common.UIString.UIString('Received'), 0); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 579 | } |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 580 | this._setState(State.StopPending); |
Sigurd Schneider | 759ef97 | 2020-01-28 09:46:06 | [diff] [blame] | 581 | if (this._startCoverage.get()) { |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 582 | await self.UI.viewManager.showView('coverage') |
| 583 | .then(() => self.UI.viewManager.view('coverage').widget()) |
Sigurd Schneider | 759ef97 | 2020-01-28 09:46:06 | [diff] [blame] | 584 | .then(widget => widget.stopRecording()); |
| 585 | } |
Sigurd Schneider | 6eecdaa | 2019-08-20 07:47:10 | [diff] [blame] | 586 | const model = await this._controller.stopRecording(); |
| 587 | this._performanceModel = model; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 588 | this._setUIControlsEnabled(true); |
Alexei Filippov | e712dbc | 2018-05-30 22:31:33 | [diff] [blame] | 589 | this._controller.dispose(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 590 | this._controller = null; |
| 591 | } |
| 592 | |
Sigurd Schneider | 6eecdaa | 2019-08-20 07:47:10 | [diff] [blame] | 593 | /** |
| 594 | * @param {string} error The error message to display |
| 595 | */ |
| 596 | _recordingFailed(error) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 597 | if (this._statusPane) { |
Sigurd Schneider | 6eecdaa | 2019-08-20 07:47:10 | [diff] [blame] | 598 | this._statusPane.hide(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 599 | } |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 600 | this._statusPane = new StatusPane({description: error}, () => this.loadingComplete(null)); |
Sigurd Schneider | 6eecdaa | 2019-08-20 07:47:10 | [diff] [blame] | 601 | this._statusPane.showPane(this._statusPaneContainer); |
| 602 | this._statusPane.updateStatus(ls`Recording failed`); |
| 603 | this._statusPane.updateButton(ls`Close`); |
| 604 | |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 605 | this._setState(State.RecordingFailed); |
Sigurd Schneider | 6eecdaa | 2019-08-20 07:47:10 | [diff] [blame] | 606 | this._performanceModel = null; |
| 607 | this._setUIControlsEnabled(false); |
| 608 | this._controller.dispose(); |
| 609 | this._controller = null; |
| 610 | } |
| 611 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 612 | _onSuspendStateChanged() { |
| 613 | this._updateTimelineControls(); |
| 614 | } |
| 615 | |
| 616 | _updateTimelineControls() { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 617 | const state = State; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 618 | this._toggleRecordAction.setToggled(this._state === state.Recording); |
| 619 | this._toggleRecordAction.setEnabled(this._state === state.Recording || this._state === state.Idle); |
| 620 | this._recordReloadAction.setEnabled(this._state === state.Idle); |
| 621 | this._historyManager.setEnabled(this._state === state.Idle); |
| 622 | this._clearButton.setEnabled(this._state === state.Idle); |
| 623 | this._panelToolbar.setEnabled(this._state !== state.Loading); |
Erik Luo | 6355f4d | 2018-06-01 03:32:24 | [diff] [blame] | 624 | this._panelRightToolbar.setEnabled(this._state !== state.Loading); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 625 | this._dropTarget.setEnabled(this._state === state.Idle); |
| 626 | this._loadButton.setEnabled(this._state === state.Idle); |
| 627 | this._saveButton.setEnabled(this._state === state.Idle && !!this._performanceModel); |
| 628 | } |
| 629 | |
| 630 | _toggleRecording() { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 631 | if (this._state === State.Idle) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 632 | this._recordingPageReload = false; |
| 633 | this._startRecording(); |
| 634 | Host.userMetrics.actionTaken(Host.UserMetrics.Action.TimelineStarted); |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 635 | } else if (this._state === State.Recording) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 636 | this._stopRecording(); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | _recordReload() { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 641 | if (this._state !== State.Idle) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 642 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 643 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 644 | this._recordingPageReload = true; |
| 645 | this._startRecording(); |
| 646 | Host.userMetrics.actionTaken(Host.UserMetrics.Action.TimelinePageReloadStarted); |
| 647 | } |
| 648 | |
| 649 | _onClearButton() { |
| 650 | this._historyManager.clear(); |
| 651 | this._clear(); |
| 652 | } |
| 653 | |
| 654 | _clear() { |
| 655 | this._showLandingPage(); |
| 656 | this._reset(); |
| 657 | } |
| 658 | |
| 659 | _reset() { |
Alexei Filippov | f2e42e4 | 2019-04-04 21:40:45 | [diff] [blame] | 660 | self.runtime.sharedInstance(PerfUI.LineLevelProfile.Performance).reset(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 661 | this._setModel(null); |
| 662 | } |
| 663 | |
| 664 | /** |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 665 | * @param {!PerformanceModel} model |
Alexei Filippov | 35f97d6 | 2018-04-28 01:02:31 | [diff] [blame] | 666 | */ |
| 667 | _applyFilters(model) { |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 668 | if (model.timelineModel().isGenericTrace() || Root.Runtime.experiments.isEnabled('timelineShowAllEvents')) { |
Alexei Filippov | 35f97d6 | 2018-04-28 01:02:31 | [diff] [blame] | 669 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 670 | } |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 671 | model.setFilters([TimelineUIUtils.visibleEventsFilter()]); |
Alexei Filippov | 35f97d6 | 2018-04-28 01:02:31 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | /** |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 675 | * @param {?PerformanceModel} model |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 676 | */ |
| 677 | _setModel(model) { |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 678 | if (this._performanceModel) { |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 679 | this._performanceModel.removeEventListener(Events.WindowChanged, this._onModelWindowChanged, this); |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 680 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 681 | this._performanceModel = model; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 682 | if (model) { |
Jack Lynch | d9a5b6e | 2020-02-24 20:35:19 | [diff] [blame] | 683 | this._searchableView.showWidget(); |
Alexei Filippov | 35f97d6 | 2018-04-28 01:02:31 | [diff] [blame] | 684 | this._applyFilters(model); |
Jack Lynch | d9a5b6e | 2020-02-24 20:35:19 | [diff] [blame] | 685 | } else { |
| 686 | this._searchableView.hideWidget(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 687 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 688 | this._flameChart.setModel(model); |
| 689 | |
Alexei Filippov | eddfd84 | 2018-04-28 01:01:13 | [diff] [blame] | 690 | this._updateOverviewControls(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 691 | this._overviewPane.reset(); |
| 692 | if (model) { |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 693 | this._performanceModel.addEventListener(Events.WindowChanged, this._onModelWindowChanged, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 694 | this._overviewPane.setBounds( |
| 695 | model.timelineModel().minimumRecordTime(), model.timelineModel().maximumRecordTime()); |
Alexei Filippov | f2e42e4 | 2019-04-04 21:40:45 | [diff] [blame] | 696 | const lineLevelProfile = self.runtime.sharedInstance(PerfUI.LineLevelProfile.Performance); |
Alexei Filippov | 6c89282 | 2019-03-06 22:30:42 | [diff] [blame] | 697 | lineLevelProfile.reset(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 698 | for (const profile of model.timelineModel().cpuProfiles()) { |
Alexei Filippov | 6c89282 | 2019-03-06 22:30:42 | [diff] [blame] | 699 | lineLevelProfile.appendCPUProfile(profile); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 700 | } |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 701 | this._setMarkers(model.timelineModel()); |
| 702 | this._flameChart.setSelection(null); |
| 703 | this._overviewPane.setWindowTimes(model.window().left, model.window().right); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 704 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 705 | for (const control of this._overviewControls) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 706 | control.setModel(model); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 707 | } |
| 708 | if (this._flameChart) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 709 | this._flameChart.resizeToPreferredHeights(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 710 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 711 | this._updateTimelineControls(); |
| 712 | } |
| 713 | |
| 714 | _recordingStarted() { |
| 715 | if (this._recordingPageReload) { |
| 716 | const target = this._controller.mainTarget(); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 717 | const resourceModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 718 | if (resourceModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 719 | resourceModel.reloadPage(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 720 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 721 | } |
| 722 | this._reset(); |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 723 | this._setState(State.Recording); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 724 | this._showRecordingStarted(); |
Tony Ross | ba14dc6 | 2020-02-18 18:37:05 | [diff] [blame] | 725 | this._statusPane.enableAndFocusStopButton(); |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame^] | 726 | this._statusPane.updateStatus(Common.UIString.UIString('Profiling…')); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 727 | this._statusPane.updateProgressBar(Common.UIString.UIString('Buffer usage'), 0); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 728 | this._statusPane.startTimer(); |
| 729 | this._hideLandingPage(); |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * @override |
| 734 | * @param {number} usage |
| 735 | */ |
| 736 | recordingProgress(usage) { |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 737 | this._statusPane.updateProgressBar(Common.UIString.UIString('Buffer usage'), usage * 100); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | _showLandingPage() { |
| 741 | if (this._landingPage) { |
| 742 | this._landingPage.show(this._statusPaneContainer); |
| 743 | return; |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * @param {string} tagName |
| 748 | * @param {string} contents |
| 749 | */ |
| 750 | function encloseWithTag(tagName, contents) { |
| 751 | const e = createElement(tagName); |
| 752 | e.textContent = contents; |
| 753 | return e; |
| 754 | } |
| 755 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 756 | const learnMoreNode = UI.XLink.XLink.create( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 757 | 'https://developers.google.com/web/tools/chrome-devtools/evaluate-performance/', |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 758 | Common.UIString.UIString('Learn\xa0more')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 759 | |
| 760 | const recordKey = |
Paul Lewis | 05eb37f | 2020-01-24 14:31:40 | [diff] [blame] | 761 | encloseWithTag('b', self.UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.toggle-recording')[0].name); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 762 | const reloadKey = |
Paul Lewis | 05eb37f | 2020-01-24 14:31:40 | [diff] [blame] | 763 | encloseWithTag('b', self.UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.record-reload')[0].name); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 764 | const navigateNode = encloseWithTag('b', Common.UIString.UIString('WASD')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 765 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 766 | this._landingPage = new UI.Widget.VBox(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 767 | this._landingPage.contentElement.classList.add('timeline-landing-page', 'fill'); |
| 768 | const centered = this._landingPage.contentElement.createChild('div'); |
| 769 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 770 | const recordButton = UI.UIUtils.createInlineButton(UI.Toolbar.Toolbar.createActionButton(this._toggleRecordAction)); |
| 771 | const reloadButton = |
| 772 | UI.UIUtils.createInlineButton(UI.Toolbar.Toolbar.createActionButtonForId('timeline.record-reload')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 773 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 774 | centered.createChild('p').appendChild(UI.UIUtils.formatLocalized( |
Lorne Mitchell | 7aa2c6c | 2019-04-03 03:50:10 | [diff] [blame] | 775 | 'Click the record button %s or hit %s to start a new recording.\nClick the reload button %s or hit %s to record the page load.', |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 776 | [recordButton, recordKey, reloadButton, reloadKey])); |
| 777 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 778 | centered.createChild('p').appendChild(UI.UIUtils.formatLocalized( |
Lorne Mitchell | 7aa2c6c | 2019-04-03 03:50:10 | [diff] [blame] | 779 | 'After recording, select an area of interest in the overview by dragging.\nThen, zoom and pan the timeline with the mousewheel or %s keys.\n%s', |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 780 | [navigateNode, learnMoreNode])); |
| 781 | |
| 782 | this._landingPage.show(this._statusPaneContainer); |
| 783 | } |
| 784 | |
| 785 | _hideLandingPage() { |
| 786 | this._landingPage.detach(); |
| 787 | } |
| 788 | |
| 789 | /** |
| 790 | * @override |
| 791 | */ |
| 792 | loadingStarted() { |
| 793 | this._hideLandingPage(); |
| 794 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 795 | if (this._statusPane) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 796 | this._statusPane.hide(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 797 | } |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 798 | this._statusPane = new StatusPane({showProgress: true}, this._cancelLoading.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 799 | this._statusPane.showPane(this._statusPaneContainer); |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame^] | 800 | this._statusPane.updateStatus(Common.UIString.UIString('Loading profile…')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 801 | // FIXME: make loading from backend cancelable as well. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 802 | if (!this._loader) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 803 | this._statusPane.finish(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 804 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 805 | this.loadingProgress(0); |
| 806 | } |
| 807 | |
| 808 | /** |
| 809 | * @override |
| 810 | * @param {number=} progress |
| 811 | */ |
| 812 | loadingProgress(progress) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 813 | if (typeof progress === 'number') { |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 814 | this._statusPane.updateProgressBar(Common.UIString.UIString('Received'), progress * 100); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 815 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | /** |
| 819 | * @override |
| 820 | */ |
| 821 | processingStarted() { |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame^] | 822 | this._statusPane.updateStatus(Common.UIString.UIString('Processing profile…')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | /** |
| 826 | * @override |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 827 | * @param {?SDK.TracingModel.TracingModel} tracingModel |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 828 | */ |
| 829 | loadingComplete(tracingModel) { |
| 830 | delete this._loader; |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 831 | this._setState(State.Idle); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 832 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 833 | if (this._statusPane) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 834 | this._statusPane.hide(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 835 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 836 | delete this._statusPane; |
| 837 | |
| 838 | if (!tracingModel) { |
| 839 | this._clear(); |
| 840 | return; |
| 841 | } |
| 842 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 843 | if (!this._performanceModel) { |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 844 | this._performanceModel = new PerformanceModel(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 845 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 846 | this._performanceModel.setTracingModel(tracingModel); |
| 847 | this._setModel(this._performanceModel); |
| 848 | this._historyManager.addRecording(this._performanceModel); |
Jan Scheffler | fc2f383 | 2019-09-24 14:03:32 | [diff] [blame] | 849 | |
| 850 | if (this._startCoverage.get()) { |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 851 | self.UI.viewManager.showView('coverage') |
| 852 | .then(() => self.UI.viewManager.view('coverage').widget()) |
Sigurd Schneider | 759ef97 | 2020-01-28 09:46:06 | [diff] [blame] | 853 | .then(widget => widget.processBacklog()) |
Sigurd Schneider | 89d42ef | 2019-09-25 15:08:40 | [diff] [blame] | 854 | .then(() => this._updateOverviewControls()); |
Jan Scheffler | fc2f383 | 2019-09-24 14:03:32 | [diff] [blame] | 855 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | _showRecordingStarted() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 859 | if (this._statusPane) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 860 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 861 | } |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 862 | this._statusPane = new StatusPane({showTimer: true, showProgress: true}, this._stopRecording.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 863 | this._statusPane.showPane(this._statusPaneContainer); |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame^] | 864 | this._statusPane.updateStatus(Common.UIString.UIString('Initializing profiler…')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | _cancelLoading() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 868 | if (this._loader) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 869 | this._loader.cancel(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 870 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | /** |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 874 | * @param {!TimelineModel.TimelineModel.TimelineModelImpl} timelineModel |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 875 | */ |
| 876 | _setMarkers(timelineModel) { |
| 877 | const markers = new Map(); |
| 878 | const recordTypes = TimelineModel.TimelineModel.RecordType; |
| 879 | const zeroTime = timelineModel.minimumRecordTime(); |
Alexei Filippov | 45dbf98 | 2018-05-01 22:51:52 | [diff] [blame] | 880 | for (const event of timelineModel.timeMarkerEvents()) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 881 | if (event.name === recordTypes.TimeStamp || event.name === recordTypes.ConsoleTime) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 882 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 883 | } |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 884 | markers.set(event.startTime, TimelineUIUtils.createEventDivider(event, zeroTime)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 885 | } |
| 886 | this._overviewPane.setMarkers(markers); |
| 887 | } |
| 888 | |
| 889 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 890 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 891 | */ |
| 892 | async _loadEventFired(event) { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 893 | if (this._state !== State.Recording || !this._recordingPageReload || |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 894 | this._controller.mainTarget() !== event.data.resourceTreeModel.target()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 895 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 896 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 897 | const controller = this._controller; |
| 898 | await new Promise(r => setTimeout(r, this._millisecondsToRecordAfterLoadEvent)); |
| 899 | |
| 900 | // Check if we're still in the same recording session. |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 901 | if (controller !== this._controller || this._state !== State.Recording) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 902 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 903 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 904 | this._stopRecording(); |
| 905 | } |
| 906 | |
| 907 | /** |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 908 | * @param {!TimelineSelection} selection |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 909 | * @return {?TimelineModel.TimelineFrameModel.TimelineFrame} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 910 | */ |
| 911 | _frameForSelection(selection) { |
| 912 | switch (selection.type()) { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 913 | case TimelineSelection.Type.Frame: |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 914 | return /** @type {!TimelineModel.TimelineFrameModel.TimelineFrame} */ (selection.object()); |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 915 | case TimelineSelection.Type.Range: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 916 | return null; |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 917 | case TimelineSelection.Type.TraceEvent: |
Alexei Filippov | eddfd84 | 2018-04-28 01:01:13 | [diff] [blame] | 918 | return this._performanceModel.frameModel().frames(selection._endTime, selection._endTime)[0]; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 919 | default: |
| 920 | console.assert(false, 'Should never be reached'); |
| 921 | return null; |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | /** |
| 926 | * @param {number} offset |
| 927 | */ |
| 928 | _jumpToFrame(offset) { |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 929 | const currentFrame = this._selection && this._frameForSelection(this._selection); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 930 | if (!currentFrame) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 931 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 932 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 933 | const frames = this._performanceModel.frames(); |
| 934 | let index = frames.indexOf(currentFrame); |
| 935 | console.assert(index >= 0, 'Can\'t find current frame in the frame list'); |
| 936 | index = Number.constrain(index + offset, 0, frames.length - 1); |
| 937 | const frame = frames[index]; |
| 938 | this._revealTimeRange(frame.startTime, frame.endTime); |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 939 | this.select(TimelineSelection.fromFrame(frame)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 940 | return true; |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * @override |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 945 | * @param {?TimelineSelection} selection |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 946 | */ |
| 947 | select(selection) { |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 948 | this._selection = selection; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 949 | this._flameChart.setSelection(selection); |
| 950 | } |
| 951 | |
| 952 | /** |
| 953 | * @override |
| 954 | * @param {?Array<!SDK.TracingModel.Event>} events |
| 955 | * @param {number} time |
| 956 | */ |
| 957 | selectEntryAtTime(events, time) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 958 | if (!events) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 959 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 960 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 961 | // Find best match, then backtrack to the first visible entry. |
| 962 | for (let index = events.upperBound(time, (time, event) => time - event.startTime) - 1; index >= 0; --index) { |
| 963 | const event = events[index]; |
| 964 | const endTime = event.endTime || event.startTime; |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 965 | if (SDK.TracingModel.TracingModel.isTopLevelEvent(event) && endTime < time) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 966 | break; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 967 | } |
Alexei Filippov | 35f97d6 | 2018-04-28 01:02:31 | [diff] [blame] | 968 | if (this._performanceModel.isVisible(event) && endTime >= time) { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 969 | this.select(TimelineSelection.fromTraceEvent(event)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 970 | return; |
| 971 | } |
| 972 | } |
| 973 | this.select(null); |
| 974 | } |
| 975 | |
| 976 | /** |
| 977 | * @override |
| 978 | * @param {?SDK.TracingModel.Event} event |
| 979 | */ |
| 980 | highlightEvent(event) { |
| 981 | this._flameChart.highlightEvent(event); |
| 982 | } |
| 983 | |
| 984 | /** |
| 985 | * @param {number} startTime |
| 986 | * @param {number} endTime |
| 987 | */ |
| 988 | _revealTimeRange(startTime, endTime) { |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 989 | const window = this._performanceModel.window(); |
| 990 | let offset = 0; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 991 | if (window.right < endTime) { |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 992 | offset = endTime - window.right; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 993 | } else if (window.left > startTime) { |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 994 | offset = startTime - window.left; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 995 | } |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 996 | this._performanceModel.setWindow({left: window.left + offset, right: window.right + offset}, /* animate */ true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | /** |
| 1000 | * @param {!DataTransfer} dataTransfer |
| 1001 | */ |
| 1002 | _handleDrop(dataTransfer) { |
| 1003 | const items = dataTransfer.items; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1004 | if (!items.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1005 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1006 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1007 | const item = items[0]; |
| 1008 | if (item.kind === 'string') { |
| 1009 | const url = dataTransfer.getData('text/uri-list'); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 1010 | if (new Common.ParsedURL.ParsedURL(url).isValid) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1011 | this._loadFromURL(url); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1012 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1013 | } else if (item.kind === 'file') { |
| 1014 | const entry = items[0].webkitGetAsEntry(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1015 | if (!entry.isFile) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1016 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1017 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1018 | entry.file(this._loadFromFile.bind(this)); |
| 1019 | } |
| 1020 | } |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1021 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1022 | |
| 1023 | /** |
| 1024 | * @enum {symbol} |
| 1025 | */ |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1026 | export const State = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1027 | Idle: Symbol('Idle'), |
| 1028 | StartPending: Symbol('StartPending'), |
| 1029 | Recording: Symbol('Recording'), |
| 1030 | StopPending: Symbol('StopPending'), |
Sigurd Schneider | 6eecdaa | 2019-08-20 07:47:10 | [diff] [blame] | 1031 | Loading: Symbol('Loading'), |
| 1032 | RecordingFailed: Symbol('RecordingFailed') |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1033 | }; |
| 1034 | |
| 1035 | /** |
| 1036 | * @enum {string} |
| 1037 | */ |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1038 | export const ViewMode = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1039 | FlameChart: 'FlameChart', |
| 1040 | BottomUp: 'BottomUp', |
| 1041 | CallTree: 'CallTree', |
| 1042 | EventLog: 'EventLog' |
| 1043 | }; |
| 1044 | |
| 1045 | // Define row and header height, should be in sync with styles for timeline graphs. |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1046 | export const rowHeight = 18; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1047 | |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1048 | export const headerHeight = 20; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1049 | |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1050 | export class TimelineSelection { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1051 | /** |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1052 | * @param {!TimelineSelection.Type} type |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1053 | * @param {number} startTime |
| 1054 | * @param {number} endTime |
| 1055 | * @param {!Object=} object |
| 1056 | */ |
| 1057 | constructor(type, startTime, endTime, object) { |
| 1058 | this._type = type; |
| 1059 | this._startTime = startTime; |
| 1060 | this._endTime = endTime; |
| 1061 | this._object = object || null; |
| 1062 | } |
| 1063 | |
| 1064 | /** |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 1065 | * @param {!TimelineModel.TimelineFrameModel.TimelineFrame} frame |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1066 | * @return {!TimelineSelection} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1067 | */ |
| 1068 | static fromFrame(frame) { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1069 | return new TimelineSelection(TimelineSelection.Type.Frame, frame.startTime, frame.endTime, frame); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | /** |
| 1073 | * @param {!TimelineModel.TimelineModel.NetworkRequest} request |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1074 | * @return {!TimelineSelection} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1075 | */ |
| 1076 | static fromNetworkRequest(request) { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1077 | return new TimelineSelection( |
| 1078 | TimelineSelection.Type.NetworkRequest, request.startTime, request.endTime || request.startTime, request); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | /** |
| 1082 | * @param {!SDK.TracingModel.Event} event |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1083 | * @return {!TimelineSelection} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1084 | */ |
| 1085 | static fromTraceEvent(event) { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1086 | return new TimelineSelection( |
| 1087 | TimelineSelection.Type.TraceEvent, event.startTime, event.endTime || (event.startTime + 1), event); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * @param {number} startTime |
| 1092 | * @param {number} endTime |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1093 | * @return {!TimelineSelection} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1094 | */ |
| 1095 | static fromRange(startTime, endTime) { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1096 | return new TimelineSelection(TimelineSelection.Type.Range, startTime, endTime); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | /** |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1100 | * @return {!TimelineSelection.Type} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1101 | */ |
| 1102 | type() { |
| 1103 | return this._type; |
| 1104 | } |
| 1105 | |
| 1106 | /** |
| 1107 | * @return {?Object} |
| 1108 | */ |
| 1109 | object() { |
| 1110 | return this._object; |
| 1111 | } |
| 1112 | |
| 1113 | /** |
| 1114 | * @return {number} |
| 1115 | */ |
| 1116 | startTime() { |
| 1117 | return this._startTime; |
| 1118 | } |
| 1119 | |
| 1120 | /** |
| 1121 | * @return {number} |
| 1122 | */ |
| 1123 | endTime() { |
| 1124 | return this._endTime; |
| 1125 | } |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1126 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1127 | |
| 1128 | /** |
| 1129 | * @enum {string} |
| 1130 | */ |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1131 | TimelineSelection.Type = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1132 | Frame: 'Frame', |
| 1133 | NetworkRequest: 'NetworkRequest', |
| 1134 | TraceEvent: 'TraceEvent', |
| 1135 | Range: 'Range' |
| 1136 | }; |
| 1137 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1138 | /** |
| 1139 | * @interface |
| 1140 | */ |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1141 | export class TimelineModeViewDelegate { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1142 | /** |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1143 | * @param {?TimelineSelection} selection |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1144 | */ |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1145 | select(selection) { |
| 1146 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1147 | |
| 1148 | /** |
| 1149 | * @param {?Array<!SDK.TracingModel.Event>} events |
| 1150 | * @param {number} time |
| 1151 | */ |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1152 | selectEntryAtTime(events, time) { |
| 1153 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1154 | |
| 1155 | /** |
| 1156 | * @param {?SDK.TracingModel.Event} event |
| 1157 | */ |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1158 | highlightEvent(event) { |
| 1159 | } |
| 1160 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1161 | |
| 1162 | /** |
| 1163 | * @unrestricted |
| 1164 | */ |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 1165 | export class StatusPane extends UI.Widget.VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1166 | /** |
Sigurd Schneider | 6eecdaa | 2019-08-20 07:47:10 | [diff] [blame] | 1167 | * @param {!{showTimer: (boolean|undefined), showProgress: (boolean|undefined), description: (string|undefined)}} options - a collection of options controlling the appearance of the pane. |
| 1168 | * The options object can have the following properties: |
| 1169 | * - **showTimer** - `{boolean}` - Display seconds since dialog opened |
| 1170 | * - **showProgress** - `{boolean}` - Display a progress bar |
| 1171 | * - **description** - `{string}` - Display this string in a description line |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1172 | * @param {function()} stopCallback |
| 1173 | */ |
Sigurd Schneider | 6eecdaa | 2019-08-20 07:47:10 | [diff] [blame] | 1174 | constructor(options, stopCallback) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1175 | super(true); |
| 1176 | this.registerRequiredCSS('timeline/timelineStatusDialog.css'); |
| 1177 | this.contentElement.classList.add('timeline-status-dialog'); |
| 1178 | |
| 1179 | const statusLine = this.contentElement.createChild('div', 'status-dialog-line status'); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 1180 | statusLine.createChild('div', 'label').textContent = Common.UIString.UIString('Status'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1181 | this._status = statusLine.createChild('div', 'content'); |
Chandani Shrestha | 19ee3a2 | 2019-07-18 18:10:39 | [diff] [blame] | 1182 | UI.ARIAUtils.markAsStatus(this._status); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1183 | |
Sigurd Schneider | 6eecdaa | 2019-08-20 07:47:10 | [diff] [blame] | 1184 | if (options.showTimer) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1185 | const timeLine = this.contentElement.createChild('div', 'status-dialog-line time'); |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 1186 | timeLine.createChild('div', 'label').textContent = Common.UIString.UIString('Time'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1187 | this._time = timeLine.createChild('div', 'content'); |
| 1188 | } |
Sigurd Schneider | 6eecdaa | 2019-08-20 07:47:10 | [diff] [blame] | 1189 | |
| 1190 | if (options.showProgress) { |
| 1191 | const progressLine = this.contentElement.createChild('div', 'status-dialog-line progress'); |
| 1192 | this._progressLabel = progressLine.createChild('div', 'label'); |
| 1193 | this._progressBar = progressLine.createChild('div', 'indicator-container').createChild('div', 'indicator'); |
| 1194 | UI.ARIAUtils.markAsProgressBar(this._progressBar); |
| 1195 | } |
| 1196 | |
| 1197 | if (typeof options.description === 'string') { |
| 1198 | const descriptionLine = this.contentElement.createChild('div', 'status-dialog-line description'); |
| 1199 | descriptionLine.createChild('div', 'label').textContent = ls`Description`; |
| 1200 | this._description = descriptionLine.createChild('div', 'content'); |
| 1201 | this._description.innerText = options.description; |
| 1202 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1203 | |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 1204 | this._stopButton = UI.UIUtils.createTextButton(Common.UIString.UIString('Stop'), stopCallback, '', true); |
Sigurd Schneider | ce8ef94 | 2019-12-18 14:11:45 | [diff] [blame] | 1205 | // Profiling can't be stopped during initialization. |
| 1206 | this._stopButton.disabled = true; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1207 | this.contentElement.createChild('div', 'stop-button').appendChild(this._stopButton); |
| 1208 | } |
| 1209 | |
| 1210 | finish() { |
| 1211 | this._stopTimer(); |
| 1212 | this._stopButton.disabled = true; |
| 1213 | } |
| 1214 | |
| 1215 | hide() { |
| 1216 | this.element.parentNode.classList.remove('tinted'); |
| 1217 | this.element.remove(); |
| 1218 | } |
| 1219 | |
| 1220 | /** |
| 1221 | * @param {!Element} parent |
| 1222 | */ |
| 1223 | showPane(parent) { |
| 1224 | this.show(parent); |
| 1225 | parent.classList.add('tinted'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1226 | } |
| 1227 | |
Tony Ross | ba14dc6 | 2020-02-18 18:37:05 | [diff] [blame] | 1228 | enableAndFocusStopButton() { |
Sigurd Schneider | ce8ef94 | 2019-12-18 14:11:45 | [diff] [blame] | 1229 | this._stopButton.disabled = false; |
Tony Ross | ba14dc6 | 2020-02-18 18:37:05 | [diff] [blame] | 1230 | this._stopButton.focus(); |
Sigurd Schneider | ce8ef94 | 2019-12-18 14:11:45 | [diff] [blame] | 1231 | } |
| 1232 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1233 | /** |
| 1234 | * @param {string} text |
| 1235 | */ |
| 1236 | updateStatus(text) { |
| 1237 | this._status.textContent = text; |
| 1238 | } |
| 1239 | |
| 1240 | /** |
| 1241 | * @param {string} activity |
| 1242 | * @param {number} percent |
| 1243 | */ |
| 1244 | updateProgressBar(activity, percent) { |
| 1245 | this._progressLabel.textContent = activity; |
| 1246 | this._progressBar.style.width = percent.toFixed(1) + '%'; |
Chandani Shrestha | 20bddac | 2019-11-27 19:11:00 | [diff] [blame] | 1247 | UI.ARIAUtils.setValueNow(this._progressBar, percent); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1248 | this._updateTimer(); |
| 1249 | } |
| 1250 | |
Sigurd Schneider | 6eecdaa | 2019-08-20 07:47:10 | [diff] [blame] | 1251 | /** |
| 1252 | * @param {string} caption |
| 1253 | */ |
| 1254 | updateButton(caption) { |
| 1255 | this._stopButton.innerText = caption; |
| 1256 | } |
| 1257 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1258 | startTimer() { |
| 1259 | this._startTime = Date.now(); |
| 1260 | this._timeUpdateTimer = setInterval(this._updateTimer.bind(this, false), 1000); |
| 1261 | this._updateTimer(); |
| 1262 | } |
| 1263 | |
| 1264 | _stopTimer() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1265 | if (!this._timeUpdateTimer) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1266 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1267 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1268 | clearInterval(this._timeUpdateTimer); |
| 1269 | this._updateTimer(true); |
| 1270 | delete this._timeUpdateTimer; |
| 1271 | } |
| 1272 | |
| 1273 | /** |
| 1274 | * @param {boolean=} precise |
| 1275 | */ |
| 1276 | _updateTimer(precise) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1277 | if (!this._timeUpdateTimer) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1278 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1279 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1280 | const elapsed = (Date.now() - this._startTime) / 1000; |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 1281 | this._time.textContent = Common.UIString.UIString('%s\xa0sec', elapsed.toFixed(precise ? 1 : 0)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1282 | } |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1283 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1284 | |
| 1285 | |
| 1286 | /** |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 1287 | * @implements {Common.QueryParamHandler.QueryParamHandler} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1288 | * @unrestricted |
| 1289 | */ |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1290 | export class LoadTimelineHandler { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1291 | /** |
| 1292 | * @override |
| 1293 | * @param {string} value |
| 1294 | */ |
| 1295 | handleQueryParam(value) { |
Paul Lewis | 5099369 | 2020-01-23 15:22:26 | [diff] [blame] | 1296 | self.UI.viewManager.showView('timeline').then(() => { |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1297 | TimelinePanel.instance()._loadFromURL(window.decodeURIComponent(value)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1298 | }); |
| 1299 | } |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1300 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1301 | |
| 1302 | /** |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 1303 | * @implements {UI.ActionDelegate.ActionDelegate} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1304 | * @unrestricted |
| 1305 | */ |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1306 | export class ActionDelegate { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1307 | /** |
| 1308 | * @override |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 1309 | * @param {!UI.Context.Context} context |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1310 | * @param {string} actionId |
| 1311 | * @return {boolean} |
| 1312 | */ |
| 1313 | handleAction(context, actionId) { |
Paul Lewis | d990734 | 2020-01-24 13:49:47 | [diff] [blame] | 1314 | const panel = self.UI.context.flavor(TimelinePanel); |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1315 | console.assert(panel && panel instanceof TimelinePanel); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1316 | switch (actionId) { |
| 1317 | case 'timeline.toggle-recording': |
| 1318 | panel._toggleRecording(); |
| 1319 | return true; |
| 1320 | case 'timeline.record-reload': |
| 1321 | panel._recordReload(); |
| 1322 | return true; |
| 1323 | case 'timeline.save-to-file': |
| 1324 | panel._saveToFile(); |
| 1325 | return true; |
| 1326 | case 'timeline.load-from-file': |
| 1327 | panel._selectFileToLoad(); |
| 1328 | return true; |
| 1329 | case 'timeline.jump-to-previous-frame': |
| 1330 | panel._jumpToFrame(-1); |
| 1331 | return true; |
| 1332 | case 'timeline.jump-to-next-frame': |
| 1333 | panel._jumpToFrame(1); |
| 1334 | return true; |
| 1335 | case 'timeline.show-history': |
| 1336 | panel._showHistory(); |
| 1337 | return true; |
| 1338 | case 'timeline.previous-recording': |
| 1339 | panel._navigateHistory(1); |
| 1340 | return true; |
| 1341 | case 'timeline.next-recording': |
| 1342 | panel._navigateHistory(-1); |
| 1343 | return true; |
| 1344 | } |
| 1345 | return false; |
| 1346 | } |
Tim van der Lippe | 0176f6c | 2020-01-08 11:07:01 | [diff] [blame] | 1347 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1348 | |
Paul Lewis | 897ad8b | 2020-01-15 16:49:17 | [diff] [blame] | 1349 | export const traceProviderSettingSymbol = Symbol('traceProviderSetting'); |