📄 profilespanel.js
字号:
/* * Copyright (C) 2008 Apple Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */const UserInitiatedProfileName = "org.webkit.profiles.user-initiated";WebInspector.ProfilesPanel = function(){ WebInspector.Panel.call(this); this.element.addStyleClass("profiles"); 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."); var panelEnablerButton = WebInspector.UIString("Enable Profiling"); this.panelEnablerView = new WebInspector.PanelEnablerView("profiles", panelEnablerHeading, panelEnablerDisclaimer, panelEnablerButton); this.panelEnablerView.addEventListener("enable clicked", this._enableProfiling, this); this.element.appendChild(this.panelEnablerView.element); this.sidebarElement = document.createElement("div"); this.sidebarElement.id = "profiles-sidebar"; this.sidebarElement.className = "sidebar"; this.element.appendChild(this.sidebarElement); this.sidebarResizeElement = document.createElement("div"); this.sidebarResizeElement.className = "sidebar-resizer-vertical"; this.sidebarResizeElement.addEventListener("mousedown", this._startSidebarDragging.bind(this), false); this.element.appendChild(this.sidebarResizeElement); this.sidebarTreeElement = document.createElement("ol"); this.sidebarTreeElement.className = "sidebar-tree"; this.sidebarElement.appendChild(this.sidebarTreeElement); this.sidebarTree = new TreeOutline(this.sidebarTreeElement); this.profileViews = document.createElement("div"); this.profileViews.id = "profile-views"; this.element.appendChild(this.profileViews); this.enableToggleButton = document.createElement("button"); this.enableToggleButton.className = "enable-toggle-status-bar-item status-bar-item"; this.enableToggleButton.addEventListener("click", this._toggleProfiling.bind(this), false); this.recordButton = document.createElement("button"); this.recordButton.title = WebInspector.UIString("Start profiling."); this.recordButton.id = "record-profile-status-bar-item"; this.recordButton.className = "status-bar-item"; this.recordButton.addEventListener("click", this._recordClicked.bind(this), false); this.recording = false; this.profileViewStatusBarItemsContainer = document.createElement("div"); this.profileViewStatusBarItemsContainer.id = "profile-view-status-bar-items"; this.reset();}WebInspector.ProfilesPanel.prototype = { toolbarItemClass: "profiles", get toolbarItemLabel() { return WebInspector.UIString("Profiles"); }, get statusBarItems() { return [this.enableToggleButton, this.recordButton, this.profileViewStatusBarItemsContainer]; }, show: function() { WebInspector.Panel.prototype.show.call(this); this._updateSidebarWidth(); if (this._shouldPopulateProfiles) this._populateProfiles(); }, populateInterface: function() { if (this.visible) this._populateProfiles(); else this._shouldPopulateProfiles = true; }, profilerWasEnabled: function() { this.reset(); this.populateInterface(); }, profilerWasDisabled: function() { this.reset(); }, 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; } } delete this.currentQuery; this.searchCanceled(); this._profiles = []; this._profilesIdMap = {}; this._profileGroups = {}; this._profileGroupsForLinks = {} this.sidebarTreeElement.removeStyleClass("some-expandable"); this.sidebarTree.removeChildren(); this.profileViews.removeChildren(); this.profileViewStatusBarItemsContainer.removeChildren(); this._updateInterface(); }, handleKeyEvent: function(event) { this.sidebarTree.handleKeyEvent(event); }, addProfile: function(profile) { this._profiles.push(profile); this._profilesIdMap[profile.uid] = profile; var sidebarParent = this.sidebarTree; var small = false; var alternateTitle; if (profile.title.indexOf(UserInitiatedProfileName) !== 0) { if (!(profile.title in this._profileGroups)) this._profileGroups[profile.title] = []; var group = this._profileGroups[profile.title]; group.push(profile); if (group.length === 2) { // Make a group TreeElement now that there are 2 profiles. 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); // Move the first profile to the group. var selected = group[0]._profilesTreeElement.selected; this.sidebarTree.removeChild(group[0]._profilesTreeElement); group._profilesTreeElement.appendChild(group[0]._profilesTreeElement); if (selected) { group[0]._profilesTreeElement.select(); group[0]._profilesTreeElement.reveal(); } group[0]._profilesTreeElement.small = true; group[0]._profilesTreeElement.mainTitle = WebInspector.UIString("Run %d", 1); this.sidebarTreeElement.addStyleClass("some-expandable"); } if (group.length >= 2) { sidebarParent = group._profilesTreeElement; alternateTitle = WebInspector.UIString("Run %d", group.length); small = true; } } var profileTreeElement = new WebInspector.ProfileSidebarTreeElement(profile); profileTreeElement.small = small; if (alternateTitle) profileTreeElement.mainTitle = alternateTitle; profile._profilesTreeElement = profileTreeElement; sidebarParent.appendChild(profileTreeElement); }, showProfile: function(profile) { if (!profile) return; if (this.visibleView) this.visibleView.hide(); var view = this.profileViewForProfile(profile); view.show(this.profileViews); profile._profilesTreeElement.select(true); profile._profilesTreeElement.reveal() this.visibleView = view; this.profileViewStatusBarItemsContainer.removeChildren(); var statusBarItems = view.statusBarItems; for (var i = 0; i < statusBarItems.length; ++i) this.profileViewStatusBarItemsContainer.appendChild(statusBarItems[i]); }, showView: function(view) { // Always use the treeProfile, since the heavy profile might be showing. this.showProfile(view.profile.treeProfile); }, profileViewForProfile: function(profile) { if (!profile) return null; if (!profile._profileView) profile._profileView = new WebInspector.ProfileView(profile); return profile._profileView; }, showProfileById: function(uid) { this.showProfile(this._profilesIdMap[uid]); }, closeVisibleView: function() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -