Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Alexei Filippov | 6d2eb59 | 2018-10-25 21:48:56 | [diff] [blame] | 4 | |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 5 | import * as Bindings from '../bindings/bindings.js'; |
| 6 | import * as Common from '../common/common.js'; |
| 7 | import * as Components from '../components/components.js'; |
| 8 | import * as DataGrid from '../data_grid/data_grid.js'; // eslint-disable-line no-unused-vars |
| 9 | import * as Host from '../host/host.js'; |
Tim van der Lippe | 8ef250c | 2020-02-20 16:29:25 | [diff] [blame] | 10 | import * as PerfUI from '../perf_ui/perf_ui.js'; |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 11 | import * as SDK from '../sdk/sdk.js'; // eslint-disable-line no-unused-vars |
| 12 | import * as UI from '../ui/ui.js'; |
| 13 | |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 14 | import {BottomUpProfileDataGridTree} from './BottomUpProfileDataGrid.js'; |
| 15 | import {CPUProfileFlameChart, ProfileFlameChartDataProvider} from './CPUProfileFlameChart.js'; // eslint-disable-line no-unused-vars |
| 16 | import {Formatter, ProfileDataGridNode, ProfileDataGridTree} from './ProfileDataGrid.js'; // eslint-disable-line no-unused-vars |
| 17 | import {DataDisplayDelegate, Events, ProfileHeader, ProfileType} from './ProfileHeader.js'; // eslint-disable-line no-unused-vars |
| 18 | import {ProfileSidebarTreeElement} from './ProfileSidebarTreeElement.js'; |
| 19 | import {TopDownProfileDataGridTree} from './TopDownProfileDataGrid.js'; |
| 20 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 21 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 22 | * @implements {UI.SearchableView.Searchable} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 23 | * @unrestricted |
| 24 | */ |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 25 | export class ProfileView extends UI.View.SimpleView { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 26 | constructor() { |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 27 | super(Common.UIString.UIString('Profile')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 28 | |
Alexei Filippov | 6d2eb59 | 2018-10-25 21:48:56 | [diff] [blame] | 29 | this._profile = null; |
| 30 | |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 31 | this._searchableView = new UI.SearchableView.SearchableView(this); |
| 32 | this._searchableView.setPlaceholder(Common.UIString.UIString('Find by cost (>50ms), name or file')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 33 | this._searchableView.show(this.element); |
| 34 | |
Tim van der Lippe | 9a9aba8 | 2020-02-14 14:52:29 | [diff] [blame] | 35 | const columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([]); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 36 | columns.push({ |
| 37 | id: 'self', |
| 38 | title: this.columnHeader('self'), |
| 39 | width: '120px', |
| 40 | fixedWidth: true, |
| 41 | sortable: true, |
| 42 | sort: DataGrid.DataGrid.Order.Descending |
| 43 | }); |
| 44 | columns.push({id: 'total', title: this.columnHeader('total'), width: '120px', fixedWidth: true, sortable: true}); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 45 | columns.push({id: 'function', title: Common.UIString.UIString('Function'), disclosure: true, sortable: true}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 46 | |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 47 | this.dataGrid = new DataGrid.DataGrid.DataGridImpl({displayName: ls`Profiler`, columns}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 48 | this.dataGrid.addEventListener(DataGrid.DataGrid.Events.SortingChanged, this._sortProfile, this); |
| 49 | this.dataGrid.addEventListener(DataGrid.DataGrid.Events.SelectedNode, this._nodeSelected.bind(this, true)); |
| 50 | this.dataGrid.addEventListener(DataGrid.DataGrid.Events.DeselectedNode, this._nodeSelected.bind(this, false)); |
Brandon Goddard | bfe54a6 | 2019-10-16 20:52:08 | [diff] [blame] | 51 | this.dataGrid.setRowContextMenuCallback(this._populateContextMenu.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 52 | |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 53 | this.viewSelectComboBox = new UI.Toolbar.ToolbarComboBox(this._changeView.bind(this), ls`Profile view mode`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 54 | |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 55 | this.focusButton = |
| 56 | new UI.Toolbar.ToolbarButton(Common.UIString.UIString('Focus selected function'), 'largeicon-visibility'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 57 | this.focusButton.setEnabled(false); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 58 | this.focusButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, this._focusClicked, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 59 | |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 60 | this.excludeButton = |
| 61 | new UI.Toolbar.ToolbarButton(Common.UIString.UIString('Exclude selected function'), 'largeicon-delete'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 62 | this.excludeButton.setEnabled(false); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 63 | this.excludeButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, this._excludeClicked, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 64 | |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 65 | this.resetButton = |
| 66 | new UI.Toolbar.ToolbarButton(Common.UIString.UIString('Restore all functions'), 'largeicon-refresh'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 67 | this.resetButton.setEnabled(false); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 68 | this.resetButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, this._resetClicked, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 69 | |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 70 | this._linkifier = new Components.Linkifier.Linkifier(maxLinkLength); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @param {!Array<!{title: string, value: string}>} entryInfo |
| 75 | * @return {!Element} |
| 76 | */ |
| 77 | static buildPopoverTable(entryInfo) { |
| 78 | const table = createElement('table'); |
| 79 | for (const entry of entryInfo) { |
| 80 | const row = table.createChild('tr'); |
| 81 | row.createChild('td').textContent = entry.title; |
| 82 | row.createChild('td').textContent = entry.value; |
| 83 | } |
| 84 | return table; |
| 85 | } |
| 86 | |
| 87 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 88 | * @param {!SDK.ProfileTreeModel.ProfileTreeModel} profile |
Alexei Filippov | 6d2eb59 | 2018-10-25 21:48:56 | [diff] [blame] | 89 | */ |
| 90 | setProfile(profile) { |
| 91 | this._profile = profile; |
| 92 | this._bottomUpProfileDataGridTree = null; |
| 93 | this._topDownProfileDataGridTree = null; |
| 94 | this._changeView(); |
| 95 | this.refresh(); |
| 96 | } |
| 97 | |
| 98 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 99 | * @return {?SDK.ProfileTreeModel.ProfileTreeModel} |
Alexei Filippov | 6d2eb59 | 2018-10-25 21:48:56 | [diff] [blame] | 100 | */ |
| 101 | profile() { |
| 102 | return this._profile; |
| 103 | } |
| 104 | |
| 105 | /** |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 106 | * @param {!Formatter} nodeFormatter |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 107 | * @param {!Array<string>=} viewTypes |
| 108 | * @protected |
| 109 | */ |
| 110 | initialize(nodeFormatter, viewTypes) { |
| 111 | this._nodeFormatter = nodeFormatter; |
| 112 | |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 113 | this._viewType = self.Common.settings.createSetting('profileView', ViewTypes.Heavy); |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 114 | viewTypes = viewTypes || [ViewTypes.Flame, ViewTypes.Heavy, ViewTypes.Tree]; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 115 | |
| 116 | const optionNames = new Map([ |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 117 | [ViewTypes.Flame, ls`Chart`], |
| 118 | [ViewTypes.Heavy, ls`Heavy (Bottom Up)`], |
| 119 | [ViewTypes.Tree, ls`Tree (Top Down)`], |
| 120 | [ViewTypes.Text, ls`Text (Top Down)`], |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 121 | ]); |
| 122 | |
| 123 | const options = |
Sigurd Schneider | 8a6ad9c | 2019-09-23 08:45:52 | [diff] [blame] | 124 | new Map(viewTypes.map(type => [type, this.viewSelectComboBox.createOption(optionNames.get(type), type)])); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 125 | const optionName = this._viewType.get() || viewTypes[0]; |
| 126 | const option = options.get(optionName) || options.get(viewTypes[0]); |
| 127 | this.viewSelectComboBox.select(option); |
| 128 | |
| 129 | this._changeView(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 130 | if (this._flameChart) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 131 | this._flameChart.update(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 132 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /** |
| 136 | * @override |
| 137 | */ |
| 138 | focus() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 139 | if (this._flameChart) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 140 | this._flameChart.focus(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 141 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 142 | super.focus(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 143 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /** |
| 147 | * @param {string} columnId |
| 148 | * @return {string} |
| 149 | */ |
| 150 | columnHeader(columnId) { |
| 151 | throw 'Not implemented'; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * @param {number} timeLeft |
| 156 | * @param {number} timeRight |
| 157 | */ |
| 158 | selectRange(timeLeft, timeRight) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 159 | if (!this._flameChart) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 160 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 161 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 162 | this._flameChart.selectRange(timeLeft, timeRight); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * @override |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 167 | * @return {!Promise<!Array<!UI.Toolbar.ToolbarItem>>} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 168 | */ |
Simon ZĂĽnd | 308c74f | 2020-01-16 06:53:37 | [diff] [blame] | 169 | async toolbarItems() { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 170 | return [this.viewSelectComboBox, this.focusButton, this.excludeButton, this.resetButton]; |
| 171 | } |
| 172 | |
| 173 | /** |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 174 | * @return {!ProfileDataGridTree} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 175 | */ |
| 176 | _getBottomUpProfileDataGridTree() { |
| 177 | if (!this._bottomUpProfileDataGridTree) { |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 178 | this._bottomUpProfileDataGridTree = new BottomUpProfileDataGridTree( |
Alexei Filippov | 6d2eb59 | 2018-10-25 21:48:56 | [diff] [blame] | 179 | this._nodeFormatter, this._searchableView, this._profile.root, this.adjustedTotal); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 180 | } |
| 181 | return this._bottomUpProfileDataGridTree; |
| 182 | } |
| 183 | |
| 184 | /** |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 185 | * @return {!ProfileDataGridTree} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 186 | */ |
| 187 | _getTopDownProfileDataGridTree() { |
| 188 | if (!this._topDownProfileDataGridTree) { |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 189 | this._topDownProfileDataGridTree = new TopDownProfileDataGridTree( |
Alexei Filippov | 6d2eb59 | 2018-10-25 21:48:56 | [diff] [blame] | 190 | this._nodeFormatter, this._searchableView, this._profile.root, this.adjustedTotal); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 191 | } |
| 192 | return this._topDownProfileDataGridTree; |
| 193 | } |
| 194 | |
| 195 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 196 | * @param {!UI.ContextMenu.ContextMenu} contextMenu |
| 197 | * @param {!DataGrid.DataGrid.DataGridNode} gridNode |
Brandon Goddard | bfe54a6 | 2019-10-16 20:52:08 | [diff] [blame] | 198 | */ |
| 199 | _populateContextMenu(contextMenu, gridNode) { |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 200 | const node = /** @type {!ProfileDataGridNode} */ (gridNode); |
Brandon Goddard | bfe54a6 | 2019-10-16 20:52:08 | [diff] [blame] | 201 | if (node.linkElement && !contextMenu.containsTarget(node.linkElement)) { |
| 202 | contextMenu.appendApplicableItems(node.linkElement); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 207 | * @override |
| 208 | */ |
| 209 | willHide() { |
| 210 | this._currentSearchResultIndex = -1; |
| 211 | } |
| 212 | |
| 213 | refresh() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 214 | if (!this.profileDataGridTree) { |
Alexei Filippov | 6d2eb59 | 2018-10-25 21:48:56 | [diff] [blame] | 215 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 216 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 217 | const selectedProfileNode = this.dataGrid.selectedNode ? this.dataGrid.selectedNode.profileNode : null; |
| 218 | |
| 219 | this.dataGrid.rootNode().removeChildren(); |
| 220 | |
| 221 | const children = this.profileDataGridTree.children; |
| 222 | const count = children.length; |
| 223 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 224 | for (let index = 0; index < count; ++index) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 225 | this.dataGrid.rootNode().appendChild(children[index]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 226 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 227 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 228 | if (selectedProfileNode) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 229 | selectedProfileNode.selected = true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 230 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | refreshVisibleData() { |
| 234 | let child = this.dataGrid.rootNode().children[0]; |
| 235 | while (child) { |
| 236 | child.refresh(); |
| 237 | child = child.traverseNextNode(false, null, true); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 242 | * @return {!UI.SearchableView.SearchableView} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 243 | */ |
| 244 | searchableView() { |
| 245 | return this._searchableView; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * @override |
| 250 | * @return {boolean} |
| 251 | */ |
| 252 | supportsCaseSensitiveSearch() { |
| 253 | return true; |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * @override |
| 258 | * @return {boolean} |
| 259 | */ |
| 260 | supportsRegexSearch() { |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * @override |
| 266 | */ |
| 267 | searchCanceled() { |
| 268 | this._searchableElement.searchCanceled(); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * @override |
| 273 | * @param {!UI.SearchableView.SearchConfig} searchConfig |
| 274 | * @param {boolean} shouldJump |
| 275 | * @param {boolean=} jumpBackwards |
| 276 | */ |
| 277 | performSearch(searchConfig, shouldJump, jumpBackwards) { |
| 278 | this._searchableElement.performSearch(searchConfig, shouldJump, jumpBackwards); |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * @override |
| 283 | */ |
| 284 | jumpToNextSearchResult() { |
| 285 | this._searchableElement.jumpToNextSearchResult(); |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * @override |
| 290 | */ |
| 291 | jumpToPreviousSearchResult() { |
| 292 | this._searchableElement.jumpToPreviousSearchResult(); |
| 293 | } |
| 294 | |
| 295 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 296 | * @return {!Components.Linkifier.Linkifier} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 297 | */ |
| 298 | linkifier() { |
| 299 | return this._linkifier; |
| 300 | } |
| 301 | |
Alexei Filippov | 8ad16d4 | 2018-07-10 00:17:48 | [diff] [blame] | 302 | _ensureTextViewCreated() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 303 | if (this._textView) { |
Alexei Filippov | 8ad16d4 | 2018-07-10 00:17:48 | [diff] [blame] | 304 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 305 | } |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 306 | this._textView = new UI.View.SimpleView(ls`Call tree`); |
Alexei Filippov | 8ad16d4 | 2018-07-10 00:17:48 | [diff] [blame] | 307 | this._textView.registerRequiredCSS('profiler/profilesPanel.css'); |
| 308 | this.populateTextView(this._textView); |
| 309 | } |
| 310 | |
| 311 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 312 | * @param {!UI.View.SimpleView} view |
Alexei Filippov | 8ad16d4 | 2018-07-10 00:17:48 | [diff] [blame] | 313 | */ |
| 314 | populateTextView(view) { |
| 315 | } |
| 316 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 317 | /** |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 318 | * @return {!ProfileFlameChartDataProvider} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 319 | */ |
| 320 | createFlameChartDataProvider() { |
| 321 | throw 'Not implemented'; |
| 322 | } |
| 323 | |
| 324 | _ensureFlameChartCreated() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 325 | if (this._flameChart) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 326 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 327 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 328 | this._dataProvider = this.createFlameChartDataProvider(); |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 329 | this._flameChart = new CPUProfileFlameChart(this._searchableView, this._dataProvider); |
Michael Liao | 712bbc2 | 2019-10-15 19:21:51 | [diff] [blame] | 330 | this._flameChart.addEventListener(PerfUI.FlameChart.Events.EntryInvoked, this._onEntryInvoked.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 334 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 335 | */ |
Simon ZĂĽnd | 3cb141b | 2020-02-26 13:29:41 | [diff] [blame] | 336 | async _onEntryInvoked(event) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 337 | const entryIndex = event.data; |
| 338 | const node = this._dataProvider._entryNodes[entryIndex]; |
| 339 | const debuggerModel = this._profileHeader._debuggerModel; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 340 | if (!node || !node.scriptId || !debuggerModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 341 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 342 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 343 | const script = debuggerModel.scriptForId(node.scriptId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 344 | if (!script) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 345 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 346 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 347 | const location = /** @type {!SDK.DebuggerModel.Location} */ ( |
| 348 | debuggerModel.createRawLocation(script, node.lineNumber, node.columnNumber)); |
Simon ZĂĽnd | 3cb141b | 2020-02-26 13:29:41 | [diff] [blame] | 349 | const uiLocation = await self.Bindings.DebuggerWorkspaceBinding.rawLocationToUILocation(location); |
| 350 | Common.Revealer.reveal(uiLocation); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | _changeView() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 354 | if (!this._profile) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 355 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 356 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 357 | |
| 358 | this._searchableView.closeSearch(); |
| 359 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 360 | if (this._visibleView) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 361 | this._visibleView.detach(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 362 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 363 | |
| 364 | this._viewType.set(this.viewSelectComboBox.selectedOption().value); |
| 365 | switch (this._viewType.get()) { |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 366 | case ViewTypes.Flame: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 367 | this._ensureFlameChartCreated(); |
| 368 | this._visibleView = this._flameChart; |
| 369 | this._searchableElement = this._flameChart; |
| 370 | break; |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 371 | case ViewTypes.Tree: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 372 | this.profileDataGridTree = this._getTopDownProfileDataGridTree(); |
| 373 | this._sortProfile(); |
| 374 | this._visibleView = this.dataGrid.asWidget(); |
| 375 | this._searchableElement = this.profileDataGridTree; |
| 376 | break; |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 377 | case ViewTypes.Heavy: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 378 | this.profileDataGridTree = this._getBottomUpProfileDataGridTree(); |
| 379 | this._sortProfile(); |
| 380 | this._visibleView = this.dataGrid.asWidget(); |
| 381 | this._searchableElement = this.profileDataGridTree; |
| 382 | break; |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 383 | case ViewTypes.Text: |
Alexei Filippov | 8ad16d4 | 2018-07-10 00:17:48 | [diff] [blame] | 384 | this._ensureTextViewCreated(); |
| 385 | this._visibleView = this._textView; |
| 386 | this._searchableElement = this._textView; |
| 387 | break; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 388 | } |
| 389 | |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 390 | const isFlame = this._viewType.get() === ViewTypes.Flame; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 391 | this.focusButton.setVisible(!isFlame); |
| 392 | this.excludeButton.setVisible(!isFlame); |
| 393 | this.resetButton.setVisible(!isFlame); |
| 394 | |
| 395 | this._visibleView.show(this._searchableView.element); |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * @param {boolean} selected |
| 400 | */ |
| 401 | _nodeSelected(selected) { |
| 402 | this.focusButton.setEnabled(selected); |
| 403 | this.excludeButton.setEnabled(selected); |
| 404 | } |
| 405 | |
| 406 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 407 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 408 | */ |
| 409 | _focusClicked(event) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 410 | if (!this.dataGrid.selectedNode) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 411 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 412 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 413 | |
| 414 | this.resetButton.setEnabled(true); |
Tony Ross | 88fd132 | 2020-02-21 16:46:41 | [diff] [blame] | 415 | this.resetButton.element.focus(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 416 | this.profileDataGridTree.focus(this.dataGrid.selectedNode); |
| 417 | this.refresh(); |
| 418 | this.refreshVisibleData(); |
| 419 | Host.userMetrics.actionTaken(Host.UserMetrics.Action.CpuProfileNodeFocused); |
| 420 | } |
| 421 | |
| 422 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 423 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 424 | */ |
| 425 | _excludeClicked(event) { |
| 426 | const selectedNode = this.dataGrid.selectedNode; |
| 427 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 428 | if (!selectedNode) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 429 | return; |
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 | |
Tony Ross | 88fd132 | 2020-02-21 16:46:41 | [diff] [blame] | 432 | this.resetButton.setEnabled(true); |
| 433 | this.resetButton.element.focus(); |
| 434 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 435 | selectedNode.deselect(); |
| 436 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 437 | this.profileDataGridTree.exclude(selectedNode); |
| 438 | this.refresh(); |
| 439 | this.refreshVisibleData(); |
| 440 | Host.userMetrics.actionTaken(Host.UserMetrics.Action.CpuProfileNodeExcluded); |
| 441 | } |
| 442 | |
| 443 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 444 | * @param {!Common.EventTarget.EventTargetEvent} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 445 | */ |
| 446 | _resetClicked(event) { |
Tony Ross | 88fd132 | 2020-02-21 16:46:41 | [diff] [blame] | 447 | this.viewSelectComboBox.selectElement().focus(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 448 | this.resetButton.setEnabled(false); |
| 449 | this.profileDataGridTree.restore(); |
| 450 | this._linkifier.reset(); |
| 451 | this.refresh(); |
| 452 | this.refreshVisibleData(); |
| 453 | } |
| 454 | |
| 455 | _sortProfile() { |
| 456 | const sortAscending = this.dataGrid.isSortOrderAscending(); |
| 457 | const sortColumnId = this.dataGrid.sortColumnId(); |
| 458 | const sortProperty = sortColumnId === 'function' ? 'functionName' : sortColumnId || ''; |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 459 | this.profileDataGridTree.sort(ProfileDataGridTree.propertyComparator(sortProperty, sortAscending)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 460 | |
| 461 | this.refresh(); |
| 462 | } |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 463 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 464 | |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 465 | export const maxLinkLength = 30; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 466 | |
| 467 | /** @enum {string} */ |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 468 | export const ViewTypes = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 469 | Flame: 'Flame', |
| 470 | Tree: 'Tree', |
Alexei Filippov | 8ad16d4 | 2018-07-10 00:17:48 | [diff] [blame] | 471 | Heavy: 'Heavy', |
| 472 | Text: 'Text' |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 473 | }; |
| 474 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 475 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 476 | * @implements {Common.StringOutputStream.OutputStream} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 477 | * @unrestricted |
| 478 | */ |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 479 | export class WritableProfileHeader extends ProfileHeader { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 480 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 481 | * @param {?SDK.DebuggerModel.DebuggerModel} debuggerModel |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 482 | * @param {!ProfileType} type |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 483 | * @param {string=} title |
| 484 | */ |
| 485 | constructor(debuggerModel, type, title) { |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 486 | super(type, title || Common.UIString.UIString('Profile %d', type.nextProfileUid())); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 487 | this._debuggerModel = debuggerModel; |
| 488 | this._tempFile = null; |
| 489 | } |
| 490 | |
| 491 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 492 | * @param {!Bindings.FileUtils.ChunkedReader} reader |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 493 | */ |
| 494 | _onChunkTransferred(reader) { |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 495 | this.updateStatus( |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame^] | 496 | Common.UIString.UIString('Loading… %d%%', Number.bytesToString(this._jsonifiedProfile.length))); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 500 | * @param {!Bindings.FileUtils.ChunkedReader} reader |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 501 | */ |
| 502 | _onError(reader) { |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame^] | 503 | this.updateStatus(Common.UIString.UIString('File \'%s\' read error: %s', reader.fileName(), reader.error().message)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /** |
| 507 | * @override |
| 508 | * @param {string} text |
| 509 | * @return {!Promise} |
| 510 | */ |
| 511 | async write(text) { |
| 512 | this._jsonifiedProfile += text; |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * @override |
| 517 | */ |
| 518 | close() { |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * @override |
| 523 | */ |
| 524 | dispose() { |
| 525 | this.removeTempFile(); |
| 526 | } |
| 527 | |
| 528 | /** |
| 529 | * @override |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 530 | * @param {!DataDisplayDelegate} panel |
| 531 | * @return {!ProfileSidebarTreeElement} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 532 | */ |
| 533 | createSidebarTreeElement(panel) { |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 534 | return new ProfileSidebarTreeElement(panel, this, 'profile-sidebar-tree-item'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | /** |
| 538 | * @override |
| 539 | * @return {boolean} |
| 540 | */ |
| 541 | canSaveToFile() { |
| 542 | return !this.fromFile() && this._protocolProfile; |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * @override |
| 547 | */ |
| 548 | async saveToFile() { |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 549 | const fileOutputStream = new Bindings.FileUtils.FileOutputStream(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 550 | this._fileName = this._fileName || |
| 551 | `${this.profileType().typeName()}-${new Date().toISO8601Compact()}${this.profileType().fileExtension()}`; |
| 552 | const accepted = await fileOutputStream.open(this._fileName); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 553 | if (!accepted || !this._tempFile) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 554 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 555 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 556 | const data = await this._tempFile.read(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 557 | if (data) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 558 | await fileOutputStream.write(data); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 559 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 560 | fileOutputStream.close(); |
| 561 | } |
| 562 | |
| 563 | /** |
| 564 | * @override |
| 565 | * @param {!File} file |
| 566 | * @return {!Promise<?Error>} |
| 567 | */ |
| 568 | async loadFromFile(file) { |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame^] | 569 | this.updateStatus(Common.UIString.UIString('Loading…'), true); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 570 | const fileReader = new Bindings.FileUtils.ChunkedFileReader(file, 10000000, this._onChunkTransferred.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 571 | this._jsonifiedProfile = ''; |
| 572 | |
| 573 | const success = await fileReader.read(this); |
| 574 | if (!success) { |
| 575 | this._onError(fileReader); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 576 | return new Error(Common.UIString.UIString('Failed to read file')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 577 | } |
| 578 | |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame^] | 579 | this.updateStatus(Common.UIString.UIString('Parsing…'), true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 580 | let error = null; |
| 581 | try { |
| 582 | this._profile = /** @type {!Protocol.Profiler.Profile} */ (JSON.parse(this._jsonifiedProfile)); |
| 583 | this.setProfile(this._profile); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 584 | this.updateStatus(Common.UIString.UIString('Loaded'), false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 585 | } catch (e) { |
| 586 | error = e; |
| 587 | this.profileType().removeProfile(this); |
| 588 | } |
| 589 | this._jsonifiedProfile = null; |
| 590 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 591 | if (this.profileType().profileBeingRecorded() === this) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 592 | this.profileType().setProfileBeingRecorded(null); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 593 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 594 | return error; |
| 595 | } |
| 596 | |
| 597 | /** |
| 598 | * @param {!Protocol.Profiler.Profile} profile |
| 599 | */ |
| 600 | setProtocolProfile(profile) { |
| 601 | this.setProfile(profile); |
| 602 | this._protocolProfile = profile; |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 603 | this._tempFile = new Bindings.TempFile.TempFile(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 604 | this._tempFile.write([JSON.stringify(profile)]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 605 | if (this.canSaveToFile()) { |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 606 | this.dispatchEventToListeners(Events.ProfileReceived); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 607 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 608 | } |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 609 | } |