| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 this.excludeButton.setEnabled(false); | 67 this.excludeButton.setEnabled(false); |
| 68 this.excludeButton.addEventListener("click", this._excludeClicked, this); | 68 this.excludeButton.addEventListener("click", this._excludeClicked, this); |
| 69 this._statusBarButtonsElement.appendChild(this.excludeButton.element); | 69 this._statusBarButtonsElement.appendChild(this.excludeButton.element); |
| 70 | 70 |
| 71 this.resetButton = new WebInspector.StatusBarButton(WebInspector.UIString("R
estore all functions."), "reset-profile-status-bar-item"); | 71 this.resetButton = new WebInspector.StatusBarButton(WebInspector.UIString("R
estore all functions."), "reset-profile-status-bar-item"); |
| 72 this.resetButton.visible = false; | 72 this.resetButton.visible = false; |
| 73 this.resetButton.addEventListener("click", this._resetClicked, this); | 73 this.resetButton.addEventListener("click", this._resetClicked, this); |
| 74 this._statusBarButtonsElement.appendChild(this.resetButton.element); | 74 this._statusBarButtonsElement.appendChild(this.resetButton.element); |
| 75 | 75 |
| 76 this._profileHeader = profileHeader; | 76 this._profileHeader = profileHeader; |
| 77 this._target = profileHeader.target(); |
| 77 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa
ultFormatter(30)); | 78 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa
ultFormatter(30)); |
| 78 | 79 |
| 79 this.profile = new WebInspector.CPUProfileDataModel(profileHeader._profile |
| profileHeader.protocolProfile()); | 80 this.profile = new WebInspector.CPUProfileDataModel(profileHeader._profile |
| profileHeader.protocolProfile()); |
| 80 | 81 |
| 81 this._changeView(); | 82 this._changeView(); |
| 82 if (this._flameChart) | 83 if (this._flameChart) |
| 83 this._flameChart.update(); | 84 this._flameChart.update(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 WebInspector.CPUProfileView._TypeFlame = "Flame"; | 87 WebInspector.CPUProfileView._TypeFlame = "Flame"; |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 return; | 346 return; |
| 346 | 347 |
| 347 var profileNode = searchResult.profileNode; | 348 var profileNode = searchResult.profileNode; |
| 348 profileNode.revealAndSelect(); | 349 profileNode.revealAndSelect(); |
| 349 }, | 350 }, |
| 350 | 351 |
| 351 _ensureFlameChartCreated: function() | 352 _ensureFlameChartCreated: function() |
| 352 { | 353 { |
| 353 if (this._flameChart) | 354 if (this._flameChart) |
| 354 return; | 355 return; |
| 355 this._dataProvider = new WebInspector.CPUFlameChartDataProvider(this.pro
file, this._profileHeader.target()); | 356 this._dataProvider = new WebInspector.CPUFlameChartDataProvider(this.pro
file, this._target); |
| 356 this._flameChart = new WebInspector.CPUProfileFlameChart(this._dataProvi
der); | 357 this._flameChart = new WebInspector.CPUProfileFlameChart(this._dataProvi
der); |
| 357 this._flameChart.addEventListener(WebInspector.FlameChart.Events.EntrySe
lected, this._onEntrySelected.bind(this)); | 358 this._flameChart.addEventListener(WebInspector.FlameChart.Events.EntrySe
lected, this._onEntrySelected.bind(this)); |
| 358 }, | 359 }, |
| 359 | 360 |
| 360 /** | 361 /** |
| 361 * @param {!WebInspector.Event} event | 362 * @param {!WebInspector.Event} event |
| 362 */ | 363 */ |
| 363 _onEntrySelected: function(event) | 364 _onEntrySelected: function(event) |
| 364 { | 365 { |
| 365 var entryIndex = event.data; | 366 var entryIndex = event.data; |
| 366 var node = this._dataProvider._entryNodes[entryIndex]; | 367 var node = this._dataProvider._entryNodes[entryIndex]; |
| 367 if (!node || !node.scriptId) | 368 if (!node || !node.scriptId || !this._target) |
| 368 return; | 369 return; |
| 369 var script = WebInspector.debuggerModel.scriptForId(node.scriptId) | 370 var script = this._target.debuggerModel.scriptForId(node.scriptId) |
| 370 if (!script) | 371 if (!script) |
| 371 return; | 372 return; |
| 372 WebInspector.Revealer.reveal(script.rawLocationToUILocation(node.lineNum
ber)); | 373 WebInspector.Revealer.reveal(script.rawLocationToUILocation(node.lineNum
ber)); |
| 373 }, | 374 }, |
| 374 | 375 |
| 375 _changeView: function() | 376 _changeView: function() |
| 376 { | 377 { |
| 377 if (!this.profile) | 378 if (!this.profile) |
| 378 return; | 379 return; |
| 379 | 380 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 | 475 |
| 475 this.refresh(); | 476 this.refresh(); |
| 476 }, | 477 }, |
| 477 | 478 |
| 478 __proto__: WebInspector.VBox.prototype | 479 __proto__: WebInspector.VBox.prototype |
| 479 } | 480 } |
| 480 | 481 |
| 481 /** | 482 /** |
| 482 * @constructor | 483 * @constructor |
| 483 * @extends {WebInspector.ProfileType} | 484 * @extends {WebInspector.ProfileType} |
| 484 * @implements {WebInspector.CPUProfilerModel.Delegate} | 485 * @implements {WebInspector.TargetManager.Observer} |
| 485 */ | 486 */ |
| 486 WebInspector.CPUProfileType = function() | 487 WebInspector.CPUProfileType = function() |
| 487 { | 488 { |
| 488 WebInspector.ProfileType.call(this, WebInspector.CPUProfileType.TypeId, WebI
nspector.UIString("Collect JavaScript CPU Profile")); | 489 WebInspector.ProfileType.call(this, WebInspector.CPUProfileType.TypeId, WebI
nspector.UIString("Collect JavaScript CPU Profile")); |
| 489 this._recording = false; | 490 this._recording = false; |
| 490 | 491 |
| 491 this._nextAnonymousConsoleProfileNumber = 1; | 492 this._nextAnonymousConsoleProfileNumber = 1; |
| 492 this._anonymousConsoleProfileIdToTitle = {}; | 493 this._anonymousConsoleProfileIdToTitle = {}; |
| 493 | 494 |
| 494 WebInspector.CPUProfileType.instance = this; | 495 WebInspector.CPUProfileType.instance = this; |
| 495 WebInspector.cpuProfilerModel.setDelegate(this); | 496 WebInspector.targetManager.observeTargets(this); |
| 496 } | 497 } |
| 497 | 498 |
| 498 WebInspector.CPUProfileType.TypeId = "CPU"; | 499 WebInspector.CPUProfileType.TypeId = "CPU"; |
| 499 | 500 |
| 500 WebInspector.CPUProfileType.prototype = { | 501 WebInspector.CPUProfileType.prototype = { |
| 501 /** | 502 /** |
| 503 * @param {!WebInspector.Target} target |
| 504 */ |
| 505 targetAdded: function(target) |
| 506 { |
| 507 target.cpuProfilerModel.addEventListener(WebInspector.CPUProfilerModel.E
ventTypes.ConsoleProfileStarted, this._consoleProfileStarted, this); |
| 508 target.cpuProfilerModel.addEventListener(WebInspector.CPUProfilerModel.E
ventTypes.ConsoleProfileFinished, this._consoleProfileFinished, this); |
| 509 }, |
| 510 |
| 511 /** |
| 512 * @param {!WebInspector.Target} target |
| 513 */ |
| 514 targetRemoved: function(target) |
| 515 { |
| 516 target.cpuProfilerModel.removeEventListener(WebInspector.CPUProfilerMode
l.EventTypes.ConsoleProfileStarted, this._consoleProfileStarted, this); |
| 517 target.cpuProfilerModel.removeEventListener(WebInspector.CPUProfilerMode
l.EventTypes.ConsoleProfileFinished, this._consoleProfileFinished, this); |
| 518 }, |
| 519 |
| 520 /** |
| 502 * @override | 521 * @override |
| 503 * @return {string} | 522 * @return {string} |
| 504 */ | 523 */ |
| 505 fileExtension: function() | 524 fileExtension: function() |
| 506 { | 525 { |
| 507 return ".cpuprofile"; | 526 return ".cpuprofile"; |
| 508 }, | 527 }, |
| 509 | 528 |
| 510 get buttonTooltip() | 529 get buttonTooltip() |
| 511 { | 530 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 531 { | 550 { |
| 532 return WebInspector.UIString("CPU PROFILES"); | 551 return WebInspector.UIString("CPU PROFILES"); |
| 533 }, | 552 }, |
| 534 | 553 |
| 535 get description() | 554 get description() |
| 536 { | 555 { |
| 537 return WebInspector.UIString("CPU profiles show where the execution time
is spent in your page's JavaScript functions."); | 556 return WebInspector.UIString("CPU profiles show where the execution time
is spent in your page's JavaScript functions."); |
| 538 }, | 557 }, |
| 539 | 558 |
| 540 /** | 559 /** |
| 541 * @param {string} id | 560 * @param {!WebInspector.Event} event |
| 542 * @param {!WebInspector.DebuggerModel.Location} scriptLocation | |
| 543 * @param {string=} title | |
| 544 */ | 561 */ |
| 545 consoleProfileStarted: function(id, scriptLocation, title) | 562 _consoleProfileStarted: function(event) |
| 546 { | 563 { |
| 547 var resolvedTitle = title; | 564 var protocolId = /** @type {string} */ (event.data.protocolId); |
| 565 var scriptLocation = /** @type {!WebInspector.DebuggerModel.Location} */
(event.data.scriptLocation); |
| 566 var resolvedTitle = /** @type {string|undefined} */ (event.data.title); |
| 548 if (!resolvedTitle) { | 567 if (!resolvedTitle) { |
| 549 resolvedTitle = WebInspector.UIString("Profile %s", this._nextAnonym
ousConsoleProfileNumber++); | 568 resolvedTitle = WebInspector.UIString("Profile %s", this._nextAnonym
ousConsoleProfileNumber++); |
| 550 this._anonymousConsoleProfileIdToTitle[id] = resolvedTitle; | 569 this._anonymousConsoleProfileIdToTitle[protocolId] = resolvedTitle; |
| 551 } | 570 } |
| 552 this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.Profil
e, scriptLocation, WebInspector.UIString("Profile '%s' started.", resolvedTitle)
); | 571 this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.Profil
e, scriptLocation, WebInspector.UIString("Profile '%s' started.", resolvedTitle)
); |
| 553 }, | 572 }, |
| 554 | 573 |
| 555 /** | 574 /** |
| 556 * @param {string} protocolId | 575 * @param {!WebInspector.Event} event |
| 557 * @param {!WebInspector.DebuggerModel.Location} scriptLocation | |
| 558 * @param {!ProfilerAgent.CPUProfile} cpuProfile | |
| 559 * @param {string=} title | |
| 560 */ | 576 */ |
| 561 consoleProfileFinished: function(protocolId, scriptLocation, cpuProfile, tit
le) | 577 _consoleProfileFinished: function(event) |
| 562 { | 578 { |
| 563 var resolvedTitle = title; | 579 var protocolId = /** @type {string} */ (event.data.protocolId); |
| 564 if (typeof title === "undefined") { | 580 var scriptLocation = /** @type {!WebInspector.DebuggerModel.Location} */
(event.data.scriptLocation); |
| 581 var cpuProfile = /** @type {!ProfilerAgent.CPUProfile} */ (event.data.cp
uProfile); |
| 582 var resolvedTitle = /** @type {string|undefined} */ (event.data.title); |
| 583 if (typeof resolvedTitle === "undefined") { |
| 565 resolvedTitle = this._anonymousConsoleProfileIdToTitle[protocolId]; | 584 resolvedTitle = this._anonymousConsoleProfileIdToTitle[protocolId]; |
| 566 delete this._anonymousConsoleProfileIdToTitle[protocolId]; | 585 delete this._anonymousConsoleProfileIdToTitle[protocolId]; |
| 567 } | 586 } |
| 568 | 587 |
| 569 var target = /** @type {!WebInspector.Target} */ (WebInspector.targetMan
ager.activeTarget()); | 588 var profile = new WebInspector.CPUProfileHeader(scriptLocation.target(),
this, resolvedTitle); |
| 570 var profile = new WebInspector.CPUProfileHeader(target, this, resolvedTi
tle); | |
| 571 profile.setProtocolProfile(cpuProfile); | 589 profile.setProtocolProfile(cpuProfile); |
| 572 this.addProfile(profile); | 590 this.addProfile(profile); |
| 573 this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.Profil
eEnd, scriptLocation, WebInspector.UIString("Profile '%s' finished.", resolvedTi
tle)); | 591 this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.Profil
eEnd, scriptLocation, WebInspector.UIString("Profile '%s' finished.", resolvedTi
tle)); |
| 574 }, | 592 }, |
| 575 | 593 |
| 576 /** | 594 /** |
| 577 * @param {string} type | 595 * @param {string} type |
| 578 * @param {!WebInspector.DebuggerModel.Location} scriptLocation | 596 * @param {!WebInspector.DebuggerModel.Location} scriptLocation |
| 579 * @param {string} messageText | 597 * @param {string} messageText |
| 580 */ | 598 */ |
| 581 _addMessageToConsole: function(type, scriptLocation, messageText) | 599 _addMessageToConsole: function(type, scriptLocation, messageText) |
| 582 { | 600 { |
| 583 var script = scriptLocation.script(); | 601 var script = scriptLocation.script(); |
| 602 var target = scriptLocation.target(); |
| 584 var message = new WebInspector.ConsoleMessage( | 603 var message = new WebInspector.ConsoleMessage( |
| 585 WebInspector.console.target(), | 604 target, |
| 586 WebInspector.ConsoleMessage.MessageSource.ConsoleAPI, | 605 WebInspector.ConsoleMessage.MessageSource.ConsoleAPI, |
| 587 WebInspector.ConsoleMessage.MessageLevel.Debug, | 606 WebInspector.ConsoleMessage.MessageLevel.Debug, |
| 588 messageText, | 607 messageText, |
| 589 type, | 608 type, |
| 590 undefined, | 609 undefined, |
| 591 undefined, | 610 undefined, |
| 592 undefined, | 611 undefined, |
| 593 undefined, | 612 undefined, |
| 594 undefined, | 613 undefined, |
| 595 [{ | 614 [{ |
| 596 functionName: "", | 615 functionName: "", |
| 597 scriptId: scriptLocation.scriptId, | 616 scriptId: scriptLocation.scriptId, |
| 598 url: script ? script.contentURL() : "", | 617 url: script ? script.contentURL() : "", |
| 599 lineNumber: scriptLocation.lineNumber, | 618 lineNumber: scriptLocation.lineNumber, |
| 600 columnNumber: scriptLocation.columnNumber || 0 | 619 columnNumber: scriptLocation.columnNumber || 0 |
| 601 }]); | 620 }]); |
| 602 | 621 |
| 603 WebInspector.console.addMessage(message); | 622 target.consoleModel.addMessage(message); |
| 604 }, | |
| 605 | |
| 606 /** | |
| 607 * @return {boolean} | |
| 608 */ | |
| 609 isRecordingProfile: function() | |
| 610 { | |
| 611 return this._recording; | |
| 612 }, | 623 }, |
| 613 | 624 |
| 614 startRecordingProfile: function() | 625 startRecordingProfile: function() |
| 615 { | 626 { |
| 616 if (this._profileBeingRecorded) | 627 var target = WebInspector.context.flavor(WebInspector.Target); |
| 628 if (this._profileBeingRecorded || !target) |
| 617 return; | 629 return; |
| 618 var target = /** @type {!WebInspector.Target} */ (WebInspector.targetMan
ager.activeTarget()); | |
| 619 var profile = new WebInspector.CPUProfileHeader(target, this); | 630 var profile = new WebInspector.CPUProfileHeader(target, this); |
| 620 this.setProfileBeingRecorded(profile); | 631 this.setProfileBeingRecorded(profile); |
| 621 this.addProfile(profile); | 632 this.addProfile(profile); |
| 622 profile.updateStatus(WebInspector.UIString("Recording\u2026")); | 633 profile.updateStatus(WebInspector.UIString("Recording\u2026")); |
| 623 this._recording = true; | 634 this._recording = true; |
| 624 WebInspector.cpuProfilerModel.setRecording(true); | 635 target.cpuProfilerModel.startRecording(); |
| 625 WebInspector.userMetrics.ProfilesCPUProfileTaken.record(); | |
| 626 ProfilerAgent.start(); | |
| 627 }, | 636 }, |
| 628 | 637 |
| 629 stopRecordingProfile: function() | 638 stopRecordingProfile: function() |
| 630 { | 639 { |
| 631 this._recording = false; | 640 this._recording = false; |
| 632 WebInspector.cpuProfilerModel.setRecording(false); | 641 if (!this._profileBeingRecorded || !this._profileBeingRecorded.target()) |
| 642 return; |
| 633 | 643 |
| 634 /** | 644 /** |
| 635 * @param {?string} error | 645 * @param {?string} error |
| 636 * @param {?ProfilerAgent.CPUProfile} profile | 646 * @param {?ProfilerAgent.CPUProfile} profile |
| 637 * @this {WebInspector.CPUProfileType} | 647 * @this {WebInspector.CPUProfileType} |
| 638 */ | 648 */ |
| 639 function didStopProfiling(error, profile) | 649 function didStopProfiling(error, profile) |
| 640 { | 650 { |
| 641 if (!this._profileBeingRecorded) | 651 if (!this._profileBeingRecorded) |
| 642 return; | 652 return; |
| 643 this._profileBeingRecorded.setProtocolProfile(profile); | 653 this._profileBeingRecorded.setProtocolProfile(profile); |
| 644 this._profileBeingRecorded.updateStatus(""); | 654 this._profileBeingRecorded.updateStatus(""); |
| 645 var recordedProfile = this._profileBeingRecorded; | 655 var recordedProfile = this._profileBeingRecorded; |
| 646 this.setProfileBeingRecorded(null); | 656 this.setProfileBeingRecorded(null); |
| 647 this.dispatchEventToListeners(WebInspector.ProfileType.Events.Profil
eComplete, recordedProfile); | 657 this.dispatchEventToListeners(WebInspector.ProfileType.Events.Profil
eComplete, recordedProfile); |
| 648 } | 658 } |
| 649 ProfilerAgent.stop(didStopProfiling.bind(this)); | 659 this._profileBeingRecorded.target().cpuProfilerModel.stopRecording(didSt
opProfiling.bind(this)); |
| 650 }, | 660 }, |
| 651 | 661 |
| 652 /** | 662 /** |
| 653 * @override | 663 * @override |
| 654 * @param {string} title | 664 * @param {string} title |
| 655 * @return {!WebInspector.ProfileHeader} | 665 * @return {!WebInspector.ProfileHeader} |
| 656 */ | 666 */ |
| 657 createProfileLoadedFromFile: function(title) | 667 createProfileLoadedFromFile: function(title) |
| 658 { | 668 { |
| 659 return new WebInspector.CPUProfileHeader(null, this, title); | 669 return new WebInspector.CPUProfileHeader(null, this, title); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 _notifyTempFileReady: function() | 897 _notifyTempFileReady: function() |
| 888 { | 898 { |
| 889 if (this._onTempFileReady) { | 899 if (this._onTempFileReady) { |
| 890 this._onTempFileReady(); | 900 this._onTempFileReady(); |
| 891 this._onTempFileReady = null; | 901 this._onTempFileReady = null; |
| 892 } | 902 } |
| 893 }, | 903 }, |
| 894 | 904 |
| 895 __proto__: WebInspector.ProfileHeader.prototype | 905 __proto__: WebInspector.ProfileHeader.prototype |
| 896 } | 906 } |
| OLD | NEW |