Index: Source/devtools/front_end/timeline/TracingTimelineModel.js |
diff --git a/Source/devtools/front_end/timeline/TracingTimelineModel.js b/Source/devtools/front_end/timeline/TracingTimelineModel.js |
index 52a723183a0665eb42897f1d8b5d5853bcf12acb..a89089e572fe069f942a55303ca43d96cc593f93 100644 |
--- a/Source/devtools/front_end/timeline/TracingTimelineModel.js |
+++ b/Source/devtools/front_end/timeline/TracingTimelineModel.js |
@@ -139,12 +139,8 @@ WebInspector.TracingTimelineModel.prototype = { |
]; |
if (captureStacks) { |
categoriesArray.push(disabledByDefault("devtools.timeline.stack")); |
- if (Runtime.experiments.isEnabled("timelineJSCPUProfile")) { |
- this._jsProfilerStarted = true; |
- this._currentTarget = WebInspector.context.flavor(WebInspector.Target); |
- this._configureCpuProfilerSamplingInterval(); |
- this._currentTarget.profilerAgent().start(); |
- } |
+ if (Runtime.experiments.isEnabled("timelineJSCPUProfile")) |
+ this._startCpuProfilingOnAllTargets(); |
} |
if (capturePictures) { |
categoriesArray = categoriesArray.concat([ |
@@ -158,11 +154,8 @@ WebInspector.TracingTimelineModel.prototype = { |
stopRecording: function() |
{ |
- if (this._jsProfilerStarted) { |
- this._stopCallbackBarrier = new CallbackBarrier(); |
- this._currentTarget.profilerAgent().stop(this._stopCallbackBarrier.createCallback(this._didStopRecordingJSSamples.bind(this))); |
- this._jsProfilerStarted = false; |
- } |
+ this._stopCallbackBarrier = new CallbackBarrier(); |
+ this._stopProfilingOnAllTargets(); |
this._tracingManager.stop(); |
}, |
@@ -176,10 +169,34 @@ WebInspector.TracingTimelineModel.prototype = { |
this._onTracingComplete(); |
}, |
- _configureCpuProfilerSamplingInterval: function() |
+ _startCpuProfilingOnAllTargets: function() |
+ { |
+ this._profilingTargets = WebInspector.targetManager.targets(); |
+ for (var i = 0; i < this._profilingTargets.length; ++i) { |
+ var target = this._profilingTargets[i]; |
+ this._configureCpuProfilerSamplingInterval(target); |
loislo
2014/10/10 17:13:08
what would happen when we start another worker jus
alph
2014/11/11 10:18:07
I plan to address this usecase in a separate patch
|
+ target.profilerAgent().start(); |
+ } |
+ }, |
+ |
+ _stopProfilingOnAllTargets: function() |
+ { |
+ if (!this._profilingTargets) |
+ return; |
+ for (var i = 0; i < this._profilingTargets.length; ++i) { |
+ var target = this._profilingTargets[i]; |
+ target.profilerAgent().stop(this._stopCallbackBarrier.createCallback(this._didStopRecordingJSSamples.bind(this, target))); |
+ } |
+ this._profilingTargets = null; |
+ }, |
+ |
+ /** |
+ * @param {!WebInspector.Target} target |
+ */ |
+ _configureCpuProfilerSamplingInterval: function(target) |
{ |
var intervalUs = WebInspector.settings.highResolutionCpuProfiling.get() ? 100 : 1000; |
- this._currentTarget.profilerAgent().setSamplingInterval(intervalUs, didChangeInterval); |
+ target.profilerAgent().setSamplingInterval(intervalUs, didChangeInterval); |
function didChangeInterval(error) |
{ |
@@ -214,31 +231,30 @@ WebInspector.TracingTimelineModel.prototype = { |
_onTracingComplete: function() |
{ |
- if (this._stopCallbackBarrier) |
+ if (this._stopCallbackBarrier) { |
loislo
2014/10/10 17:13:08
As far as I see we always have _stopCallbackBarrie
alph
2014/11/11 10:18:07
No. Tests do not call stopRecording. They use setE
|
this._stopCallbackBarrier.callWhenDone(this._didStopRecordingTraceEvents.bind(this)); |
- else |
+ this._stopCallbackBarrier = null; |
+ } else { |
this._didStopRecordingTraceEvents(); |
+ } |
}, |
/** |
+ * @param {!WebInspector.Target} target |
* @param {?Protocol.Error} error |
* @param {?ProfilerAgent.CPUProfile} cpuProfile |
*/ |
- _didStopRecordingJSSamples: function(error, cpuProfile) |
+ _didStopRecordingJSSamples: function(target, error, cpuProfile) |
{ |
if (error) |
WebInspector.console.error(error); |
- this._recordedCpuProfile = cpuProfile; |
+ if (!this._cpuProfiles) |
+ this._cpuProfiles = {}; |
+ this._cpuProfiles[target.id()] = cpuProfile; |
}, |
_didStopRecordingTraceEvents: function() |
{ |
- this._stopCallbackBarrier = null; |
- |
- if (this._recordedCpuProfile) { |
- this._injectCpuProfileEvent(this._recordedCpuProfile); |
- this._recordedCpuProfile = null; |
- } |
this._tracingModel.tracingComplete(); |
var events = this._tracingModel.devtoolsPageMetadataEvents(); |
@@ -257,7 +273,7 @@ WebInspector.TracingTimelineModel.prototype = { |
var threads = process.sortedThreads(); |
for (var j = 0; j < threads.length; j++) { |
var thread = threads[j]; |
- if (thread.name() === "WebCore: Worker" && !workerMetadataEvents.some(function(e) { return e.args["data"]["workerThreadId"] === thread.id(); })) |
+ if (thread.name() === "WebCore: Worker" && workerMetadataEvents.every(function(e) { return e.args["data"]["workerThreadId"] !== thread.id(); })) |
continue; |
this._processThreadEvents(startTime, endTime, event.thread, thread); |
} |
@@ -266,10 +282,8 @@ WebInspector.TracingTimelineModel.prototype = { |
this._inspectedTargetEvents.sort(WebInspector.TracingModel.Event.compareStartTime); |
- if (this._cpuProfile) { |
- this._processCpuProfile(this._cpuProfile); |
- this._cpuProfile = null; |
- } |
+ this._cpuProfiles = null; |
+ |
this._buildTimelineRecords(); |
this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordingStopped); |
}, |
@@ -295,16 +309,6 @@ WebInspector.TracingTimelineModel.prototype = { |
}, |
/** |
- * @param {!ProfilerAgent.CPUProfile} cpuProfile |
- */ |
- _processCpuProfile: function(cpuProfile) |
- { |
- var jsSamples = WebInspector.TimelineJSProfileProcessor.generateTracingEventsFromCpuProfile(this, cpuProfile); |
- this._inspectedTargetEvents = this._inspectedTargetEvents.mergeOrdered(jsSamples, WebInspector.TracingModel.Event.orderedCompareStartTime); |
- this._setMainThreadEvents(this.mainThreadEvents().mergeOrdered(jsSamples, WebInspector.TracingModel.Event.orderedCompareStartTime)); |
- }, |
- |
- /** |
* @return {number} |
*/ |
minimumRecordTime: function() |
@@ -498,11 +502,12 @@ WebInspector.TracingTimelineModel.prototype = { |
var i = events.lowerBound(startTime, function (time, event) { return time - event.startTime }); |
var threadEvents; |
+ var virtualThread = null; |
if (thread === mainThread) { |
threadEvents = this._mainThreadEvents; |
this._mainThreadAsyncEvents = this._mainThreadAsyncEvents.concat(thread.asyncEvents()); |
} else { |
- var virtualThread = new WebInspector.TracingTimelineModel.VirtualThread(thread.name()); |
+ virtualThread = new WebInspector.TracingTimelineModel.VirtualThread(thread.name()); |
threadEvents = virtualThread.events; |
virtualThread.asyncEvents = virtualThread.asyncEvents.concat(thread.asyncEvents()); |
this._virtualThreads.push(virtualThread); |
@@ -517,6 +522,19 @@ WebInspector.TracingTimelineModel.prototype = { |
threadEvents.push(event); |
this._inspectedTargetEvents.push(event); |
} |
+ |
+ if (this._cpuProfiles) { |
+ var cpuProfile = this._cpuProfiles[thread.target().id()]; |
+ if (cpuProfile) { |
+ var jsSamples = WebInspector.TimelineJSProfileProcessor.generateTracingEventsFromCpuProfile(cpuProfile, thread); |
+ var mergedEvents = threadEvents.mergeOrdered(jsSamples, WebInspector.TracingModel.Event.orderedCompareStartTime); |
+ if (virtualThread) |
+ virtualThread.events = mergedEvents; |
+ else |
+ this._mainThreadEvents = mergedEvents; |
+ this._inspectedTargetEvents = this._inspectedTargetEvents.concat(jsSamples); |
+ } |
+ } |
}, |
/** |