Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/timeline/TimelineController.js

Issue 2722993002: [DevTools] Turn TracingManager into SDKModel. (Closed)
Patch Set: review comment Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @implements {SDK.SDKModelObserver<!SDK.CPUProfilerModel>} 6 * @implements {SDK.SDKModelObserver<!SDK.CPUProfilerModel>}
7 * @implements {SDK.TracingManagerClient} 7 * @implements {SDK.TracingManagerClient}
8 * @unrestricted 8 * @unrestricted
9 */ 9 */
10 Timeline.TimelineController = class { 10 Timeline.TimelineController = class {
11 /** 11 /**
12 * @param {!SDK.Target} target 12 * @param {!SDK.TracingManager} tracingManager
13 * @param {!Timeline.PerformanceModel} performanceModel 13 * @param {!Timeline.PerformanceModel} performanceModel
14 * @param {!Timeline.TimelineController.Client} client 14 * @param {!Timeline.TimelineController.Client} client
15 */ 15 */
16 constructor(target, performanceModel, client) { 16 constructor(tracingManager, performanceModel, client) {
17 this._target = target; 17 this._tracingManager = tracingManager;
18 this._performanceModel = performanceModel; 18 this._performanceModel = performanceModel;
19 this._client = client; 19 this._client = client;
20 20
21 this._tracingModelBackingStorage = new Bindings.TempFileBackingStorage('trac ing'); 21 this._tracingModelBackingStorage = new Bindings.TempFileBackingStorage('trac ing');
22 this._tracingModel = new SDK.TracingModel(this._tracingModelBackingStorage); 22 this._tracingModel = new SDK.TracingModel(this._tracingModelBackingStorage);
23 23
24 this._performanceModel.setMainTarget(target); 24 this._performanceModel.setMainTarget(tracingManager.target());
25 25
26 /** @type {!Array<!Timeline.ExtensionTracingSession>} */ 26 /** @type {!Array<!Timeline.ExtensionTracingSession>} */
27 this._extensionSessions = []; 27 this._extensionSessions = [];
28 SDK.targetManager.observeModels(SDK.CPUProfilerModel, this); 28 SDK.targetManager.observeModels(SDK.CPUProfilerModel, this);
29 } 29 }
30 30
31 /** 31 /**
32 * @param {!Timeline.TimelineController.RecordingOptions} options 32 * @param {!Timeline.TimelineController.RecordingOptions} options
33 * @param {!Array<!Extensions.ExtensionTraceProvider>} providers 33 * @param {!Array<!Extensions.ExtensionTraceProvider>} providers
34 * @return {!Promise} 34 * @return {!Promise}
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 this._extensionSessions.forEach(session => session.start()); 73 this._extensionSessions.forEach(session => session.start());
74 var startPromise = this._startRecordingWithCategories(categoriesArray.join(' ,'), options.enableJSSampling); 74 var startPromise = this._startRecordingWithCategories(categoriesArray.join(' ,'), options.enableJSSampling);
75 this._performanceModel.setRecordStartTime(Date.now()); 75 this._performanceModel.setRecordStartTime(Date.now());
76 return startPromise; 76 return startPromise;
77 } 77 }
78 78
79 stopRecording() { 79 stopRecording() {
80 var tracingStoppedPromises = []; 80 var tracingStoppedPromises = [];
81 tracingStoppedPromises.push(new Promise(resolve => this._tracingCompleteCall back = resolve)); 81 tracingStoppedPromises.push(new Promise(resolve => this._tracingCompleteCall back = resolve));
82 tracingStoppedPromises.push(this._stopProfilingOnAllModels()); 82 tracingStoppedPromises.push(this._stopProfilingOnAllModels());
83 this._target.tracingManager.stop(); 83 this._tracingManager.stop();
84 tracingStoppedPromises.push(SDK.targetManager.resumeAllTargets()); 84 tracingStoppedPromises.push(SDK.targetManager.resumeAllTargets());
85 85
86 this._client.loadingStarted(); 86 this._client.loadingStarted();
87 87
88 var extensionCompletionPromises = this._extensionSessions.map(session => ses sion.stop()); 88 var extensionCompletionPromises = this._extensionSessions.map(session => ses sion.stop());
89 if (extensionCompletionPromises.length) { 89 if (extensionCompletionPromises.length) {
90 var timerId; 90 var timerId;
91 var timeoutPromise = new Promise(fulfill => timerId = setTimeout(fulfill, 5000)); 91 var timeoutPromise = new Promise(fulfill => timerId = setTimeout(fulfill, 5000));
92 tracingStoppedPromises.push( 92 tracingStoppedPromises.push(
93 Promise.race([Promise.all(extensionCompletionPromises).then(() => clea rTimeout(timerId)), timeoutPromise])); 93 Promise.race([Promise.all(extensionCompletionPromises).then(() => clea rTimeout(timerId)), timeoutPromise]));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 * @param {boolean=} enableJSSampling 156 * @param {boolean=} enableJSSampling
157 * @return {!Promise} 157 * @return {!Promise}
158 */ 158 */
159 _startRecordingWithCategories(categories, enableJSSampling) { 159 _startRecordingWithCategories(categories, enableJSSampling) {
160 SDK.targetManager.suspendAllTargets(); 160 SDK.targetManager.suspendAllTargets();
161 var profilingStartedPromise = enableJSSampling && !Runtime.experiments.isEna bled('timelineTracingJSProfile') ? 161 var profilingStartedPromise = enableJSSampling && !Runtime.experiments.isEna bled('timelineTracingJSProfile') ?
162 this._startProfilingOnAllModels() : 162 this._startProfilingOnAllModels() :
163 Promise.resolve(); 163 Promise.resolve();
164 var samplingFrequencyHz = Common.moduleSetting('highResolutionCpuProfiling') .get() ? 10000 : 1000; 164 var samplingFrequencyHz = Common.moduleSetting('highResolutionCpuProfiling') .get() ? 10000 : 1000;
165 var options = 'sampling-frequency=' + samplingFrequencyHz; 165 var options = 'sampling-frequency=' + samplingFrequencyHz;
166 var tracingManager = this._target.tracingManager; 166 return profilingStartedPromise.then(() => this._tracingManager.start(this, c ategories, options));
167 return profilingStartedPromise.then(() => tracingManager.start(this, categor ies, options));
168 } 167 }
169 168
170 /** 169 /**
171 * @param {!Array.<!SDK.TracingManager.EventPayload>} events 170 * @param {!Array.<!SDK.TracingManager.EventPayload>} events
172 * @override 171 * @override
173 */ 172 */
174 traceEventsCollected(events) { 173 traceEventsCollected(events) {
175 this._tracingModel.addEvents(events); 174 this._tracingModel.addEvents(events);
176 } 175 }
177 176
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 return; 218 return;
220 219
221 var metadataEventTypes = TimelineModel.TimelineModel.DevToolsMetadataEvent; 220 var metadataEventTypes = TimelineModel.TimelineModel.DevToolsMetadataEvent;
222 var metadataEvents = this._tracingModel.devToolsMetadataEvents(); 221 var metadataEvents = this._tracingModel.devToolsMetadataEvents();
223 var mainMetaEvent = 222 var mainMetaEvent =
224 metadataEvents.filter(event => event.name === metadataEventTypes.Tracing StartedInPage).peekLast(); 223 metadataEvents.filter(event => event.name === metadataEventTypes.Tracing StartedInPage).peekLast();
225 if (!mainMetaEvent) 224 if (!mainMetaEvent)
226 return; 225 return;
227 226
228 var pid = mainMetaEvent.thread.process().id(); 227 var pid = mainMetaEvent.thread.process().id();
229 var mainCpuProfile = this._cpuProfiles.get(this._target.id()); 228 var mainCpuProfile = this._cpuProfiles.get(this._tracingManager.target().id( ));
230 this._injectCpuProfileEvent(pid, mainMetaEvent.thread.id(), mainCpuProfile); 229 this._injectCpuProfileEvent(pid, mainMetaEvent.thread.id(), mainCpuProfile);
231 230
232 var workerMetaEvents = metadataEvents.filter(event => event.name === metadat aEventTypes.TracingSessionIdForWorker); 231 var workerMetaEvents = metadataEvents.filter(event => event.name === metadat aEventTypes.TracingSessionIdForWorker);
233 for (var metaEvent of workerMetaEvents) { 232 for (var metaEvent of workerMetaEvents) {
234 var workerId = metaEvent.args['data']['workerId']; 233 var workerId = metaEvent.args['data']['workerId'];
235 var workerTarget = SDK.targetManager.targetById(workerId); 234 var cpuProfile = this._cpuProfiles.get(workerId);
236 if (!workerTarget)
237 continue;
238 var cpuProfile = this._cpuProfiles.get(workerTarget.id());
239 this._injectCpuProfileEvent( 235 this._injectCpuProfileEvent(
240 metaEvent.thread.process().id(), metaEvent.args['data']['workerThreadI d'], cpuProfile); 236 metaEvent.thread.process().id(), metaEvent.args['data']['workerThreadI d'], cpuProfile);
241 } 237 }
242 this._cpuProfiles = null; 238 this._cpuProfiles = null;
243 } 239 }
244 240
245 /** 241 /**
246 * @param {number} usage 242 * @param {number} usage
247 * @override 243 * @override
248 */ 244 */
(...skipping 24 matching lines...) Expand all
273 }; 269 };
274 270
275 /** 271 /**
276 * @typedef {!{ 272 * @typedef {!{
277 * enableJSSampling: (boolean|undefined), 273 * enableJSSampling: (boolean|undefined),
278 * capturePictures: (boolean|undefined), 274 * capturePictures: (boolean|undefined),
279 * captureFilmStrip: (boolean|undefined) 275 * captureFilmStrip: (boolean|undefined)
280 * }} 276 * }}
281 */ 277 */
282 Timeline.TimelineController.RecordingOptions; 278 Timeline.TimelineController.RecordingOptions;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698