Chromium Code Reviews| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 this.excludeButton = new WebInspector.StatusBarButton(WebInspector.UIString( "Exclude selected function."), "exclude-profile-node-status-bar-item"); | 66 this.excludeButton = new WebInspector.StatusBarButton(WebInspector.UIString( "Exclude selected function."), "exclude-profile-node-status-bar-item"); |
| 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._target = profileHeader.target(); |
| 77 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa ultFormatter(30)); | 77 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa ultFormatter(30)); |
| 78 | 78 |
| 79 this.profile = new WebInspector.CPUProfileDataModel(profileHeader._profile | | profileHeader.protocolProfile()); | 79 this.profile = new WebInspector.CPUProfileDataModel(profileHeader._profile | | profileHeader.protocolProfile()); |
| 80 | 80 |
| 81 this._changeView(); | 81 this._changeView(); |
| 82 if (this._flameChart) | 82 if (this._flameChart) |
| 83 this._flameChart.update(); | 83 this._flameChart.update(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 WebInspector.CPUProfileView._TypeFlame = "Flame"; | 86 WebInspector.CPUProfileView._TypeFlame = "Flame"; |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 return; | 345 return; |
| 346 | 346 |
| 347 var profileNode = searchResult.profileNode; | 347 var profileNode = searchResult.profileNode; |
| 348 profileNode.revealAndSelect(); | 348 profileNode.revealAndSelect(); |
| 349 }, | 349 }, |
| 350 | 350 |
| 351 _ensureFlameChartCreated: function() | 351 _ensureFlameChartCreated: function() |
| 352 { | 352 { |
| 353 if (this._flameChart) | 353 if (this._flameChart) |
| 354 return; | 354 return; |
| 355 this._dataProvider = new WebInspector.CPUFlameChartDataProvider(this.pro file, this._profileHeader.target()); | 355 this._dataProvider = new WebInspector.CPUFlameChartDataProvider(this.pro file, this._target); |
| 356 this._flameChart = new WebInspector.CPUProfileFlameChart(this._dataProvi der); | 356 this._flameChart = new WebInspector.CPUProfileFlameChart(this._dataProvi der); |
| 357 this._flameChart.addEventListener(WebInspector.FlameChart.Events.EntrySe lected, this._onEntrySelected.bind(this)); | 357 this._flameChart.addEventListener(WebInspector.FlameChart.Events.EntrySe lected, this._onEntrySelected.bind(this)); |
| 358 }, | 358 }, |
| 359 | 359 |
| 360 /** | 360 /** |
| 361 * @param {!WebInspector.Event} event | 361 * @param {!WebInspector.Event} event |
| 362 */ | 362 */ |
| 363 _onEntrySelected: function(event) | 363 _onEntrySelected: function(event) |
| 364 { | 364 { |
| 365 var entryIndex = event.data; | 365 var entryIndex = event.data; |
| 366 var node = this._dataProvider._entryNodes[entryIndex]; | 366 var node = this._dataProvider._entryNodes[entryIndex]; |
| 367 if (!node || !node.scriptId) | 367 if (!node || !node.scriptId || !this._target) |
| 368 return; | 368 return; |
| 369 var script = WebInspector.debuggerModel.scriptForId(node.scriptId) | 369 var script = this._target.debuggerModel.scriptForId(node.scriptId) |
| 370 if (!script) | 370 if (!script) |
| 371 return; | 371 return; |
| 372 WebInspector.Revealer.reveal(script.rawLocationToUILocation(node.lineNum ber)); | 372 WebInspector.Revealer.reveal(script.rawLocationToUILocation(node.lineNum ber)); |
| 373 }, | 373 }, |
| 374 | 374 |
| 375 _changeView: function() | 375 _changeView: function() |
| 376 { | 376 { |
| 377 if (!this.profile) | 377 if (!this.profile) |
| 378 return; | 378 return; |
| 379 | 379 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 this.refresh(); | 475 this.refresh(); |
| 476 }, | 476 }, |
| 477 | 477 |
| 478 __proto__: WebInspector.VBox.prototype | 478 __proto__: WebInspector.VBox.prototype |
| 479 } | 479 } |
| 480 | 480 |
| 481 /** | 481 /** |
| 482 * @constructor | 482 * @constructor |
| 483 * @extends {WebInspector.ProfileType} | 483 * @extends {WebInspector.ProfileType} |
| 484 * @implements {WebInspector.CPUProfilerModel.Delegate} | 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.setDelegate(this); | |
|
vsevik
2014/07/01 08:48:54
Let's use event listeners instead of delegate.
sergeyv
2014/07/01 12:22:56
Done.
| |
| 508 }, | |
| 509 | |
| 510 /** | |
| 511 * @param {!WebInspector.Target} target | |
| 512 */ | |
| 513 targetRemoved: function(target) | |
| 514 { | |
| 515 target.cpuProfilerModel.setDelegate(null); | |
| 516 }, | |
| 517 | |
| 518 /** | |
| 502 * @override | 519 * @override |
| 503 * @return {string} | 520 * @return {string} |
| 504 */ | 521 */ |
| 505 fileExtension: function() | 522 fileExtension: function() |
| 506 { | 523 { |
| 507 return ".cpuprofile"; | 524 return ".cpuprofile"; |
| 508 }, | 525 }, |
| 509 | 526 |
| 510 get buttonTooltip() | 527 get buttonTooltip() |
| 511 { | 528 { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 * @param {string=} title | 576 * @param {string=} title |
| 560 */ | 577 */ |
| 561 consoleProfileFinished: function(protocolId, scriptLocation, cpuProfile, tit le) | 578 consoleProfileFinished: function(protocolId, scriptLocation, cpuProfile, tit le) |
| 562 { | 579 { |
| 563 var resolvedTitle = title; | 580 var resolvedTitle = title; |
| 564 if (typeof title === "undefined") { | 581 if (typeof title === "undefined") { |
| 565 resolvedTitle = this._anonymousConsoleProfileIdToTitle[protocolId]; | 582 resolvedTitle = this._anonymousConsoleProfileIdToTitle[protocolId]; |
| 566 delete this._anonymousConsoleProfileIdToTitle[protocolId]; | 583 delete this._anonymousConsoleProfileIdToTitle[protocolId]; |
| 567 } | 584 } |
| 568 | 585 |
| 569 var target = /** @type {!WebInspector.Target} */ (WebInspector.targetMan ager.activeTarget()); | 586 var profile = new WebInspector.CPUProfileHeader(scriptLocation.target(), this, resolvedTitle); |
| 570 var profile = new WebInspector.CPUProfileHeader(target, this, resolvedTi tle); | |
| 571 profile.setProtocolProfile(cpuProfile); | 587 profile.setProtocolProfile(cpuProfile); |
| 572 this.addProfile(profile); | 588 this.addProfile(profile); |
| 573 this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.Profil eEnd, scriptLocation, WebInspector.UIString("Profile '%s' finished.", resolvedTi tle)); | 589 this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.Profil eEnd, scriptLocation, WebInspector.UIString("Profile '%s' finished.", resolvedTi tle)); |
| 574 }, | 590 }, |
| 575 | 591 |
| 576 /** | 592 /** |
| 577 * @param {string} type | 593 * @param {string} type |
| 578 * @param {!WebInspector.DebuggerModel.Location} scriptLocation | 594 * @param {!WebInspector.DebuggerModel.Location} scriptLocation |
| 579 * @param {string} messageText | 595 * @param {string} messageText |
| 580 */ | 596 */ |
| 581 _addMessageToConsole: function(type, scriptLocation, messageText) | 597 _addMessageToConsole: function(type, scriptLocation, messageText) |
| 582 { | 598 { |
| 583 var script = scriptLocation.script(); | 599 var script = scriptLocation.script(); |
| 600 var target = scriptLocation.target(); | |
| 584 var message = new WebInspector.ConsoleMessage( | 601 var message = new WebInspector.ConsoleMessage( |
| 585 WebInspector.console.target(), | 602 target, |
| 586 WebInspector.ConsoleMessage.MessageSource.ConsoleAPI, | 603 WebInspector.ConsoleMessage.MessageSource.ConsoleAPI, |
| 587 WebInspector.ConsoleMessage.MessageLevel.Debug, | 604 WebInspector.ConsoleMessage.MessageLevel.Debug, |
| 588 messageText, | 605 messageText, |
| 589 type, | 606 type, |
| 590 undefined, | 607 undefined, |
| 591 undefined, | 608 undefined, |
| 592 undefined, | 609 undefined, |
| 593 undefined, | 610 undefined, |
| 594 undefined, | 611 undefined, |
| 595 [{ | 612 [{ |
| 596 functionName: "", | 613 functionName: "", |
| 597 scriptId: scriptLocation.scriptId, | 614 scriptId: scriptLocation.scriptId, |
| 598 url: script ? script.contentURL() : "", | 615 url: script ? script.contentURL() : "", |
| 599 lineNumber: scriptLocation.lineNumber, | 616 lineNumber: scriptLocation.lineNumber, |
| 600 columnNumber: scriptLocation.columnNumber || 0 | 617 columnNumber: scriptLocation.columnNumber || 0 |
| 601 }]); | 618 }]); |
| 602 | 619 |
| 603 WebInspector.console.addMessage(message); | 620 target.consoleModel.addMessage(message); |
| 604 }, | 621 }, |
| 605 | 622 |
| 606 /** | 623 /** |
| 607 * @return {boolean} | 624 * @return {boolean} |
| 608 */ | 625 */ |
| 609 isRecordingProfile: function() | 626 isRecordingProfile: function() |
| 610 { | 627 { |
| 611 return this._recording; | 628 return this._recording; |
| 612 }, | 629 }, |
| 613 | 630 |
| 614 startRecordingProfile: function() | 631 startRecordingProfile: function() |
| 615 { | 632 { |
| 616 if (this._profileBeingRecorded) | 633 var target = WebInspector.context.flavor(WebInspector.Target); |
| 634 if (this._profileBeingRecorded || !target) | |
| 617 return; | 635 return; |
| 618 var target = /** @type {!WebInspector.Target} */ (WebInspector.targetMan ager.activeTarget()); | |
| 619 var profile = new WebInspector.CPUProfileHeader(target, this); | 636 var profile = new WebInspector.CPUProfileHeader(target, this); |
| 620 this.setProfileBeingRecorded(profile); | 637 this.setProfileBeingRecorded(profile); |
| 621 this.addProfile(profile); | 638 this.addProfile(profile); |
| 622 profile.updateStatus(WebInspector.UIString("Recording\u2026")); | 639 profile.updateStatus(WebInspector.UIString("Recording\u2026")); |
| 623 this._recording = true; | 640 this._recording = true; |
| 624 WebInspector.cpuProfilerModel.setRecording(true); | 641 target.cpuProfilerModel.startRecording(); |
| 625 WebInspector.userMetrics.ProfilesCPUProfileTaken.record(); | |
| 626 ProfilerAgent.start(); | |
| 627 }, | 642 }, |
| 628 | 643 |
| 629 stopRecordingProfile: function() | 644 stopRecordingProfile: function() |
| 630 { | 645 { |
| 631 this._recording = false; | 646 this._recording = false; |
| 632 WebInspector.cpuProfilerModel.setRecording(false); | 647 if (!this._profileBeingRecorded || !this._profileBeingRecorded.target()) |
|
vsevik
2014/07/01 08:48:54
What will happen if the worker closes while we are
sergeyv
2014/07/01 12:22:56
In current behavior - nothing will happen, lets ha
| |
| 648 return; | |
| 633 | 649 |
| 634 /** | 650 /** |
| 635 * @param {?string} error | 651 * @param {?string} error |
| 636 * @param {?ProfilerAgent.CPUProfile} profile | 652 * @param {?ProfilerAgent.CPUProfile} profile |
| 637 * @this {WebInspector.CPUProfileType} | 653 * @this {WebInspector.CPUProfileType} |
| 638 */ | 654 */ |
| 639 function didStopProfiling(error, profile) | 655 function didStopProfiling(error, profile) |
| 640 { | 656 { |
| 641 if (!this._profileBeingRecorded) | 657 if (!this._profileBeingRecorded) |
| 642 return; | 658 return; |
| 643 this._profileBeingRecorded.setProtocolProfile(profile); | 659 this._profileBeingRecorded.setProtocolProfile(profile); |
| 644 this._profileBeingRecorded.updateStatus(""); | 660 this._profileBeingRecorded.updateStatus(""); |
| 645 var recordedProfile = this._profileBeingRecorded; | 661 var recordedProfile = this._profileBeingRecorded; |
| 646 this.setProfileBeingRecorded(null); | 662 this.setProfileBeingRecorded(null); |
| 647 this.dispatchEventToListeners(WebInspector.ProfileType.Events.Profil eComplete, recordedProfile); | 663 this.dispatchEventToListeners(WebInspector.ProfileType.Events.Profil eComplete, recordedProfile); |
| 648 } | 664 } |
| 649 ProfilerAgent.stop(didStopProfiling.bind(this)); | 665 this._profileBeingRecorded.target().cpuProfilerModel.stopRecording(didSt opProfiling.bind(this)); |
| 650 }, | 666 }, |
| 651 | 667 |
| 652 /** | 668 /** |
| 653 * @override | 669 * @override |
| 654 * @param {string} title | 670 * @param {string} title |
| 655 * @return {!WebInspector.ProfileHeader} | 671 * @return {!WebInspector.ProfileHeader} |
| 656 */ | 672 */ |
| 657 createProfileLoadedFromFile: function(title) | 673 createProfileLoadedFromFile: function(title) |
| 658 { | 674 { |
| 659 return new WebInspector.CPUProfileHeader(null, this, title); | 675 return new WebInspector.CPUProfileHeader(null, this, title); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 887 _notifyTempFileReady: function() | 903 _notifyTempFileReady: function() |
| 888 { | 904 { |
| 889 if (this._onTempFileReady) { | 905 if (this._onTempFileReady) { |
| 890 this._onTempFileReady(); | 906 this._onTempFileReady(); |
| 891 this._onTempFileReady = null; | 907 this._onTempFileReady = null; |
| 892 } | 908 } |
| 893 }, | 909 }, |
| 894 | 910 |
| 895 __proto__: WebInspector.ProfileHeader.prototype | 911 __proto__: WebInspector.ProfileHeader.prototype |
| 896 } | 912 } |
| OLD | NEW |