1 /* 2 * Copyright (C) 2014 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.TargetAwareObject} 32 * @param {!WebInspector.Target} target 33 * @implements {ProfilerAgent.Dispatcher} 34 */ 35 WebInspector.CPUProfilerModel = function(target) 36 { 37 WebInspector.TargetAwareObject.call(this, target); 38 39 /** @type {?WebInspector.CPUProfilerModel.Delegate} */ 40 this._delegate = null; 41 this._isRecording = false; 42 InspectorBackend.registerProfilerDispatcher(this); 43 ProfilerAgent.enable(); 44 } 45 46 WebInspector.CPUProfilerModel.EventTypes = { 47 ProfileStarted: "profile-started", 48 ProfileStopped: "profile-stopped" 49 }; 50 51 WebInspector.CPUProfilerModel.prototype = { 52 /** 53 * @param {!WebInspector.CPUProfilerModel.Delegate} delegate 54 */ 55 setDelegate: function(delegate) 56 { 57 this._delegate = delegate; 58 }, 59 60 /** 61 * @param {string} id 62 * @param {!DebuggerAgent.Location} scriptLocation 63 * @param {!ProfilerAgent.CPUProfile} cpuProfile 64 * @param {string=} title 65 */ 66 consoleProfileFinished: function(id, scriptLocation, cpuProfile, title) 67 { 68 // Make sure ProfilesPanel is initialized and CPUProfileType is created. 69 WebInspector.moduleManager.loadModule("profiler"); 70 this._delegate.consoleProfileFinished(id, WebInspector.DebuggerModel.Location.fromPayload(this.target(), scriptLocation), cpuProfile, title); 71 }, 72 73 /** 74 * @param {string} id 75 * @param {!DebuggerAgent.Location} scriptLocation 76 * @param {string=} title 77 */ 78 consoleProfileStarted: function(id, scriptLocation, title) 79 { 80 // Make sure ProfilesPanel is initialized and CPUProfileType is created. 81 WebInspector.moduleManager.loadModule("profiler"); 82 this._delegate.consoleProfileStarted(id, WebInspector.DebuggerModel.Location.fromPayload(this.target(), scriptLocation), title); 83 }, 84 85 /** 86 * @param {boolean} isRecording 87 */ 88 setRecording: function(isRecording) 89 { 90 this._isRecording = isRecording; 91 this.dispatchEventToListeners(isRecording ? 92 WebInspector.CPUProfilerModel.EventTypes.ProfileStarted : 93 WebInspector.CPUProfilerModel.EventTypes.ProfileStopped); 94 }, 95 96 /** 97 * @return {boolean} 98 */ 99 isRecordingProfile: function() 100 { 101 return this._isRecording; 102 }, 103 104 __proto__: WebInspector.TargetAwareObject.prototype 105 } 106 107 /** @interface */ 108 WebInspector.CPUProfilerModel.Delegate = function() {}; 109 110 WebInspector.CPUProfilerModel.Delegate.prototype = { 111 /** 112 * @param {string} protocolId 113 * @param {!WebInspector.DebuggerModel.Location} scriptLocation 114 * @param {string=} title 115 */ 116 consoleProfileStarted: function(protocolId, scriptLocation, title) {}, 117 118 /** 119 * @param {string} protocolId 120 * @param {!WebInspector.DebuggerModel.Location} scriptLocation 121 * @param {!ProfilerAgent.CPUProfile} cpuProfile 122 * @param {string=} title 123 */ 124 consoleProfileFinished: function(protocolId, scriptLocation, cpuProfile, title) {} 125 } 126 127 /** 128 * @type {!WebInspector.CPUProfilerModel} 129 */ 130 WebInspector.cpuProfilerModel; 131