Commit e522b2df authored by caseq's avatar caseq Committed by Commit bot

Timeline: rearrange trace completion logic for better extensibility

This generalize the way we finialize timeline recording so that it's
easier to plug in extension trace providers.

BUG=620066

Review-Url: https://codereview.chromium.org/2137213004
Cr-Commit-Position: refs/heads/master@{#405918}
parent 09f0997b
...@@ -287,12 +287,10 @@ function test() ...@@ -287,12 +287,10 @@ function test()
var timelineController = InspectorTest.timelineController(); var timelineController = InspectorTest.timelineController();
timelineController._addCpuProfile(WebInspector.targetManager.mainTarget().id(), null, cpuProfile); timelineController._addCpuProfile(WebInspector.targetManager.mainTarget().id(), null, cpuProfile);
timelineController.traceEventsCollected(rawTraceEvents); timelineController.traceEventsCollected(rawTraceEvents);
timelineController.tracingComplete(); timelineController._allSourcesFinished();
InspectorTest.addSniffer(WebInspector.panels.timeline, "loadingComplete", () => { var events = InspectorTest.timelineModel().inspectedTargetEvents();
var events = InspectorTest.timelineModel().inspectedTargetEvents(); events.forEach(e => InspectorTest.addResult(e.name + ": " + e.startTime + " " + (e.selfTime || 0).toFixed(2) + "/" + (e.duration || 0).toFixed(2)));
events.forEach(e => InspectorTest.addResult(e.name + ": " + e.startTime + " " + (e.selfTime || 0).toFixed(2) + "/" + (e.duration || 0).toFixed(2))); InspectorTest.completeTest();
InspectorTest.completeTest();
});
} }
</script> </script>
......
...@@ -16,8 +16,6 @@ WebInspector.TimelineController = function(target, delegate, tracingModel) ...@@ -16,8 +16,6 @@ WebInspector.TimelineController = function(target, delegate, tracingModel)
this._target = target; this._target = target;
this._tracingModel = tracingModel; this._tracingModel = tracingModel;
this._targets = []; this._targets = [];
this._allProfilesStoppedPromise = Promise.resolve();
this._targetsResumedPromise = Promise.resolve();
WebInspector.targetManager.observeTargets(this); WebInspector.targetManager.observeTargets(this);
} }
...@@ -73,9 +71,13 @@ WebInspector.TimelineController.prototype = { ...@@ -73,9 +71,13 @@ WebInspector.TimelineController.prototype = {
stopRecording: function() stopRecording: function()
{ {
this._allProfilesStoppedPromise = this._stopProfilingOnAllTargets(); var tracingStoppedPromises = [];
tracingStoppedPromises.push(new Promise(resolve => this._tracingCompleteCallback = resolve));
tracingStoppedPromises.push(this._stopProfilingOnAllTargets());
this._target.tracingManager.stop(); this._target.tracingManager.stop();
this._targetsResumedPromise = WebInspector.targetManager.resumeAllTargets(); tracingStoppedPromises.push(WebInspector.targetManager.resumeAllTargets());
Promise.all(tracingStoppedPromises).then(() => this._allSourcesFinished());
this._delegate.loadingStarted(); this._delegate.loadingStarted();
}, },
...@@ -206,11 +208,11 @@ WebInspector.TimelineController.prototype = { ...@@ -206,11 +208,11 @@ WebInspector.TimelineController.prototype = {
*/ */
tracingComplete: function() tracingComplete: function()
{ {
Promise.all([this._allProfilesStoppedPromise, this._targetsResumedPromise]) this._tracingCompleteCallback();
.then(this._didStopRecordingTraceEvents.bind(this)); this._tracingCompleteCallback = null;
}, },
_didStopRecordingTraceEvents: function() _allSourcesFinished: function()
{ {
this._injectCpuProfileEvents(); this._injectCpuProfileEvents();
this._tracingModel.tracingComplete(); this._tracingModel.tracingComplete();
......
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