WebInspector.CPUProfileView.prototype = {
/**
+ * @return {?WebInspector.Target}
+ */
+ target: function()
+ {
+ return this._profileHeader.target();
+ },
+
+ /**
* @param {!number} timeLeft
* @param {!number} timeRight
*/
{
if (this._flameChart)
return;
- this._dataProvider = new WebInspector.CPUFlameChartDataProvider(this.profile, this._profileHeader.target());
+ this._dataProvider = new WebInspector.CPUFlameChartDataProvider(this.profile, this._profileHeader.weakTarget());
this._flameChart = new WebInspector.CPUProfileFlameChart(this._dataProvider);
this._flameChart.addEventListener(WebInspector.FlameChart.Events.EntrySelected, this._onEntrySelected.bind(this));
},
{
var entryIndex = event.data;
var node = this._dataProvider._entryNodes[entryIndex];
- if (!node || !node.scriptId)
+ var target = this._profileHeader.target();
+ if (!node || !node.scriptId || !target)
return;
- var script = WebInspector.debuggerModel.scriptForId(node.scriptId)
+ var script = target.debuggerModel.scriptForId(node.scriptId)
if (!script)
return;
- WebInspector.Revealer.reveal(script.rawLocationToUILocation(node.lineNumber));
+ var location = /** @type {!WebInspector.DebuggerModel.Location} */ (script.target().debuggerModel.createRawLocation(script, node.lineNumber, 0));
+ WebInspector.Revealer.reveal(WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location));
},
_changeView: function()
/**
* @constructor
* @extends {WebInspector.ProfileType}
- * @implements {WebInspector.CPUProfilerModel.Delegate}
*/
WebInspector.CPUProfileType = function()
{
this._anonymousConsoleProfileIdToTitle = {};
WebInspector.CPUProfileType.instance = this;
- WebInspector.cpuProfilerModel.setDelegate(this);
+ WebInspector.targetManager.addModelListener(WebInspector.CPUProfilerModel, WebInspector.CPUProfilerModel.EventTypes.ConsoleProfileStarted, this._consoleProfileStarted, this);
+ WebInspector.targetManager.addModelListener(WebInspector.CPUProfilerModel, WebInspector.CPUProfilerModel.EventTypes.ConsoleProfileFinished, this._consoleProfileFinished, this);
}
WebInspector.CPUProfileType.TypeId = "CPU";
},
/**
- * @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 protocolId = /** @type {string} */ (event.data.protocolId);
+ var scriptLocation = /** @type {!WebInspector.DebuggerModel.Location} */ (event.data.scriptLocation);
+ var resolvedTitle = /** @type {string|undefined} */ (event.data.title);
if (!resolvedTitle) {
resolvedTitle = WebInspector.UIString("Profile %s", this._nextAnonymousConsoleProfileNumber++);
- this._anonymousConsoleProfileIdToTitle[id] = resolvedTitle;
+ this._anonymousConsoleProfileIdToTitle[protocolId] = resolvedTitle;
}
this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.Profile, 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") {
+ var protocolId = /** @type {string} */ (event.data.protocolId);
+ var scriptLocation = /** @type {!WebInspector.DebuggerModel.Location} */ (event.data.scriptLocation);
+ var cpuProfile = /** @type {!ProfilerAgent.CPUProfile} */ (event.data.cpuProfile);
+ var resolvedTitle = /** @type {string|undefined} */ (event.data.title);
+ if (typeof resolvedTitle === "undefined") {
resolvedTitle = this._anonymousConsoleProfileIdToTitle[protocolId];
delete this._anonymousConsoleProfileIdToTitle[protocolId];
}
- var target = /** @type {!WebInspector.Target} */ (WebInspector.targetManager.activeTarget());
- var profile = new WebInspector.CPUProfileHeader(target, this, resolvedTitle);
+ var profile = new WebInspector.CPUProfileHeader(scriptLocation.target(), this, resolvedTitle);
profile.setProtocolProfile(cpuProfile);
this.addProfile(profile);
this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.ProfileEnd, scriptLocation, WebInspector.UIString("Profile '%s' finished.", resolvedTitle));
_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,
columnNumber: scriptLocation.columnNumber || 0
}]);
- WebInspector.console.addMessage(message);
- },
-
- /**
- * @return {boolean}
- */
- isRecordingProfile: function()
- {
- return this._recording;
+ target.consoleModel.addMessage(message);
},
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
this.setProfileBeingRecorded(null);
this.dispatchEventToListeners(WebInspector.ProfileType.Events.ProfileComplete, recordedProfile);
}
- ProfilerAgent.stop(didStopProfiling.bind(this));
+ this._profileBeingRecorded.target().cpuProfilerModel.stopRecording(didStopProfiling.bind(this));
},
/**
*/
createProfileLoadedFromFile: function(title)
{
- var target = /** @type {!WebInspector.Target} */ (WebInspector.targetManager.activeTarget());
- return new WebInspector.CPUProfileHeader(target, this, title);
+ return new WebInspector.CPUProfileHeader(null, this, title);
},
/**
* @extends {WebInspector.ProfileHeader}
* @implements {WebInspector.OutputStream}
* @implements {WebInspector.OutputStreamDelegate}
- * @param {!WebInspector.Target} target
+ * @param {?WebInspector.Target} target
* @param {!WebInspector.CPUProfileType} type
* @param {string=} title
*/
WebInspector.CPUProfileHeader = function(target, type, title)
{
- WebInspector.ProfileHeader.call(this, target, type, title || WebInspector.UIString("Profile %d", type._nextProfileUid));
+ WebInspector.ProfileHeader.call(this, target, type, title || WebInspector.UIString("Profile %d", type.nextProfileUid()));
this._tempFile = null;
}
/**
* @param {!WebInspector.ChunkedReader} reader
- * @param {?Event} e
+ * @param {!Event} e
*/
onError: function(reader, e)
{
fileOutputStream.close();
}
if (this._failedToCreateTempFile) {
- WebInspector.messageSink.addErrorMessage("Failed to open temp file with heap snapshot");
+ WebInspector.console.error("Failed to open temp file with heap snapshot");
fileOutputStream.close();
} else if (this._tempFile) {
this._tempFile.read(didRead);