Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/timeline/TimelineController.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/timeline/TimelineController.js b/third_party/WebKit/Source/devtools/front_end/timeline/TimelineController.js |
| index 853765d809ae17427fce6fd88ee911a0fb84e292..885c7d4e90777961ee836ac6ba402fa22a1391c8 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/timeline/TimelineController.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/timeline/TimelineController.js |
| @@ -70,10 +70,11 @@ WebInspector.TimelineController.prototype = { |
| stopRecording: function() |
| { |
| - WebInspector.targetManager.resumeAllTargets(); |
| this._allProfilesStoppedPromise = this._stopProfilingOnAllTargets(); |
| - if (this._targets[0]) |
| - this._targets[0].tracingManager.stop(); |
| + var mainTarget = WebInspector.targetManager.mainTarget(); |
| + if (mainTarget) |
| + mainTarget.tracingManager.stop(); |
| + WebInspector.targetManager.resumeAllTargets(); |
| this._delegate.loadingStarted(); |
| }, |
| @@ -114,7 +115,9 @@ WebInspector.TimelineController.prototype = { |
| _startProfilingOnAllTargets: function() |
| { |
| var intervalUs = WebInspector.moduleSetting("highResolutionCpuProfiling").get() ? 100 : 1000; |
| - this._targets[0].profilerAgent().setSamplingInterval(intervalUs); |
| + var mainTarget = WebInspector.targetManager.mainTarget(); |
| + if (mainTarget) |
| + mainTarget.profilerAgent().setSamplingInterval(intervalUs); |
| this._profiling = true; |
| return Promise.all(this._targets.map(this._startProfilingOnTarget)); |
| }, |
| @@ -125,16 +128,23 @@ WebInspector.TimelineController.prototype = { |
| */ |
| _stopProfilingOnTarget: function(target) |
| { |
| - /** |
| - * @param {?Protocol.Error} error |
| - * @param {?ProfilerAgent.CPUProfile} profile |
| - * @return {?ProfilerAgent.CPUProfile} |
| - */ |
| - function extractProfile(error, profile) |
| - { |
| - return !error && profile ? profile : null; |
| + return target.profilerAgent().stop(this._addCpuProfile.bind(this, target.id())); |
| + }, |
| + |
| + /** |
| + * @param {number} targetId |
| + * @param {?Protocol.Error} error |
| + * @param {?ProfilerAgent.CPUProfile} cpuProfile |
| + */ |
| + _addCpuProfile: function(targetId, error, cpuProfile) |
| + { |
| + if (!cpuProfile) { |
| + WebInspector.console.log(WebInspector.UIString("CPU profile for a target is not available. %s", error || "")); |
|
pfeldman
2016/03/17 19:04:04
this could be a warning.
alph
2016/03/17 21:12:39
Done.
|
| + return; |
| } |
| - return target.profilerAgent().stop(extractProfile).then(this._addCpuProfile.bind(this, target.id())); |
| + if (!this._cpuProfiles) |
| + this._cpuProfiles = new Map(); |
| + this._cpuProfiles.set(targetId, cpuProfile); |
| }, |
| /** |
| @@ -161,7 +171,7 @@ WebInspector.TimelineController.prototype = { |
| this._startProfilingOnAllTargets() : Promise.resolve(); |
| var samplingFrequencyHz = WebInspector.moduleSetting("highResolutionCpuProfiling").get() ? 10000 : 1000; |
| var options = "sampling-frequency=" + samplingFrequencyHz; |
| - var mainTarget = this._targets[0]; |
| + var mainTarget = WebInspector.targetManager.mainTarget(); |
| var tracingManager = mainTarget.tracingManager; |
| mainTarget.resourceTreeModel.suspendReload(); |
| profilingStartedPromise.then(tracingManager.start.bind(tracingManager, this, categories, options, onTraceStarted)); |
| @@ -247,7 +257,7 @@ WebInspector.TimelineController.prototype = { |
| return; |
| var pid = mainMetaEvent.thread.process().id(); |
| - var mainTarget = this._targets[0]; |
| + var mainTarget = WebInspector.targetManager.mainTarget(); |
| var mainCpuProfile = this._cpuProfiles.get(mainTarget.id()); |
| this._injectCpuProfileEvent(pid, mainMetaEvent.thread.id(), mainCpuProfile); |
| @@ -279,18 +289,5 @@ WebInspector.TimelineController.prototype = { |
| eventsRetrievalProgress: function(progress) |
| { |
| this._delegate.loadingProgress(progress); |
| - }, |
| - |
| - /** |
| - * @param {number} targetId |
| - * @param {?ProfilerAgent.CPUProfile} cpuProfile |
| - */ |
| - _addCpuProfile: function(targetId, cpuProfile) |
| - { |
| - if (!cpuProfile) |
| - return; |
| - if (!this._cpuProfiles) |
| - this._cpuProfiles = new Map(); |
| - this._cpuProfiles.set(targetId, cpuProfile); |
| } |
| } |