| 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 if (this._collectionEnabled) |
| 156 return; | 159 return; |
| 157 this.reset(); | 160 this.reset(); |
| 158 var maxStackFrames = WebInspector.settings.timelineLimitStackFramesFlag.
get() ? WebInspector.settings.timelineStackFramesToCapture.get() : 30; | 161 var maxStackFrames = WebInspector.settings.timelineLimitStackFramesFlag.
get() ? WebInspector.settings.timelineStackFramesToCapture.get() : 30; |
| 159 WebInspector.timelineManager.start(maxStackFrames, includeDomCounters); | 162 WebInspector.timelineManager.start(maxStackFrames, includeDomCounters, f
alse, this._fireRecordingStarted.bind(this)); |
| 160 this._collectionEnabled = true; | 163 this._collectionEnabled = true; |
| 161 }, | 164 }, |
| 162 | 165 |
| 163 stopRecord: function() | 166 stopRecording: function() |
| 164 { | 167 { |
| 165 if (!this._collectionEnabled) | 168 if (!this._collectionEnabled) |
| 166 return; | 169 return; |
| 167 WebInspector.timelineManager.stop(); | 170 WebInspector.timelineManager.stop(this._fireRecordingStopped.bind(this))
; |
| 168 this._collectionEnabled = false; | 171 this._collectionEnabled = false; |
| 169 }, | 172 }, |
| 170 | 173 |
| 171 get records() | 174 get records() |
| 172 { | 175 { |
| 173 return this._records; | 176 return this._records; |
| 174 }, | 177 }, |
| 175 | 178 |
| 179 /** |
| 180 * @param {WebInspector.Event} event |
| 181 */ |
| 176 _onRecordAdded: function(event) | 182 _onRecordAdded: function(event) |
| 177 { | 183 { |
| 178 if (this._collectionEnabled) | 184 if (this._collectionEnabled) |
| 179 this._addRecord(event.data); | 185 this._addRecord(/** @type {TimelineAgent.TimelineEvent} */(event.dat
a)); |
| 180 }, | 186 }, |
| 181 | 187 |
| 188 /** |
| 189 * @param {WebInspector.Event} event |
| 190 */ |
| 191 _onStarted: function(event) |
| 192 { |
| 193 if (event.data) { |
| 194 // Started from console |
| 195 this._collectionEnabled = true; |
| 196 this._fireRecordingStarted(); |
| 197 } |
| 198 }, |
| 199 |
| 200 /** |
| 201 * @param {WebInspector.Event} event |
| 202 */ |
| 203 _onStopped: function(event) |
| 204 { |
| 205 if (event.data) { |
| 206 this._collectionEnabled = false; |
| 207 this._fireRecordingStopped(); |
| 208 } |
| 209 }, |
| 210 |
| 211 _fireRecordingStarted: function() |
| 212 { |
| 213 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStarted); |
| 214 }, |
| 215 |
| 216 _fireRecordingStopped: function() |
| 217 { |
| 218 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStopped); |
| 219 }, |
| 220 |
| 221 /** |
| 222 * @param {TimelineAgent.TimelineEvent} record |
| 223 */ |
| 182 _addRecord: function(record) | 224 _addRecord: function(record) |
| 183 { | 225 { |
| 184 this._stringPool.internObjectStrings(record); | 226 this._stringPool.internObjectStrings(record); |
| 185 this._records.push(record); | 227 this._records.push(record); |
| 186 this._updateBoundaries(record); | 228 this._updateBoundaries(record); |
| 187 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordAd
ded, record); | 229 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordAd
ded, record); |
| 188 }, | 230 }, |
| 189 | 231 |
| 190 /** | 232 /** |
| 191 * @param {!Blob} file | 233 * @param {!Blob} file |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 minimumRecordTime: function() | 287 minimumRecordTime: function() |
| 246 { | 288 { |
| 247 return this._minimumRecordTime; | 289 return this._minimumRecordTime; |
| 248 }, | 290 }, |
| 249 | 291 |
| 250 maximumRecordTime: function() | 292 maximumRecordTime: function() |
| 251 { | 293 { |
| 252 return this._maximumRecordTime; | 294 return this._maximumRecordTime; |
| 253 }, | 295 }, |
| 254 | 296 |
| 297 /** |
| 298 * @param {TimelineAgent.TimelineEvent} record |
| 299 */ |
| 255 _updateBoundaries: function(record) | 300 _updateBoundaries: function(record) |
| 256 { | 301 { |
| 257 var startTime = WebInspector.TimelineModel.startTimeInSeconds(record); | 302 var startTime = WebInspector.TimelineModel.startTimeInSeconds(record); |
| 258 var endTime = WebInspector.TimelineModel.endTimeInSeconds(record); | 303 var endTime = WebInspector.TimelineModel.endTimeInSeconds(record); |
| 259 | 304 |
| 260 if (this._minimumRecordTime === -1 || startTime < this._minimumRecordTim
e) | 305 if (this._minimumRecordTime === -1 || startTime < this._minimumRecordTim
e) |
| 261 this._minimumRecordTime = startTime; | 306 this._minimumRecordTime = startTime; |
| 262 if (this._maximumRecordTime === -1 || endTime > this._maximumRecordTime) | 307 if (this._maximumRecordTime === -1 || endTime > this._maximumRecordTime) |
| 263 this._maximumRecordTime = endTime; | 308 this._maximumRecordTime = endTime; |
| 264 }, | 309 }, |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 break; | 494 break; |
| 450 length += itemLength; | 495 length += itemLength; |
| 451 data.push(item); | 496 data.push(item); |
| 452 ++this._recordIndex; | 497 ++this._recordIndex; |
| 453 } | 498 } |
| 454 if (this._recordIndex === this._records.length) | 499 if (this._recordIndex === this._records.length) |
| 455 data.push(data.pop() + "]"); | 500 data.push(data.pop() + "]"); |
| 456 stream.write(data.join(separator), this._writeNextChunk.bind(this)); | 501 stream.write(data.join(separator), this._writeNextChunk.bind(this)); |
| 457 } | 502 } |
| 458 } | 503 } |
| OLD | NEW |