Changeset 145357 in webkit
- Timestamp:
- Mar 11, 2013 5:43:10 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r145354 r145357 1 2013-03-11 Yury Semikhatsky <yurys@chromium.org> 2 3 Web Inspector: extract common parts of native profiles 4 https://bugs.webkit.org/show_bug.cgi?id=111965 5 6 Reviewed by Alexander Pavlov. 7 8 Extracted common parts of native profiles into NativeProfileTypeBase. Memory 9 domain dispatcher is now a separate class as it is shared by two native memory 10 profile types. 11 12 Both native memory profile types now capture native heap graph. 13 14 * inspector/front-end/NativeMemorySnapshotView.js: 15 (WebInspector.MemoryAgentDispatcher.instance): 16 (WebInspector.NativeProfileTypeBase.prototype.buttonClicked.didReceiveMemorySnapshot): 17 (WebInspector.NativeProfileTypeBase.prototype.buttonClicked): 18 (WebInspector.NativeSnapshotProfileType): 19 (WebInspector.NativeSnapshotProfileHeader.prototype._didReceiveMemorySnapshot): 20 (WebInspector.NativeMemoryProfileType): 21 (WebInspector.NativeMemoryProfileHeader.prototype._updateSnapshotStatus): 22 (WebInspector.NativeMemoryProfileHeader.prototype._didReceiveMemorySnapshot): 23 1 24 2013-03-11 Sheriff Bot <webkit.review.bot@gmail.com> 2 25 -
trunk/Source/WebCore/inspector/front-end/NativeMemorySnapshotView.js
r145074 r145357 233 233 } 234 234 235 236 /** 237 * @constructor 238 * @implements {MemoryAgent.Dispatcher} 239 */ 240 WebInspector.MemoryAgentDispatcher = function() 241 { 242 InspectorBackend.registerMemoryDispatcher(this); 243 this._currentProfileHeader = null; 244 } 245 246 WebInspector.MemoryAgentDispatcher.instance = function() 247 { 248 if (!WebInspector.MemoryAgentDispatcher._instance) 249 WebInspector.MemoryAgentDispatcher._instance = new WebInspector.MemoryAgentDispatcher(); 250 return WebInspector.MemoryAgentDispatcher._instance; 251 } 252 253 WebInspector.MemoryAgentDispatcher.prototype = { 254 /** 255 * @override 256 * @param {MemoryAgent.HeapSnapshotChunk} chunk 257 */ 258 addNativeSnapshotChunk: function(chunk) 259 { 260 if (this._currentProfileHeader) 261 this._currentProfileHeader.addNativeSnapshotChunk(chunk); 262 }, 263 264 _onRemoveProfileHeader: function(event) 265 { 266 if (event.data === this._currentProfileHeader) 267 this._currentProfileHeader = null; 268 } 269 }; 270 271 235 272 /** 236 273 * @constructor 237 274 * @extends {WebInspector.ProfileType} 238 * @implements {MemoryAgent.Dispatcher} 239 */ 240 WebInspector.NativeSnapshotProfileType = function() 241 { 242 WebInspector.ProfileType.call(this, WebInspector.NativeSnapshotProfileType.TypeId, WebInspector.UIString("Take Native Heap Snapshot")); 243 InspectorBackend.registerMemoryDispatcher(this); 275 * @param {string} id 276 * @param {string} name 277 */ 278 WebInspector.NativeProfileTypeBase = function(profileHeaderConstructor, id, name) 279 { 280 WebInspector.ProfileType.call(this, id, name); 281 this._profileHeaderConstructor = profileHeaderConstructor; 244 282 this._nextProfileUid = 1; 245 } 246 247 WebInspector.NativeSnapshotProfileType.TypeId = "NATIVE_SNAPSHOT"; 248 249 WebInspector.NativeSnapshotProfileType.prototype = { 250 get buttonTooltip() 251 { 252 return WebInspector.UIString("Capture native heap graph."); 253 }, 254 283 this.addEventListener(WebInspector.ProfileType.Events.RemoveProfileHeader, 284 WebInspector.MemoryAgentDispatcher.prototype._onRemoveProfileHeader, 285 WebInspector.MemoryAgentDispatcher.instance()); 286 } 287 288 WebInspector.NativeProfileTypeBase.prototype = { 255 289 /** 256 290 * @override … … 268 302 buttonClicked: function() 269 303 { 270 var profileHeader = new WebInspector.NativeSnapshotProfileHeader(this, WebInspector.UIString("Snapshot %d", this._nextProfileUid), this._nextProfileUid); 304 if (WebInspector.MemoryAgentDispatcher.instance()._currentProfileHeader) 305 return false; 306 307 var profileHeader = new this._profileHeaderConstructor(this, WebInspector.UIString("Snapshot %d", this._nextProfileUid), this._nextProfileUid); 271 308 ++this._nextProfileUid; 272 309 profileHeader.isTemporary = true; 273 310 this.addProfile(profileHeader); 311 WebInspector.MemoryAgentDispatcher.instance()._currentProfileHeader = profileHeader; 274 312 profileHeader.load(function() { }); 313 275 314 276 315 /** … … 281 320 function didReceiveMemorySnapshot(error, memoryBlock, graphMetaInformation) 282 321 { 283 var metaInformation = /** @type{HeapSnapshotMetainfo} */(graphMetaInformation); 284 this.isTemporary = false; 285 this.sidebarElement.subtitle = Number.bytesToString(/** @type{number} */(memoryBlock.size)); 286 287 var edgeFieldCount = metaInformation.edge_fields.length; 288 var nodeFieldCount = metaInformation.node_fields.length; 289 var nodeIdFieldOffset = metaInformation.node_fields.indexOf("id"); 290 var toNodeIdFieldOffset = metaInformation.edge_fields.indexOf("to_node"); 291 292 var baseToRealNodeIdMap = {}; 293 for (var i = 0; i < this._baseToRealNodeId.length; i += 2) 294 baseToRealNodeIdMap[this._baseToRealNodeId[i]] = this._baseToRealNodeId[i + 1]; 295 296 var nodeId2NodeIndex = {}; 297 for (var i = nodeIdFieldOffset; i < this._nodes.length; i += nodeFieldCount) 298 nodeId2NodeIndex[this._nodes[i]] = i - nodeIdFieldOffset; 299 300 // Translate nodeId to nodeIndex. 301 var edges = this._edges; 302 for (var i = toNodeIdFieldOffset; i < edges.length; i += edgeFieldCount) { 303 if (edges[i] in baseToRealNodeIdMap) 304 edges[i] = baseToRealNodeIdMap[edges[i]]; 305 edges[i] = nodeId2NodeIndex[edges[i]]; 306 } 307 308 var heapSnapshot = { 309 "snapshot": { 310 "meta": metaInformation, 311 node_count: this._nodes.length / nodeFieldCount, 312 edge_count: this._edges.length / edgeFieldCount, 313 root_index: this._nodes.length - nodeFieldCount 314 }, 315 nodes: this._nodes, 316 edges: this._edges, 317 strings: this._strings 318 }; 319 320 var chunk = JSON.stringify(heapSnapshot); 321 this.transferChunk(chunk); 322 this.finishHeapSnapshot(); 322 console.assert(this === WebInspector.MemoryAgentDispatcher.instance()._currentProfileHeader); 323 WebInspector.MemoryAgentDispatcher.instance()._currentProfileHeader = null; 324 this._didReceiveMemorySnapshot(error, memoryBlock, graphMetaInformation); 323 325 } 324 325 326 MemoryAgent.getProcessMemoryDistribution(true, didReceiveMemorySnapshot.bind(profileHeader)); 326 327 return false; 327 328 }, 328 329 329 get treeItemTitle() 330 { 331 return WebInspector.UIString("NATIVE SNAPSHOT"); 332 }, 333 334 get description() 335 { 336 return WebInspector.UIString("Native memory snapshot profiles show native heap graph."); 330 /** 331 * @override 332 * @param {!WebInspector.ProfileHeader} profile 333 */ 334 removeProfile: function(profile) 335 { 336 if (WebInspector.MemoryAgentDispatcher.instance()._currentProfileHeader === profile) 337 WebInspector.MemoryAgentDispatcher.instance()._currentProfileHeader = null; 338 WebInspector.ProfileType.prototype.removeProfile.call(this, profile); 337 339 }, 338 340 … … 345 347 { 346 348 title = title || WebInspector.UIString("Snapshotting\u2026"); 347 return new WebInspector.NativeSnapshotProfileHeader(this, title);349 return new this._profileHeaderConstructor(this, title); 348 350 }, 349 351 … … 355 357 createProfile: function(profile) 356 358 { 357 return new WebInspector.NativeSnapshotProfileHeader(this, profile.title, -1); 358 }, 359 360 /** 361 * @override 362 * @param {MemoryAgent.HeapSnapshotChunk} chunk 363 */ 364 addNativeSnapshotChunk: function(chunk) 365 { 366 var tempProfile = this.findTemporaryProfile(); 367 if (tempProfile) 368 tempProfile.addNativeSnapshotChunk(chunk); 359 return new this._profileHeaderConstructor(this, profile.title, -1); 369 360 }, 370 361 … … 372 363 } 373 364 365 /** 366 * @constructor 367 * @extends {WebInspector.NativeProfileTypeBase} 368 */ 369 WebInspector.NativeSnapshotProfileType = function() 370 { 371 WebInspector.NativeProfileTypeBase.call(this, WebInspector.NativeSnapshotProfileHeader, WebInspector.NativeSnapshotProfileType.TypeId, WebInspector.UIString("Take Native Heap Snapshot")); 372 } 373 374 WebInspector.NativeSnapshotProfileType.TypeId = "NATIVE_SNAPSHOT"; 375 376 WebInspector.NativeSnapshotProfileType.prototype = { 377 get buttonTooltip() 378 { 379 return WebInspector.UIString("Capture native heap graph."); 380 }, 381 382 get treeItemTitle() 383 { 384 return WebInspector.UIString("NATIVE SNAPSHOT"); 385 }, 386 387 get description() 388 { 389 return WebInspector.UIString("Native memory snapshot profiles show native heap graph."); 390 }, 391 392 __proto__: WebInspector.NativeProfileTypeBase.prototype 393 } 394 374 395 375 396 /** 376 397 * @constructor 377 398 * @extends {WebInspector.HeapProfileHeader} 378 * @param {!WebInspector. NativeSnapshotProfileType} type399 * @param {!WebInspector.ProfileType} type 379 400 * @param {string} title 380 401 * @param {number=} uid … … 416 437 }, 417 438 439 /** 440 * @param {?string} error 441 * @param {?MemoryAgent.MemoryBlock} memoryBlock 442 * @param {Object=} graphMetaInformation 443 */ 444 _didReceiveMemorySnapshot: function(error, memoryBlock, graphMetaInformation) 445 { 446 var metaInformation = /** @type{HeapSnapshotMetainfo} */ (graphMetaInformation); 447 this.isTemporary = false; 448 449 var edgeFieldCount = metaInformation.edge_fields.length; 450 var nodeFieldCount = metaInformation.node_fields.length; 451 var nodeIdFieldOffset = metaInformation.node_fields.indexOf("id"); 452 var toNodeIdFieldOffset = metaInformation.edge_fields.indexOf("to_node"); 453 454 var baseToRealNodeIdMap = {}; 455 for (var i = 0; i < this._baseToRealNodeId.length; i += 2) 456 baseToRealNodeIdMap[this._baseToRealNodeId[i]] = this._baseToRealNodeId[i + 1]; 457 458 var nodeId2NodeIndex = {}; 459 for (var i = nodeIdFieldOffset; i < this._nodes.length; i += nodeFieldCount) 460 nodeId2NodeIndex[this._nodes[i]] = i - nodeIdFieldOffset; 461 462 // Translate nodeId to nodeIndex. 463 var edges = this._edges; 464 for (var i = toNodeIdFieldOffset; i < edges.length; i += edgeFieldCount) { 465 if (edges[i] in baseToRealNodeIdMap) 466 edges[i] = baseToRealNodeIdMap[edges[i]]; 467 edges[i] = nodeId2NodeIndex[edges[i]]; 468 } 469 470 var heapSnapshot = { 471 "snapshot": { 472 "meta": metaInformation, 473 node_count: this._nodes.length / nodeFieldCount, 474 edge_count: this._edges.length / edgeFieldCount, 475 root_index: this._nodes.length - nodeFieldCount 476 }, 477 nodes: this._nodes, 478 edges: this._edges, 479 strings: this._strings 480 }; 481 482 var chunk = JSON.stringify(heapSnapshot); 483 this.transferChunk(chunk); 484 this.finishHeapSnapshot(); 485 }, 486 418 487 __proto__: WebInspector.HeapProfileHeader.prototype 419 488 } … … 445 514 /** 446 515 * @constructor 447 * @extends {WebInspector. ProfileType}516 * @extends {WebInspector.NativeProfileTypeBase} 448 517 */ 449 518 WebInspector.NativeMemoryProfileType = function() 450 519 { 451 WebInspector.ProfileType.call(this, WebInspector.NativeMemoryProfileType.TypeId, WebInspector.UIString("Capture Native Memory Distribution")); 452 this._nextProfileUid = 1; 520 WebInspector.NativeProfileTypeBase.call(this, WebInspector.NativeMemoryProfileHeader, WebInspector.NativeMemoryProfileType.TypeId, WebInspector.UIString("Capture Native Memory Distribution")); 453 521 } 454 522 … … 461 529 }, 462 530 463 /**464 * @override465 * @return {boolean}466 */467 isInstantProfile: function()468 {469 return true;470 },471 472 /**473 * @override474 * @return {boolean}475 */476 buttonClicked: function()477 {478 var profileHeader = new WebInspector.NativeMemoryProfileHeader(this, WebInspector.UIString("Snapshot %d", this._nextProfileUid), this._nextProfileUid);479 ++this._nextProfileUid;480 profileHeader.isTemporary = true;481 this.addProfile(profileHeader);482 /**483 * @param {?string} error484 * @param {?MemoryAgent.MemoryBlock} memoryBlock485 */486 function didReceiveMemorySnapshot(error, memoryBlock)487 {488 if (memoryBlock.size && memoryBlock.children) {489 var knownSize = 0;490 for (var i = 0; i < memoryBlock.children.length; i++) {491 var size = memoryBlock.children[i].size;492 if (size)493 knownSize += size;494 }495 var otherSize = memoryBlock.size - knownSize;496 497 if (otherSize) {498 memoryBlock.children.push({499 name: "Other",500 size: otherSize501 });502 }503 }504 profileHeader._memoryBlock = memoryBlock;505 profileHeader.isTemporary = false;506 profileHeader.sidebarElement.subtitle = Number.bytesToString(/** @type{number} */(memoryBlock.size));507 }508 MemoryAgent.getProcessMemoryDistribution(false, didReceiveMemorySnapshot.bind(this));509 return false;510 },511 512 531 get treeItemTitle() 513 532 { … … 520 539 }, 521 540 522 /** 523 * @override 524 * @param {string=} title 525 * @return {WebInspector.ProfileHeader} 526 */ 527 createTemporaryProfile: function(title) 528 { 529 title = title || WebInspector.UIString("Snapshotting\u2026"); 530 return new WebInspector.NativeMemoryProfileHeader(this, title); 531 }, 532 533 /** 534 * @override 535 * @param {ProfilerAgent.ProfileHeader} profile 536 * @return {WebInspector.ProfileHeader} 537 */ 538 createProfile: function(profile) 539 { 540 return new WebInspector.NativeMemoryProfileHeader(this, profile.title, -1); 541 }, 542 543 __proto__: WebInspector.ProfileType.prototype 544 } 545 546 /** 547 * @constructor 548 * @extends {WebInspector.ProfileHeader} 549 * @param {!WebInspector.NativeMemoryProfileType} type 541 __proto__: WebInspector.NativeProfileTypeBase.prototype 542 } 543 544 /** 545 * @constructor 546 * @extends {WebInspector.NativeSnapshotProfileHeader} 547 * @param {!WebInspector.ProfileType} type 550 548 * @param {string} title 551 549 * @param {number=} uid … … 553 551 WebInspector.NativeMemoryProfileHeader = function(type, title, uid) 554 552 { 555 WebInspector. ProfileHeader.call(this, type, title, uid);553 WebInspector.NativeSnapshotProfileHeader.call(this, type, title, uid); 556 554 557 555 /** … … 579 577 }, 580 578 581 __proto__: WebInspector.ProfileHeader.prototype 579 /** 580 * @override 581 */ 582 _updateSnapshotStatus: function() 583 { 584 WebInspector.NativeSnapshotProfileHeader.prototype._updateSnapshotStatus.call(this); 585 this.sidebarElement.subtitle = Number.bytesToString(/** @type{number} */ (this._memoryBlock.size)); 586 }, 587 588 /** 589 * @override 590 * @param {?string} error 591 * @param {?MemoryAgent.MemoryBlock} memoryBlock 592 * @param {Object=} graphMetaInformation 593 */ 594 _didReceiveMemorySnapshot: function(error, memoryBlock, graphMetaInformation) 595 { 596 WebInspector.NativeSnapshotProfileHeader.prototype._didReceiveMemorySnapshot.call(this, error, memoryBlock, graphMetaInformation); 597 if (memoryBlock.size && memoryBlock.children) { 598 var knownSize = 0; 599 for (var i = 0; i < memoryBlock.children.length; i++) { 600 var size = memoryBlock.children[i].size; 601 if (size) 602 knownSize += size; 603 } 604 var otherSize = memoryBlock.size - knownSize; 605 606 if (otherSize) { 607 memoryBlock.children.push({ 608 name: "Other", 609 size: otherSize 610 }); 611 } 612 } 613 this._memoryBlock = memoryBlock; 614 }, 615 616 __proto__: WebInspector.NativeSnapshotProfileHeader.prototype 582 617 } 583 618
Note: See TracChangeset
for help on using the changeset viewer.