2 * Copyright (C) 2014 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
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
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.
31 * @extends {WebInspector.TargetAwareObject}
32 * @param {!WebInspector.Target} target
33 * @implements {ProfilerAgent.Dispatcher}
35 WebInspector.CPUProfilerModel = function(target)
37 WebInspector.TargetAwareObject.call(this, target);
39 /** @type {?WebInspector.CPUProfilerModel.Delegate} */
40 this._delegate = null;
41 this._isRecording = false;
42 InspectorBackend.registerProfilerDispatcher(this);
43 ProfilerAgent.enable();
46 WebInspector.CPUProfilerModel.EventTypes = {
47 ProfileStarted: "profile-started",
48 ProfileStopped: "profile-stopped"
51 WebInspector.CPUProfilerModel.prototype = {
53 * @param {!WebInspector.CPUProfilerModel.Delegate} delegate
55 setDelegate: function(delegate)
57 this._delegate = delegate;
62 * @param {!DebuggerAgent.Location} scriptLocation
63 * @param {!ProfilerAgent.CPUProfile} cpuProfile
64 * @param {string=} title
66 consoleProfileFinished: function(id, scriptLocation, cpuProfile, title)
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);
75 * @param {!DebuggerAgent.Location} scriptLocation
76 * @param {string=} title
78 consoleProfileStarted: function(id, scriptLocation, title)
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);
86 * @param {boolean} isRecording
88 setRecording: function(isRecording)
90 this._isRecording = isRecording;
91 this.dispatchEventToListeners(isRecording ?
92 WebInspector.CPUProfilerModel.EventTypes.ProfileStarted :
93 WebInspector.CPUProfilerModel.EventTypes.ProfileStopped);
99 isRecordingProfile: function()
101 return this._isRecording;
104 __proto__: WebInspector.TargetAwareObject.prototype
108 WebInspector.CPUProfilerModel.Delegate = function() {};
110 WebInspector.CPUProfilerModel.Delegate.prototype = {
112 * @param {string} protocolId
113 * @param {!WebInspector.DebuggerModel.Location} scriptLocation
114 * @param {string=} title
116 consoleProfileStarted: function(protocolId, scriptLocation, title) {},
119 * @param {string} protocolId
120 * @param {!WebInspector.DebuggerModel.Location} scriptLocation
121 * @param {!ProfilerAgent.CPUProfile} cpuProfile
122 * @param {string=} title
124 consoleProfileFinished: function(protocolId, scriptLocation, cpuProfile, title) {}
128 * @type {!WebInspector.CPUProfilerModel}
130 WebInspector.cpuProfilerModel;