blob: 88a4a582d99e7f530a865f843b678883bc9905e9 [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
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 Scheffler77e3e682020-07-30 09:00:5431// @ts-nocheck
32// TODO(crbug.com/1011811): Enable TypeScript compiler checks
33
Tim van der Lippee54f66e2020-02-03 18:20:3234import * as Common from '../common/common.js';
35import * as UI from '../ui/ui.js';
36
Paul Lewis0d43b802020-01-14 13:34:2337import {IsolateSelector} from './IsolateSelector.js';
38import {ProfileType} from './ProfileHeader.js'; // eslint-disable-line no-unused-vars
39
Blink Reformat4c46d092018-04-07 15:32:3740/**
41 * @unrestricted
42 */
Tim van der Lippee54f66e2020-02-03 18:20:3243export class ProfileLauncherView extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3744 /**
Tim van der Lippee54f66e2020-02-03 18:20:3245 * @param {!UI.Panel.PanelWithSidebar} profilesPanel
Blink Reformat4c46d092018-04-07 15:32:3746 */
47 constructor(profilesPanel) {
48 super();
Jack Franklin71519f82020-11-03 12:08:5949 this.registerRequiredCSS('profiler/profileLauncherView.css', {enableLegacyPatching: true});
Alexei Filippov2de5d1b2019-05-02 00:03:4850
Blink Reformat4c46d092018-04-07 15:32:3751 this._panel = profilesPanel;
52 this.element.classList.add('profile-launcher-view');
Alexei Filippov472a1712019-05-04 00:59:5753 this._contentElement = this.element.createChild('div', 'profile-launcher-view-content vbox');
Blink Reformat4c46d092018-04-07 15:32:3754
Alexei Filippov472a1712019-05-04 00:59:5755 const profileTypeSelectorElement = this._contentElement.createChild('div', 'vbox');
Paul Lewis2d7d65c2020-03-16 17:26:3056 this._selectedProfileTypeSetting = Common.Settings.Settings.instance().createSetting('selectedProfileType', 'CPU');
Alexei Filippov472a1712019-05-04 00:59:5757 this._profileTypeHeaderElement = profileTypeSelectorElement.createChild('h1');
58 this._profileTypeSelectorForm = profileTypeSelectorElement.createChild('form');
Junyi Xiao363065c2019-06-25 05:10:5159 UI.ARIAUtils.markAsRadioGroup(this._profileTypeSelectorForm);
Alexei Filippov472a1712019-05-04 00:59:5760
61 const isolateSelectorElement = this._contentElement.createChild('div', 'vbox profile-isolate-selector-block');
62 isolateSelectorElement.createChild('h1').textContent = ls`Select JavaScript VM instance`;
Paul Lewis0d43b802020-01-14 13:34:2363 const isolateSelector = new IsolateSelector();
Alexei Filippov472a1712019-05-04 00:59:5764 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 Lippee54f66e2020-02-03 18:20:3268 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 Filippov472a1712019-05-04 00:59:5771 buttonsDiv.appendChild(this._controlButton);
72 buttonsDiv.appendChild(this._loadButton);
73 this._recordButtonEnabled = true;
74
Paul Lewis3cc17a82020-10-16 10:25:2375 /** @type {!Map<string, !HTMLInputElement>} */
Blink Reformat4c46d092018-04-07 15:32:3776 this._typeIdToOptionElement = new Map();
77 }
78
79 _loadButtonClicked() {
80 this._panel.showLoadFromFileDialog();
81 }
82
83 _updateControls() {
Tim van der Lippe1d6e57a2019-09-30 11:55:3484 if (this._isEnabled && this._recordButtonEnabled) {
Blink Reformat4c46d092018-04-07 15:32:3785 this._controlButton.removeAttribute('disabled');
Tim van der Lippe1d6e57a2019-09-30 11:55:3486 } else {
Blink Reformat4c46d092018-04-07 15:32:3787 this._controlButton.setAttribute('disabled', '');
Tim van der Lippe1d6e57a2019-09-30 11:55:3488 }
Tim van der Lippee54f66e2020-02-03 18:20:3289 this._controlButton.title = this._recordButtonEnabled ? '' : UI.UIUtils.anotherProfilerActiveLabel();
Blink Reformat4c46d092018-04-07 15:32:3790 if (this._isInstantProfile) {
91 this._controlButton.classList.remove('running');
92 this._controlButton.classList.add('primary-button');
Tim van der Lippee54f66e2020-02-03 18:20:3293 this._controlButton.textContent = Common.UIString.UIString('Take snapshot');
Blink Reformat4c46d092018-04-07 15:32:3794 } else if (this._isProfiling) {
95 this._controlButton.classList.add('running');
96 this._controlButton.classList.remove('primary-button');
Tim van der Lippee54f66e2020-02-03 18:20:3297 this._controlButton.textContent = Common.UIString.UIString('Stop');
Blink Reformat4c46d092018-04-07 15:32:3798 } else {
99 this._controlButton.classList.remove('running');
100 this._controlButton.classList.add('primary-button');
Tim van der Lippee54f66e2020-02-03 18:20:32101 this._controlButton.textContent = Common.UIString.UIString('Start');
Blink Reformat4c46d092018-04-07 15:32:37102 }
Tim van der Lippe1d6e57a2019-09-30 11:55:34103 for (const item of this._typeIdToOptionElement.values()) {
Blink Reformat4c46d092018-04-07 15:32:37104 item.disabled = !!this._isProfiling;
Tim van der Lippe1d6e57a2019-09-30 11:55:34105 }
Blink Reformat4c46d092018-04-07 15:32:37106 }
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 Lewis0d43b802020-01-14 13:34:23119 * @param {!ProfileType} profileType
Blink Reformat4c46d092018-04-07 15:32:37120 * @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 Lewis0d43b802020-01-14 13:34:23130 * @param {!ProfileType} profileType
Blink Reformat4c46d092018-04-07 15:32:37131 */
132 addProfileType(profileType) {
Tim van der Lippee54f66e2020-02-03 18:20:32133 const labelElement = UI.UIUtils.createRadioLabel('profile-type', profileType.name);
Blink Reformat4c46d092018-04-07 15:32:37134 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 Einbindereaef6162019-07-15 17:42:55142 UI.ARIAUtils.setDescription(optionElement, profileType.description);
Blink Reformat4c46d092018-04-07 15:32:37143 const customContent = profileType.customContent();
Junyi Xiao363065c2019-06-25 05:10:51144 if (customContent) {
Blink Reformat4c46d092018-04-07 15:32:37145 this._profileTypeSelectorForm.createChild('p').appendChild(customContent);
Junyi Xiao363065c2019-06-25 05:10:51146 profileType.setCustomContentEnabled(false);
147 }
Joel Einbindereaef6162019-07-15 17:42:55148 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 Reformat4c46d092018-04-07 15:32:37151 }
152
153 restoreSelectedProfileType() {
154 let typeId = this._selectedProfileTypeSetting.get();
Junyi Xiao363065c2019-06-25 05:10:51155 if (!this._typeIdToOptionElement.has(typeId)) {
Blink Reformat4c46d092018-04-07 15:32:37156 typeId = this._typeIdToOptionElement.keys().next().value;
Junyi Xiao363065c2019-06-25 05:10:51157 this._selectedProfileTypeSetting.set(typeId);
158 }
Blink Reformat4c46d092018-04-07 15:32:37159 this._typeIdToOptionElement.get(typeId).checked = true;
160 const type = this._typeIdToOptionElement.get(typeId)._profileType;
Junyi Xiao363065c2019-06-25 05:10:51161 for (const [id, element] of this._typeIdToOptionElement) {
162 const enabled = (id === typeId);
163 element._profileType.setCustomContentEnabled(enabled);
164 }
Tim van der Lippe6288cf32020-01-07 16:58:40165 this.dispatchEventToListeners(Events.ProfileTypeSelected, type);
Blink Reformat4c46d092018-04-07 15:32:37166 }
167
168 _controlButtonClicked() {
169 this._panel.toggleRecord();
170 }
171
172 /**
Paul Lewis0d43b802020-01-14 13:34:23173 * @param {!ProfileType} profileType
Blink Reformat4c46d092018-04-07 15:32:37174 */
175 _profileTypeChanged(profileType) {
Junyi Xiao363065c2019-06-25 05:10:51176 const typeId = this._selectedProfileTypeSetting.get();
177 const type = this._typeIdToOptionElement.get(typeId)._profileType;
178 type.setCustomContentEnabled(false);
179 profileType.setCustomContentEnabled(true);
Tim van der Lippe6288cf32020-01-07 16:58:40180 this.dispatchEventToListeners(Events.ProfileTypeSelected, profileType);
Blink Reformat4c46d092018-04-07 15:32:37181 this._isInstantProfile = profileType.isInstantProfile();
182 this._isEnabled = profileType.isEnabled();
183 this._updateControls();
184 this._selectedProfileTypeSetting.set(profileType.id);
185 }
Tim van der Lippe6288cf32020-01-07 16:58:40186}
Blink Reformat4c46d092018-04-07 15:32:37187
188/** @enum {symbol} */
Tim van der Lippe6288cf32020-01-07 16:58:40189export const Events = {
Blink Reformat4c46d092018-04-07 15:32:37190 ProfileTypeSelected: Symbol('ProfileTypeSelected')
191};