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 console.assert(this._currentTarget); |
| 55 |
45 this._clientInitiatedRecording = true; | 56 this._clientInitiatedRecording = true; |
46 this.reset(); | |
47 var maxStackFrames = captureStacks ? 30 : 0; | 57 var maxStackFrames = captureStacks ? 30 : 0; |
48 var includeGPUEvents = WebInspector.experimentsSettings.gpuTimeline.isEn
abled(); | 58 var includeGPUEvents = WebInspector.experimentsSettings.gpuTimeline.isEn
abled(); |
49 var liveEvents = [ WebInspector.TimelineModel.RecordType.BeginFrame, | 59 var liveEvents = [ WebInspector.TimelineModel.RecordType.BeginFrame, |
50 WebInspector.TimelineModel.RecordType.DrawFrame, | 60 WebInspector.TimelineModel.RecordType.DrawFrame, |
51 WebInspector.TimelineModel.RecordType.RequestMainThre
adFrame, | 61 WebInspector.TimelineModel.RecordType.RequestMainThre
adFrame, |
52 WebInspector.TimelineModel.RecordType.ActivateLayerTr
ee ]; | 62 WebInspector.TimelineModel.RecordType.ActivateLayerTr
ee ]; |
53 this._timelineManager.start(maxStackFrames, WebInspector.experimentsSett
ings.timelineNoLiveUpdate.isEnabled(), liveEvents.join(","), captureMemory, incl
udeGPUEvents, this._fireRecordingStarted.bind(this)); | 63 this._currentTarget.timelineManager.start(maxStackFrames, WebInspector.e
xperimentsSettings.timelineNoLiveUpdate.isEnabled(), liveEvents.join(","), captu
reMemory, includeGPUEvents, this._fireRecordingStarted.bind(this)); |
54 }, | 64 }, |
55 | 65 |
56 stopRecording: function() | 66 stopRecording: function() |
57 { | 67 { |
| 68 if (!this._currentTarget) |
| 69 return; |
| 70 |
58 if (!this._clientInitiatedRecording) { | 71 if (!this._clientInitiatedRecording) { |
59 this._timelineManager.start(undefined, undefined, undefined, undefin
ed, undefined, stopTimeline.bind(this)); | 72 this._currentTarget.timelineManager.start(undefined, undefined, unde
fined, undefined, undefined, stopTimeline.bind(this)); |
60 return; | 73 return; |
61 } | 74 } |
62 | 75 |
63 /** | 76 /** |
64 * Console started this one and we are just sniffing it. Initiate record
ing so that we | 77 * Console started this one and we are just sniffing it. Initiate record
ing so that we |
65 * could stop it. | 78 * could stop it. |
66 * @this {WebInspector.TimelineModelImpl} | 79 * @this {WebInspector.TimelineModelImpl} |
67 */ | 80 */ |
68 function stopTimeline() | 81 function stopTimeline() |
69 { | 82 { |
70 this._timelineManager.stop(this._fireRecordingStopped.bind(this)); | 83 this._currentTarget.timelineManager.stop(this._fireRecordingStopped.
bind(this)); |
71 } | 84 } |
72 | 85 |
73 this._clientInitiatedRecording = false; | 86 this._clientInitiatedRecording = false; |
74 this._timelineManager.stop(this._fireRecordingStopped.bind(this)); | 87 this._currentTarget.timelineManager.stop(this._fireRecordingStopped.bind
(this)); |
75 }, | 88 }, |
76 | 89 |
77 /** | 90 /** |
78 * @return {!Array.<!WebInspector.TimelineModel.Record>} | 91 * @return {!Array.<!WebInspector.TimelineModel.Record>} |
79 */ | 92 */ |
80 records: function() | 93 records: function() |
81 { | 94 { |
82 return this._records; | 95 return this._records; |
83 }, | 96 }, |
84 | 97 |
85 /** | 98 /** |
86 * @param {!WebInspector.Event} event | 99 * @param {!WebInspector.Event} event |
87 */ | 100 */ |
88 _onRecordAdded: function(event) | 101 _onRecordAdded: function(event) |
89 { | 102 { |
90 if (this._collectionEnabled) | 103 var timelineManager = /** @type {!WebInspector.TimelineManager} */ (even
t.target); |
| 104 if (this._collectionEnabled && timelineManager.target() === this._curren
tTarget) |
91 this._addRecord(/** @type {!TimelineAgent.TimelineEvent} */(event.da
ta)); | 105 this._addRecord(/** @type {!TimelineAgent.TimelineEvent} */(event.da
ta)); |
92 }, | 106 }, |
93 | 107 |
94 /** | 108 /** |
95 * @param {!WebInspector.Event} event | 109 * @param {!WebInspector.Event} event |
96 */ | 110 */ |
97 _onStarted: function(event) | 111 _onStarted: function(event) |
98 { | 112 { |
99 if (event.data) { | 113 if (!event.data || this._collectionEnabled) |
100 // Started from console. | 114 return; |
101 this._fireRecordingStarted(); | 115 // Started from console. |
| 116 var timelineManager = /** @type {!WebInspector.TimelineManager} */ (even
t.target); |
| 117 if (this._currentTarget !== timelineManager.target()) { |
| 118 this.reset(); |
| 119 this._currentTarget = timelineManager.target(); |
102 } | 120 } |
| 121 this._fireRecordingStarted(); |
103 }, | 122 }, |
104 | 123 |
105 /** | 124 /** |
106 * @param {!WebInspector.Event} event | 125 * @param {!WebInspector.Event} event |
107 */ | 126 */ |
108 _onStopped: function(event) | 127 _onStopped: function(event) |
109 { | 128 { |
| 129 var timelineManager = /** @type {!WebInspector.TimelineManager} */ (even
t.target); |
| 130 if (timelineManager.target() !== this._currentTarget) |
| 131 return; |
110 // If we were buffering events, discard those that got through, the real
ones are coming! | 132 // If we were buffering events, discard those that got through, the real
ones are coming! |
111 if (WebInspector.experimentsSettings.timelineNoLiveUpdate.isEnabled()) | 133 if (WebInspector.experimentsSettings.timelineNoLiveUpdate.isEnabled()) { |
112 this.reset(); | 134 this.reset(); |
| 135 this._currentTarget = timelineManager.target(); |
| 136 } |
113 if (event.data) { | 137 if (event.data) { |
114 // Stopped from console. | 138 // Stopped from console. |
115 this._fireRecordingStopped(null, null); | 139 this._fireRecordingStopped(null, null); |
116 } | 140 } |
117 }, | 141 }, |
118 | 142 |
119 /** | 143 /** |
120 * @param {!WebInspector.Event} event | 144 * @param {!WebInspector.Event} event |
121 */ | 145 */ |
122 _onProgress: function(event) | 146 _onProgress: function(event) |
123 { | 147 { |
124 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gProgress, event.data); | 148 var timelineManager = /** @type {!WebInspector.TimelineManager} */ (even
t.target); |
| 149 if (timelineManager.target() === this._currentTarget) |
| 150 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Reco
rdingProgress, event.data); |
125 }, | 151 }, |
126 | 152 |
127 _fireRecordingStarted: function() | 153 _fireRecordingStarted: function() |
128 { | 154 { |
129 this._collectionEnabled = true; | 155 this._collectionEnabled = true; |
130 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStarted); | 156 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStarted); |
131 }, | 157 }, |
132 | 158 |
133 /** | 159 /** |
134 * @param {?Protocol.Error} error | 160 * @param {?Protocol.Error} error |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 if (!accepted) | 255 if (!accepted) |
230 return; | 256 return; |
231 var saver = new WebInspector.TimelineSaver(stream); | 257 var saver = new WebInspector.TimelineSaver(stream); |
232 saver.save(this._payloads, window.navigator.appVersion); | 258 saver.save(this._payloads, window.navigator.appVersion); |
233 } | 259 } |
234 stream.open(fileName, callback.bind(this)); | 260 stream.open(fileName, callback.bind(this)); |
235 }, | 261 }, |
236 | 262 |
237 reset: function() | 263 reset: function() |
238 { | 264 { |
239 this._loadedFromFile = false; | 265 this._currentTarget = null; |
240 this._payloads = []; | 266 this._payloads = []; |
241 this._stringPool = {}; | 267 this._stringPool = {}; |
242 this._bindings._reset(); | 268 this._bindings._reset(); |
243 WebInspector.TimelineModel.prototype.reset.call(this); | 269 WebInspector.TimelineModel.prototype.reset.call(this); |
244 }, | 270 }, |
245 | 271 |
246 /** | 272 /** |
247 * @param {!TimelineAgent.TimelineEvent} record | 273 * @param {!TimelineAgent.TimelineEvent} record |
248 */ | 274 */ |
249 _internStrings: function(record) | 275 _internStrings: function(record) |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 initiator: function() | 415 initiator: function() |
390 { | 416 { |
391 return this._initiator; | 417 return this._initiator; |
392 }, | 418 }, |
393 | 419 |
394 /** | 420 /** |
395 * @return {?WebInspector.Target} | 421 * @return {?WebInspector.Target} |
396 */ | 422 */ |
397 target: function() | 423 target: function() |
398 { | 424 { |
399 return this._model._target; | 425 return this._model._currentTarget; |
400 }, | 426 }, |
401 | 427 |
402 /** | 428 /** |
403 * @return {number} | 429 * @return {number} |
404 */ | 430 */ |
405 selfTime: function() | 431 selfTime: function() |
406 { | 432 { |
407 return this._selfTime; | 433 return this._selfTime; |
408 }, | 434 }, |
409 | 435 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 this._model.reset(); | 605 this._model.reset(); |
580 } | 606 } |
581 | 607 |
582 // Skip 0-th element - it is either version or 0. | 608 // Skip 0-th element - it is either version or 0. |
583 for (var i = 1, size = items.length; i < size; ++i) | 609 for (var i = 1, size = items.length; i < size; ++i) |
584 this._model._addRecord(items[i]); | 610 this._model._addRecord(items[i]); |
585 }, | 611 }, |
586 | 612 |
587 close: function() | 613 close: function() |
588 { | 614 { |
589 this._model._loadedFromFile = true; | |
590 } | 615 } |
591 } | 616 } |
592 | 617 |
593 /** | 618 /** |
594 * @constructor | 619 * @constructor |
595 * @implements {WebInspector.OutputStreamDelegate} | 620 * @implements {WebInspector.OutputStreamDelegate} |
596 * @param {!WebInspector.TimelineModel} model | 621 * @param {!WebInspector.TimelineModel} model |
597 * @param {!WebInspector.Progress} progress | 622 * @param {!WebInspector.Progress} progress |
598 */ | 623 */ |
599 WebInspector.TimelineModelLoadFromFileDelegate = function(model, progress) | 624 WebInspector.TimelineModelLoadFromFileDelegate = function(model, progress) |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 break; | 727 break; |
703 length += itemLength; | 728 length += itemLength; |
704 data.push(item); | 729 data.push(item); |
705 ++this._recordIndex; | 730 ++this._recordIndex; |
706 } | 731 } |
707 if (this._recordIndex === this._payloads.length) | 732 if (this._recordIndex === this._payloads.length) |
708 data.push(data.pop() + "]"); | 733 data.push(data.pop() + "]"); |
709 stream.write(data.join(separator), this._writeNextChunk.bind(this)); | 734 stream.write(data.join(separator), this._writeNextChunk.bind(this)); |
710 } | 735 } |
711 } | 736 } |
OLD | NEW |