@@ -99,7 +99,11 @@ WebInspector.TracingTimelineModel.RecordType = {
99
99
100
100
LazyPixelRef : "LazyPixelRef" ,
101
101
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"
103
107
} ;
104
108
105
109
/**
@@ -154,8 +158,8 @@ WebInspector.TracingTimelineModel.prototype = {
154
158
155
159
stopRecording : function ( )
156
160
{
157
- this . _stopCallbackBarrier = new CallbackBarrier ( ) ;
158
161
if ( this . _jsProfilerStarted ) {
162
+ this . _stopCallbackBarrier = new CallbackBarrier ( ) ;
159
163
this . _currentTarget . profilerAgent ( ) . stop ( this . _stopCallbackBarrier . createCallback ( this . _didStopRecordingJSSamples . bind ( this ) ) ) ;
160
164
this . _jsProfilerStarted = false ;
161
165
}
@@ -210,7 +214,6 @@ WebInspector.TracingTimelineModel.prototype = {
210
214
211
215
_onTracingComplete : function ( )
212
216
{
213
- this . _tracingModel . tracingComplete ( ) ;
214
217
if ( this . _stopCallbackBarrier )
215
218
this . _stopCallbackBarrier . callWhenDone ( this . _didStopRecordingTraceEvents . bind ( this ) ) ;
216
219
else
@@ -225,12 +228,19 @@ WebInspector.TracingTimelineModel.prototype = {
225
228
{
226
229
if ( error )
227
230
WebInspector . console . error ( error ) ;
228
- this . _cpuProfile = cpuProfile ;
231
+ this . _recordedCpuProfile = cpuProfile ;
229
232
} ,
230
233
231
234
_didStopRecordingTraceEvents : function ( )
232
235
{
233
236
this . _stopCallbackBarrier = null ;
237
+
238
+ if ( this . _recordedCpuProfile ) {
239
+ this . _injectCpuProfileEvent ( this . _recordedCpuProfile ) ;
240
+ this . _recordedCpuProfile = null ;
241
+ }
242
+ this . _tracingModel . tracingComplete ( ) ;
243
+
234
244
var events = this . _tracingModel . devtoolsPageMetadataEvents ( ) ;
235
245
var workerMetadataEvents = this . _tracingModel . devtoolsWorkerMetadataEvents ( ) ;
236
246
@@ -257,16 +267,43 @@ WebInspector.TracingTimelineModel.prototype = {
257
267
this . _inspectedTargetEvents . sort ( WebInspector . TracingModel . Event . compareStartTime ) ;
258
268
259
269
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 ) ;
263
271
this . _cpuProfile = null ;
264
272
}
265
-
266
273
this . _buildTimelineRecords ( ) ;
267
274
this . dispatchEventToListeners ( WebInspector . TimelineModel . Events . RecordingStopped ) ;
268
275
} ,
269
276
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
+
270
307
/**
271
308
* @return {number }
272
309
*/
@@ -554,6 +591,10 @@ WebInspector.TracingTimelineModel.prototype = {
554
591
lastMainThreadEvent . stackTrace = event . args [ "stack" ] ;
555
592
break ;
556
593
594
+ case recordTypes . CpuProfile :
595
+ this . _cpuProfile = event . args [ "data" ] [ "cpuProfile" ] ;
596
+ break ;
597
+
557
598
case recordTypes . ResourceSendRequest :
558
599
this . _sendRequestEvents [ event . args [ "data" ] [ "requestId" ] ] = event ;
559
600
event . imageURL = event . args [ "data" ] [ "url" ] ;
0 commit comments