Commit 001da8df authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

DevTools: Remove _pendingPerformanceModel

Change-Id: Id6c781b5f3d113d6575f314b301f923c4221b83d
Reviewed-on: https://chromium-review.googlesource.com/998675
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548666}
parent f7bae46e
...@@ -8,42 +8,41 @@ ...@@ -8,42 +8,41 @@
await TestRunner.loadModule('performance_test_runner'); await TestRunner.loadModule('performance_test_runner');
await TestRunner.showPanel('timeline'); await TestRunner.showPanel('timeline');
TestTimelineControllerClient = function() { class TestTimelineControllerClient {
this._hadLoadingProgress = false; constructor() {
}; this._hadLoadingProgress = false;
}
TestTimelineControllerClient.prototype = { recordingProgress() {
recordingProgress: function() {
if (!controller) if (!controller)
return; return;
TestRunner.addResult('TimelineControllerClient.recordingProgress'); TestRunner.addResult('TimelineControllerClient.recordingProgress');
controller.stopRecording(); controller.stopRecording();
controller = null; controller = null;
}, }
loadingStarted: function() { loadingStarted() {
TestRunner.addResult('TimelineControllerClient.loadingStarted'); TestRunner.addResult('TimelineControllerClient.loadingStarted');
}, }
loadingProgress: function() { loadingProgress() {
if (this._hadLoadingProgress) if (this._hadLoadingProgress)
return; return;
this._hadLoadingProgress = true; this._hadLoadingProgress = true;
TestRunner.addResult('TimelineControllerClient.loadingProgress'); TestRunner.addResult('TimelineControllerClient.loadingProgress');
}, }
processingStarted: function() { processingStarted() {
TestRunner.addResult('TimelineControllerClient.processingStarted'); TestRunner.addResult('TimelineControllerClient.processingStarted');
}, }
loadingComplete: function() { loadingComplete() {
TestRunner.addResult('TimelineControllerClient.loadingComplete'); TestRunner.addResult('TimelineControllerClient.loadingComplete');
TestRunner.completeTest(); TestRunner.completeTest();
} }
}; };
var performanceModel = new Timeline.PerformanceModel();
var controller = let controller = new Timeline.TimelineController(SDK.targetManager.mainTarget(), new TestTimelineControllerClient());
new Timeline.TimelineController(TestRunner.tracingManager, performanceModel, new TestTimelineControllerClient());
controller.startRecording({}, []).then(() => { controller.startRecording({}, []).then(() => {
TestRunner.addResult('TimelineControllerClient.recordingStarted'); TestRunner.addResult('TimelineControllerClient.recordingStarted');
}); });
......
...@@ -236,11 +236,11 @@ ...@@ -236,11 +236,11 @@
samples: [2, 2, 3, 3, 3, 4, 4, 2, 2] samples: [2, 2, 3, 3, 3, 4, 4, 2, 2]
}; };
var timelineController = PerformanceTestRunner.timelineController(); var timelineController = PerformanceTestRunner.createTimelineController();
timelineController._addCpuProfile(SDK.targetManager.mainTarget().id(), cpuProfile); timelineController._addCpuProfile(SDK.targetManager.mainTarget().id(), cpuProfile);
timelineController.traceEventsCollected(rawTraceEvents); timelineController.traceEventsCollected(rawTraceEvents);
timelineController._finalizeTrace(); timelineController._finalizeTrace();
var events = timelineController._performanceModel.timelineModel().inspectedTargetEvents(); var events = UI.panels.timeline._performanceModel.timelineModel().inspectedTargetEvents();
events.forEach( events.forEach(
e => TestRunner.addResult( e => TestRunner.addResult(
`${e.name}: ${e.startTime} ${(e.selfTime || 0).toFixed(2)}/${(e.duration || 0).toFixed(2)}`)); `${e.name}: ${e.startTime} ${(e.selfTime || 0).toFixed(2)}/${(e.duration || 0).toFixed(2)}`));
......
...@@ -89,7 +89,7 @@ PerformanceTestRunner.invokeWithTracing = function(functionName, callback, addit ...@@ -89,7 +89,7 @@ PerformanceTestRunner.invokeWithTracing = function(functionName, callback, addit
categories += ',' + additionalCategories; categories += ',' + additionalCategories;
const timelinePanel = UI.panels.timeline; const timelinePanel = UI.panels.timeline;
const timelineController = PerformanceTestRunner.timelineController(); const timelineController = PerformanceTestRunner.createTimelineController();
timelinePanel._timelineController = timelineController; timelinePanel._timelineController = timelineController;
timelineController._startRecordingWithCategories(categories, enableJSSampling).then(tracingStarted); timelineController._startRecordingWithCategories(categories, enableJSSampling).then(tracingStarted);
...@@ -126,10 +126,10 @@ PerformanceTestRunner.createPerformanceModelWithEvents = function(events) { ...@@ -126,10 +126,10 @@ PerformanceTestRunner.createPerformanceModelWithEvents = function(events) {
return performanceModel; return performanceModel;
}; };
PerformanceTestRunner.timelineController = function() { PerformanceTestRunner.createTimelineController = function() {
const performanceModel = new Timeline.PerformanceModel(); const controller = new Timeline.TimelineController(SDK.targetManager.mainTarget(), UI.panels.timeline);
UI.panels.timeline._pendingPerformanceModel = performanceModel; controller._tracingManager = TestRunner.tracingManager;
return new Timeline.TimelineController(TestRunner.tracingManager, performanceModel, UI.panels.timeline); return controller;
}; };
PerformanceTestRunner.runWhenTimelineIsReady = function(callback) { PerformanceTestRunner.runWhenTimelineIsReady = function(callback) {
......
...@@ -9,20 +9,18 @@ ...@@ -9,20 +9,18 @@
*/ */
Timeline.TimelineController = class { Timeline.TimelineController = class {
/** /**
* @param {!SDK.TracingManager} tracingManager * @param {!SDK.Target} target
* @param {!Timeline.PerformanceModel} performanceModel
* @param {!Timeline.TimelineController.Client} client * @param {!Timeline.TimelineController.Client} client
*/ */
constructor(tracingManager, performanceModel, client) { constructor(target, client) {
this._tracingManager = tracingManager; this._tracingManager = target.model(SDK.TracingManager);
this._performanceModel = performanceModel; this._performanceModel = new Timeline.PerformanceModel();
this._performanceModel.setMainTarget(target);
this._client = client; this._client = client;
const backingStorage = new Bindings.TempFileBackingStorage(); const backingStorage = new Bindings.TempFileBackingStorage();
this._tracingModel = new SDK.TracingModel(backingStorage); this._tracingModel = new SDK.TracingModel(backingStorage);
this._performanceModel.setMainTarget(tracingManager.target());
/** @type {!Array<!Timeline.ExtensionTracingSession>} */ /** @type {!Array<!Timeline.ExtensionTracingSession>} */
this._extensionSessions = []; this._extensionSessions = [];
SDK.targetManager.observeModels(SDK.CPUProfilerModel, this); SDK.targetManager.observeModels(SDK.CPUProfilerModel, this);
...@@ -86,7 +84,10 @@ Timeline.TimelineController = class { ...@@ -86,7 +84,10 @@ Timeline.TimelineController = class {
return startPromise; return startPromise;
} }
stopRecording() { /**
* @return {!Promise<!Timeline.PerformanceModel>}
*/
async stopRecording() {
const tracingStoppedPromises = []; const tracingStoppedPromises = [];
tracingStoppedPromises.push(new Promise(resolve => this._tracingCompleteCallback = resolve)); tracingStoppedPromises.push(new Promise(resolve => this._tracingCompleteCallback = resolve));
tracingStoppedPromises.push(this._stopProfilingOnAllModels()); tracingStoppedPromises.push(this._stopProfilingOnAllModels());
...@@ -97,12 +98,12 @@ Timeline.TimelineController = class { ...@@ -97,12 +98,12 @@ Timeline.TimelineController = class {
const extensionCompletionPromises = this._extensionSessions.map(session => session.stop()); const extensionCompletionPromises = this._extensionSessions.map(session => session.stop());
if (extensionCompletionPromises.length) { if (extensionCompletionPromises.length) {
let timerId;
const timeoutPromise = new Promise(fulfill => timerId = setTimeout(fulfill, 5000));
tracingStoppedPromises.push( tracingStoppedPromises.push(
Promise.race([Promise.all(extensionCompletionPromises).then(() => clearTimeout(timerId)), timeoutPromise])); Promise.race([Promise.all(extensionCompletionPromises), new Promise(r => setTimeout(r, 5000))]));
} }
Promise.all(tracingStoppedPromises).then(() => this._allSourcesFinished()); await Promise.all(tracingStoppedPromises);
this._allSourcesFinished();
return this._performanceModel;
} }
/** /**
......
...@@ -55,17 +55,15 @@ Timeline.TimelineLoader = class { ...@@ -55,17 +55,15 @@ Timeline.TimelineLoader = class {
setTimeout(async () => { setTimeout(async () => {
const eventsPerChunk = 5000; const eventsPerChunk = 5000;
const yieldEventLoopToPaint = () => new Promise(res => setTimeout(res, 0));
client.loadingStarted(); client.loadingStarted();
for (let i = 0; i < events.length; i += eventsPerChunk) { for (let i = 0; i < events.length; i += eventsPerChunk) {
const chunk = events.slice(i, i + eventsPerChunk); const chunk = events.slice(i, i + eventsPerChunk);
loader._tracingModel.addEvents(chunk); loader._tracingModel.addEvents(chunk);
client.loadingProgress((i + chunk.length) / events.length); client.loadingProgress((i + chunk.length) / events.length);
await yieldEventLoopToPaint(); await new Promise(r => setTimeout(r)); // Yield event loop to paint.
} }
loader.close(); loader.close();
}, 0); });
return loader; return loader;
} }
......
...@@ -64,8 +64,6 @@ Timeline.TimelinePanel = class extends UI.Panel { ...@@ -64,8 +64,6 @@ Timeline.TimelinePanel = class extends UI.Panel {
/** @type {?Timeline.PerformanceModel} */ /** @type {?Timeline.PerformanceModel} */
this._performanceModel = null; this._performanceModel = null;
/** @type {?Timeline.PerformanceModel} */
this._pendingPerformanceModel = null;
this._viewModeSetting = this._viewModeSetting =
Common.settings.createSetting('timelineViewMode', Timeline.TimelinePanel.ViewMode.FlameChart); Common.settings.createSetting('timelineViewMode', Timeline.TimelinePanel.ViewMode.FlameChart);
...@@ -331,7 +329,10 @@ Timeline.TimelinePanel = class extends UI.Panel { ...@@ -331,7 +329,10 @@ Timeline.TimelinePanel = class extends UI.Panel {
_prepareToLoadTimeline() { _prepareToLoadTimeline() {
console.assert(this._state === Timeline.TimelinePanel.State.Idle); console.assert(this._state === Timeline.TimelinePanel.State.Idle);
this._setState(Timeline.TimelinePanel.State.Loading); this._setState(Timeline.TimelinePanel.State.Loading);
this._pendingPerformanceModel = new Timeline.PerformanceModel(); if (this._performanceModel) {
this._performanceModel.dispose();
this._performanceModel = null;
}
} }
_createFileSelector() { _createFileSelector() {
...@@ -479,11 +480,7 @@ Timeline.TimelinePanel = class extends UI.Panel { ...@@ -479,11 +480,7 @@ Timeline.TimelinePanel = class extends UI.Panel {
/** /**
* @return {!Promise} * @return {!Promise}
*/ */
_startRecording() { async _startRecording() {
const tracingManagers = SDK.targetManager.models(SDK.TracingManager);
if (!tracingManagers.length)
return Promise.resolve();
console.assert(!this._statusPane, 'Status pane is already opened.'); console.assert(!this._statusPane, 'Status pane is already opened.');
this._setState(Timeline.TimelinePanel.State.StartPending); this._setState(Timeline.TimelinePanel.State.StartPending);
this._showRecordingStarted(); this._showRecordingStarted();
...@@ -497,24 +494,24 @@ Timeline.TimelinePanel = class extends UI.Panel { ...@@ -497,24 +494,24 @@ Timeline.TimelinePanel = class extends UI.Panel {
captureFilmStrip: this._showScreenshotsSetting.get() captureFilmStrip: this._showScreenshotsSetting.get()
}; };
this._pendingPerformanceModel = new Timeline.PerformanceModel(); const mainTarget = /** @type {!SDK.Target} */ (SDK.targetManager.mainTarget());
this._controller = new Timeline.TimelineController(tracingManagers[0], this._pendingPerformanceModel, this); this._controller = new Timeline.TimelineController(mainTarget, this);
this._setUIControlsEnabled(false); this._setUIControlsEnabled(false);
this._hideLandingPage(); this._hideLandingPage();
return this._controller.startRecording(recordingOptions, enabledTraceProviders) await this._controller.startRecording(recordingOptions, enabledTraceProviders);
.then(() => this._recordingStarted()); this._recordingStarted();
} }
_stopRecording() { async _stopRecording() {
if (this._statusPane) { if (this._statusPane) {
this._statusPane.finish(); this._statusPane.finish();
this._statusPane.updateStatus(Common.UIString('Stopping timeline\u2026')); this._statusPane.updateStatus(Common.UIString('Stopping timeline\u2026'));
this._statusPane.updateProgressBar(Common.UIString('Received'), 0); this._statusPane.updateProgressBar(Common.UIString('Received'), 0);
} }
this._setState(Timeline.TimelinePanel.State.StopPending); this._setState(Timeline.TimelinePanel.State.StopPending);
this._controller.stopRecording(); this._performanceModel = await this._controller.stopRecording();
this._controller = null;
this._setUIControlsEnabled(true); this._setUIControlsEnabled(true);
this._controller = null;
} }
_onSuspendStateChanged() { _onSuspendStateChanged() {
...@@ -720,22 +717,21 @@ Timeline.TimelinePanel = class extends UI.Panel { ...@@ -720,22 +717,21 @@ Timeline.TimelinePanel = class extends UI.Panel {
loadingComplete(tracingModel) { loadingComplete(tracingModel) {
delete this._loader; delete this._loader;
this._setState(Timeline.TimelinePanel.State.Idle); this._setState(Timeline.TimelinePanel.State.Idle);
const performanceModel = this._pendingPerformanceModel;
this._pendingPerformanceModel = null;
if (this._statusPane) if (this._statusPane)
this._statusPane.hide(); this._statusPane.hide();
delete this._statusPane; delete this._statusPane;
if (!tracingModel) { if (!tracingModel) {
performanceModel.dispose();
this._clear(); this._clear();
return; return;
} }
performanceModel.setTracingModel(tracingModel); if (!this._performanceModel)
this._setModel(performanceModel); this._performanceModel = new Timeline.PerformanceModel();
this._historyManager.addRecording(performanceModel); this._performanceModel.setTracingModel(tracingModel);
this._setModel(this._performanceModel);
this._historyManager.addRecording(this._performanceModel);
} }
_showRecordingStarted() { _showRecordingStarted() {
...@@ -772,23 +768,18 @@ Timeline.TimelinePanel = class extends UI.Panel { ...@@ -772,23 +768,18 @@ Timeline.TimelinePanel = class extends UI.Panel {
/** /**
* @param {!Common.Event} event * @param {!Common.Event} event
*/ */
_loadEventFired(event) { async _loadEventFired(event) {
if (this._state !== Timeline.TimelinePanel.State.Recording || !this._recordingPageReload || if (this._state !== Timeline.TimelinePanel.State.Recording || !this._recordingPageReload ||
this._controller.mainTarget() !== event.data.resourceTreeModel.target()) this._controller.mainTarget() !== event.data.resourceTreeModel.target())
return; return;
setTimeout(stopRecordingOnReload.bind(this, this._controller), this._millisecondsToRecordAfterLoadEvent); const controller = this._controller;
await new Promise(r => setTimeout(r, this._millisecondsToRecordAfterLoadEvent));
/** // Check if we're still in the same recording session.
* @param {!Timeline.TimelineController} controller if (controller !== this._controller)
* @this {Timeline.TimelinePanel} return;
*/ this._recordingPageReload = false;
function stopRecordingOnReload(controller) { this._stopRecording();
// Check if we're still in the same recording session.
if (controller !== this._controller)
return;
this._recordingPageReload = false;
this._stopRecording();
}
} }
/** /**
......
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