2 * Copyright (C) 2011 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 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * @extends {WebInspector.SDKModel}
34 * @param {!WebInspector.Target} target
36 WebInspector.TimelineManager = function(target)
38 WebInspector.SDKModel.call(this, WebInspector.TimelineManager, target);
39 this._dispatcher = new WebInspector.TimelineDispatcher(this);
40 this._enablementCount = 0;
41 target.timelineAgent().enable();
44 WebInspector.TimelineManager.EventTypes = {
45 TimelineStarted: "TimelineStarted",
46 TimelineStopped: "TimelineStopped",
47 TimelineEventRecorded: "TimelineEventRecorded",
48 TimelineProgress: "TimelineProgress"
51 WebInspector.TimelineManager.prototype = {
57 return this._dispatcher.isStarted();
61 * @param {number=} maxCallStackDepth
62 * @param {string=} liveEvents
63 * @param {boolean=} includeCounters
64 * @param {boolean=} includeGPUEvents
65 * @param {function(?Protocol.Error)=} callback
67 start: function(maxCallStackDepth, liveEvents, includeCounters, includeGPUEvents, callback)
69 this._enablementCount++;
70 WebInspector.targetManager.suspendAllTargets();
71 if (this._enablementCount === 1)
72 this.target().timelineAgent().start(maxCallStackDepth, true, liveEvents, includeCounters, includeGPUEvents, callback);
78 * @param {function(?Protocol.Error)} callback
80 stop: function(callback)
82 this._enablementCount--;
83 if (this._enablementCount < 0) {
84 console.error("WebInspector.TimelineManager start/stop calls are unbalanced " + new Error().stack);
88 if (!this._enablementCount)
89 this.target().timelineAgent().stop(allDoneCallback);
92 * @param {?Protocol.Error} error
94 function allDoneCallback(error)
96 WebInspector.targetManager.resumeAllTargets();
102 * @param {boolean=} consoleTimeline
103 * @param {!Array.<!TimelineAgent.TimelineEvent>=} events
105 _stopped: function(consoleTimeline, events)
108 consoleTimeline: consoleTimeline,
111 this.dispatchEventToListeners(WebInspector.TimelineManager.EventTypes.TimelineStopped, data);
114 __proto__: WebInspector.SDKModel.prototype
119 * @implements {TimelineAgent.Dispatcher}
121 WebInspector.TimelineDispatcher = function(manager)
123 this._manager = manager;
124 this._manager.target().registerTimelineDispatcher(this);
127 WebInspector.TimelineDispatcher.prototype = {
129 * @param {!TimelineAgent.TimelineEvent} record
131 eventRecorded: function(record)
133 this._manager.dispatchEventToListeners(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, record);
139 isStarted: function()
141 return !!this._started;
145 * @param {boolean=} consoleTimeline
147 started: function(consoleTimeline)
149 this._started = true;
150 this._manager.dispatchEventToListeners(WebInspector.TimelineManager.EventTypes.TimelineStarted, consoleTimeline);
154 * @param {boolean=} consoleTimeline
155 * @param {!Array.<!TimelineAgent.TimelineEvent>=} events
157 stopped: function(consoleTimeline, events)
159 this._started = false;
160 this._manager._stopped(consoleTimeline, events);
164 * @param {number} count
166 progress: function(count)
168 this._manager.dispatchEventToListeners(WebInspector.TimelineManager.EventTypes.TimelineProgress, count);