Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Jan Scheffler | 77e3e68 | 2020-07-30 09:00:54 | [diff] [blame] | 5 | // @ts-nocheck |
| 6 | // TODO(crbug.com/1011811): Enable TypeScript compiler checks |
| 7 | |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 8 | import * as Common from '../common/common.js'; |
| 9 | import * as DataGrid from '../data_grid/data_grid.js'; |
| 10 | import * as SDK from '../sdk/sdk.js'; |
| 11 | import * as UI from '../ui/ui.js'; |
Paul Lewis | 7cbdcae | 2020-03-19 10:48:12 | [diff] [blame] | 12 | import * as Workspace from '../workspace/workspace.js'; |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 13 | |
Paul Lewis | 0d43b80 | 2020-01-14 13:34:23 | [diff] [blame] | 14 | import {SamplingHeapProfileNode} from './HeapProfileView.js'; // eslint-disable-line no-unused-vars |
| 15 | |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 16 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 17 | * @extends {UI.Widget.VBox} |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 18 | */ |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 19 | export class LiveHeapProfileView extends UI.Widget.VBox { |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 20 | constructor() { |
| 21 | super(true); |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 22 | /** @type {!Map<string, !GridNode>} */ |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 23 | this._gridNodeByUrl = new Map(); |
Jack Franklin | 71519f8 | 2020-11-03 12:08:59 | [diff] [blame^] | 24 | this.registerRequiredCSS('profiler/liveHeapProfile.css', {enableLegacyPatching: true}); |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 25 | |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame] | 26 | this._setting = Common.Settings.Settings.instance().moduleSetting('memoryLiveHeapProfile'); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 27 | const toolbar = new UI.Toolbar.Toolbar('live-heap-profile-toolbar', this.contentElement); |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 28 | |
| 29 | this._toggleRecordAction = |
Tim van der Lippe | 177c0b2 | 2020-08-19 14:56:02 | [diff] [blame] | 30 | /** @type {!UI.Action.Action }*/ ( |
| 31 | UI.ActionRegistry.ActionRegistry.instance().action('live-heap-profile.toggle-recording')); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 32 | this._toggleRecordButton = UI.Toolbar.Toolbar.createActionButton(this._toggleRecordAction); |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 33 | this._toggleRecordButton.setToggled(this._setting.get()); |
| 34 | toolbar.appendToolbarItem(this._toggleRecordButton); |
| 35 | |
Paul Lewis | daac106 | 2020-03-05 14:37:10 | [diff] [blame] | 36 | const mainTarget = SDK.SDKModel.TargetManager.instance().mainTarget(); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 37 | if (mainTarget && mainTarget.model(SDK.ResourceTreeModel.ResourceTreeModel)) { |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 38 | const startWithReloadAction = |
Tim van der Lippe | 177c0b2 | 2020-08-19 14:56:02 | [diff] [blame] | 39 | /** @type {!UI.Action.Action }*/ ( |
| 40 | UI.ActionRegistry.ActionRegistry.instance().action('live-heap-profile.start-with-reload')); |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 41 | this._startWithReloadButton = UI.Toolbar.Toolbar.createActionButton(startWithReloadAction); |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 42 | toolbar.appendToolbarItem(this._startWithReloadButton); |
| 43 | } |
| 44 | |
| 45 | this._dataGrid = this._createDataGrid(); |
| 46 | this._dataGrid.asWidget().show(this.contentElement); |
| 47 | |
| 48 | this._currentPollId = 0; |
| 49 | } |
| 50 | |
| 51 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 52 | * @return {!DataGrid.SortableDataGrid.SortableDataGrid} |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 53 | */ |
| 54 | _createDataGrid() { |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 55 | const columns = [ |
| 56 | { |
| 57 | id: 'size', |
| 58 | title: ls`JS Heap`, |
| 59 | width: '72px', |
| 60 | fixedWidth: true, |
| 61 | sortable: true, |
| 62 | align: DataGrid.DataGrid.Align.Right, |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 63 | sort: DataGrid.DataGrid.Order.Descending, |
| 64 | tooltip: ls`Allocated JS heap size currently in use`, |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 65 | }, |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 66 | { |
| 67 | id: 'isolates', |
| 68 | title: ls`VMs`, |
| 69 | width: '40px', |
| 70 | fixedWidth: true, |
| 71 | align: DataGrid.DataGrid.Align.Right, |
| 72 | tooltip: ls`Number of VMs sharing the same script source` |
| 73 | }, |
| 74 | {id: 'url', title: ls`Script URL`, fixedWidth: false, sortable: true, tooltip: ls`URL of the script source`} |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 75 | ]; |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 76 | const dataGrid = new DataGrid.SortableDataGrid.SortableDataGrid({displayName: ls`Heap Profile`, columns}); |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 77 | dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last); |
| 78 | dataGrid.element.classList.add('flex-auto'); |
| 79 | dataGrid.element.addEventListener('keydown', this._onKeyDown.bind(this), false); |
| 80 | dataGrid.addEventListener(DataGrid.DataGrid.Events.OpenedNode, this._revealSourceForSelectedNode, this); |
| 81 | dataGrid.addEventListener(DataGrid.DataGrid.Events.SortingChanged, this._sortingChanged, this); |
| 82 | for (const info of columns) { |
| 83 | const headerCell = dataGrid.headerTableHeader(info.id); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 84 | if (headerCell) { |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 85 | headerCell.setAttribute('title', info.tooltip); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 86 | } |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 87 | } |
| 88 | return dataGrid; |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
| 92 | * @override |
| 93 | */ |
| 94 | wasShown() { |
| 95 | this._poll(); |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 96 | this._setting.addChangeListener(this._settingChanged, this); |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @override |
| 101 | */ |
| 102 | willHide() { |
Alexei Filippov | 3f8ff4b | 2019-04-30 01:08:41 | [diff] [blame] | 103 | ++this._currentPollId; |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 104 | this._setting.removeChangeListener(this._settingChanged, this); |
| 105 | } |
| 106 | |
| 107 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 108 | * @param {!Common.EventTarget.EventTargetEvent} value |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 109 | */ |
| 110 | _settingChanged(value) { |
| 111 | this._toggleRecordButton.setToggled(/** @type {boolean} */ (value.data)); |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | async _poll() { |
Alexei Filippov | 3f8ff4b | 2019-04-30 01:08:41 | [diff] [blame] | 115 | const pollId = this._currentPollId; |
| 116 | do { |
Tim van der Lippe | d5de9a0 | 2020-09-03 12:55:49 | [diff] [blame] | 117 | const isolates = Array.from(SDK.IsolateManager.IsolateManager.instance().isolates()); |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 118 | const profiles = await Promise.all( |
| 119 | isolates.map(isolate => isolate.heapProfilerModel() && isolate.heapProfilerModel().getSamplingProfile())); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 120 | if (this._currentPollId !== pollId) { |
Alexei Filippov | 3f8ff4b | 2019-04-30 01:08:41 | [diff] [blame] | 121 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 122 | } |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 123 | this._update(isolates, profiles); |
Alexei Filippov | 3f8ff4b | 2019-04-30 01:08:41 | [diff] [blame] | 124 | await new Promise(r => setTimeout(r, 3000)); |
| 125 | } while (this._currentPollId === pollId); |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /** |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 129 | * @param {!Array<!SDK.IsolateManager.Isolate>} isolates |
| 130 | * @param {!Array<?Protocol.HeapProfiler.SamplingHeapProfile>} profiles |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 131 | */ |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 132 | _update(isolates, profiles) { |
| 133 | /** @type {!Map<string, !{size: number, isolates: !Set<!SDK.IsolateManager.Isolate>}>} */ |
| 134 | const dataByUrl = new Map(); |
| 135 | profiles.forEach((profile, index) => { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 136 | if (profile) { |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 137 | processNodeTree(isolates[index], '', profile.head); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 138 | } |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 139 | }); |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 140 | |
| 141 | const rootNode = this._dataGrid.rootNode(); |
| 142 | const exisitingNodes = new Set(); |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 143 | for (const pair of dataByUrl) { |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 144 | const url = /** @type {string} */ (pair[0]); |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 145 | const size = /** @type {number} */ (pair[1].size); |
| 146 | const isolateCount = /** @type {number} */ (pair[1].isolates.size); |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 147 | if (!url) { |
| 148 | console.info(`Node with empty URL: ${size} bytes`); // eslint-disable-line no-console |
| 149 | continue; |
| 150 | } |
| 151 | let node = this._gridNodeByUrl.get(url); |
| 152 | if (node) { |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 153 | node.updateNode(size, isolateCount); |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 154 | } else { |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 155 | node = new GridNode(url, size, isolateCount); |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 156 | this._gridNodeByUrl.set(url, node); |
| 157 | rootNode.appendChild(node); |
| 158 | } |
| 159 | exisitingNodes.add(node); |
| 160 | } |
| 161 | |
| 162 | for (const node of rootNode.children.slice()) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 163 | if (!exisitingNodes.has(node)) { |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 164 | node.remove(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 165 | } |
Andres Olivares | 03d9c75 | 2020-10-01 15:08:11 | [diff] [blame] | 166 | this._gridNodeByUrl.delete(node._url); |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | this._sortingChanged(); |
| 170 | |
| 171 | /** |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 172 | * @param {!SDK.IsolateManager.Isolate} isolate |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 173 | * @param {string} parentUrl |
| 174 | * @param {!Protocol.HeapProfiler.SamplingHeapProfileNode} node |
| 175 | */ |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 176 | function processNodeTree(isolate, parentUrl, node) { |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 177 | const url = node.callFrame.url || parentUrl || systemNodeName(node) || anonymousScriptName(node); |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 178 | node.children.forEach(processNodeTree.bind(null, isolate, url)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 179 | if (!node.selfSize) { |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 180 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 181 | } |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 182 | let data = dataByUrl.get(url); |
| 183 | if (!data) { |
| 184 | data = {size: 0, isolates: new Set()}; |
| 185 | dataByUrl.set(url, data); |
| 186 | } |
| 187 | data.size += node.selfSize; |
| 188 | data.isolates.add(isolate); |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /** |
| 192 | * @param {!Protocol.HeapProfiler.SamplingHeapProfileNode} node |
| 193 | * @return {string} |
| 194 | */ |
| 195 | function systemNodeName(node) { |
| 196 | const name = node.callFrame.functionName; |
| 197 | return name.startsWith('(') && name !== '(root)' ? name : ''; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * @param {!Protocol.HeapProfiler.SamplingHeapProfileNode} node |
| 202 | * @return {string} |
| 203 | */ |
| 204 | function anonymousScriptName(node) { |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 205 | return Number(node.callFrame.scriptId) ? |
| 206 | Common.UIString.UIString('(Anonymous Script %s)', node.callFrame.scriptId) : |
| 207 | ''; |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * @param {!Event} event |
| 213 | */ |
| 214 | _onKeyDown(event) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 215 | if (!isEnterKey(event)) { |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 216 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 217 | } |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 218 | event.consume(true); |
| 219 | this._revealSourceForSelectedNode(); |
| 220 | } |
| 221 | |
| 222 | _revealSourceForSelectedNode() { |
| 223 | const node = this._dataGrid.selectedNode; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 224 | if (!node || !node._url) { |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 225 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 226 | } |
Paul Lewis | 7cbdcae | 2020-03-19 10:48:12 | [diff] [blame] | 227 | const sourceCode = Workspace.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(node._url); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 228 | if (sourceCode) { |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 229 | Common.Revealer.reveal(sourceCode); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 230 | } |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | _sortingChanged() { |
| 234 | const columnId = this._dataGrid.sortColumnId(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 235 | if (!columnId) { |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 236 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 237 | } |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 238 | const sortByUrl = (a, b) => b._url.localeCompare(a._url); |
| 239 | const sortBySize = (a, b) => b._size - a._size; |
| 240 | const sortFunction = columnId === 'url' ? sortByUrl : sortBySize; |
| 241 | this._dataGrid.sortNodes(sortFunction, this._dataGrid.isSortOrderAscending()); |
| 242 | } |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 243 | |
| 244 | _toggleRecording() { |
| 245 | const enable = !this._setting.get(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 246 | if (enable) { |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 247 | this._startRecording(false); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 248 | } else { |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 249 | this._stopRecording(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 250 | } |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /** |
| 254 | * @param {boolean=} reload |
| 255 | */ |
| 256 | _startRecording(reload) { |
| 257 | this._setting.set(true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 258 | if (!reload) { |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 259 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 260 | } |
Paul Lewis | daac106 | 2020-03-05 14:37:10 | [diff] [blame] | 261 | const mainTarget = SDK.SDKModel.TargetManager.instance().mainTarget(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 262 | if (!mainTarget) { |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 263 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 264 | } |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 265 | const resourceTreeModel = /** @type {?SDK.ResourceTreeModel.ResourceTreeModel} */ ( |
| 266 | mainTarget.model(SDK.ResourceTreeModel.ResourceTreeModel)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 267 | if (resourceTreeModel) { |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 268 | resourceTreeModel.reloadPage(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 269 | } |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | async _stopRecording() { |
| 273 | this._setting.set(false); |
| 274 | } |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 275 | } |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 276 | |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 277 | export class GridNode extends DataGrid.SortableDataGrid.SortableDataGridNode { |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 278 | /** |
| 279 | * @param {string} url |
| 280 | * @param {number} size |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 281 | * @param {number} isolateCount |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 282 | */ |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 283 | constructor(url, size, isolateCount) { |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 284 | super(); |
| 285 | this._url = url; |
| 286 | this._size = size; |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 287 | this._isolateCount = isolateCount; |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /** |
| 291 | * @param {number} size |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 292 | * @param {number} isolateCount |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 293 | */ |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 294 | updateNode(size, isolateCount) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 295 | if (this._size === size && this._isolateCount === isolateCount) { |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 296 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 297 | } |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 298 | this._size = size; |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 299 | this._isolateCount = isolateCount; |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 300 | this.refresh(); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * @override |
| 305 | * @param {string} columnId |
Sigurd Schneider | 1165791 | 2020-06-30 13:26:52 | [diff] [blame] | 306 | * @return {!HTMLElement} |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 307 | */ |
| 308 | createCell(columnId) { |
| 309 | const cell = this.createTD(columnId); |
| 310 | switch (columnId) { |
| 311 | case 'url': |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 312 | cell.textContent = this._url; |
| 313 | break; |
| 314 | case 'size': |
| 315 | cell.textContent = Number.withThousandsSeparator(Math.round(this._size / 1e3)); |
Wolfgang Beyer | d451ecd | 2020-10-23 08:35:54 | [diff] [blame] | 316 | cell.createChild('span', 'size-units').textContent = ls`kB`; |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 317 | break; |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 318 | case 'isolates': |
Sigurd Schneider | 1165791 | 2020-06-30 13:26:52 | [diff] [blame] | 319 | cell.textContent = `${this._isolateCount}`; |
Alexei Filippov | 44a8836 | 2019-05-09 01:41:05 | [diff] [blame] | 320 | break; |
Alexei Filippov | 933306d | 2019-03-26 17:40:51 | [diff] [blame] | 321 | } |
| 322 | return cell; |
| 323 | } |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 324 | } |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 325 | |
| 326 | /** |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 327 | * @implements {UI.ActionDelegate.ActionDelegate} |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 328 | */ |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 329 | export class ActionDelegate { |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 330 | /** |
| 331 | * @override |
Tim van der Lippe | e54f66e | 2020-02-03 18:20:32 | [diff] [blame] | 332 | * @param {!UI.Context.Context} context |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 333 | * @param {string} actionId |
| 334 | * @return {boolean} |
| 335 | */ |
| 336 | handleAction(context, actionId) { |
| 337 | (async () => { |
| 338 | const profileViewId = 'live_heap_profile'; |
Paul Lewis | 75c7d0d | 2020-03-19 12:17:26 | [diff] [blame] | 339 | await UI.ViewManager.ViewManager.instance().showView(profileViewId); |
| 340 | const widget = await UI.ViewManager.ViewManager.instance().view(profileViewId).widget(); |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 341 | this._innerHandleAction(/** @type {!LiveHeapProfileView} */ (widget), actionId); |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 342 | })(); |
| 343 | return true; |
| 344 | } |
| 345 | |
| 346 | /** |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 347 | * @param {!LiveHeapProfileView} profilerView |
Alexei Filippov | fc6ad27 | 2019-06-10 18:51:55 | [diff] [blame] | 348 | * @param {string} actionId |
| 349 | */ |
| 350 | _innerHandleAction(profilerView, actionId) { |
| 351 | switch (actionId) { |
| 352 | case 'live-heap-profile.toggle-recording': |
| 353 | profilerView._toggleRecording(); |
| 354 | break; |
| 355 | case 'live-heap-profile.start-with-reload': |
| 356 | profilerView._startRecording(true); |
| 357 | break; |
| 358 | default: |
| 359 | console.assert(false, `Unknown action: ${actionId}`); |
| 360 | } |
| 361 | } |
Tim van der Lippe | 6288cf3 | 2020-01-07 16:58:40 | [diff] [blame] | 362 | } |