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();
......
......@@ -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