Commit 6c57bd08 authored by caseq@chromium.org's avatar caseq@chromium.org

DevTools: extract TracingManager from TracingModel

Let TracingManager handle back-end interactions while TracingModel
acts just as a container for trace events. The model will later be
moved out of sdk and this will allow introducing backing storage for
trace events (e.g. a file).

BUG=412709

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

git-svn-id: svn://svn.chromium.org/blink/trunk@181741 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent caf030b0
......@@ -3,8 +3,9 @@ function initialize_TracingTest()
// FIXME: remove when tracing is out of experimental
WebInspector.inspectorView.showPanel("timeline");
InspectorTest.tracingModel = new WebInspector.TracingModel(WebInspector.targetManager.mainTarget());
InspectorTest.tracingTimelineModel = new WebInspector.TracingTimelineModel(InspectorTest.tracingModel, new WebInspector.TimelineRecordHiddenTypeFilter([]));
InspectorTest.tracingManager = WebInspector.panels.timeline._tracingManager || new WebInspector.TracingManager();
InspectorTest.tracingModel = new WebInspector.TracingModel();
InspectorTest.tracingTimelineModel = new WebInspector.TracingTimelineModel(InspectorTest.tracingManager, InspectorTest.tracingModel, new WebInspector.TimelineRecordHiddenTypeFilter([]));
InspectorTest.invokeWithTracing = function(functionName, callback, additionalCategories)
{
......
......@@ -21,6 +21,9 @@ function test()
{
WebInspector.inspectorView.showPanel("timeline");
var tracingManager = new WebInspector.TracingManager();
var tracingModel = new WebInspector.TracingModel();
function runEventsSanityCheck()
{
var events = [];
......@@ -61,22 +64,29 @@ function test()
function onTracingComplete()
{
tracingModel.removeEventListener(WebInspector.TracingModel.Events.TracingComplete, onTracingComplete);
tracingManager.removeEventListener(WebInspector.TracingManager.Events.TracingComplete, onTracingComplete);
InspectorTest.addResult("Tracing complete");
runEventsSanityCheck();
InspectorTest.completeTest();
}
var tracingModel = new WebInspector.TracingModel(WebInspector.targetManager.mainTarget());
tracingModel.start("", "", onTracingStarted);
tracingManager.start("", "", onTracingStarted);
tracingManager.addEventListener(WebInspector.TracingManager.Events.EventsCollected, onEventsCollected);
function onTracingStarted(error)
{
InspectorTest.addResult("Tracing started (error: " + JSON.stringify(error) + ")");
tracingModel.reset();
InspectorTest.evaluateInPage("doWork()", function() {
tracingModel.addEventListener(WebInspector.TracingModel.Events.TracingComplete, onTracingComplete);
tracingModel.stop(onTracingComplete);
tracingManager.addEventListener(WebInspector.TracingManager.Events.TracingComplete, onTracingComplete);
tracingManager.stop();
});
}
function onEventsCollected(event)
{
tracingModel.addEvents(event.data);
}
}
</script>
......
......@@ -7,11 +7,11 @@
function test()
{
InspectorTest.tracingModel.addEventListener(WebInspector.TracingModel.Events.BufferUsage, onBufferUsage, this);
InspectorTest.tracingManager.addEventListener(WebInspector.TracingManager.Events.BufferUsage, onBufferUsage, this);
InspectorTest.tracingTimelineModel.startRecording();
function onBufferUsage(event)
{
InspectorTest.tracingModel.removeEventListener(WebInspector.TracingModel.Events.BufferUsage, onBufferUsage, this);
InspectorTest.tracingManager.removeEventListener(WebInspector.TracingManager.Events.BufferUsage, onBufferUsage, this);
InspectorTest.tracingTimelineModel.stopRecording();
InspectorTest.addResult("SUCCESS: Received buffer usage update.");
InspectorTest.completeTest();
......
......@@ -9,16 +9,17 @@
* @extends {WebInspector.Object}
* @implements {WebInspector.TargetManager.Observer}
*/
WebInspector.TracingModel = function()
WebInspector.TracingManager = function()
{
this.reset();
WebInspector.Object.call(this);
this._active = false;
WebInspector.targetManager.observeTargets(this);
}
WebInspector.TracingModel.Events = {
WebInspector.TracingManager.Events = {
"BufferUsage": "BufferUsage",
"TracingStarted": "TracingStarted",
"EventsCollected": "EventsCollected",
"TracingStopped": "TracingStopped",
"TracingComplete": "TracingComplete"
}
......@@ -36,7 +37,106 @@ WebInspector.TracingModel.Events = {
s: string
}}
*/
WebInspector.TracingModel.EventPayload;
WebInspector.TracingManager.EventPayload;
WebInspector.TracingManager.prototype = {
/**
* @param {!WebInspector.Target} target
*/
targetAdded: function(target)
{
if (this._target)
return;
this._target = target;
InspectorBackend.registerTracingDispatcher(new WebInspector.TracingDispatcher(this));
},
/**
* @param {!WebInspector.Target} target
*/
targetRemoved: function(target)
{
if (this._target !== target)
return;
delete this._target;
},
/**
* @param {number} usage
*/
_bufferUsage: function(usage)
{
this.dispatchEventToListeners(WebInspector.TracingManager.Events.BufferUsage, usage);
},
/**
* @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
*/
_eventsCollected: function(events)
{
this.dispatchEventToListeners(WebInspector.TracingManager.Events.EventsCollected, events);
},
_tracingComplete: function()
{
this.dispatchEventToListeners(WebInspector.TracingManager.Events.TracingComplete);
},
_tracingStarted: function()
{
if (this._active)
return;
this._active = true;
this.dispatchEventToListeners(WebInspector.TracingManager.Events.TracingStarted);
},
/**
* @param {string} categoryFilter
* @param {string} options
* @param {function(?string)=} callback
*/
start: function(categoryFilter, options, callback)
{
if (this._active)
return;
WebInspector.profilingLock().acquire();
this._shouldReleaseLock = true;
var bufferUsageReportingIntervalMs = 500;
TracingAgent.start(categoryFilter, options, bufferUsageReportingIntervalMs, callback);
this._tracingStarted();
this._active = true;
},
stop: function()
{
if (!this._active)
return;
TracingAgent.end(this._onStop.bind(this));
if (this._shouldReleaseLock) {
this._shouldReleaseLock = false;
WebInspector.profilingLock().release();
}
},
_onStop: function()
{
if (!this._active)
return;
this.dispatchEventToListeners(WebInspector.TracingManager.Events.TracingStopped);
this._active = false;
},
__proto__: WebInspector.Object.prototype
}
/**
* @constructor
*/
WebInspector.TracingModel = function()
{
this.reset();
}
/**
* @enum {string}
......@@ -90,27 +190,6 @@ WebInspector.TracingModel.isAsyncPhase = function(phase)
}
WebInspector.TracingModel.prototype = {
/**
* @param {!WebInspector.Target} target
*/
targetAdded: function(target)
{
if (this._target)
return;
this._target = target;
InspectorBackend.registerTracingDispatcher(new WebInspector.TracingDispatcher(this));
},
/**
* @param {!WebInspector.Target} target
*/
targetRemoved: function(target)
{
if (this._target !== target)
return;
delete this._target;
},
/**
* @return {!Array.<!WebInspector.TracingModel.Event>}
*/
......@@ -127,32 +206,6 @@ WebInspector.TracingModel.prototype = {
return this._devtoolsWorkerMetadataEvents;
},
/**
* @param {string} categoryFilter
* @param {string} options
* @param {function(?string)=} callback
*/
start: function(categoryFilter, options, callback)
{
WebInspector.profilingLock().acquire();
this._shouldReleaseLock = true;
this.reset();
var bufferUsageReportingIntervalMs = 500;
TracingAgent.start(categoryFilter, options, bufferUsageReportingIntervalMs, callback);
this._tracingStarted();
},
stop: function()
{
if (!this._active)
return;
TracingAgent.end(this._onStop.bind(this));
if (this._shouldReleaseLock) {
this._shouldReleaseLock = false;
WebInspector.profilingLock().release();
}
},
/**
* @return {?string}
*/
......@@ -162,60 +215,31 @@ WebInspector.TracingModel.prototype = {
},
/**
* @param {!Array.<!WebInspector.TracingModel.EventPayload>} events
* @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
*/
setEventsForTest: function(events)
{
this._tracingStarted();
this._eventsCollected(events);
this._tracingComplete();
},
/**
* @param {number} usage
*/
_bufferUsage: function(usage)
{
this.dispatchEventToListeners(WebInspector.TracingModel.Events.BufferUsage, usage);
this.reset();
this.addEvents(events);
this.tracingComplete();
},
/**
* @param {!Array.<!WebInspector.TracingModel.EventPayload>} events
* @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
*/
_eventsCollected: function(events)
addEvents: function(events)
{
this._onStop();
for (var i = 0; i < events.length; ++i) {
this._addEvent(events[i]);
this._rawEvents.push(events[i]);
}
},
_tracingComplete: function()
tracingComplete: function()
{
this._processMetadataEvents();
this._active = false;
for (var process in this._processById)
this._processById[process]._tracingComplete(this._maximumRecordTime);
this.dispatchEventToListeners(WebInspector.TracingModel.Events.TracingComplete);
},
_tracingStarted: function()
{
if (this._active)
return;
this.reset();
this._active = true;
this._sessionId = null;
this.dispatchEventToListeners(WebInspector.TracingModel.Events.TracingStarted);
},
_onStop: function()
{
if (!this._active)
return;
this.dispatchEventToListeners(WebInspector.TracingModel.Events.TracingStopped);
this._active = false;
},
reset: function()
......@@ -230,7 +254,7 @@ WebInspector.TracingModel.prototype = {
},
/**
* @return {!Array.<!WebInspector.TracingModel.EventPayload>}
* @return {!Array.<!WebInspector.TracingManager.EventPayload>}
*/
rawEvents: function()
{
......@@ -238,7 +262,7 @@ WebInspector.TracingModel.prototype = {
},
/**
* @param {!WebInspector.TracingModel.EventPayload} payload
* @param {!WebInspector.TracingManager.EventPayload} payload
*/
_addEvent: function(payload)
{
......@@ -331,9 +355,7 @@ WebInspector.TracingModel.prototype = {
sortedProcesses: function()
{
return WebInspector.TracingModel.NamedObject._sort(Object.values(this._processById));
},
__proto__: WebInspector.Object.prototype
}
}
......@@ -349,20 +371,20 @@ WebInspector.TracingModel.Loader = function(tracingModel)
WebInspector.TracingModel.Loader.prototype = {
/**
* @param {!Array.<!WebInspector.TracingModel.EventPayload>} events
* @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
*/
loadNextChunk: function(events)
{
if (!this._firstChunkReceived) {
this._tracingModel._tracingStarted();
this._tracingModel.reset();
this._firstChunkReceived = true;
}
this._tracingModel._eventsCollected(events);
this._tracingModel.addEvents(events);
},
finish: function()
{
this._tracingModel._tracingComplete();
this._tracingModel.tracingComplete();
}
}
......@@ -402,7 +424,7 @@ WebInspector.TracingModel.Event = function(category, name, phase, startTime, thr
}
/**
* @param {!WebInspector.TracingModel.EventPayload} payload
* @param {!WebInspector.TracingManager.EventPayload} payload
* @param {?WebInspector.TracingModel.Thread} thread
* @return {!WebInspector.TracingModel.Event}
*/
......@@ -448,7 +470,7 @@ WebInspector.TracingModel.Event.prototype = {
},
/**
* @param {!WebInspector.TracingModel.EventPayload} payload
* @param {!WebInspector.TracingManager.EventPayload} payload
*/
_complete: function(payload)
{
......@@ -544,7 +566,7 @@ WebInspector.TracingModel.Process = function(id)
this._setName("Process " + id);
this._threads = {};
this._objects = {};
/** @type {!Array.<!WebInspector.TracingModel.EventPayload>} */
/** @type {!Array.<!WebInspector.TracingManager.EventPayload>} */
this._asyncEvents = [];
/** @type {!Object.<string, ?Array.<!WebInspector.TracingModel.Event>>} */
this._openAsyncEvents = [];
......@@ -566,7 +588,7 @@ WebInspector.TracingModel.Process.prototype = {
},
/**
* @param {!WebInspector.TracingModel.EventPayload} payload
* @param {!WebInspector.TracingManager.EventPayload} payload
* @return {?WebInspector.TracingModel.Event} event
*/
_addEvent: function(payload)
......@@ -590,8 +612,8 @@ WebInspector.TracingModel.Process.prototype = {
_tracingComplete: function(lastEventTime)
{
/**
* @param {!WebInspector.TracingModel.EventPayload} a
* @param {!WebInspector.TracingModel.EventPayload} b
* @param {!WebInspector.TracingManager.EventPayload} a
* @param {!WebInspector.TracingManager.EventPayload} b
*/
function comparePayloadTimestamp(a, b)
{
......@@ -611,7 +633,7 @@ WebInspector.TracingModel.Process.prototype = {
},
/**
* @param {!WebInspector.TracingModel.EventPayload} payload
* @param {!WebInspector.TracingManager.EventPayload} payload
*/
_addAsyncEvent: function(payload)
{
......@@ -713,7 +735,7 @@ WebInspector.TracingModel.Thread.prototype = {
},
/**
* @param {!WebInspector.TracingModel.EventPayload} payload
* @param {!WebInspector.TracingManager.EventPayload} payload
* @return {?WebInspector.TracingModel.Event} event
*/
_addEvent: function(payload)
......@@ -778,11 +800,11 @@ WebInspector.TracingModel.Thread.prototype = {
/**
* @constructor
* @implements {TracingAgent.Dispatcher}
* @param {!WebInspector.TracingModel} tracingModel
* @param {!WebInspector.TracingManager} tracingManager
*/
WebInspector.TracingDispatcher = function(tracingModel)
WebInspector.TracingDispatcher = function(tracingManager)
{
this._tracingModel = tracingModel;
this._tracingManager = tracingManager;
}
WebInspector.TracingDispatcher.prototype = {
......@@ -791,24 +813,24 @@ WebInspector.TracingDispatcher.prototype = {
*/
bufferUsage: function(usage)
{
this._tracingModel._bufferUsage(usage);
this._tracingManager._bufferUsage(usage);
},
/**
* @param {!Array.<!WebInspector.TracingModel.EventPayload>} data
* @param {!Array.<!WebInspector.TracingManager.EventPayload>} data
*/
dataCollected: function(data)
{
this._tracingModel._eventsCollected(data);
this._tracingManager._eventsCollected(data);
},
tracingComplete: function()
{
this._tracingModel._tracingComplete();
this._tracingManager._tracingComplete();
},
started: function()
{
this._tracingModel._tracingStarted();
this._tracingManager._tracingStarted();
}
}
......@@ -49,11 +49,12 @@ WebInspector.TimelinePanel = function()
// Create model.
if (WebInspector.experimentsSettings.timelineOnTraceEvents.isEnabled()) {
this._tracingModel = new WebInspector.TracingModel();
this._tracingModel.addEventListener(WebInspector.TracingModel.Events.BufferUsage, this._onTracingBufferUsage, this);
this._tracingManager = new WebInspector.TracingManager();
this._tracingManager.addEventListener(WebInspector.TracingManager.Events.BufferUsage, this._onTracingBufferUsage, this);
this._tracingModel = new WebInspector.TracingModel();
this._uiUtils = new WebInspector.TracingTimelineUIUtils();
this._tracingTimelineModel = new WebInspector.TracingTimelineModel(this._tracingModel, this._uiUtils.hiddenRecordsFilter());
this._tracingTimelineModel = new WebInspector.TracingTimelineModel(this._tracingManager, this._tracingModel, this._uiUtils.hiddenRecordsFilter());
this._model = this._tracingTimelineModel;
} else {
this._uiUtils = new WebInspector.TimelineUIUtilsImpl();
......
......@@ -4,17 +4,21 @@
/**
* @constructor
* @param {!WebInspector.TracingManager} tracingManager
* @param {!WebInspector.TracingModel} tracingModel
* @param {!WebInspector.TimelineModel.Filter} recordFilter
* @extends {WebInspector.TimelineModel}
*/
WebInspector.TracingTimelineModel = function(tracingModel, recordFilter)
WebInspector.TracingTimelineModel = function(tracingManager, tracingModel, recordFilter)
{
WebInspector.TimelineModel.call(this);
this._tracingManager = tracingManager;
this._tracingModel = tracingModel;
this._recordFilter = recordFilter;
this._tracingModel.addEventListener(WebInspector.TracingModel.Events.TracingStarted, this._onTracingStarted, this);
this._tracingModel.addEventListener(WebInspector.TracingModel.Events.TracingComplete, this._onTracingComplete, this);
this._tracingManager.addEventListener(WebInspector.TracingManager.Events.TracingStarted, this._onTracingStarted, this);
this._tracingManager.addEventListener(WebInspector.TracingManager.Events.EventsCollected, this._onEventsCollected, this);
this._tracingManager.addEventListener(WebInspector.TracingManager.Events.TracingComplete, this._onTracingComplete, this);
this.reset();
}
......@@ -155,15 +159,17 @@ WebInspector.TracingTimelineModel.prototype = {
this._currentTarget.profilerAgent().stop(this._stopCallbackBarrier.createCallback(this._didStopRecordingJSSamples.bind(this)));
this._jsProfilerStarted = false;
}
this._tracingModel.stop();
this._tracingManager.stop();
},
/**
* @param {!Array.<!WebInspector.TracingModel.EventPayload>} events
* @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
*/
setEventsForTest: function(events)
{
this._tracingModel.setEventsForTest(events);
this._onTracingStarted();
this._tracingModel.addEvents(events);
this._onTracingComplete();
},
_configureCpuProfilerSamplingInterval: function()
......@@ -183,18 +189,28 @@ WebInspector.TracingTimelineModel.prototype = {
*/
_startRecordingWithCategories: function(categories)
{
this.reset();
this._tracingModel.start(categories, "");
this._tracingManager.start(categories, "");
},
_onTracingStarted: function()
{
this.reset();
this._tracingModel.reset();
this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordingStarted);
},
/**
* @param {!WebInspector.Event} event
*/
_onEventsCollected: function(event)
{
var traceEvents = /** @type {!Array.<!WebInspector.TracingManager.EventPayload>} */ (event.data);
this._tracingModel.addEvents(traceEvents);
},
_onTracingComplete: function()
{
this._tracingModel.tracingComplete();
if (this._stopCallbackBarrier)
this._stopCallbackBarrier.callWhenDone(this._didStopRecordingTraceEvents.bind(this));
else
......@@ -947,7 +963,7 @@ WebInspector.TracingModelLoader.prototype = {
return;
if (this._firstChunk) {
this._model.reset();
this._model._onTracingStarted();
} else {
var commaIndex = json.indexOf(",");
if (commaIndex !== -1)
......@@ -957,7 +973,7 @@ WebInspector.TracingModelLoader.prototype = {
var items;
try {
items = /** @type {!Array.<!WebInspector.TracingModel.EventPayload>} */ (JSON.parse(json));
items = /** @type {!Array.<!WebInspector.TracingManager.EventPayload>} */ (JSON.parse(json));
} catch (e) {
this._reportErrorAndCancelLoading("Malformed timeline data: " + e);
return;
......@@ -982,6 +998,7 @@ WebInspector.TracingModelLoader.prototype = {
_reportErrorAndCancelLoading: function(messsage)
{
WebInspector.console.error(messsage);
this._model._onTracingComplete();
this._model.reset();
this._reader.cancel();
this._progress.done();
......@@ -995,6 +1012,7 @@ WebInspector.TracingModelLoader.prototype = {
close: function()
{
this._loader.finish();
this._model._onTracingComplete();
}
}
......
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