OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 20 matching lines...) Expand all Loading... |
31 /** | 31 /** |
32 * @constructor | 32 * @constructor |
33 * @extends {WebInspector.Object} | 33 * @extends {WebInspector.Object} |
34 */ | 34 */ |
35 WebInspector.TimelineModel = function() | 35 WebInspector.TimelineModel = function() |
36 { | 36 { |
37 this._records = []; | 37 this._records = []; |
38 this._stringPool = new StringPool(); | 38 this._stringPool = new StringPool(); |
39 this._minimumRecordTime = -1; | 39 this._minimumRecordTime = -1; |
40 this._maximumRecordTime = -1; | 40 this._maximumRecordTime = -1; |
41 this._collectionEnabled = false; | |
42 | 41 |
43 WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.E
ventTypes.TimelineEventRecorded, this._onRecordAdded, this); | 42 WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.E
ventTypes.TimelineEventRecorded, this._onRecordAdded, this); |
| 43 WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.E
ventTypes.TimelineStarted, this._onStarted, this); |
| 44 WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.E
ventTypes.TimelineStopped, this._onStopped, this); |
44 } | 45 } |
45 | 46 |
46 WebInspector.TimelineModel.TransferChunkLengthBytes = 5000000; | 47 WebInspector.TimelineModel.TransferChunkLengthBytes = 5000000; |
47 | 48 |
48 WebInspector.TimelineModel.RecordType = { | 49 WebInspector.TimelineModel.RecordType = { |
49 Root: "Root", | 50 Root: "Root", |
50 Program: "Program", | 51 Program: "Program", |
51 EventDispatch: "EventDispatch", | 52 EventDispatch: "EventDispatch", |
52 | 53 |
53 BeginFrame: "BeginFrame", | 54 BeginFrame: "BeginFrame", |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 FireAnimationFrame: "FireAnimationFrame", | 95 FireAnimationFrame: "FireAnimationFrame", |
95 | 96 |
96 WebSocketCreate : "WebSocketCreate", | 97 WebSocketCreate : "WebSocketCreate", |
97 WebSocketSendHandshakeRequest : "WebSocketSendHandshakeRequest", | 98 WebSocketSendHandshakeRequest : "WebSocketSendHandshakeRequest", |
98 WebSocketReceiveHandshakeResponse : "WebSocketReceiveHandshakeResponse", | 99 WebSocketReceiveHandshakeResponse : "WebSocketReceiveHandshakeResponse", |
99 WebSocketDestroy : "WebSocketDestroy", | 100 WebSocketDestroy : "WebSocketDestroy", |
100 } | 101 } |
101 | 102 |
102 WebInspector.TimelineModel.Events = { | 103 WebInspector.TimelineModel.Events = { |
103 RecordAdded: "RecordAdded", | 104 RecordAdded: "RecordAdded", |
104 RecordsCleared: "RecordsCleared" | 105 RecordsCleared: "RecordsCleared", |
| 106 RecordingStarted: "RecordingStarted", |
| 107 RecordingStopped: "RecordingStopped" |
105 } | 108 } |
106 | 109 |
107 WebInspector.TimelineModel.startTimeInSeconds = function(record) | 110 WebInspector.TimelineModel.startTimeInSeconds = function(record) |
108 { | 111 { |
109 return record.startTime / 1000; | 112 return record.startTime / 1000; |
110 } | 113 } |
111 | 114 |
112 WebInspector.TimelineModel.endTimeInSeconds = function(record) | 115 WebInspector.TimelineModel.endTimeInSeconds = function(record) |
113 { | 116 { |
114 return (typeof record.endTime === "undefined" ? record.startTime : record.en
dTime) / 1000; | 117 return (typeof record.endTime === "undefined" ? record.startTime : record.en
dTime) / 1000; |
(...skipping 28 matching lines...) Expand all Loading... |
143 WebInspector.TimelineModel.aggregateTimeByCategory = function(total, addend) | 146 WebInspector.TimelineModel.aggregateTimeByCategory = function(total, addend) |
144 { | 147 { |
145 for (var category in addend) | 148 for (var category in addend) |
146 total[category] = (total[category] || 0) + addend[category]; | 149 total[category] = (total[category] || 0) + addend[category]; |
147 } | 150 } |
148 | 151 |
149 WebInspector.TimelineModel.prototype = { | 152 WebInspector.TimelineModel.prototype = { |
150 /** | 153 /** |
151 * @param {boolean=} includeDomCounters | 154 * @param {boolean=} includeDomCounters |
152 */ | 155 */ |
153 startRecord: function(includeDomCounters) | 156 startRecording: function(includeDomCounters) |
154 { | 157 { |
155 if (this._collectionEnabled) | 158 this._clientInitiatedRecording = true; |
156 return; | |
157 this.reset(); | 159 this.reset(); |
158 var maxStackFrames = WebInspector.settings.timelineLimitStackFramesFlag.
get() ? WebInspector.settings.timelineStackFramesToCapture.get() : 30; | 160 var maxStackFrames = WebInspector.settings.timelineLimitStackFramesFlag.
get() ? WebInspector.settings.timelineStackFramesToCapture.get() : 30; |
159 WebInspector.timelineManager.start(maxStackFrames, includeDomCounters); | 161 WebInspector.timelineManager.start(maxStackFrames, includeDomCounters, f
alse, this._fireRecordingStarted.bind(this)); |
160 this._collectionEnabled = true; | |
161 }, | 162 }, |
162 | 163 |
163 stopRecord: function() | 164 stopRecording: function() |
164 { | 165 { |
165 if (!this._collectionEnabled) | 166 if (!this._clientInitiatedRecording) { |
| 167 // Console started this one and we are just sniffing it. Initiate re
cording so that we |
| 168 // could stop it. |
| 169 function stopTimeline() |
| 170 { |
| 171 WebInspector.timelineManager.stop(this._fireRecordingStopped.bin
d(this)); |
| 172 } |
| 173 |
| 174 WebInspector.timelineManager.start(undefined, undefined, undefined,
stopTimeline.bind(this)); |
166 return; | 175 return; |
167 WebInspector.timelineManager.stop(); | 176 } |
168 this._collectionEnabled = false; | 177 this._clientInitiatedRecording = false; |
| 178 WebInspector.timelineManager.stop(this._fireRecordingStopped.bind(this))
; |
169 }, | 179 }, |
170 | 180 |
171 get records() | 181 get records() |
172 { | 182 { |
173 return this._records; | 183 return this._records; |
174 }, | 184 }, |
175 | 185 |
| 186 /** |
| 187 * @param {WebInspector.Event} event |
| 188 */ |
176 _onRecordAdded: function(event) | 189 _onRecordAdded: function(event) |
177 { | 190 { |
178 if (this._collectionEnabled) | 191 if (this._collectionEnabled) |
179 this._addRecord(event.data); | 192 this._addRecord(/** @type {TimelineAgent.TimelineEvent} */(event.dat
a)); |
180 }, | 193 }, |
181 | 194 |
| 195 /** |
| 196 * @param {WebInspector.Event} event |
| 197 */ |
| 198 _onStarted: function(event) |
| 199 { |
| 200 if (event.data) { |
| 201 // Started from console. |
| 202 this._fireRecordingStarted(); |
| 203 } |
| 204 }, |
| 205 |
| 206 /** |
| 207 * @param {WebInspector.Event} event |
| 208 */ |
| 209 _onStopped: function(event) |
| 210 { |
| 211 if (event.data) { |
| 212 // Stopped from console. |
| 213 this._fireRecordingStopped(); |
| 214 } |
| 215 }, |
| 216 |
| 217 _fireRecordingStarted: function() |
| 218 { |
| 219 this._collectionEnabled = true; |
| 220 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStarted); |
| 221 }, |
| 222 |
| 223 _fireRecordingStopped: function() |
| 224 { |
| 225 this._collectionEnabled = false; |
| 226 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStopped); |
| 227 }, |
| 228 |
| 229 /** |
| 230 * @param {TimelineAgent.TimelineEvent} record |
| 231 */ |
182 _addRecord: function(record) | 232 _addRecord: function(record) |
183 { | 233 { |
184 this._stringPool.internObjectStrings(record); | 234 this._stringPool.internObjectStrings(record); |
185 this._records.push(record); | 235 this._records.push(record); |
186 this._updateBoundaries(record); | 236 this._updateBoundaries(record); |
187 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordAd
ded, record); | 237 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordAd
ded, record); |
188 }, | 238 }, |
189 | 239 |
190 /** | 240 /** |
191 * @param {!Blob} file | 241 * @param {!Blob} file |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 minimumRecordTime: function() | 295 minimumRecordTime: function() |
246 { | 296 { |
247 return this._minimumRecordTime; | 297 return this._minimumRecordTime; |
248 }, | 298 }, |
249 | 299 |
250 maximumRecordTime: function() | 300 maximumRecordTime: function() |
251 { | 301 { |
252 return this._maximumRecordTime; | 302 return this._maximumRecordTime; |
253 }, | 303 }, |
254 | 304 |
| 305 /** |
| 306 * @param {TimelineAgent.TimelineEvent} record |
| 307 */ |
255 _updateBoundaries: function(record) | 308 _updateBoundaries: function(record) |
256 { | 309 { |
257 var startTime = WebInspector.TimelineModel.startTimeInSeconds(record); | 310 var startTime = WebInspector.TimelineModel.startTimeInSeconds(record); |
258 var endTime = WebInspector.TimelineModel.endTimeInSeconds(record); | 311 var endTime = WebInspector.TimelineModel.endTimeInSeconds(record); |
259 | 312 |
260 if (this._minimumRecordTime === -1 || startTime < this._minimumRecordTim
e) | 313 if (this._minimumRecordTime === -1 || startTime < this._minimumRecordTim
e) |
261 this._minimumRecordTime = startTime; | 314 this._minimumRecordTime = startTime; |
262 if (this._maximumRecordTime === -1 || endTime > this._maximumRecordTime) | 315 if (this._maximumRecordTime === -1 || endTime > this._maximumRecordTime) |
263 this._maximumRecordTime = endTime; | 316 this._maximumRecordTime = endTime; |
264 }, | 317 }, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 break; | 502 break; |
450 length += itemLength; | 503 length += itemLength; |
451 data.push(item); | 504 data.push(item); |
452 ++this._recordIndex; | 505 ++this._recordIndex; |
453 } | 506 } |
454 if (this._recordIndex === this._records.length) | 507 if (this._recordIndex === this._records.length) |
455 data.push(data.pop() + "]"); | 508 data.push(data.pop() + "]"); |
456 stream.write(data.join(separator), this._writeNextChunk.bind(this)); | 509 stream.write(data.join(separator), this._writeNextChunk.bind(this)); |
457 } | 510 } |
458 } | 511 } |
OLD | NEW |