diff options
Diffstat (limited to 'src/3rdparty/webkit/WebCore/inspector/front-end/ProfilesPanel.js')
-rw-r--r-- | src/3rdparty/webkit/WebCore/inspector/front-end/ProfilesPanel.js | 228 |
1 files changed, 133 insertions, 95 deletions
diff --git a/src/3rdparty/webkit/WebCore/inspector/front-end/ProfilesPanel.js b/src/3rdparty/webkit/WebCore/inspector/front-end/ProfilesPanel.js index 3bd4464..55e286e 100644 --- a/src/3rdparty/webkit/WebCore/inspector/front-end/ProfilesPanel.js +++ b/src/3rdparty/webkit/WebCore/inspector/front-end/ProfilesPanel.js @@ -25,11 +25,52 @@ const UserInitiatedProfileName = "org.webkit.profiles.user-initiated"; +WebInspector.ProfileType = function(id, name) +{ + this._id = id; + this._name = name; +} + +WebInspector.ProfileType.URLRegExp = /webkit-profile:\/\/(.+)\/(.+)#([0-9]+)/; + +WebInspector.ProfileType.prototype = { + get buttonTooltip() + { + return ""; + }, + + get buttonStyle() + { + return undefined; + }, + + get buttonCaption() + { + return this.name; + }, + + get id() + { + return this._id; + }, + + get name() + { + return this._name; + }, + + buttonClicked: function() + { + } +} + WebInspector.ProfilesPanel = function() { WebInspector.Panel.call(this); this.element.addStyleClass("profiles"); + this._profileTypesByIdMap = {}; + this._profileTypeButtonsByIdMap = {}; var panelEnablerHeading = WebInspector.UIString("You need to enable profiling before you can use the Profiles panel."); var panelEnablerDisclaimer = WebInspector.UIString("Enabling profiling will make scripts run slower."); @@ -52,19 +93,8 @@ WebInspector.ProfilesPanel = function() this.sidebarTreeElement = document.createElement("ol"); this.sidebarTreeElement.className = "sidebar-tree"; this.sidebarElement.appendChild(this.sidebarTreeElement); - this.sidebarTree = new TreeOutline(this.sidebarTreeElement); - this.profilesListTreeElement = new WebInspector.SidebarSectionTreeElement(WebInspector.UIString("CPU PROFILES"), null, true); - this.sidebarTree.appendChild(this.profilesListTreeElement); - this.profilesListTreeElement.expand(); - - this.snapshotsListTreeElement = new WebInspector.SidebarSectionTreeElement(WebInspector.UIString("HEAP SNAPSHOTS"), null, true); - if (Preferences.heapProfilerPresent) { - this.sidebarTree.appendChild(this.snapshotsListTreeElement); - this.snapshotsListTreeElement.expand(); - } - this.profileViews = document.createElement("div"); this.profileViews.id = "profile-views"; this.element.appendChild(this.profileViews); @@ -72,18 +102,10 @@ WebInspector.ProfilesPanel = function() this.enableToggleButton = new WebInspector.StatusBarButton("", "enable-toggle-status-bar-item"); this.enableToggleButton.addEventListener("click", this._toggleProfiling.bind(this), false); - this.recordButton = new WebInspector.StatusBarButton(WebInspector.UIString("Start profiling."), "record-profile-status-bar-item"); - this.recordButton.addEventListener("click", this._recordClicked.bind(this), false); - - this.recording = false; - - this.snapshotButton = new WebInspector.StatusBarButton(WebInspector.UIString("Take heap snapshot."), "heap-snapshot-status-bar-item"); - this.snapshotButton.visible = Preferences.heapProfilerPresent; - this.snapshotButton.addEventListener("click", this._snapshotClicked.bind(this), false); - this.profileViewStatusBarItemsContainer = document.createElement("div"); this.profileViewStatusBarItemsContainer.id = "profile-view-status-bar-items"; + this._profiles = []; this.reset(); } @@ -97,7 +119,25 @@ WebInspector.ProfilesPanel.prototype = { get statusBarItems() { - return [this.enableToggleButton.element, this.recordButton.element, this.snapshotButton.element, this.profileViewStatusBarItemsContainer]; + function clickHandler(profileType, buttonElement) + { + profileType.buttonClicked.call(profileType); + this.updateProfileTypeButtons(); + } + + var items = [this.enableToggleButton.element]; + // FIXME: Generate a single "combo-button". + for (var typeId in this._profileTypesByIdMap) { + var profileType = this.getProfileType(typeId); + if (profileType.buttonStyle) { + var button = new WebInspector.StatusBarButton(profileType.buttonTooltip, profileType.buttonStyle, profileType.buttonCaption); + this._profileTypeButtonsByIdMap[typeId] = button.element; + button.element.addEventListener("click", clickHandler.bind(this, profileType, button.element), false); + items.push(button.element); + } + } + items.push(this.profileViewStatusBarItemsContainer); + return items; }, show: function() @@ -129,13 +169,8 @@ WebInspector.ProfilesPanel.prototype = { reset: function() { - if (this._profiles) { - var profiledLength = this._profiles.length; - for (var i = 0; i < profiledLength; ++i) { - var profile = this._profiles[i]; - delete profile._profileView; - } - } + for (var i = 0; i < this._profiles.length; ++i) + delete this._profiles[i]._profileView; delete this.currentQuery; this.searchCanceled(); @@ -147,8 +182,9 @@ WebInspector.ProfilesPanel.prototype = { this.sidebarTreeElement.removeStyleClass("some-expandable"); - this.profilesListTreeElement.removeChildren(); - this.snapshotsListTreeElement.removeChildren(); + for (var typeId in this._profileTypesByIdMap) + this.getProfileType(typeId).treeElement.removeChildren(); + this.profileViews.removeChildren(); this.profileViewStatusBarItemsContainer.removeChildren(); @@ -161,20 +197,34 @@ WebInspector.ProfilesPanel.prototype = { this.sidebarTree.handleKeyEvent(event); }, - addProfile: function(profile) + registerProfileType: function(profileType) { - this._profiles.push(profile); - this._profilesIdMap[profile.uid] = profile; + this._profileTypesByIdMap[profileType.id] = profileType; + profileType.treeElement = new WebInspector.SidebarSectionTreeElement(profileType.name, null, true); + this.sidebarTree.appendChild(profileType.treeElement); + profileType.treeElement.expand(); + }, + + _makeKey: function(text, profileTypeId) + { + return escape(text) + '/' + escape(profileTypeId); + }, - var sidebarParent = this.profilesListTreeElement; + addProfileHeader: function(typeId, profile) + { + var sidebarParent = this.getProfileType(typeId).treeElement; var small = false; var alternateTitle; + this._profiles.push(profile); + this._profilesIdMap[this._makeKey(profile.uid, typeId)] = profile; + if (profile.title.indexOf(UserInitiatedProfileName) !== 0) { - if (!(profile.title in this._profileGroups)) - this._profileGroups[profile.title] = []; + var profileTitleKey = this._makeKey(profile.title, typeId); + if (!(profileTitleKey in this._profileGroups)) + this._profileGroups[profileTitleKey] = []; - var group = this._profileGroups[profile.title]; + var group = this._profileGroups[profileTitleKey]; group.push(profile); if (group.length === 2) { @@ -182,12 +232,12 @@ WebInspector.ProfilesPanel.prototype = { group._profilesTreeElement = new WebInspector.ProfileGroupSidebarTreeElement(profile.title); // Insert at the same index for the first profile of the group. - var index = this.sidebarTree.children.indexOf(group[0]._profilesTreeElement); - this.sidebarTree.insertChild(group._profilesTreeElement, index); + var index = sidebarParent.children.indexOf(group[0]._profilesTreeElement); + sidebarParent.insertChild(group._profilesTreeElement, index); // Move the first profile to the group. var selected = group[0]._profilesTreeElement.selected; - this.sidebarTree.removeChild(group[0]._profilesTreeElement); + sidebarParent.removeChild(group[0]._profilesTreeElement); group._profilesTreeElement.appendChild(group[0]._profilesTreeElement); if (selected) { group[0]._profilesTreeElement.select(); @@ -214,6 +264,8 @@ WebInspector.ProfilesPanel.prototype = { profile._profilesTreeElement = profileTreeElement; sidebarParent.appendChild(profileTreeElement); + if (!this.visibleView) + this.showProfile(profile); }, showProfile: function(profile) @@ -224,7 +276,7 @@ WebInspector.ProfilesPanel.prototype = { if (this.visibleView) this.visibleView.hide(); - var view = this.profileViewForProfile(profile); + var view = profile.viewForProfile(); view.show(this.profileViews); @@ -245,18 +297,28 @@ WebInspector.ProfilesPanel.prototype = { this.showProfile(view.profile); }, - profileViewForProfile: function(profile) + getProfileType: function(typeId) { - if (!profile) - return null; - if (!profile._profileView) - profile._profileView = new WebInspector.ProfileView(profile); - return profile._profileView; + return this._profileTypesByIdMap[typeId]; }, - showProfileById: function(uid) + showProfileForURL: function(url) { - this.showProfile(this._profilesIdMap[uid]); + var match = url.match(WebInspector.ProfileType.URLRegExp); + if (!match) + return; + this.showProfile(this._profilesIdMap[this._makeKey(match[3], match[1])]); + }, + + updateProfileTypeButtons: function() + { + for (var typeId in this._profileTypeButtonsByIdMap) { + var buttonElement = this._profileTypeButtonsByIdMap[typeId]; + var profileType = this.getProfileType(typeId); + buttonElement.className = profileType.buttonStyle; + buttonElement.title = profileType.buttonTooltip; + // FIXME: Apply profileType.buttonCaption once captions are added to button controls. + } }, closeVisibleView: function() @@ -266,16 +328,17 @@ WebInspector.ProfilesPanel.prototype = { delete this.visibleView; }, - displayTitleForProfileLink: function(title) + displayTitleForProfileLink: function(title, typeId) { title = unescape(title); if (title.indexOf(UserInitiatedProfileName) === 0) { title = WebInspector.UIString("Profile %d", title.substring(UserInitiatedProfileName.length + 1)); } else { - if (!(title in this._profileGroupsForLinks)) - this._profileGroupsForLinks[title] = 0; + var titleKey = this._makeKey(title, typeId); + if (!(titleKey in this._profileGroupsForLinks)) + this._profileGroupsForLinks[titleKey] = 0; - groupNumber = ++this._profileGroupsForLinks[title]; + groupNumber = ++this._profileGroupsForLinks[titleKey]; if (groupNumber > 2) // The title is used in the console message announcing that a profile has started so it gets @@ -296,7 +359,7 @@ WebInspector.ProfilesPanel.prototype = { var profilesLength = this._profiles.length; for (var i = 0; i < profilesLength; ++i) { - var view = this.profileViewForProfile(this._profiles[i]); + var view = this._profiles[i].viewForProfile(); if (!view.performSearch || view === visibleView) continue; views.push(view); @@ -323,19 +386,6 @@ WebInspector.ProfilesPanel.prototype = { } }, - setRecordingProfile: function(isProfiling) - { - this.recording = isProfiling; - - if (isProfiling) { - this.recordButton.toggled = true; - this.recordButton.title = WebInspector.UIString("Stop profiling."); - } else { - this.recordButton.toggled = false; - this.recordButton.title = WebInspector.UIString("Start profiling."); - } - }, - resize: function() { var visibleView = this.visibleView; @@ -345,39 +395,24 @@ WebInspector.ProfilesPanel.prototype = { _updateInterface: function() { + // FIXME: Replace ProfileType-specific button visibility changes by a single ProfileType-agnostic "combo-button" visibility change. if (InspectorController.profilerEnabled()) { this.enableToggleButton.title = WebInspector.UIString("Profiling enabled. Click to disable."); this.enableToggleButton.toggled = true; - this.recordButton.visible = true; - if (Preferences.heapProfilerPresent) - this.snapshotButton.visible = true; + for (var typeId in this._profileTypeButtonsByIdMap) + this._profileTypeButtonsByIdMap[typeId].removeStyleClass("hidden"); this.profileViewStatusBarItemsContainer.removeStyleClass("hidden"); this.panelEnablerView.visible = false; } else { this.enableToggleButton.title = WebInspector.UIString("Profiling disabled. Click to enable."); this.enableToggleButton.toggled = false; - this.recordButton.visible = false; - this.snapshotButton.visible = false; + for (var typeId in this._profileTypeButtonsByIdMap) + this._profileTypeButtonsByIdMap[typeId].addStyleClass("hidden"); this.profileViewStatusBarItemsContainer.addStyleClass("hidden"); this.panelEnablerView.visible = true; } }, - _recordClicked: function() - { - this.recording = !this.recording; - - if (this.recording) - InspectorController.startProfiling(); - else - InspectorController.stopProfiling(); - }, - - _snapshotClicked: function() - { - InspectorController.takeHeapSnapshot(); - }, - _enableProfiling: function() { if (InspectorController.profilerEnabled()) @@ -397,19 +432,19 @@ WebInspector.ProfilesPanel.prototype = { { // FIXME: This code needs to be adjusted when more profiling types are added. // Currently defaults to CPU profiles. - var cpuProfiles = this.sidebarTree.children[0]; + var cpuProfiles = this.getProfileType(WebInspector.CPUProfileType.TypeId).treeElement; if (cpuProfiles.children.length) return; - var profiles = InspectorController.profiles(); - var profilesLength = profiles.length; - for (var i = 0; i < profilesLength; ++i) { - var profile = profiles[i]; - this.addProfile(profile); + function populateCallback(profileHeaders) { + profileHeaders.sort(function(a, b) { return a.uid - b.uid; }); + var profileHeadersLength = profileHeaders.length; + for (var i = 0; i < profileHeadersLength; ++i) + WebInspector.addProfileHeader(profileHeaders[i]); } - if (cpuProfiles.children[0]) - cpuProfiles.children[0].select(); + var callId = WebInspector.Callback.wrap(populateCallback); + InspectorController.getProfileHeaders(callId); delete this._shouldPopulateProfiles; }, @@ -535,3 +570,6 @@ WebInspector.ProfileGroupSidebarTreeElement.prototype = { } WebInspector.ProfileGroupSidebarTreeElement.prototype.__proto__ = WebInspector.SidebarTreeElement.prototype; + +WebInspector.didGetProfileHeaders = WebInspector.Callback.processCallback; +WebInspector.didGetProfile = WebInspector.Callback.processCallback; |