Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.TimelineModel} | 7 * @extends {WebInspector.TimelineModel} |
| 8 * @param {!WebInspector.TimelineManager} timelineManager | 8 * @implements {WebInspector.TargetManager.Observer} |
| 9 */ | 9 */ |
| 10 WebInspector.TimelineModelImpl = function(timelineManager) | 10 WebInspector.TimelineModelImpl = function() |
| 11 { | 11 { |
| 12 WebInspector.TimelineModel.call(this); | 12 WebInspector.TimelineModel.call(this); |
| 13 this._target = timelineManager.target(); | 13 /** @type {?WebInspector.Target} */ |
| 14 this._timelineManager = timelineManager; | 14 this._currentTarget = null; |
| 15 this._filters = []; | 15 this._filters = []; |
| 16 this._bindings = new WebInspector.TimelineModelImpl.InterRecordBindings(); | 16 this._bindings = new WebInspector.TimelineModelImpl.InterRecordBindings(); |
| 17 | 17 |
| 18 this.reset(); | 18 this.reset(); |
| 19 | 19 |
| 20 this._timelineManager.addEventListener(WebInspector.TimelineManager.EventTyp es.TimelineEventRecorded, this._onRecordAdded, this); | 20 WebInspector.targetManager.addModelListener(WebInspector.TimelineManager, We bInspector.TimelineManager.EventTypes.TimelineEventRecorded, this._onRecordAdded , this); |
| 21 this._timelineManager.addEventListener(WebInspector.TimelineManager.EventTyp es.TimelineStarted, this._onStarted, this); | 21 WebInspector.targetManager.addModelListener(WebInspector.TimelineManager, We bInspector.TimelineManager.EventTypes.TimelineStarted, this._onStarted, this); |
| 22 this._timelineManager.addEventListener(WebInspector.TimelineManager.EventTyp es.TimelineStopped, this._onStopped, this); | 22 WebInspector.targetManager.addModelListener(WebInspector.TimelineManager, We bInspector.TimelineManager.EventTypes.TimelineStopped, this._onStopped, this); |
| 23 this._timelineManager.addEventListener(WebInspector.TimelineManager.EventTyp es.TimelineProgress, this._onProgress, this); | 23 WebInspector.targetManager.addModelListener(WebInspector.TimelineManager, We bInspector.TimelineManager.EventTypes.TimelineProgress, this._onProgress, this); |
| 24 WebInspector.targetManager.observeTargets(this); | |
| 24 } | 25 } |
| 25 | 26 |
| 26 WebInspector.TimelineModelImpl.TransferChunkLengthBytes = 5000000; | 27 WebInspector.TimelineModelImpl.TransferChunkLengthBytes = 5000000; |
| 27 | 28 |
| 28 WebInspector.TimelineModelImpl.prototype = { | 29 WebInspector.TimelineModelImpl.prototype = { |
| 29 /** | 30 /** |
| 30 * @return {boolean} | 31 * @param {!WebInspector.Target} target |
| 31 */ | 32 */ |
| 32 loadedFromFile: function() | 33 targetAdded: function(target) { }, |
| 34 | |
| 35 /** | |
| 36 * @param {!WebInspector.Target} target | |
| 37 */ | |
| 38 targetRemoved: function(target) | |
| 33 { | 39 { |
| 34 return this._loadedFromFile; | 40 if (this._currentTarget === target) |
| 41 this._currentTarget = null; | |
| 35 }, | 42 }, |
| 36 | 43 |
| 37 /** | 44 /** |
| 38 * @param {boolean} captureStacks | 45 * @param {boolean} captureStacks |
| 39 * @param {boolean} captureMemory | 46 * @param {boolean} captureMemory |
| 40 * @param {boolean} capturePictures | 47 * @param {boolean} capturePictures |
| 41 */ | 48 */ |
| 42 startRecording: function(captureStacks, captureMemory, capturePictures) | 49 startRecording: function(captureStacks, captureMemory, capturePictures) |
| 43 { | 50 { |
| 44 console.assert(!capturePictures, "Legacy timeline does not support captu ring pictures"); | 51 console.assert(!capturePictures, "Legacy timeline does not support captu ring pictures"); |
| 52 this.reset(); | |
| 53 this._currentTarget = WebInspector.context.flavor(WebInspector.Target); | |
| 54 if (!this._currentTarget) | |
|
yurys
2014/07/21 09:55:20
How can this happen? Shouldn't we fail in this cas
| |
| 55 return; | |
| 56 | |
| 45 this._clientInitiatedRecording = true; | 57 this._clientInitiatedRecording = true; |
| 46 this.reset(); | |
| 47 var maxStackFrames = captureStacks ? 30 : 0; | 58 var maxStackFrames = captureStacks ? 30 : 0; |
| 48 var includeGPUEvents = WebInspector.experimentsSettings.gpuTimeline.isEn abled(); | 59 var includeGPUEvents = WebInspector.experimentsSettings.gpuTimeline.isEn abled(); |
| 49 var liveEvents = [ WebInspector.TimelineModel.RecordType.BeginFrame, | 60 var liveEvents = [ WebInspector.TimelineModel.RecordType.BeginFrame, |
| 50 WebInspector.TimelineModel.RecordType.DrawFrame, | 61 WebInspector.TimelineModel.RecordType.DrawFrame, |
| 51 WebInspector.TimelineModel.RecordType.RequestMainThre adFrame, | 62 WebInspector.TimelineModel.RecordType.RequestMainThre adFrame, |
| 52 WebInspector.TimelineModel.RecordType.ActivateLayerTr ee ]; | 63 WebInspector.TimelineModel.RecordType.ActivateLayerTr ee ]; |
| 53 this._timelineManager.start(maxStackFrames, WebInspector.experimentsSett ings.timelineNoLiveUpdate.isEnabled(), liveEvents.join(","), captureMemory, incl udeGPUEvents, this._fireRecordingStarted.bind(this)); | 64 this._currentTarget.timelineManager.start(maxStackFrames, WebInspector.e xperimentsSettings.timelineNoLiveUpdate.isEnabled(), liveEvents.join(","), captu reMemory, includeGPUEvents, this._fireRecordingStarted.bind(this)); |
| 54 }, | 65 }, |
| 55 | 66 |
| 56 stopRecording: function() | 67 stopRecording: function() |
| 57 { | 68 { |
| 69 if (!this._currentTarget) | |
| 70 return; | |
| 71 | |
| 58 if (!this._clientInitiatedRecording) { | 72 if (!this._clientInitiatedRecording) { |
| 59 this._timelineManager.start(undefined, undefined, undefined, undefin ed, undefined, stopTimeline.bind(this)); | 73 this._currentTarget.timelineManager.start(undefined, undefined, unde fined, undefined, undefined, stopTimeline.bind(this)); |
| 60 return; | 74 return; |
| 61 } | 75 } |
| 62 | 76 |
| 63 /** | 77 /** |
| 64 * Console started this one and we are just sniffing it. Initiate record ing so that we | 78 * Console started this one and we are just sniffing it. Initiate record ing so that we |
| 65 * could stop it. | 79 * could stop it. |
| 66 * @this {WebInspector.TimelineModelImpl} | 80 * @this {WebInspector.TimelineModelImpl} |
| 67 */ | 81 */ |
| 68 function stopTimeline() | 82 function stopTimeline() |
| 69 { | 83 { |
| 70 this._timelineManager.stop(this._fireRecordingStopped.bind(this)); | 84 this._currentTarget.timelineManager.stop(this._fireRecordingStopped. bind(this)); |
| 71 } | 85 } |
| 72 | 86 |
| 73 this._clientInitiatedRecording = false; | 87 this._clientInitiatedRecording = false; |
| 74 this._timelineManager.stop(this._fireRecordingStopped.bind(this)); | 88 this._currentTarget.timelineManager.stop(this._fireRecordingStopped.bind (this)); |
| 75 }, | 89 }, |
| 76 | 90 |
| 77 /** | 91 /** |
| 78 * @return {!Array.<!WebInspector.TimelineModel.Record>} | 92 * @return {!Array.<!WebInspector.TimelineModel.Record>} |
| 79 */ | 93 */ |
| 80 records: function() | 94 records: function() |
| 81 { | 95 { |
| 82 return this._records; | 96 return this._records; |
| 83 }, | 97 }, |
| 84 | 98 |
| 85 /** | 99 /** |
| 86 * @param {!WebInspector.Event} event | 100 * @param {!WebInspector.Event} event |
| 87 */ | 101 */ |
| 88 _onRecordAdded: function(event) | 102 _onRecordAdded: function(event) |
| 89 { | 103 { |
| 90 if (this._collectionEnabled) | 104 var timelineManager = /** @type {!WebInspector.TimelineManager} */ (even t.target); |
| 105 if (this._collectionEnabled && timelineManager.target() === this._curren tTarget) | |
| 91 this._addRecord(/** @type {!TimelineAgent.TimelineEvent} */(event.da ta)); | 106 this._addRecord(/** @type {!TimelineAgent.TimelineEvent} */(event.da ta)); |
| 92 }, | 107 }, |
| 93 | 108 |
| 94 /** | 109 /** |
| 95 * @param {!WebInspector.Event} event | 110 * @param {!WebInspector.Event} event |
| 96 */ | 111 */ |
| 97 _onStarted: function(event) | 112 _onStarted: function(event) |
| 98 { | 113 { |
| 99 if (event.data) { | 114 if (!event.data || this._collectionEnabled) |
|
yurys
2014/07/21 09:55:20
Why do we need to also check this._collectionEnabl
sergeyv
2014/07/21 12:39:11
we need it to prevent situation, when timeline was
| |
| 100 // Started from console. | 115 return; |
| 101 this._fireRecordingStarted(); | 116 // Started from console. |
| 117 var timelineManager = /** @type {!WebInspector.TimelineManager} */ (even t.target); | |
| 118 if (this._currentTarget !== timelineManager.target()) { | |
| 119 this.reset(); | |
| 120 this._currentTarget = timelineManager.target(); | |
| 102 } | 121 } |
| 122 this._fireRecordingStarted(); | |
| 103 }, | 123 }, |
| 104 | 124 |
| 105 /** | 125 /** |
| 106 * @param {!WebInspector.Event} event | 126 * @param {!WebInspector.Event} event |
| 107 */ | 127 */ |
| 108 _onStopped: function(event) | 128 _onStopped: function(event) |
| 109 { | 129 { |
| 130 var timelineManager = /** @type {!WebInspector.TimelineManager} */ (even t.target); | |
| 131 if (timelineManager.target() !== this._currentTarget) | |
| 132 return; | |
| 110 // If we were buffering events, discard those that got through, the real ones are coming! | 133 // If we were buffering events, discard those that got through, the real ones are coming! |
| 111 if (WebInspector.experimentsSettings.timelineNoLiveUpdate.isEnabled()) | 134 if (WebInspector.experimentsSettings.timelineNoLiveUpdate.isEnabled()) { |
| 112 this.reset(); | 135 this.reset(); |
| 136 this._currentTarget = timelineManager.target(); | |
| 137 } | |
| 113 if (event.data) { | 138 if (event.data) { |
| 114 // Stopped from console. | 139 // Stopped from console. |
| 115 this._fireRecordingStopped(null, null); | 140 this._fireRecordingStopped(null, null); |
| 116 } | 141 } |
| 117 }, | 142 }, |
| 118 | 143 |
| 119 /** | 144 /** |
| 120 * @param {!WebInspector.Event} event | 145 * @param {!WebInspector.Event} event |
| 121 */ | 146 */ |
| 122 _onProgress: function(event) | 147 _onProgress: function(event) |
| 123 { | 148 { |
| 124 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin gProgress, event.data); | 149 var timelineManager = /** @type {!WebInspector.TimelineManager} */ (even t.target); |
| 150 if (timelineManager.target() === this._currentTarget) | |
| 151 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Reco rdingProgress, event.data); | |
| 125 }, | 152 }, |
| 126 | 153 |
| 127 _fireRecordingStarted: function() | 154 _fireRecordingStarted: function() |
| 128 { | 155 { |
| 129 this._collectionEnabled = true; | 156 this._collectionEnabled = true; |
| 130 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin gStarted); | 157 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin gStarted); |
| 131 }, | 158 }, |
| 132 | 159 |
| 133 /** | 160 /** |
| 134 * @param {?Protocol.Error} error | 161 * @param {?Protocol.Error} error |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 if (!accepted) | 256 if (!accepted) |
| 230 return; | 257 return; |
| 231 var saver = new WebInspector.TimelineSaver(stream); | 258 var saver = new WebInspector.TimelineSaver(stream); |
| 232 saver.save(this._payloads, window.navigator.appVersion); | 259 saver.save(this._payloads, window.navigator.appVersion); |
| 233 } | 260 } |
| 234 stream.open(fileName, callback.bind(this)); | 261 stream.open(fileName, callback.bind(this)); |
| 235 }, | 262 }, |
| 236 | 263 |
| 237 reset: function() | 264 reset: function() |
| 238 { | 265 { |
| 239 this._loadedFromFile = false; | 266 this._currentTarget = null; |
| 240 this._payloads = []; | 267 this._payloads = []; |
| 241 this._stringPool = {}; | 268 this._stringPool = {}; |
| 242 this._bindings._reset(); | 269 this._bindings._reset(); |
| 243 WebInspector.TimelineModel.prototype.reset.call(this); | 270 WebInspector.TimelineModel.prototype.reset.call(this); |
| 244 }, | 271 }, |
| 245 | 272 |
| 246 /** | 273 /** |
| 247 * @param {!TimelineAgent.TimelineEvent} record | 274 * @param {!TimelineAgent.TimelineEvent} record |
| 248 */ | 275 */ |
| 249 _internStrings: function(record) | 276 _internStrings: function(record) |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 initiator: function() | 416 initiator: function() |
| 390 { | 417 { |
| 391 return this._initiator; | 418 return this._initiator; |
| 392 }, | 419 }, |
| 393 | 420 |
| 394 /** | 421 /** |
| 395 * @return {?WebInspector.Target} | 422 * @return {?WebInspector.Target} |
| 396 */ | 423 */ |
| 397 target: function() | 424 target: function() |
| 398 { | 425 { |
| 399 return this._model._target; | 426 return this._model._currentTarget; |
| 400 }, | 427 }, |
| 401 | 428 |
| 402 /** | 429 /** |
| 403 * @return {number} | 430 * @return {number} |
| 404 */ | 431 */ |
| 405 selfTime: function() | 432 selfTime: function() |
| 406 { | 433 { |
| 407 return this._selfTime; | 434 return this._selfTime; |
| 408 }, | 435 }, |
| 409 | 436 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 this._model.reset(); | 606 this._model.reset(); |
| 580 } | 607 } |
| 581 | 608 |
| 582 // Skip 0-th element - it is either version or 0. | 609 // Skip 0-th element - it is either version or 0. |
| 583 for (var i = 1, size = items.length; i < size; ++i) | 610 for (var i = 1, size = items.length; i < size; ++i) |
| 584 this._model._addRecord(items[i]); | 611 this._model._addRecord(items[i]); |
| 585 }, | 612 }, |
| 586 | 613 |
| 587 close: function() | 614 close: function() |
| 588 { | 615 { |
| 589 this._model._loadedFromFile = true; | |
| 590 } | 616 } |
| 591 } | 617 } |
| 592 | 618 |
| 593 /** | 619 /** |
| 594 * @constructor | 620 * @constructor |
| 595 * @implements {WebInspector.OutputStreamDelegate} | 621 * @implements {WebInspector.OutputStreamDelegate} |
| 596 * @param {!WebInspector.TimelineModel} model | 622 * @param {!WebInspector.TimelineModel} model |
| 597 * @param {!WebInspector.Progress} progress | 623 * @param {!WebInspector.Progress} progress |
| 598 */ | 624 */ |
| 599 WebInspector.TimelineModelLoadFromFileDelegate = function(model, progress) | 625 WebInspector.TimelineModelLoadFromFileDelegate = function(model, progress) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 break; | 728 break; |
| 703 length += itemLength; | 729 length += itemLength; |
| 704 data.push(item); | 730 data.push(item); |
| 705 ++this._recordIndex; | 731 ++this._recordIndex; |
| 706 } | 732 } |
| 707 if (this._recordIndex === this._payloads.length) | 733 if (this._recordIndex === this._payloads.length) |
| 708 data.push(data.pop() + "]"); | 734 data.push(data.pop() + "]"); |
| 709 stream.write(data.join(separator), this._writeNextChunk.bind(this)); | 735 stream.write(data.join(separator), this._writeNextChunk.bind(this)); |
| 710 } | 736 } |
| 711 } | 737 } |
| OLD | NEW |