Commit 2633f81e authored by sergeyv@chromium.org's avatar sergeyv@chromium.org

DevTools: Support multiple target in TimelineModelImpl

BUG=

Review URL: https://codereview.chromium.org/397823003

git-svn-id: svn://svn.chromium.org/blink/trunk@178567 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d0fa1f75
...@@ -43,6 +43,8 @@ InspectorTest.startTimeline = function(callback) ...@@ -43,6 +43,8 @@ InspectorTest.startTimeline = function(callback)
InspectorTest._timelineRecords = []; InspectorTest._timelineRecords = [];
WebInspector.inspectorView.panel("timeline").toggleTimelineButton.toggled = true; WebInspector.inspectorView.panel("timeline").toggleTimelineButton.toggled = true;
WebInspector.inspectorView.panel("timeline")._model._collectionEnabled = true; WebInspector.inspectorView.panel("timeline")._model._collectionEnabled = true;
WebInspector.inspectorView.panel("timeline")._model._currentTarget = WebInspector.targetManager.mainTarget();
TimelineAgent.start(5, false, undefined, true, false, callback); TimelineAgent.start(5, false, undefined, true, false, callback);
function addRecord(record) function addRecord(record)
{ {
......
...@@ -21,6 +21,7 @@ function test() ...@@ -21,6 +21,7 @@ function test()
{ {
WebInspector.inspectorView.showPanel("timeline"); WebInspector.inspectorView.showPanel("timeline");
WebInspector.panels.timeline._model._collectionEnabled = true; WebInspector.panels.timeline._model._collectionEnabled = true;
WebInspector.inspectorView.panel("timeline")._model._currentTarget = WebInspector.targetManager.mainTarget();
TimelineAgent.start(step1); TimelineAgent.start(step1);
......
...@@ -73,10 +73,10 @@ WebInspector.TimelineManager.prototype = { ...@@ -73,10 +73,10 @@ WebInspector.TimelineManager.prototype = {
if (WebInspector.experimentsSettings.timelineJSCPUProfile.isEnabled() && maxCallStackDepth) { if (WebInspector.experimentsSettings.timelineJSCPUProfile.isEnabled() && maxCallStackDepth) {
this._configureCpuProfilerSamplingInterval(); this._configureCpuProfilerSamplingInterval();
this._jsProfilerStarted = true; this._jsProfilerStarted = true;
ProfilerAgent.start(); this.target().profilerAgent().start();
} }
if (this._enablementCount === 1) if (this._enablementCount === 1)
TimelineAgent.start(maxCallStackDepth, bufferEvents, liveEvents, includeCounters, includeGPUEvents, callback); this.target().timelineAgent().start(maxCallStackDepth, bufferEvents, liveEvents, includeCounters, includeGPUEvents, callback);
else if (callback) else if (callback)
callback(null); callback(null);
}, },
...@@ -97,11 +97,11 @@ WebInspector.TimelineManager.prototype = { ...@@ -97,11 +97,11 @@ WebInspector.TimelineManager.prototype = {
var callbackBarrier = new CallbackBarrier(); var callbackBarrier = new CallbackBarrier();
if (this._jsProfilerStarted) { if (this._jsProfilerStarted) {
ProfilerAgent.stop(callbackBarrier.createCallback(profilerCallback)); this.target().profilerAgent().stop(callbackBarrier.createCallback(profilerCallback));
this._jsProfilerStarted = false; this._jsProfilerStarted = false;
} }
if (!this._enablementCount) if (!this._enablementCount)
TimelineAgent.stop(callbackBarrier.createCallback(this._processBufferedEvents.bind(this, timelineCallback))); this.target().timelineAgent().stop(callbackBarrier.createCallback(this._processBufferedEvents.bind(this, timelineCallback)));
callbackBarrier.callWhenDone(allDoneCallback.bind(this)); callbackBarrier.callWhenDone(allDoneCallback.bind(this));
...@@ -151,7 +151,7 @@ WebInspector.TimelineManager.prototype = { ...@@ -151,7 +151,7 @@ WebInspector.TimelineManager.prototype = {
_configureCpuProfilerSamplingInterval: function() _configureCpuProfilerSamplingInterval: function()
{ {
var intervalUs = WebInspector.settings.highResolutionCpuProfiling.get() ? 100 : 1000; var intervalUs = WebInspector.settings.highResolutionCpuProfiling.get() ? 100 : 1000;
ProfilerAgent.setSamplingInterval(intervalUs, didChangeInterval); this.target().profilerAgent().setSamplingInterval(intervalUs, didChangeInterval);
function didChangeInterval(error) function didChangeInterval(error)
{ {
......
...@@ -156,14 +156,6 @@ WebInspector.TimelineModel.prototype = { ...@@ -156,14 +156,6 @@ WebInspector.TimelineModel.prototype = {
{ {
}, },
/**
* @return {boolean}
*/
loadedFromFile: function()
{
return false;
},
/** /**
* @param {?function(!WebInspector.TimelineModel.Record)|?function(!WebInspector.TimelineModel.Record,number)} preOrderCallback * @param {?function(!WebInspector.TimelineModel.Record)|?function(!WebInspector.TimelineModel.Record,number)} preOrderCallback
* @param {function(!WebInspector.TimelineModel.Record)|function(!WebInspector.TimelineModel.Record,number)=} postOrderCallback * @param {function(!WebInspector.TimelineModel.Record)|function(!WebInspector.TimelineModel.Record,number)=} postOrderCallback
...@@ -263,7 +255,6 @@ WebInspector.TimelineModel.prototype = { ...@@ -263,7 +255,6 @@ WebInspector.TimelineModel.prototype = {
reset: function() reset: function()
{ {
this._loadedFromFile = false;
this._records = []; this._records = [];
this._minimumRecordTime = 0; this._minimumRecordTime = 0;
this._maximumRecordTime = 0; this._maximumRecordTime = 0;
......
...@@ -5,33 +5,40 @@ ...@@ -5,33 +5,40 @@
/** /**
* @constructor * @constructor
* @extends {WebInspector.TimelineModel} * @extends {WebInspector.TimelineModel}
* @param {!WebInspector.TimelineManager} timelineManager * @implements {WebInspector.TargetManager.Observer}
*/ */
WebInspector.TimelineModelImpl = function(timelineManager) WebInspector.TimelineModelImpl = function()
{ {
WebInspector.TimelineModel.call(this); WebInspector.TimelineModel.call(this);
this._target = timelineManager.target(); /** @type {?WebInspector.Target} */
this._timelineManager = timelineManager; this._currentTarget = null;
this._filters = []; this._filters = [];
this._bindings = new WebInspector.TimelineModelImpl.InterRecordBindings(); this._bindings = new WebInspector.TimelineModelImpl.InterRecordBindings();
this.reset(); this.reset();
this._timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, this._onRecordAdded, this); WebInspector.targetManager.addModelListener(WebInspector.TimelineManager, WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, this._onRecordAdded, this);
this._timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineStarted, this._onStarted, this); WebInspector.targetManager.addModelListener(WebInspector.TimelineManager, WebInspector.TimelineManager.EventTypes.TimelineStarted, this._onStarted, this);
this._timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineStopped, this._onStopped, this); WebInspector.targetManager.addModelListener(WebInspector.TimelineManager, WebInspector.TimelineManager.EventTypes.TimelineStopped, this._onStopped, this);
this._timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineProgress, this._onProgress, this); WebInspector.targetManager.addModelListener(WebInspector.TimelineManager, WebInspector.TimelineManager.EventTypes.TimelineProgress, this._onProgress, this);
WebInspector.targetManager.observeTargets(this);
} }
WebInspector.TimelineModelImpl.TransferChunkLengthBytes = 5000000; WebInspector.TimelineModelImpl.TransferChunkLengthBytes = 5000000;
WebInspector.TimelineModelImpl.prototype = { WebInspector.TimelineModelImpl.prototype = {
/** /**
* @return {boolean} * @param {!WebInspector.Target} target
*/ */
loadedFromFile: function() targetAdded: function(target) { },
/**
* @param {!WebInspector.Target} target
*/
targetRemoved: function(target)
{ {
return this._loadedFromFile; if (this._currentTarget === target)
this._currentTarget = null;
}, },
/** /**
...@@ -42,21 +49,27 @@ WebInspector.TimelineModelImpl.prototype = { ...@@ -42,21 +49,27 @@ WebInspector.TimelineModelImpl.prototype = {
startRecording: function(captureStacks, captureMemory, capturePictures) startRecording: function(captureStacks, captureMemory, capturePictures)
{ {
console.assert(!capturePictures, "Legacy timeline does not support capturing pictures"); console.assert(!capturePictures, "Legacy timeline does not support capturing pictures");
this._clientInitiatedRecording = true;
this.reset(); this.reset();
this._currentTarget = WebInspector.context.flavor(WebInspector.Target);
console.assert(this._currentTarget);
this._clientInitiatedRecording = true;
var maxStackFrames = captureStacks ? 30 : 0; var maxStackFrames = captureStacks ? 30 : 0;
var includeGPUEvents = WebInspector.experimentsSettings.gpuTimeline.isEnabled(); var includeGPUEvents = WebInspector.experimentsSettings.gpuTimeline.isEnabled();
var liveEvents = [ WebInspector.TimelineModel.RecordType.BeginFrame, var liveEvents = [ WebInspector.TimelineModel.RecordType.BeginFrame,
WebInspector.TimelineModel.RecordType.DrawFrame, WebInspector.TimelineModel.RecordType.DrawFrame,
WebInspector.TimelineModel.RecordType.RequestMainThreadFrame, WebInspector.TimelineModel.RecordType.RequestMainThreadFrame,
WebInspector.TimelineModel.RecordType.ActivateLayerTree ]; WebInspector.TimelineModel.RecordType.ActivateLayerTree ];
this._timelineManager.start(maxStackFrames, WebInspector.experimentsSettings.timelineNoLiveUpdate.isEnabled(), liveEvents.join(","), captureMemory, includeGPUEvents, this._fireRecordingStarted.bind(this)); this._currentTarget.timelineManager.start(maxStackFrames, WebInspector.experimentsSettings.timelineNoLiveUpdate.isEnabled(), liveEvents.join(","), captureMemory, includeGPUEvents, this._fireRecordingStarted.bind(this));
}, },
stopRecording: function() stopRecording: function()
{ {
if (!this._currentTarget)
return;
if (!this._clientInitiatedRecording) { if (!this._clientInitiatedRecording) {
this._timelineManager.start(undefined, undefined, undefined, undefined, undefined, stopTimeline.bind(this)); this._currentTarget.timelineManager.start(undefined, undefined, undefined, undefined, undefined, stopTimeline.bind(this));
return; return;
} }
...@@ -67,11 +80,11 @@ WebInspector.TimelineModelImpl.prototype = { ...@@ -67,11 +80,11 @@ WebInspector.TimelineModelImpl.prototype = {
*/ */
function stopTimeline() function stopTimeline()
{ {
this._timelineManager.stop(this._fireRecordingStopped.bind(this)); this._currentTarget.timelineManager.stop(this._fireRecordingStopped.bind(this));
} }
this._clientInitiatedRecording = false; this._clientInitiatedRecording = false;
this._timelineManager.stop(this._fireRecordingStopped.bind(this)); this._currentTarget.timelineManager.stop(this._fireRecordingStopped.bind(this));
}, },
/** /**
...@@ -87,7 +100,8 @@ WebInspector.TimelineModelImpl.prototype = { ...@@ -87,7 +100,8 @@ WebInspector.TimelineModelImpl.prototype = {
*/ */
_onRecordAdded: function(event) _onRecordAdded: function(event)
{ {
if (this._collectionEnabled) var timelineManager = /** @type {!WebInspector.TimelineManager} */ (event.target);
if (this._collectionEnabled && timelineManager.target() === this._currentTarget)
this._addRecord(/** @type {!TimelineAgent.TimelineEvent} */(event.data)); this._addRecord(/** @type {!TimelineAgent.TimelineEvent} */(event.data));
}, },
...@@ -96,10 +110,15 @@ WebInspector.TimelineModelImpl.prototype = { ...@@ -96,10 +110,15 @@ WebInspector.TimelineModelImpl.prototype = {
*/ */
_onStarted: function(event) _onStarted: function(event)
{ {
if (event.data) { if (!event.data || this._collectionEnabled)
// Started from console. return;
this._fireRecordingStarted(); // Started from console.
var timelineManager = /** @type {!WebInspector.TimelineManager} */ (event.target);
if (this._currentTarget !== timelineManager.target()) {
this.reset();
this._currentTarget = timelineManager.target();
} }
this._fireRecordingStarted();
}, },
/** /**
...@@ -107,9 +126,14 @@ WebInspector.TimelineModelImpl.prototype = { ...@@ -107,9 +126,14 @@ WebInspector.TimelineModelImpl.prototype = {
*/ */
_onStopped: function(event) _onStopped: function(event)
{ {
var timelineManager = /** @type {!WebInspector.TimelineManager} */ (event.target);
if (timelineManager.target() !== this._currentTarget)
return;
// If we were buffering events, discard those that got through, the real ones are coming! // If we were buffering events, discard those that got through, the real ones are coming!
if (WebInspector.experimentsSettings.timelineNoLiveUpdate.isEnabled()) if (WebInspector.experimentsSettings.timelineNoLiveUpdate.isEnabled()) {
this.reset(); this.reset();
this._currentTarget = timelineManager.target();
}
if (event.data) { if (event.data) {
// Stopped from console. // Stopped from console.
this._fireRecordingStopped(null, null); this._fireRecordingStopped(null, null);
...@@ -121,7 +145,9 @@ WebInspector.TimelineModelImpl.prototype = { ...@@ -121,7 +145,9 @@ WebInspector.TimelineModelImpl.prototype = {
*/ */
_onProgress: function(event) _onProgress: function(event)
{ {
this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordingProgress, event.data); var timelineManager = /** @type {!WebInspector.TimelineManager} */ (event.target);
if (timelineManager.target() === this._currentTarget)
this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordingProgress, event.data);
}, },
_fireRecordingStarted: function() _fireRecordingStarted: function()
...@@ -236,7 +262,7 @@ WebInspector.TimelineModelImpl.prototype = { ...@@ -236,7 +262,7 @@ WebInspector.TimelineModelImpl.prototype = {
reset: function() reset: function()
{ {
this._loadedFromFile = false; this._currentTarget = null;
this._payloads = []; this._payloads = [];
this._stringPool = {}; this._stringPool = {};
this._bindings._reset(); this._bindings._reset();
...@@ -396,7 +422,7 @@ WebInspector.TimelineModel.RecordImpl.prototype = { ...@@ -396,7 +422,7 @@ WebInspector.TimelineModel.RecordImpl.prototype = {
*/ */
target: function() target: function()
{ {
return this._model._target; return this._model._currentTarget;
}, },
/** /**
...@@ -586,7 +612,6 @@ WebInspector.TimelineModelLoader.prototype = { ...@@ -586,7 +612,6 @@ WebInspector.TimelineModelLoader.prototype = {
close: function() close: function()
{ {
this._model._loadedFromFile = true;
} }
} }
......
...@@ -84,7 +84,7 @@ WebInspector.TimelinePanel = function() ...@@ -84,7 +84,7 @@ WebInspector.TimelinePanel = function()
this._model = this._tracingTimelineModel; this._model = this._tracingTimelineModel;
} else { } else {
this._uiUtils = new WebInspector.TimelineUIUtilsImpl(); this._uiUtils = new WebInspector.TimelineUIUtilsImpl();
this._model = new WebInspector.TimelineModelImpl(WebInspector.timelineManager); this._model = new WebInspector.TimelineModelImpl();
} }
this._model.addEventListener(WebInspector.TimelineModel.Events.RecordingStarted, this._onRecordingStarted, this); this._model.addEventListener(WebInspector.TimelineModel.Events.RecordingStarted, this._onRecordingStarted, this);
...@@ -1040,7 +1040,7 @@ WebInspector.TimelinePanel.prototype = { ...@@ -1040,7 +1040,7 @@ WebInspector.TimelinePanel.prototype = {
break; break;
} }
var title = this._uiUtils.titleForRecord(record); var title = this._uiUtils.titleForRecord(record);
this._uiUtils.generateDetailsContent(record, this._model, this._detailsLinkifier, this.showInDetails.bind(this, title), this._model.loadedFromFile()); this._uiUtils.generateDetailsContent(record, this._model, this._detailsLinkifier, this.showInDetails.bind(this, title));
break; break;
case WebInspector.TimelineSelection.Type.TraceEvent: case WebInspector.TimelineSelection.Type.TraceEvent:
var event = /** @type {!WebInspector.TracingModel.Event} */ (this._selection.object()); var event = /** @type {!WebInspector.TracingModel.Event} */ (this._selection.object());
......
...@@ -582,7 +582,7 @@ WebInspector.TimelineView.prototype = { ...@@ -582,7 +582,7 @@ WebInspector.TimelineView.prototype = {
this._graphRowsElement.appendChild(graphRowElement); this._graphRowsElement.appendChild(graphRowElement);
} }
listRowElement.row.update(record, visibleTop, this._model.loadedFromFile(), this._uiUtils); listRowElement.row.update(record, visibleTop, this._uiUtils);
graphRowElement.row.update(record, this._calculator, this._expandOffset, i, this._uiUtils); graphRowElement.row.update(record, this._calculator, this._expandOffset, i, this._uiUtils);
if (this._lastSelectedRecord === record) { if (this._lastSelectedRecord === record) {
listRowElement.row.renderAsSelected(true); listRowElement.row.renderAsSelected(true);
...@@ -1055,10 +1055,9 @@ WebInspector.TimelineRecordListRow.prototype = { ...@@ -1055,10 +1055,9 @@ WebInspector.TimelineRecordListRow.prototype = {
/** /**
* @param {!WebInspector.TimelinePresentationModel.Record} presentationRecord * @param {!WebInspector.TimelinePresentationModel.Record} presentationRecord
* @param {number} offset * @param {number} offset
* @param {boolean} loadedFromFile
* @param {!WebInspector.TimelineUIUtils} uiUtils * @param {!WebInspector.TimelineUIUtils} uiUtils
*/ */
update: function(presentationRecord, offset, loadedFromFile, uiUtils) update: function(presentationRecord, offset, uiUtils)
{ {
this._record = presentationRecord; this._record = presentationRecord;
var record = presentationRecord.record(); var record = presentationRecord.record();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment