Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1762)

Unified Diff: Source/devtools/front_end/profiler/CPUProfileView.js

Issue 360053003: DevTools: Basic support of multiple targets for CPU profiler (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Migrate to events Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/devtools/front_end/sdk/CPUProfilerModel.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/profiler/CPUProfileView.js
diff --git a/Source/devtools/front_end/profiler/CPUProfileView.js b/Source/devtools/front_end/profiler/CPUProfileView.js
index 448328e5d46a11383abe14d72201a4cf8a0ea9d6..5eea907cf79801abcf159670f0943ba50266e123 100644
--- a/Source/devtools/front_end/profiler/CPUProfileView.js
+++ b/Source/devtools/front_end/profiler/CPUProfileView.js
@@ -73,7 +73,7 @@ WebInspector.CPUProfileView = function(profileHeader)
this.resetButton.addEventListener("click", this._resetClicked, this);
this._statusBarButtonsElement.appendChild(this.resetButton.element);
- this._profileHeader = profileHeader;
+ this._target = profileHeader.target();
this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.DefaultFormatter(30));
this.profile = new WebInspector.CPUProfileDataModel(profileHeader._profile || profileHeader.protocolProfile());
@@ -352,7 +352,7 @@ WebInspector.CPUProfileView.prototype = {
{
if (this._flameChart)
return;
- this._dataProvider = new WebInspector.CPUFlameChartDataProvider(this.profile, this._profileHeader.target());
+ this._dataProvider = new WebInspector.CPUFlameChartDataProvider(this.profile, this._target);
this._flameChart = new WebInspector.CPUProfileFlameChart(this._dataProvider);
this._flameChart.addEventListener(WebInspector.FlameChart.Events.EntrySelected, this._onEntrySelected.bind(this));
},
@@ -364,9 +364,9 @@ WebInspector.CPUProfileView.prototype = {
{
var entryIndex = event.data;
var node = this._dataProvider._entryNodes[entryIndex];
- if (!node || !node.scriptId)
+ if (!node || !node.scriptId || !this._target)
return;
- var script = WebInspector.debuggerModel.scriptForId(node.scriptId)
+ var script = this._target.debuggerModel.scriptForId(node.scriptId)
if (!script)
return;
WebInspector.Revealer.reveal(script.rawLocationToUILocation(node.lineNumber));
@@ -481,7 +481,7 @@ WebInspector.CPUProfileView.prototype = {
/**
* @constructor
* @extends {WebInspector.ProfileType}
- * @implements {WebInspector.CPUProfilerModel.Delegate}
+ * @implements {WebInspector.TargetManager.Observer}
*/
WebInspector.CPUProfileType = function()
{
@@ -492,13 +492,31 @@ WebInspector.CPUProfileType = function()
this._anonymousConsoleProfileIdToTitle = {};
WebInspector.CPUProfileType.instance = this;
- WebInspector.cpuProfilerModel.setDelegate(this);
+ WebInspector.targetManager.observeTargets(this);
}
WebInspector.CPUProfileType.TypeId = "CPU";
WebInspector.CPUProfileType.prototype = {
/**
+ * @param {!WebInspector.Target} target
+ */
+ targetAdded: function(target)
+ {
+ target.cpuProfilerModel.addEventListener(WebInspector.CPUProfilerModel.EventTypes.ConsoleProfileStarted, this._consoleProfileStarted, this);
+ target.cpuProfilerModel.addEventListener(WebInspector.CPUProfilerModel.EventTypes.ConsoleProfileFinished, this._consoleProfileFinished, this);
+ },
+
+ /**
+ * @param {!WebInspector.Target} target
+ */
+ targetRemoved: function(target)
+ {
+ target.cpuProfilerModel.removeEventListener(WebInspector.CPUProfilerModel.EventTypes.ConsoleProfileStarted, this._consoleProfileStarted, this);
+ target.cpuProfilerModel.removeEventListener(WebInspector.CPUProfilerModel.EventTypes.ConsoleProfileFinished, this._consoleProfileFinished, this);
+ },
+
+ /**
* @override
* @return {string}
*/
@@ -538,39 +556,35 @@ WebInspector.CPUProfileType.prototype = {
},
/**
- * @param {string} id
- * @param {!WebInspector.DebuggerModel.Location} scriptLocation
- * @param {string=} title
+ * @param {!WebInspector.Event} event
*/
- consoleProfileStarted: function(id, scriptLocation, title)
+ _consoleProfileStarted: function(event)
{
- var resolvedTitle = title;
+ var data = /** @type {{protocolId: string, scriptLocation: !WebInspector.DebuggerModel.Location, title: (string|undefined)}} */ (event.data);
+ var resolvedTitle = data.title;
if (!resolvedTitle) {
resolvedTitle = WebInspector.UIString("Profile %s", this._nextAnonymousConsoleProfileNumber++);
- this._anonymousConsoleProfileIdToTitle[id] = resolvedTitle;
+ this._anonymousConsoleProfileIdToTitle[data.protocolId] = resolvedTitle;
}
- this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.Profile, scriptLocation, WebInspector.UIString("Profile '%s' started.", resolvedTitle));
+ this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.Profile, data.scriptLocation, WebInspector.UIString("Profile '%s' started.", resolvedTitle));
},
/**
- * @param {string} protocolId
- * @param {!WebInspector.DebuggerModel.Location} scriptLocation
- * @param {!ProfilerAgent.CPUProfile} cpuProfile
- * @param {string=} title
+ * @param {!WebInspector.Event} event
*/
- consoleProfileFinished: function(protocolId, scriptLocation, cpuProfile, title)
+ _consoleProfileFinished: function(event)
{
- var resolvedTitle = title;
- if (typeof title === "undefined") {
- resolvedTitle = this._anonymousConsoleProfileIdToTitle[protocolId];
- delete this._anonymousConsoleProfileIdToTitle[protocolId];
+ var data = /** @type {{protocolId: string, scriptLocation: !WebInspector.DebuggerModel.Location, cpuProfile: !ProfilerAgent.CPUProfile, title: (string|undefined)}} */ (event.data);
vsevik 2014/07/02 09:08:49 Consider casting each field separately instead.
sergeyv 2014/07/02 12:45:42 Done.
+ var resolvedTitle = data.title;
+ if (typeof data.title === "undefined") {
+ resolvedTitle = this._anonymousConsoleProfileIdToTitle[data.protocolId];
+ delete this._anonymousConsoleProfileIdToTitle[data.protocolId];
}
- var target = /** @type {!WebInspector.Target} */ (WebInspector.targetManager.activeTarget());
- var profile = new WebInspector.CPUProfileHeader(target, this, resolvedTitle);
- profile.setProtocolProfile(cpuProfile);
+ var profile = new WebInspector.CPUProfileHeader(data.scriptLocation.target(), this, resolvedTitle);
+ profile.setProtocolProfile(data.cpuProfile);
this.addProfile(profile);
- this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.ProfileEnd, scriptLocation, WebInspector.UIString("Profile '%s' finished.", resolvedTitle));
+ this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.ProfileEnd, data.scriptLocation, WebInspector.UIString("Profile '%s' finished.", resolvedTitle));
},
/**
@@ -581,8 +595,9 @@ WebInspector.CPUProfileType.prototype = {
_addMessageToConsole: function(type, scriptLocation, messageText)
{
var script = scriptLocation.script();
+ var target = scriptLocation.target();
var message = new WebInspector.ConsoleMessage(
- WebInspector.console.target(),
+ target,
WebInspector.ConsoleMessage.MessageSource.ConsoleAPI,
WebInspector.ConsoleMessage.MessageLevel.Debug,
messageText,
@@ -600,7 +615,7 @@ WebInspector.CPUProfileType.prototype = {
columnNumber: scriptLocation.columnNumber || 0
}]);
- WebInspector.console.addMessage(message);
+ target.consoleModel.addMessage(message);
},
/**
@@ -613,23 +628,22 @@ WebInspector.CPUProfileType.prototype = {
startRecordingProfile: function()
{
- if (this._profileBeingRecorded)
+ var target = WebInspector.context.flavor(WebInspector.Target);
+ if (this._profileBeingRecorded || !target)
return;
- var target = /** @type {!WebInspector.Target} */ (WebInspector.targetManager.activeTarget());
var profile = new WebInspector.CPUProfileHeader(target, this);
this.setProfileBeingRecorded(profile);
this.addProfile(profile);
profile.updateStatus(WebInspector.UIString("Recording\u2026"));
this._recording = true;
- WebInspector.cpuProfilerModel.setRecording(true);
- WebInspector.userMetrics.ProfilesCPUProfileTaken.record();
- ProfilerAgent.start();
+ target.cpuProfilerModel.startRecording();
},
stopRecordingProfile: function()
{
this._recording = false;
- WebInspector.cpuProfilerModel.setRecording(false);
+ if (!this._profileBeingRecorded || !this._profileBeingRecorded.target())
+ return;
/**
* @param {?string} error
@@ -646,7 +660,7 @@ WebInspector.CPUProfileType.prototype = {
this.setProfileBeingRecorded(null);
this.dispatchEventToListeners(WebInspector.ProfileType.Events.ProfileComplete, recordedProfile);
}
- ProfilerAgent.stop(didStopProfiling.bind(this));
+ this._profileBeingRecorded.target().cpuProfilerModel.stopRecording(didStopProfiling.bind(this));
},
/**
« no previous file with comments | « no previous file | Source/devtools/front_end/sdk/CPUProfilerModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698