Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following disclaimer |
| 12 | * in the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * * Neither the name of Google Inc. nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived from |
| 16 | * this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Jan Scheffler | 77e3e68 | 2020-07-30 09:00:54 | [diff] [blame] | 31 | // @ts-nocheck |
| 32 | // TODO(crbug.com/1011811): Enable TypeScript compiler checks |
| 33 | |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 34 | import * as Common from '../common/common.js'; |
| 35 | import * as UI from '../ui/ui.js'; |
| 36 | |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 37 | import {IsolateSelector} from './IsolateSelector.js'; |
| 38 | import {ProfileType} from './ProfileHeader.js'; // eslint-disable-line no-unused-vars |
| 39 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 40 | /** |
| 41 | * @unrestricted |
| 42 | */ |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 43 | export class ProfileLauncherView extends UI.Widget.VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 44 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 45 | * @param {!UI.Panel.PanelWithSidebar} profilesPanel |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 46 | */ |
| 47 | constructor(profilesPanel) { |
| 48 | super(); |
Jack Franklin | 71519f8 | 2020-11-03 12:08:59 | [diff] [blame^] | 49 | this.registerRequiredCSS('profiler/profileLauncherView.css', {enableLegacyPatching: true}); |
Alexei Filippov | 2de5d1b | 2019-05-02 00:03:48 | [diff] [blame] | 50 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 51 | this._panel = profilesPanel; |
| 52 | this.element.classList.add('profile-launcher-view'); |
Alexei Filippov | 472a171 | 2019-05-04 00:59:57 | [diff] [blame] | 53 | this._contentElement = this.element.createChild('div', 'profile-launcher-view-content vbox'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 54 | |
Alexei Filippov | 472a171 | 2019-05-04 00:59:57 | [diff] [blame] | 55 | const profileTypeSelectorElement = this._contentElement.createChild('div', 'vbox'); |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame] | 56 | this._selectedProfileTypeSetting = Common.Settings.Settings.instance().createSetting('selectedProfileType', 'CPU'); |
Alexei Filippov | 472a171 | 2019-05-04 00:59:57 | [diff] [blame] | 57 | this._profileTypeHeaderElement = profileTypeSelectorElement.createChild('h1'); |
| 58 | this._profileTypeSelectorForm = profileTypeSelectorElement.createChild('form'); |
Junyi Xiao | 363065c | 2019-06-25 05:10:51 | [diff] [blame] | 59 | UI.ARIAUtils.markAsRadioGroup(this._profileTypeSelectorForm); |
Alexei Filippov | 472a171 | 2019-05-04 00:59:57 | [diff] [blame] | 60 | |
| 61 | const isolateSelectorElement = this._contentElement.createChild('div', 'vbox profile-isolate-selector-block'); |
| 62 | isolateSelectorElement.createChild('h1').textContent = ls`Select JavaScript VM instance`; |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 63 | const isolateSelector = new IsolateSelector(); |
Alexei Filippov | 472a171 | 2019-05-04 00:59:57 | [diff] [blame] | 64 | isolateSelector.show(isolateSelectorElement.createChild('div', 'vbox profile-launcher-target-list')); |
| 65 | isolateSelectorElement.appendChild(isolateSelector.totalMemoryElement()); |
| 66 | |
| 67 | const buttonsDiv = this._contentElement.createChild('div', 'hbox profile-launcher-buttons'); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 68 | this._controlButton = |
| 69 | UI.UIUtils.createTextButton('', this._controlButtonClicked.bind(this), '', /* primary */ true); |
| 70 | this._loadButton = UI.UIUtils.createTextButton(ls`Load`, this._loadButtonClicked.bind(this), ''); |
Alexei Filippov | 472a171 | 2019-05-04 00:59:57 | [diff] [blame] | 71 | buttonsDiv.appendChild(this._controlButton); |
| 72 | buttonsDiv.appendChild(this._loadButton); |
| 73 | this._recordButtonEnabled = true; |
| 74 | |
Paul Lewis | 3cc17a8 | 2020-10-16 10:25:23 | [diff] [blame] | 75 | /** @type {!Map<string, !HTMLInputElement>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 76 | this._typeIdToOptionElement = new Map(); |
| 77 | } |
| 78 | |
| 79 | _loadButtonClicked() { |
| 80 | this._panel.showLoadFromFileDialog(); |
| 81 | } |
| 82 | |
| 83 | _updateControls() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 84 | if (this._isEnabled && this._recordButtonEnabled) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 85 | this._controlButton.removeAttribute('disabled'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 86 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 87 | this._controlButton.setAttribute('disabled', ''); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 88 | } |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 89 | this._controlButton.title = this._recordButtonEnabled ? '' : UI.UIUtils.anotherProfilerActiveLabel(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 90 | if (this._isInstantProfile) { |
| 91 | this._controlButton.classList.remove('running'); |
| 92 | this._controlButton.classList.add('primary-button'); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 93 | this._controlButton.textContent = Common.UIString.UIString('Take snapshot'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 94 | } else if (this._isProfiling) { |
| 95 | this._controlButton.classList.add('running'); |
| 96 | this._controlButton.classList.remove('primary-button'); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 97 | this._controlButton.textContent = Common.UIString.UIString('Stop'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 98 | } else { |
| 99 | this._controlButton.classList.remove('running'); |
| 100 | this._controlButton.classList.add('primary-button'); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 101 | this._controlButton.textContent = Common.UIString.UIString('Start'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 102 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 103 | for (const item of this._typeIdToOptionElement.values()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 104 | item.disabled = !!this._isProfiling; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 105 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | profileStarted() { |
| 109 | this._isProfiling = true; |
| 110 | this._updateControls(); |
| 111 | } |
| 112 | |
| 113 | profileFinished() { |
| 114 | this._isProfiling = false; |
| 115 | this._updateControls(); |
| 116 | } |
| 117 | |
| 118 | /** |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 119 | * @param {!ProfileType} profileType |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 120 | * @param {boolean} recordButtonEnabled |
| 121 | */ |
| 122 | updateProfileType(profileType, recordButtonEnabled) { |
| 123 | this._isInstantProfile = profileType.isInstantProfile(); |
| 124 | this._recordButtonEnabled = recordButtonEnabled; |
| 125 | this._isEnabled = profileType.isEnabled(); |
| 126 | this._updateControls(); |
| 127 | } |
| 128 | |
| 129 | /** |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 130 | * @param {!ProfileType} profileType |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 131 | */ |
| 132 | addProfileType(profileType) { |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 133 | const labelElement = UI.UIUtils.createRadioLabel('profile-type', profileType.name); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 134 | this._profileTypeSelectorForm.appendChild(labelElement); |
| 135 | const optionElement = labelElement.radioElement; |
| 136 | this._typeIdToOptionElement.set(profileType.id, optionElement); |
| 137 | optionElement._profileType = profileType; |
| 138 | optionElement.style.hidden = true; |
| 139 | optionElement.addEventListener('change', this._profileTypeChanged.bind(this, profileType), false); |
| 140 | const descriptionElement = this._profileTypeSelectorForm.createChild('p'); |
| 141 | descriptionElement.textContent = profileType.description; |
Joel Einbinder | eaef616 | 2019-07-15 17:42:55 | [diff] [blame] | 142 | UI.ARIAUtils.setDescription(optionElement, profileType.description); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 143 | const customContent = profileType.customContent(); |
Junyi Xiao | 363065c | 2019-06-25 05:10:51 | [diff] [blame] | 144 | if (customContent) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 145 | this._profileTypeSelectorForm.createChild('p').appendChild(customContent); |
Junyi Xiao | 363065c | 2019-06-25 05:10:51 | [diff] [blame] | 146 | profileType.setCustomContentEnabled(false); |
| 147 | } |
Joel Einbinder | eaef616 | 2019-07-15 17:42:55 | [diff] [blame] | 148 | const headerText = this._typeIdToOptionElement.size > 1 ? ls`Select profiling type` : profileType.name; |
| 149 | this._profileTypeHeaderElement.textContent = headerText; |
| 150 | UI.ARIAUtils.setAccessibleName(this._profileTypeSelectorForm, headerText); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | restoreSelectedProfileType() { |
| 154 | let typeId = this._selectedProfileTypeSetting.get(); |
Junyi Xiao | 363065c | 2019-06-25 05:10:51 | [diff] [blame] | 155 | if (!this._typeIdToOptionElement.has(typeId)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 156 | typeId = this._typeIdToOptionElement.keys().next().value; |
Junyi Xiao | 363065c | 2019-06-25 05:10:51 | [diff] [blame] | 157 | this._selectedProfileTypeSetting.set(typeId); |
| 158 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 159 | this._typeIdToOptionElement.get(typeId).checked = true; |
| 160 | const type = this._typeIdToOptionElement.get(typeId)._profileType; |
Junyi Xiao | 363065c | 2019-06-25 05:10:51 | [diff] [blame] | 161 | for (const [id, element] of this._typeIdToOptionElement) { |
| 162 | const enabled = (id === typeId); |
| 163 | element._profileType.setCustomContentEnabled(enabled); |
| 164 | } |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 165 | this.dispatchEventToListeners(Events.ProfileTypeSelected, type); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | _controlButtonClicked() { |
| 169 | this._panel.toggleRecord(); |
| 170 | } |
| 171 | |
| 172 | /** |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 173 | * @param {!ProfileType} profileType |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 174 | */ |
| 175 | _profileTypeChanged(profileType) { |
Junyi Xiao | 363065c | 2019-06-25 05:10:51 | [diff] [blame] | 176 | const typeId = this._selectedProfileTypeSetting.get(); |
| 177 | const type = this._typeIdToOptionElement.get(typeId)._profileType; |
| 178 | type.setCustomContentEnabled(false); |
| 179 | profileType.setCustomContentEnabled(true); |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 180 | this.dispatchEventToListeners(Events.ProfileTypeSelected, profileType); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 181 | this._isInstantProfile = profileType.isInstantProfile(); |
| 182 | this._isEnabled = profileType.isEnabled(); |
| 183 | this._updateControls(); |
| 184 | this._selectedProfileTypeSetting.set(profileType.id); |
| 185 | } |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 186 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 187 | |
| 188 | /** @enum {symbol} */ |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 189 | export const Events = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 190 | ProfileTypeSelected: Symbol('ProfileTypeSelected') |
| 191 | }; |