1/* 2 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following disclaimer 13 * in the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. 20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29/** 30 * @constructor 31 * @extends {WebInspector.PanelDescriptor} 32 */ 33WebInspector.ProfilesPanelDescriptor = function() 34{ 35 WebInspector.PanelDescriptor.call(this, "profiles", WebInspector.UIString("Profiles"), "ProfilesPanel", "ProfilesPanel.js"); 36} 37 38WebInspector.ProfilesPanelDescriptor.prototype = { 39 registerShortcuts: function() 40 { 41 var section = WebInspector.shortcutsScreen.section(WebInspector.UIString("Profiles Panel")); 42 section.addAlternateKeys(WebInspector.ProfilesPanelDescriptor.ShortcutKeys.StartStopRecording, WebInspector.UIString("Start/stop recording")); 43 }, 44 45 __proto__: WebInspector.PanelDescriptor.prototype 46} 47 48WebInspector.ProfilesPanelDescriptor.ShortcutKeys = { 49 StartStopRecording: [ 50 WebInspector.KeyboardShortcut.makeDescriptor("e", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta) 51 ] 52} 53 54WebInspector.ProfilesPanelDescriptor.ProfileURLRegExp = /webkit-profile:\/\/(.+)\/(.+)/; 55 56/** @interface */ 57WebInspector.CPUProfilerModelDelegate = function() {}; 58 59WebInspector.CPUProfilerModelDelegate.prototype = { 60 /** 61 * @param {string} protocolId 62 * @param {!DebuggerAgent.Location} scriptLocation 63 * @param {string=} title 64 */ 65 consoleProfile: function(protocolId, scriptLocation, title) {}, 66 67 /** 68 * @param {string} protocolId 69 * @param {!DebuggerAgent.Location} scriptLocation 70 * @param {!ProfilerAgent.CPUProfile} cpuProfile 71 * @param {string=} title 72 */ 73 consoleProfileEnd: function(protocolId, scriptLocation, cpuProfile, title) {}, 74 75 resetProfiles: function() {} 76} 77 78/** 79 * @constructor 80 * @extends {WebInspector.Object} 81 * @implements {ProfilerAgent.Dispatcher} 82 */ 83WebInspector.CPUProfilerModel = function() 84{ 85 /** @type {?WebInspector.CPUProfilerModelDelegate} */ 86 this._delegate = null; 87 this._isRecording = false; 88 InspectorBackend.registerProfilerDispatcher(this); 89 ProfilerAgent.enable(); 90} 91 92WebInspector.CPUProfilerModel.EventTypes = { 93 ProfileStarted: "profile-started", 94 ProfileStopped: "profile-stopped" 95}; 96 97WebInspector.CPUProfilerModel.prototype = { 98 /** 99 * @param {!WebInspector.CPUProfilerModelDelegate} delegate 100 */ 101 setDelegate: function(delegate) 102 { 103 this._delegate = delegate; 104 }, 105 106 /** 107 * @param {string} id 108 * @param {!DebuggerAgent.Location} scriptLocation 109 * @param {!ProfilerAgent.CPUProfile} cpuProfile 110 * @param {string=} title 111 */ 112 addProfileHeader: function(id, scriptLocation, cpuProfile, title) 113 { 114 // Make sure ProfilesPanel is initialized and CPUProfileType is created. 115 WebInspector.inspectorView.panel("profiles"); 116 this._delegate.consoleProfileEnd(id, scriptLocation, cpuProfile, title); 117 }, 118 119 /** 120 * @param {string} id 121 * @param {!DebuggerAgent.Location} scriptLocation 122 * @param {string=} title 123 */ 124 consoleProfile: function(id, scriptLocation, title) 125 { 126 // Make sure ProfilesPanel is initialized and CPUProfileType is created. 127 WebInspector.inspectorView.panel("profiles"); 128 this._delegate.consoleProfile(id, scriptLocation, title); 129 }, 130 131 /** 132 * @override 133 */ 134 resetProfiles: function() 135 { 136 if (this._delegate) 137 this._delegate.resetProfiles(); 138 }, 139 140 /** 141 * @param {boolean} isRecording 142 */ 143 setRecording: function(isRecording) 144 { 145 this._isRecording = isRecording; 146 this.dispatchEventToListeners(isRecording ? 147 WebInspector.CPUProfilerModel.EventTypes.ProfileStarted : 148 WebInspector.CPUProfilerModel.EventTypes.ProfileStopped); 149 }, 150 151 /** 152 * @return {boolean} 153 */ 154 isRecordingProfile: function() 155 { 156 return this._isRecording; 157 }, 158 159 __proto__: WebInspector.Object.prototype 160} 161 162/** 163 * @type {!WebInspector.CPUProfilerModel} 164 */ 165WebInspector.cpuProfilerModel; 166