{
WebInspector.View.call(this);
- this.element.classList.add("profile-view");
+ this.element.classList.add("cpu-profile-view");
this.showSelfTimeAsPercent = WebInspector.settings.createSetting("cpuProfilerShowSelfTimeAsPercent", true);
this.showTotalTimeAsPercent = WebInspector.settings.createSetting("cpuProfilerShowTotalTimeAsPercent", true);
var script = WebInspector.debuggerModel.scriptForId(node.scriptId)
if (!script)
return;
- var uiLocation = script.rawLocationToUILocation(node.lineNumber);
- if (uiLocation)
- uiLocation.reveal();
+ WebInspector.Revealer.reveal(script.rawLocationToUILocation(node.lineNumber));
},
_changeView: function()
{
WebInspector.ProfileType.call(this, WebInspector.CPUProfileType.TypeId, WebInspector.UIString("Collect JavaScript CPU Profile"));
this._recording = false;
- this._nextProfileId = 1;
this._nextAnonymousConsoleProfileNumber = 1;
this._anonymousConsoleProfileIdToTitle = {};
delete this._anonymousConsoleProfileIdToTitle[protocolId];
}
- var id = this._nextProfileId++;
- var profile = new WebInspector.CPUProfileHeader(this, resolvedTitle, id);
+ var profile = new WebInspector.CPUProfileHeader(this, resolvedTitle);
profile.setProtocolProfile(cpuProfile);
this.addProfile(profile);
var a = messageElement.createChild("span", "link");
a.title = resolvedTitle;
a.textContent = resolvedTitle;
- a.addEventListener("click", onClick.bind(this), true);
- function onClick(event)
+ a.addEventListener("click", onClick.bind(this, profile.uid), true);
+ function onClick(profileUid, event)
{
- WebInspector.showPanel("profiles").showProfile(WebInspector.CPUProfileType.TypeId, id);
+ var profile = WebInspector.ProfileTypeRegistry.instance.cpuProfileType.getProfile(profileUid);
+ if (profile)
+ WebInspector.showPanel("profiles").showProfile(profile);
}
messageElement.createTextChild("' finished.");
{
if (this._profileBeingRecorded)
return;
- var id = this._nextProfileId++;
- this._profileBeingRecorded = new WebInspector.CPUProfileHeader(this, WebInspector.UIString("Recording\u2026"), id);
+ this._profileBeingRecorded = new WebInspector.CPUProfileHeader(this);
this.addProfile(this._profileBeingRecorded);
-
+ this._profileBeingRecorded.updateStatus(WebInspector.UIString("Recording\u2026"));
this._recording = true;
WebInspector.cpuProfilerModel.setRecording(true);
WebInspector.userMetrics.ProfilesCPUProfileTaken.record();
if (!this._profileBeingRecorded)
return;
this._profileBeingRecorded.setProtocolProfile(profile);
-
- var title = WebInspector.UIString("Profile %d", this._profileBeingRecorded.uid);
- this._profileBeingRecorded.title = title;
- this._profileBeingRecorded.sidebarElement.mainTitle = title;
+ this._profileBeingRecorded.updateStatus("");
var recordedProfile = this._profileBeingRecorded;
this._profileBeingRecorded = null;
- WebInspector.panels.profiles._showProfile(recordedProfile);
+ WebInspector.panels.profiles.showProfile(recordedProfile);
}
ProfilerAgent.stop(didStopProfiling.bind(this));
},
/**
* @override
*/
- removeProfile: function(profile)
+ profileBeingRecordedRemoved: function()
{
- if (this._profileBeingRecorded === profile)
- this.stopRecordingProfile();
- WebInspector.ProfileType.prototype.removeProfile.call(this, profile);
+ this.stopRecordingProfile();
},
__proto__: WebInspector.ProfileType.prototype
* @implements {WebInspector.OutputStream}
* @implements {WebInspector.OutputStreamDelegate}
* @param {!WebInspector.CPUProfileType} type
- * @param {string} title
- * @param {number=} uid
+ * @param {string=} title
*/
-WebInspector.CPUProfileHeader = function(type, title, uid)
+WebInspector.CPUProfileHeader = function(type, title)
{
- WebInspector.ProfileHeader.call(this, type, title, uid);
+ WebInspector.ProfileHeader.call(this, type, title || WebInspector.UIString("Profile %d", type._nextProfileUid));
this._tempFile = null;
}
onTransferStarted: function()
{
this._jsonifiedProfile = "";
- this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026 %s", Number.bytesToString(this._jsonifiedProfile.length));
+ this.updateStatus(WebInspector.UIString("Loading\u2026 %s", Number.bytesToString(this._jsonifiedProfile.length)));
},
/**
*/
onChunkTransferred: function(reader)
{
- this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026 %d\%", Number.bytesToString(this._jsonifiedProfile.length));
+ this.updateStatus(WebInspector.UIString("Loading\u2026 %d\%", Number.bytesToString(this._jsonifiedProfile.length)));
},
onTransferFinished: function()
{
- this.sidebarElement.subtitle = WebInspector.UIString("Parsing\u2026");
+ this.updateStatus(WebInspector.UIString("Parsing\u2026"));
this._profile = JSON.parse(this._jsonifiedProfile);
this._jsonifiedProfile = null;
- this.sidebarElement.subtitle = WebInspector.UIString("Loaded");
+ this.updateStatus(WebInspector.UIString("Loaded"));
if (this._profileType._profileBeingRecorded === this)
this._profileType._profileBeingRecorded = null;
*/
onError: function(reader, e)
{
+ var subtitle;
switch(e.target.error.code) {
case e.target.error.NOT_FOUND_ERR:
- this.sidebarElement.subtitle = WebInspector.UIString("'%s' not found.", reader.fileName());
- break;
+ subtitle = WebInspector.UIString("'%s' not found.", reader.fileName());
+ break;
case e.target.error.NOT_READABLE_ERR:
- this.sidebarElement.subtitle = WebInspector.UIString("'%s' is not readable", reader.fileName());
- break;
- case e.target.error.ABORT_ERR:
+ subtitle = WebInspector.UIString("'%s' is not readable", reader.fileName());
break;
+ case e.target.error.ABORT_ERR:
+ return;
default:
- this.sidebarElement.subtitle = WebInspector.UIString("'%s' error %d", reader.fileName(), e.target.error.code);
+ subtitle = WebInspector.UIString("'%s' error %d", reader.fileName(), e.target.error.code);
}
+ this.updateStatus(subtitle);
},
/**
/**
* @override
- * @param {!WebInspector.ProfilesPanel} profilesPanel
* @return {!WebInspector.CPUProfileView}
*/
- createView: function(profilesPanel)
+ createView: function()
{
return new WebInspector.CPUProfileView(this);
},
*/
canSaveToFile: function()
{
- return !!this._tempFile;
+ return !this.fromFile() && this._protocolProfile;
},
saveToFile: function()
else
fileOutputStream.close();
}
- this._tempFile.read(didRead.bind(this));
+ if (this._failedToCreateTempFile) {
+ WebInspector.log("Failed to open temp file with heap snapshot",
+ WebInspector.ConsoleMessage.MessageLevel.Error);
+ fileOutputStream.close();
+ } else if (this._tempFile) {
+ this._tempFile.read(didRead.bind(this));
+ } else {
+ this._onTempFileReady = onOpenForSave.bind(this, accepted);
+ }
}
this._fileName = this._fileName || "CPU-" + new Date().toISO8601Compact() + this._profileType.fileExtension();
fileOutputStream.open(this._fileName, onOpenForSave.bind(this));
*/
loadFromFile: function(file)
{
- this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026");
- this.sidebarElement.wait = true;
-
+ this.updateStatus(WebInspector.UIString("Loading\u2026"), true);
var fileReader = new WebInspector.ChunkedFileReader(file, 10000000, this);
fileReader.start(this);
},
{
this._protocolProfile = cpuProfile;
this._saveProfileDataToTempFile(cpuProfile);
+ if (this.canSaveToFile())
+ this.dispatchEventToListeners(WebInspector.ProfileHeader.Events.ProfileReceived);
},
/**
_writeToTempFile: function(tempFile, serializedData)
{
this._tempFile = tempFile;
- if (tempFile)
- tempFile.write(serializedData, tempFile.finishWriting.bind(tempFile));
+ if (!tempFile) {
+ this._failedToCreateTempFile = true;
+ this._notifyTempFileReady();
+ return;
+ }
+ /**
+ * @param {boolean} success
+ * @this {WebInspector.CPUProfileHeader}
+ */
+ function didWriteToTempFile(success)
+ {
+ if (!success)
+ this._failedToCreateTempFile = true;
+ tempFile.finishWriting();
+ this._notifyTempFileReady();
+ }
+ tempFile.write(serializedData, didWriteToTempFile.bind(this));
+ },
+
+ _notifyTempFileReady: function()
+ {
+ if (this._onTempFileReady) {
+ this._onTempFileReady();
+ this._onTempFileReady = null;
+ }
},
__proto__: WebInspector.ProfileHeader.prototype
}
/**
+ * @return {!WebInspector.FlameChart.ColorGenerator}
+ */
+WebInspector.CPUProfileView.colorGenerator = function()
+{
+ if (!WebInspector.CPUProfileView._colorGenerator) {
+ var colorGenerator = new WebInspector.FlameChart.ColorGenerator();
+ colorGenerator.colorPairForID("(idle)::0", 50);
+ colorGenerator.colorPairForID("(program)::0", 50);
+ colorGenerator.colorPairForID("(garbage collector)::0", 50);
+ WebInspector.CPUProfileView._colorGenerator = colorGenerator;
+ }
+ return WebInspector.CPUProfileView._colorGenerator;
+}
+
+/**
* @constructor
* @implements {WebInspector.FlameChartDataProvider}
*/
{
WebInspector.FlameChartDataProvider.call(this);
this._cpuProfileView = cpuProfileView;
+ this._colorGenerator = WebInspector.CPUProfileView.colorGenerator();
}
WebInspector.CPUFlameChartDataProvider.prototype = {
/**
- * @param {!WebInspector.FlameChart.ColorGenerator} colorGenerator
- * @return {!Object}
+ * @return {?WebInspector.FlameChart.TimelineData}
+ */
+ timelineData: function()
+ {
+ return this._timelineData || this._calculateTimelineData();
+ },
+
+ /**
+ * @return {!WebInspector.FlameChart.ColorGenerator}
*/
- timelineData: function(colorGenerator)
+ colorGenerator: function()
{
- return this._timelineData || this._calculateTimelineData(colorGenerator);
+ return this._colorGenerator;
},
/**
- * @param {!WebInspector.FlameChart.ColorGenerator} colorGenerator
- * @return {?Object}
+ * @return {?WebInspector.FlameChart.TimelineData}
*/
- _calculateTimelineData: function(colorGenerator)
+ _calculateTimelineData: function()
{
if (!this._cpuProfileView.profileHead)
return null;
continue;
}
+ var colorGenerator = this._colorGenerator;
while (node) {
- var colorPair = colorGenerator._colorPairForID(node.functionName + ":" + node.url + ":" + node.lineNumber);
+ var colorPair = colorGenerator.colorPairForID(node.functionName + ":" + node.url + ":" + node.lineNumber);
var indexesForColor = colorEntryIndexes[colorPair.index];
if (!indexesForColor)
indexesForColor = colorEntryIndexes[colorPair.index] = [];
entryDeoptFlags: entryDeoptFlags
};
- return this._timelineData;
+ return /** @type {!WebInspector.FlameChart.TimelineData} */ (this._timelineData);
},
/**