Skip to content

Commit dbb53d4

Browse files
committed
DevTools: Support JS frames save/load for tracing timeline.
BUG=363976 Review URL: https://codereview.chromium.org/620123002 git-svn-id: svn://svn.chromium.org/blink/trunk@183164 bbb929c8-8fbe-4397-9dbb-9b2b20218538
1 parent c705428 commit dbb53d4

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

LayoutTests/inspector/tracing/timeline-enum-stability-expected.txt

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Applications outside of WebKit depend on the stability of the mapping of these t
1010
CancelAnimationFrame : "CancelAnimationFrame"
1111
CompositeLayers : "CompositeLayers"
1212
ConsoleTime : "ConsoleTime"
13+
CpuProfile : "CpuProfile"
1314
DecodeImage : "Decode Image"
1415
DecodeLazyPixelRef : "Decode LazyPixelRef"
1516
DrawFrame : "DrawFrame"

Source/devtools/front_end/timeline/TracingModel.js

+9
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ WebInspector.TracingModel.Process = function(id)
568568
{
569569
WebInspector.TracingModel.NamedObject.call(this);
570570
this._setName("Process " + id);
571+
this._id = id;
571572
this._threads = {};
572573
this._objects = {};
573574
/** @type {!Array.<!WebInspector.TracingManager.EventPayload>} */
@@ -577,6 +578,14 @@ WebInspector.TracingModel.Process = function(id)
577578
}
578579

579580
WebInspector.TracingModel.Process.prototype = {
581+
/**
582+
* @return {number}
583+
*/
584+
id: function()
585+
{
586+
return this._id;
587+
},
588+
580589
/**
581590
* @param {number} id
582591
* @return {!WebInspector.TracingModel.Thread}

Source/devtools/front_end/timeline/TracingTimelineModel.js

+49-8
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ WebInspector.TracingTimelineModel.RecordType = {
9999

100100
LazyPixelRef: "LazyPixelRef",
101101
LayerTreeHostImplSnapshot: "cc::LayerTreeHostImpl",
102-
PictureSnapshot: "cc::Picture"
102+
PictureSnapshot: "cc::Picture",
103+
104+
// CpuProfile is a virtual event created on frontend to support
105+
// serialization of CPU Profiles within tracing timeline data.
106+
CpuProfile: "CpuProfile"
103107
};
104108

105109
/**
@@ -154,8 +158,8 @@ WebInspector.TracingTimelineModel.prototype = {
154158

155159
stopRecording: function()
156160
{
157-
this._stopCallbackBarrier = new CallbackBarrier();
158161
if (this._jsProfilerStarted) {
162+
this._stopCallbackBarrier = new CallbackBarrier();
159163
this._currentTarget.profilerAgent().stop(this._stopCallbackBarrier.createCallback(this._didStopRecordingJSSamples.bind(this)));
160164
this._jsProfilerStarted = false;
161165
}
@@ -210,7 +214,6 @@ WebInspector.TracingTimelineModel.prototype = {
210214

211215
_onTracingComplete: function()
212216
{
213-
this._tracingModel.tracingComplete();
214217
if (this._stopCallbackBarrier)
215218
this._stopCallbackBarrier.callWhenDone(this._didStopRecordingTraceEvents.bind(this));
216219
else
@@ -225,12 +228,19 @@ WebInspector.TracingTimelineModel.prototype = {
225228
{
226229
if (error)
227230
WebInspector.console.error(error);
228-
this._cpuProfile = cpuProfile;
231+
this._recordedCpuProfile = cpuProfile;
229232
},
230233

231234
_didStopRecordingTraceEvents: function()
232235
{
233236
this._stopCallbackBarrier = null;
237+
238+
if (this._recordedCpuProfile) {
239+
this._injectCpuProfileEvent(this._recordedCpuProfile);
240+
this._recordedCpuProfile = null;
241+
}
242+
this._tracingModel.tracingComplete();
243+
234244
var events = this._tracingModel.devtoolsPageMetadataEvents();
235245
var workerMetadataEvents = this._tracingModel.devtoolsWorkerMetadataEvents();
236246

@@ -257,16 +267,43 @@ WebInspector.TracingTimelineModel.prototype = {
257267
this._inspectedTargetEvents.sort(WebInspector.TracingModel.Event.compareStartTime);
258268

259269
if (this._cpuProfile) {
260-
var jsSamples = WebInspector.TimelineJSProfileProcessor.generateTracingEventsFromCpuProfile(this, this._cpuProfile);
261-
this._inspectedTargetEvents = this._inspectedTargetEvents.mergeOrdered(jsSamples, WebInspector.TracingModel.Event.orderedCompareStartTime);
262-
this._setMainThreadEvents(this.mainThreadEvents().mergeOrdered(jsSamples, WebInspector.TracingModel.Event.orderedCompareStartTime));
270+
this._processCpuProfile(this._cpuProfile);
263271
this._cpuProfile = null;
264272
}
265-
266273
this._buildTimelineRecords();
267274
this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordingStopped);
268275
},
269276

277+
/**
278+
* @param {!ProfilerAgent.CPUProfile} cpuProfile
279+
*/
280+
_injectCpuProfileEvent: function(cpuProfile)
281+
{
282+
var metaEvent = this._tracingModel.devtoolsPageMetadataEvents().peekLast();
283+
if (!metaEvent)
284+
return;
285+
var cpuProfileEvent = /** @type {!WebInspector.TracingManager.EventPayload} */ ({
286+
cat: WebInspector.TracingModel.DevToolsMetadataEventCategory,
287+
ph: WebInspector.TracingModel.Phase.Instant,
288+
ts: this._tracingModel.maximumRecordTime() * 1000,
289+
pid: metaEvent.thread.process().id(),
290+
tid: metaEvent.thread.id(),
291+
name: WebInspector.TracingTimelineModel.RecordType.CpuProfile,
292+
args: { data: { cpuProfile: cpuProfile } }
293+
});
294+
this._tracingModel.addEvents([cpuProfileEvent]);
295+
},
296+
297+
/**
298+
* @param {!ProfilerAgent.CPUProfile} cpuProfile
299+
*/
300+
_processCpuProfile: function(cpuProfile)
301+
{
302+
var jsSamples = WebInspector.TimelineJSProfileProcessor.generateTracingEventsFromCpuProfile(this, cpuProfile);
303+
this._inspectedTargetEvents = this._inspectedTargetEvents.mergeOrdered(jsSamples, WebInspector.TracingModel.Event.orderedCompareStartTime);
304+
this._setMainThreadEvents(this.mainThreadEvents().mergeOrdered(jsSamples, WebInspector.TracingModel.Event.orderedCompareStartTime));
305+
},
306+
270307
/**
271308
* @return {number}
272309
*/
@@ -554,6 +591,10 @@ WebInspector.TracingTimelineModel.prototype = {
554591
lastMainThreadEvent.stackTrace = event.args["stack"];
555592
break;
556593

594+
case recordTypes.CpuProfile:
595+
this._cpuProfile = event.args["data"]["cpuProfile"];
596+
break;
597+
557598
case recordTypes.ResourceSendRequest:
558599
this._sendRequestEvents[event.args["data"]["requestId"]] = event;
559600
event.imageURL = event.args["data"]["url"];

0 commit comments

Comments
 (0)