| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 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 | |
| 5 /** | |
| 6 * @fileoverview Heap profiler panel implementation. | |
| 7 */ | |
| 8 | |
| 9 WebInspector.ProfilesPanel.prototype.addSnapshot = function(snapshot) { | |
| 10 snapshot.title = WebInspector.UIString("Snapshot %d", snapshot.number); | |
| 11 | |
| 12 var snapshots = WebInspector.HeapSnapshotProfileType.snapshots; | |
| 13 snapshots.push(snapshot); | |
| 14 | |
| 15 snapshot.listIndex = snapshots.length - 1; | |
| 16 | |
| 17 this.addProfileHeader(WebInspector.HeapSnapshotProfileType.TypeId, snapshot)
; | |
| 18 | |
| 19 this.dispatchEventToListeners("snapshot added"); | |
| 20 } | |
| 21 | |
| 22 | |
| 23 WebInspector.HeapSnapshotView = function(parent, profile) | |
| 24 { | |
| 25 WebInspector.View.call(this); | |
| 26 | |
| 27 this.element.addStyleClass("heap-snapshot-view"); | |
| 28 | |
| 29 this.parent = parent; | |
| 30 this.parent.addEventListener("snapshot added", this._updateBaseOptions, this
); | |
| 31 | |
| 32 this.showCountAsPercent = true; | |
| 33 this.showSizeAsPercent = true; | |
| 34 this.showCountDeltaAsPercent = true; | |
| 35 this.showSizeDeltaAsPercent = true; | |
| 36 | |
| 37 this.summaryBar = new WebInspector.SummaryBar(this.categories); | |
| 38 this.summaryBar.element.id = "heap-snapshot-summary"; | |
| 39 this.summaryBar.calculator = new WebInspector.HeapSummaryCalculator(profile.
used); | |
| 40 this.element.appendChild(this.summaryBar.element); | |
| 41 | |
| 42 var columns = { "cons": { title: WebInspector.UIString("Constructor"), discl
osure: true, sortable: true }, | |
| 43 "count": { title: WebInspector.UIString("Count"), width: "54
px", sortable: true }, | |
| 44 "size": { title: WebInspector.UIString("Size"), width: "72px
", sort: "descending", sortable: true }, | |
| 45 "countDelta": { title: WebInspector.UIString("\xb1 Count"),
width: "72px", sortable: true }, | |
| 46 "sizeDelta": { title: WebInspector.UIString("\xb1 Size"), wi
dth: "72px", sortable: true } }; | |
| 47 | |
| 48 this.dataGrid = new WebInspector.DataGrid(columns); | |
| 49 this.dataGrid.addEventListener("sorting changed", this._sortData, this); | |
| 50 this.dataGrid.element.addEventListener("mousedown", this._mouseDownInDataGri
d.bind(this), true); | |
| 51 this.element.appendChild(this.dataGrid.element); | |
| 52 | |
| 53 this.profile = profile; | |
| 54 | |
| 55 this.baseSelectElement = document.createElement("select"); | |
| 56 this.baseSelectElement.className = "status-bar-item"; | |
| 57 this.baseSelectElement.addEventListener("change", this._changeBase.bind(this
), false); | |
| 58 this._updateBaseOptions(); | |
| 59 if (this.profile.listIndex > 0) | |
| 60 this.baseSelectElement.selectedIndex = this.profile.listIndex - 1; | |
| 61 else | |
| 62 this.baseSelectElement.selectedIndex = this.profile.listIndex; | |
| 63 this._resetDataGridList(); | |
| 64 | |
| 65 this.percentButton = new WebInspector.StatusBarButton("", "percent-time-stat
us-bar-item status-bar-item"); | |
| 66 this.percentButton.addEventListener("click", this._percentClicked.bind(this)
, false); | |
| 67 | |
| 68 this.refresh(); | |
| 69 | |
| 70 this._updatePercentButton(); | |
| 71 }; | |
| 72 | |
| 73 WebInspector.HeapSnapshotView.prototype = { | |
| 74 | |
| 75 get categories() | |
| 76 { | |
| 77 return {code: {title: WebInspector.UIString("Code"), color: {r: 255, g:
121, b: 0}}, data: {title: WebInspector.UIString("Objects and Data"), color: {r:
47, g: 102, b: 236}}, other: {title: WebInspector.UIString("Other"), color: {r:
186, g: 186, b: 186}}}; | |
| 78 }, | |
| 79 | |
| 80 get statusBarItems() | |
| 81 { | |
| 82 return [this.baseSelectElement, this.percentButton.element]; | |
| 83 }, | |
| 84 | |
| 85 get profile() | |
| 86 { | |
| 87 return this._profile; | |
| 88 }, | |
| 89 | |
| 90 set profile(profile) | |
| 91 { | |
| 92 this._profile = profile; | |
| 93 }, | |
| 94 | |
| 95 show: function(parentElement) | |
| 96 { | |
| 97 WebInspector.View.prototype.show.call(this, parentElement); | |
| 98 this.dataGrid.updateWidths(); | |
| 99 }, | |
| 100 | |
| 101 resize: function() | |
| 102 { | |
| 103 if (this.dataGrid) | |
| 104 this.dataGrid.updateWidths(); | |
| 105 }, | |
| 106 | |
| 107 refresh: function() | |
| 108 { | |
| 109 this.dataGrid.removeChildren(); | |
| 110 | |
| 111 var children = this.snapshotDataGridList.children; | |
| 112 var count = children.length; | |
| 113 for (var index = 0; index < count; ++index) | |
| 114 this.dataGrid.appendChild(children[index]); | |
| 115 | |
| 116 this._updateSummaryGraph(); | |
| 117 }, | |
| 118 | |
| 119 refreshShowAsPercents: function() | |
| 120 { | |
| 121 this._updatePercentButton(); | |
| 122 this.refreshVisibleData(); | |
| 123 }, | |
| 124 | |
| 125 refreshVisibleData: function() | |
| 126 { | |
| 127 var child = this.dataGrid.children[0]; | |
| 128 while (child) { | |
| 129 child.refresh(); | |
| 130 child = child.traverseNextNode(false, null, true); | |
| 131 } | |
| 132 this._updateSummaryGraph(); | |
| 133 }, | |
| 134 | |
| 135 _changeBase: function() { | |
| 136 if (this.baseSnapshot === WebInspector.HeapSnapshotProfileType.snapshots
[this.baseSelectElement.selectedIndex]) | |
| 137 return; | |
| 138 | |
| 139 this._resetDataGridList(); | |
| 140 this.refresh(); | |
| 141 }, | |
| 142 | |
| 143 _createSnapshotDataGridList: function() | |
| 144 { | |
| 145 if (this._snapshotDataGridList) | |
| 146 delete this._snapshotDataGridList; | |
| 147 | |
| 148 this._snapshotDataGridList = new WebInspector.HeapSnapshotDataGridList(t
his, this.baseSnapshot.entries, this.profile.entries); | |
| 149 return this._snapshotDataGridList; | |
| 150 }, | |
| 151 | |
| 152 _mouseDownInDataGrid: function(event) | |
| 153 { | |
| 154 if (event.detail < 2) | |
| 155 return; | |
| 156 | |
| 157 var cell = event.target.enclosingNodeOrSelfWithNodeName("td"); | |
| 158 if (!cell || (!cell.hasStyleClass("count-column") && !cell.hasStyleClass
("size-column") && !cell.hasStyleClass("countDelta-column") && !cell.hasStyleCla
ss("sizeDelta-column"))) | |
| 159 return; | |
| 160 | |
| 161 if (cell.hasStyleClass("count-column")) | |
| 162 this.showCountAsPercent = !this.showCountAsPercent; | |
| 163 else if (cell.hasStyleClass("size-column")) | |
| 164 this.showSizeAsPercent = !this.showSizeAsPercent; | |
| 165 else if (cell.hasStyleClass("countDelta-column")) | |
| 166 this.showCountDeltaAsPercent = !this.showCountDeltaAsPercent; | |
| 167 else if (cell.hasStyleClass("sizeDelta-column")) | |
| 168 this.showSizeDeltaAsPercent = !this.showSizeDeltaAsPercent; | |
| 169 | |
| 170 this.refreshShowAsPercents(); | |
| 171 | |
| 172 event.preventDefault(); | |
| 173 event.stopPropagation(); | |
| 174 }, | |
| 175 | |
| 176 get _isShowingAsPercent() | |
| 177 { | |
| 178 return this.showCountAsPercent && this.showSizeAsPercent && this.showCou
ntDeltaAsPercent && this.showSizeDeltaAsPercent; | |
| 179 }, | |
| 180 | |
| 181 _percentClicked: function(event) | |
| 182 { | |
| 183 var currentState = this._isShowingAsPercent; | |
| 184 this.showCountAsPercent = !currentState; | |
| 185 this.showSizeAsPercent = !currentState; | |
| 186 this.showCountDeltaAsPercent = !currentState; | |
| 187 this.showSizeDeltaAsPercent = !currentState; | |
| 188 this.refreshShowAsPercents(); | |
| 189 }, | |
| 190 | |
| 191 _resetDataGridList: function() | |
| 192 { | |
| 193 this.baseSnapshot = WebInspector.HeapSnapshotProfileType.snapshots[this.
baseSelectElement.selectedIndex]; | |
| 194 var lastComparator = WebInspector.HeapSnapshotDataGridList.propertyCompa
rator("size", false); | |
| 195 if (this.snapshotDataGridList) { | |
| 196 lastComparator = this.snapshotDataGridList.lastComparator; | |
| 197 } | |
| 198 this.snapshotDataGridList = this._createSnapshotDataGridList(); | |
| 199 this.snapshotDataGridList.sort(lastComparator, true); | |
| 200 }, | |
| 201 | |
| 202 _sortData: function() | |
| 203 { | |
| 204 var sortAscending = this.dataGrid.sortOrder === "ascending"; | |
| 205 var sortColumnIdentifier = this.dataGrid.sortColumnIdentifier; | |
| 206 var sortProperty = { | |
| 207 "cons": "constructorName", | |
| 208 "count": "count", | |
| 209 "size": "size", | |
| 210 "countDelta": this.showCountDeltaAsPercent ? "countDeltaPercent"
: "countDelta", | |
| 211 "sizeDelta": this.showSizeDeltaAsPercent ? "sizeDeltaPercent" :
"sizeDelta" | |
| 212 }[sortColumnIdentifier]; | |
| 213 | |
| 214 this.snapshotDataGridList.sort(WebInspector.HeapSnapshotDataGridList.pro
pertyComparator(sortProperty, sortAscending)); | |
| 215 | |
| 216 this.refresh(); | |
| 217 }, | |
| 218 | |
| 219 _updateBaseOptions: function() | |
| 220 { | |
| 221 var list = WebInspector.HeapSnapshotProfileType.snapshots; | |
| 222 // We're assuming that snapshots can only be added. | |
| 223 if (this.baseSelectElement.length == list.length) | |
| 224 return; | |
| 225 | |
| 226 for (var i = this.baseSelectElement.length, n = list.length; i < n; ++i)
{ | |
| 227 var baseOption = document.createElement("option"); | |
| 228 baseOption.label = WebInspector.UIString("Compared to %s", list[i].t
itle); | |
| 229 this.baseSelectElement.appendChild(baseOption); | |
| 230 } | |
| 231 }, | |
| 232 | |
| 233 _updatePercentButton: function() | |
| 234 { | |
| 235 if (this._isShowingAsPercent) { | |
| 236 this.percentButton.title = WebInspector.UIString("Show absolute coun
ts and sizes."); | |
| 237 this.percentButton.toggled = true; | |
| 238 } else { | |
| 239 this.percentButton.title = WebInspector.UIString("Show counts and si
zes as percentages."); | |
| 240 this.percentButton.toggled = false; | |
| 241 } | |
| 242 }, | |
| 243 | |
| 244 _updateSummaryGraph: function() | |
| 245 { | |
| 246 this.summaryBar.calculator.showAsPercent = this._isShowingAsPercent; | |
| 247 this.summaryBar.update(this.profile.lowlevels); | |
| 248 } | |
| 249 }; | |
| 250 | |
| 251 WebInspector.HeapSnapshotView.prototype.__proto__ = WebInspector.View.prototype; | |
| 252 | |
| 253 WebInspector.HeapSummaryCalculator = function(total) | |
| 254 { | |
| 255 this.total = total; | |
| 256 } | |
| 257 | |
| 258 WebInspector.HeapSummaryCalculator.prototype = { | |
| 259 computeSummaryValues: function(lowLevels) | |
| 260 { | |
| 261 function highFromLow(type) { | |
| 262 if (type == "CODE_TYPE" || type == "SHARED_FUNCTION_INFO_TYPE" || ty
pe == "SCRIPT_TYPE") return "code"; | |
| 263 if (type == "STRING_TYPE" || type == "HEAP_NUMBER_TYPE" || type.matc
h(/^JS_/) || type.match(/_ARRAY_TYPE$/)) return "data"; | |
| 264 return "other"; | |
| 265 } | |
| 266 var highLevels = {data: 0, code: 0, other: 0}; | |
| 267 for (var item in lowLevels) { | |
| 268 var highItem = highFromLow(item); | |
| 269 highLevels[highItem] += lowLevels[item].size; | |
| 270 } | |
| 271 return {categoryValues: highLevels}; | |
| 272 }, | |
| 273 | |
| 274 formatValue: function(value) | |
| 275 { | |
| 276 if (this.showAsPercent) | |
| 277 return WebInspector.UIString("%.2f%%", value / this.total * 100.0); | |
| 278 else | |
| 279 return Number.bytesToString(value); | |
| 280 }, | |
| 281 | |
| 282 get showAsPercent() | |
| 283 { | |
| 284 return this._showAsPercent; | |
| 285 }, | |
| 286 | |
| 287 set showAsPercent(x) | |
| 288 { | |
| 289 this._showAsPercent = x; | |
| 290 } | |
| 291 } | |
| 292 | |
| 293 WebInspector.HeapSnapshotSidebarTreeElement = function(snapshot) | |
| 294 { | |
| 295 this.profile = snapshot; | |
| 296 | |
| 297 WebInspector.SidebarTreeElement.call(this, "heap-snapshot-sidebar-tree-item"
, "", "", snapshot, false); | |
| 298 | |
| 299 this.refreshTitles(); | |
| 300 }; | |
| 301 | |
| 302 WebInspector.HeapSnapshotSidebarTreeElement.prototype = { | |
| 303 get mainTitle() | |
| 304 { | |
| 305 if (this._mainTitle) | |
| 306 return this._mainTitle; | |
| 307 return this.profile.title; | |
| 308 }, | |
| 309 | |
| 310 set mainTitle(x) | |
| 311 { | |
| 312 this._mainTitle = x; | |
| 313 this.refreshTitles(); | |
| 314 }, | |
| 315 | |
| 316 get subtitle() | |
| 317 { | |
| 318 if (this._subTitle) | |
| 319 return this._subTitle; | |
| 320 return WebInspector.UIString("Used %s of %s (%.0f%%)", Number.bytesToStr
ing(this.profile.used, null, false), Number.bytesToString(this.profile.capacity,
null, false), this.profile.used / this.profile.capacity * 100.0); | |
| 321 }, | |
| 322 | |
| 323 set subtitle(x) | |
| 324 { | |
| 325 this._subTitle = x; | |
| 326 this.refreshTitles(); | |
| 327 } | |
| 328 }; | |
| 329 | |
| 330 WebInspector.HeapSnapshotSidebarTreeElement.prototype.__proto__ = WebInspector.P
rofileSidebarTreeElement.prototype; | |
| 331 | |
| 332 WebInspector.HeapSnapshotDataGridNodeWithRetainers = function(owningTree) | |
| 333 { | |
| 334 this.tree = owningTree; | |
| 335 | |
| 336 WebInspector.DataGridNode.call(this, null, this._hasRetainers); | |
| 337 | |
| 338 this.addEventListener("populate", this._populate, this); | |
| 339 }; | |
| 340 | |
| 341 WebInspector.HeapSnapshotDataGridNodeWithRetainers.prototype = { | |
| 342 isEmptySet: function(set) | |
| 343 { | |
| 344 for (var x in set) | |
| 345 return false; | |
| 346 return true; | |
| 347 }, | |
| 348 | |
| 349 get _hasRetainers() | |
| 350 { | |
| 351 return !this.isEmptySet(this.retainers); | |
| 352 }, | |
| 353 | |
| 354 get _parent() | |
| 355 { | |
| 356 // For top-level nodes, return owning tree as a parent, not data grid. | |
| 357 return this.parent !== this.dataGrid ? this.parent : this.tree; | |
| 358 }, | |
| 359 | |
| 360 _populate: function(event) | |
| 361 { | |
| 362 var self = this; | |
| 363 this.produceDiff(this.baseRetainers, this.retainers, function(baseItem,
snapshotItem) { | |
| 364 self.appendChild(new WebInspector.HeapSnapshotDataGridRetainerNode(s
elf.snapshotView, baseItem, snapshotItem, self.tree)); | |
| 365 }); | |
| 366 | |
| 367 if (this._parent) { | |
| 368 var currentComparator = this._parent.lastComparator; | |
| 369 if (currentComparator) | |
| 370 this.sort(currentComparator, true); | |
| 371 } | |
| 372 | |
| 373 this.removeEventListener("populate", this._populate, this); | |
| 374 }, | |
| 375 | |
| 376 produceDiff: function(baseEntries, currentEntries, callback) | |
| 377 { | |
| 378 for (var item in currentEntries) | |
| 379 callback(baseEntries[item], currentEntries[item]); | |
| 380 | |
| 381 for (item in baseEntries) { | |
| 382 if (!(item in currentEntries)) | |
| 383 callback(baseEntries[item], null); | |
| 384 } | |
| 385 }, | |
| 386 | |
| 387 sort: function(comparator, force) { | |
| 388 if (!force && this.lastComparator === comparator) | |
| 389 return; | |
| 390 | |
| 391 this.children.sort(comparator); | |
| 392 var childCount = this.children.length; | |
| 393 for (var childIndex = 0; childIndex < childCount; ++childIndex) | |
| 394 this.children[childIndex]._recalculateSiblings(childIndex); | |
| 395 for (var i = 0; i < this.children.length; ++i) { | |
| 396 var child = this.children[i]; | |
| 397 if (!force && (!child.expanded || child.lastComparator === comparato
r)) | |
| 398 continue; | |
| 399 child.sort(comparator, force); | |
| 400 } | |
| 401 this.lastComparator = comparator; | |
| 402 }, | |
| 403 | |
| 404 signForDelta: function(delta) { | |
| 405 if (delta == 0) | |
| 406 return ""; | |
| 407 if (delta > 0) | |
| 408 return "+"; | |
| 409 else | |
| 410 // Math minus sign, same width as plus. | |
| 411 return "\u2212"; | |
| 412 }, | |
| 413 | |
| 414 showDeltaAsPercent: function(value) { | |
| 415 if (value === Number.POSITIVE_INFINITY) | |
| 416 return WebInspector.UIString("new"); | |
| 417 else if (value === Number.NEGATIVE_INFINITY) | |
| 418 return WebInspector.UIString("deleted"); | |
| 419 if (value > 1000.0) | |
| 420 return WebInspector.UIString("%s >1000%%", this.signForDelta(value))
; | |
| 421 return WebInspector.UIString("%s%.2f%%", this.signForDelta(value), Math.
abs(value)); | |
| 422 }, | |
| 423 | |
| 424 getTotalCount: function() { | |
| 425 if (!this._count) { | |
| 426 this._count = 0; | |
| 427 for (var i = 0, n = this.children.length; i < n; ++i) { | |
| 428 this._count += this.children[i].count; | |
| 429 } | |
| 430 } | |
| 431 return this._count; | |
| 432 }, | |
| 433 | |
| 434 getTotalSize: function() { | |
| 435 if (!this._size) { | |
| 436 this._size = 0; | |
| 437 for (var i = 0, n = this.children.length; i < n; ++i) { | |
| 438 this._size += this.children[i].size; | |
| 439 } | |
| 440 } | |
| 441 return this._size; | |
| 442 }, | |
| 443 | |
| 444 get countPercent() | |
| 445 { | |
| 446 return this.count / this._parent.getTotalCount() * 100.0; | |
| 447 }, | |
| 448 | |
| 449 get sizePercent() | |
| 450 { | |
| 451 return this.size / this._parent.getTotalSize() * 100.0; | |
| 452 }, | |
| 453 | |
| 454 get countDeltaPercent() | |
| 455 { | |
| 456 if (this.baseCount > 0) { | |
| 457 if (this.count > 0) | |
| 458 return this.countDelta / this.baseCount * 100.0; | |
| 459 else | |
| 460 return Number.NEGATIVE_INFINITY; | |
| 461 } else | |
| 462 return Number.POSITIVE_INFINITY; | |
| 463 }, | |
| 464 | |
| 465 get sizeDeltaPercent() | |
| 466 { | |
| 467 if (this.baseSize > 0) { | |
| 468 if (this.size > 0) | |
| 469 return this.sizeDelta / this.baseSize * 100.0; | |
| 470 else | |
| 471 return Number.NEGATIVE_INFINITY; | |
| 472 } else | |
| 473 return Number.POSITIVE_INFINITY; | |
| 474 }, | |
| 475 | |
| 476 getData: function(showSize) | |
| 477 { | |
| 478 var data = {}; | |
| 479 | |
| 480 data["cons"] = this.constructorName; | |
| 481 | |
| 482 if (this.snapshotView.showCountAsPercent) | |
| 483 data["count"] = WebInspector.UIString("%.2f%%", this.countPercent); | |
| 484 else | |
| 485 data["count"] = this.count; | |
| 486 | |
| 487 if (showSize) { | |
| 488 if (this.snapshotView.showSizeAsPercent) | |
| 489 data["size"] = WebInspector.UIString("%.2f%%", this.sizePercent)
; | |
| 490 else | |
| 491 data["size"] = Number.bytesToString(this.size); | |
| 492 } else { | |
| 493 data["size"] = ""; | |
| 494 } | |
| 495 | |
| 496 if (this.snapshotView.showCountDeltaAsPercent) | |
| 497 data["countDelta"] = this.showDeltaAsPercent(this.countDeltaPercent)
; | |
| 498 else | |
| 499 data["countDelta"] = WebInspector.UIString("%s%d", this.signForDelta
(this.countDelta), Math.abs(this.countDelta)); | |
| 500 | |
| 501 if (showSize) { | |
| 502 if (this.snapshotView.showSizeDeltaAsPercent) | |
| 503 data["sizeDelta"] = this.showDeltaAsPercent(this.sizeDeltaPercen
t); | |
| 504 else | |
| 505 data["sizeDelta"] = WebInspector.UIString("%s%s", this.signForDe
lta(this.sizeDelta), Number.bytesToString(Math.abs(this.sizeDelta))); | |
| 506 } else { | |
| 507 data["sizeDelta"] = ""; | |
| 508 } | |
| 509 | |
| 510 return data; | |
| 511 } | |
| 512 }; | |
| 513 | |
| 514 WebInspector.HeapSnapshotDataGridNodeWithRetainers.prototype.__proto__ = WebInsp
ector.DataGridNode.prototype; | |
| 515 | |
| 516 WebInspector.HeapSnapshotDataGridNode = function(snapshotView, baseEntry, snapsh
otEntry, owningTree) | |
| 517 { | |
| 518 this.snapshotView = snapshotView; | |
| 519 | |
| 520 if (!snapshotEntry) | |
| 521 snapshotEntry = { cons: baseEntry.cons, count: 0, size: 0, retainers: {}
}; | |
| 522 this.constructorName = snapshotEntry.cons; | |
| 523 this.count = snapshotEntry.count; | |
| 524 this.size = snapshotEntry.size; | |
| 525 this.retainers = snapshotEntry.retainers; | |
| 526 | |
| 527 if (!baseEntry) | |
| 528 baseEntry = { count: 0, size: 0, retainers: {} }; | |
| 529 this.baseCount = baseEntry.count; | |
| 530 this.countDelta = this.count - this.baseCount; | |
| 531 this.baseSize = baseEntry.size; | |
| 532 this.sizeDelta = this.size - this.baseSize; | |
| 533 this.baseRetainers = baseEntry.retainers; | |
| 534 | |
| 535 WebInspector.HeapSnapshotDataGridNodeWithRetainers.call(this, owningTree); | |
| 536 }; | |
| 537 | |
| 538 WebInspector.HeapSnapshotDataGridNode.prototype = { | |
| 539 get data() | |
| 540 { | |
| 541 return this.getData(true); | |
| 542 } | |
| 543 }; | |
| 544 | |
| 545 WebInspector.HeapSnapshotDataGridNode.prototype.__proto__ = WebInspector.HeapSna
pshotDataGridNodeWithRetainers.prototype; | |
| 546 | |
| 547 WebInspector.HeapSnapshotDataGridList = function(snapshotView, baseEntries, snap
shotEntries) | |
| 548 { | |
| 549 this.tree = this; | |
| 550 this.snapshotView = snapshotView; | |
| 551 this.children = []; | |
| 552 this.lastComparator = null; | |
| 553 this.populateChildren(baseEntries, snapshotEntries); | |
| 554 }; | |
| 555 | |
| 556 WebInspector.HeapSnapshotDataGridList.prototype = { | |
| 557 appendChild: function(child) | |
| 558 { | |
| 559 this.insertChild(child, this.children.length); | |
| 560 }, | |
| 561 | |
| 562 insertChild: function(child, index) | |
| 563 { | |
| 564 this.children.splice(index, 0, child); | |
| 565 }, | |
| 566 | |
| 567 removeChildren: function() | |
| 568 { | |
| 569 this.children = []; | |
| 570 }, | |
| 571 | |
| 572 populateChildren: function(baseEntries, snapshotEntries) | |
| 573 { | |
| 574 var self = this; | |
| 575 this.produceDiff(baseEntries, snapshotEntries, function(baseItem, snapsh
otItem) { | |
| 576 self.appendChild(new WebInspector.HeapSnapshotDataGridNode(self.snap
shotView, baseItem, snapshotItem, self)); | |
| 577 }); | |
| 578 }, | |
| 579 | |
| 580 produceDiff: WebInspector.HeapSnapshotDataGridNodeWithRetainers.prototype.pr
oduceDiff, | |
| 581 sort: WebInspector.HeapSnapshotDataGridNodeWithRetainers.prototype.sort, | |
| 582 getTotalCount: WebInspector.HeapSnapshotDataGridNodeWithRetainers.prototype.
getTotalCount, | |
| 583 getTotalSize: WebInspector.HeapSnapshotDataGridNodeWithRetainers.prototype.g
etTotalSize | |
| 584 }; | |
| 585 | |
| 586 WebInspector.HeapSnapshotDataGridList.propertyComparators = [{}, {}]; | |
| 587 | |
| 588 WebInspector.HeapSnapshotDataGridList.propertyComparator = function(property, is
Ascending) | |
| 589 { | |
| 590 var comparator = this.propertyComparators[(isAscending ? 1 : 0)][property]; | |
| 591 if (!comparator) { | |
| 592 comparator = function(lhs, rhs) { | |
| 593 var l = lhs[property], r = rhs[property]; | |
| 594 var result = l < r ? -1 : (l > r ? 1 : 0); | |
| 595 return isAscending ? result : -result; | |
| 596 }; | |
| 597 this.propertyComparators[(isAscending ? 1 : 0)][property] = comparator; | |
| 598 } | |
| 599 return comparator; | |
| 600 }; | |
| 601 | |
| 602 WebInspector.HeapSnapshotDataGridRetainerNode = function(snapshotView, baseEntry
, snapshotEntry, owningTree) | |
| 603 { | |
| 604 this.snapshotView = snapshotView; | |
| 605 | |
| 606 if (!snapshotEntry) | |
| 607 snapshotEntry = { cons: baseEntry.cons, count: 0, clusters: {} }; | |
| 608 this.constructorName = snapshotEntry.cons; | |
| 609 this.count = snapshotEntry.count; | |
| 610 this.retainers = this._calculateRetainers(this.snapshotView.profile, snapsho
tEntry.clusters); | |
| 611 | |
| 612 if (!baseEntry) | |
| 613 baseEntry = { count: 0, clusters: {} }; | |
| 614 this.baseCount = baseEntry.count; | |
| 615 this.countDelta = this.count - this.baseCount; | |
| 616 this.baseRetainers = this._calculateRetainers(this.snapshotView.baseSnapshot
, baseEntry.clusters); | |
| 617 | |
| 618 this.size = this.count; // This way, when sorting by sizes entries will be
sorted by references count. | |
| 619 | |
| 620 WebInspector.HeapSnapshotDataGridNodeWithRetainers.call(this, owningTree); | |
| 621 } | |
| 622 | |
| 623 WebInspector.HeapSnapshotDataGridRetainerNode.prototype = { | |
| 624 get data() | |
| 625 { | |
| 626 return this.getData(false); | |
| 627 }, | |
| 628 | |
| 629 _calculateRetainers: function(snapshot, clusters) { | |
| 630 var retainers = {}; | |
| 631 if (this.isEmptySet(clusters)) { | |
| 632 if (this.constructorName in snapshot.entries) | |
| 633 return snapshot.entries[this.constructorName].retainers; | |
| 634 } else { | |
| 635 // In case when an entry is retained by clusters, we need to gather
up the list | |
| 636 // of retainers by merging retainers of every cluster. | |
| 637 // E.g. having such a tree: | |
| 638 // A | |
| 639 // Object:1 10 | |
| 640 // X 3 | |
| 641 // Y 4 | |
| 642 // Object:2 5 | |
| 643 // X 6 | |
| 644 // | |
| 645 // will result in a following retainers list: X 9, Y 4. | |
| 646 for (var clusterName in clusters) { | |
| 647 if (clusterName in snapshot.clusters) { | |
| 648 var clusterRetainers = snapshot.clusters[clusterName].retain
ers; | |
| 649 for (var clusterRetainer in clusterRetainers) { | |
| 650 var clusterRetainerEntry = clusterRetainers[clusterRetai
ner]; | |
| 651 if (!(clusterRetainer in retainers)) | |
| 652 retainers[clusterRetainer] = { cons: clusterRetainer
Entry.cons, count: 0, clusters: {} }; | |
| 653 retainers[clusterRetainer].count += clusterRetainerEntry
.count; | |
| 654 for (var clusterRetainerCluster in clusterRetainerEntry.
clusters) | |
| 655 retainers[clusterRetainer].clusters[clusterRetainerC
luster] = true; | |
| 656 } | |
| 657 } | |
| 658 } | |
| 659 } | |
| 660 return retainers; | |
| 661 } | |
| 662 }; | |
| 663 | |
| 664 WebInspector.HeapSnapshotDataGridRetainerNode.prototype.__proto__ = WebInspector
.HeapSnapshotDataGridNodeWithRetainers.prototype; | |
| 665 | |
| 666 | |
| 667 WebInspector.HeapSnapshotProfileType = function() | |
| 668 { | |
| 669 WebInspector.ProfileType.call(this, WebInspector.HeapSnapshotProfileType.Typ
eId, WebInspector.UIString("HEAP SNAPSHOTS")); | |
| 670 } | |
| 671 | |
| 672 WebInspector.HeapSnapshotProfileType.TypeId = "HEAP"; | |
| 673 | |
| 674 WebInspector.HeapSnapshotProfileType.snapshots = []; | |
| 675 | |
| 676 WebInspector.HeapSnapshotProfileType.prototype = { | |
| 677 get buttonTooltip() | |
| 678 { | |
| 679 return WebInspector.UIString("Take heap snapshot."); | |
| 680 }, | |
| 681 | |
| 682 get buttonStyle() | |
| 683 { | |
| 684 return "heap-snapshot-status-bar-item status-bar-item"; | |
| 685 }, | |
| 686 | |
| 687 buttonClicked: function() | |
| 688 { | |
| 689 InspectorController.takeHeapSnapshot(); | |
| 690 }, | |
| 691 | |
| 692 createSidebarTreeElementForProfile: function(profile) | |
| 693 { | |
| 694 var element = new WebInspector.HeapSnapshotSidebarTreeElement(profile); | |
| 695 element.small = false; | |
| 696 return element; | |
| 697 }, | |
| 698 | |
| 699 createView: function(profile) | |
| 700 { | |
| 701 return new WebInspector.HeapSnapshotView(WebInspector.panels.profiles, p
rofile); | |
| 702 } | |
| 703 } | |
| 704 | |
| 705 WebInspector.HeapSnapshotProfileType.prototype.__proto__ = WebInspector.ProfileT
ype.prototype; | |
| 706 | |
| 707 | |
| 708 (function() { | |
| 709 var originalCreatePanels = WebInspector._createPanels; | |
| 710 WebInspector._createPanels = function() { | |
| 711 originalCreatePanels.apply(this, arguments); | |
| 712 if (WebInspector.panels.profiles) | |
| 713 WebInspector.panels.profiles.registerProfileType(new WebInspector.He
apSnapshotProfileType()); | |
| 714 } | |
| 715 })(); | |
| OLD | NEW |