OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @constructor | 6 * @constructor |
7 * @param {!WebInspector.TracingManager} tracingManager | 7 * @param {!WebInspector.TracingManager} tracingManager |
8 * @param {!WebInspector.TracingModel} tracingModel | 8 * @param {!WebInspector.TracingModel} tracingModel |
9 * @param {!WebInspector.TimelineModel.Filter} recordFilter | 9 * @param {!WebInspector.TimelineModel.Filter} recordFilter |
10 * @extends {WebInspector.TimelineModel} | 10 * @extends {WebInspector.TimelineModel} |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 TracingStartedInPage: "TracingStartedInPage", | 92 TracingStartedInPage: "TracingStartedInPage", |
93 TracingSessionIdForWorker: "TracingSessionIdForWorker", | 93 TracingSessionIdForWorker: "TracingSessionIdForWorker", |
94 | 94 |
95 DecodeImage: "Decode Image", | 95 DecodeImage: "Decode Image", |
96 ResizeImage: "Resize Image", | 96 ResizeImage: "Resize Image", |
97 DrawLazyPixelRef: "Draw LazyPixelRef", | 97 DrawLazyPixelRef: "Draw LazyPixelRef", |
98 DecodeLazyPixelRef: "Decode LazyPixelRef", | 98 DecodeLazyPixelRef: "Decode LazyPixelRef", |
99 | 99 |
100 LazyPixelRef: "LazyPixelRef", | 100 LazyPixelRef: "LazyPixelRef", |
101 LayerTreeHostImplSnapshot: "cc::LayerTreeHostImpl", | 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 /** |
106 * @constructor | 110 * @constructor |
107 * @param {string} name | 111 * @param {string} name |
108 */ | 112 */ |
109 WebInspector.TracingTimelineModel.VirtualThread = function(name) | 113 WebInspector.TracingTimelineModel.VirtualThread = function(name) |
110 { | 114 { |
111 this.name = name; | 115 this.name = name; |
112 /** @type {!Array.<!WebInspector.TracingModel.Event>} */ | 116 /** @type {!Array.<!WebInspector.TracingModel.Event>} */ |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 disabledByDefault("devtools.timeline.layers"), | 151 disabledByDefault("devtools.timeline.layers"), |
148 disabledByDefault("devtools.timeline.picture"), | 152 disabledByDefault("devtools.timeline.picture"), |
149 disabledByDefault("blink.graphics_context_annotations")]); | 153 disabledByDefault("blink.graphics_context_annotations")]); |
150 } | 154 } |
151 var categories = categoriesArray.join(","); | 155 var categories = categoriesArray.join(","); |
152 this._startRecordingWithCategories(categories); | 156 this._startRecordingWithCategories(categories); |
153 }, | 157 }, |
154 | 158 |
155 stopRecording: function() | 159 stopRecording: function() |
156 { | 160 { |
157 this._stopCallbackBarrier = new CallbackBarrier(); | |
158 if (this._jsProfilerStarted) { | 161 if (this._jsProfilerStarted) { |
| 162 this._stopCallbackBarrier = new CallbackBarrier(); |
159 this._currentTarget.profilerAgent().stop(this._stopCallbackBarrier.c
reateCallback(this._didStopRecordingJSSamples.bind(this))); | 163 this._currentTarget.profilerAgent().stop(this._stopCallbackBarrier.c
reateCallback(this._didStopRecordingJSSamples.bind(this))); |
160 this._jsProfilerStarted = false; | 164 this._jsProfilerStarted = false; |
161 } | 165 } |
162 this._tracingManager.stop(); | 166 this._tracingManager.stop(); |
163 }, | 167 }, |
164 | 168 |
165 /** | 169 /** |
166 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events | 170 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events |
167 */ | 171 */ |
168 setEventsForTest: function(events) | 172 setEventsForTest: function(events) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 * @param {!WebInspector.Event} event | 207 * @param {!WebInspector.Event} event |
204 */ | 208 */ |
205 _onEventsCollected: function(event) | 209 _onEventsCollected: function(event) |
206 { | 210 { |
207 var traceEvents = /** @type {!Array.<!WebInspector.TracingManager.EventP
ayload>} */ (event.data); | 211 var traceEvents = /** @type {!Array.<!WebInspector.TracingManager.EventP
ayload>} */ (event.data); |
208 this._tracingModel.addEvents(traceEvents); | 212 this._tracingModel.addEvents(traceEvents); |
209 }, | 213 }, |
210 | 214 |
211 _onTracingComplete: function() | 215 _onTracingComplete: function() |
212 { | 216 { |
213 this._tracingModel.tracingComplete(); | |
214 if (this._stopCallbackBarrier) | 217 if (this._stopCallbackBarrier) |
215 this._stopCallbackBarrier.callWhenDone(this._didStopRecordingTraceEv
ents.bind(this)); | 218 this._stopCallbackBarrier.callWhenDone(this._didStopRecordingTraceEv
ents.bind(this)); |
216 else | 219 else |
217 this._didStopRecordingTraceEvents(); | 220 this._didStopRecordingTraceEvents(); |
218 }, | 221 }, |
219 | 222 |
220 /** | 223 /** |
221 * @param {?Protocol.Error} error | 224 * @param {?Protocol.Error} error |
222 * @param {?ProfilerAgent.CPUProfile} cpuProfile | 225 * @param {?ProfilerAgent.CPUProfile} cpuProfile |
223 */ | 226 */ |
224 _didStopRecordingJSSamples: function(error, cpuProfile) | 227 _didStopRecordingJSSamples: function(error, cpuProfile) |
225 { | 228 { |
226 if (error) | 229 if (error) |
227 WebInspector.console.error(error); | 230 WebInspector.console.error(error); |
228 this._cpuProfile = cpuProfile; | 231 this._recordedCpuProfile = cpuProfile; |
229 }, | 232 }, |
230 | 233 |
231 _didStopRecordingTraceEvents: function() | 234 _didStopRecordingTraceEvents: function() |
232 { | 235 { |
233 this._stopCallbackBarrier = null; | 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 var events = this._tracingModel.devtoolsPageMetadataEvents(); | 244 var events = this._tracingModel.devtoolsPageMetadataEvents(); |
235 var workerMetadataEvents = this._tracingModel.devtoolsWorkerMetadataEven
ts(); | 245 var workerMetadataEvents = this._tracingModel.devtoolsWorkerMetadataEven
ts(); |
236 | 246 |
237 this._resetProcessingState(); | 247 this._resetProcessingState(); |
238 for (var i = 0, length = events.length; i < length; i++) { | 248 for (var i = 0, length = events.length; i < length; i++) { |
239 var event = events[i]; | 249 var event = events[i]; |
240 var process = event.thread.process(); | 250 var process = event.thread.process(); |
241 var startTime = event.startTime; | 251 var startTime = event.startTime; |
242 | 252 |
243 var endTime = Infinity; | 253 var endTime = Infinity; |
244 if (i + 1 < length) | 254 if (i + 1 < length) |
245 endTime = events[i + 1].startTime; | 255 endTime = events[i + 1].startTime; |
246 | 256 |
247 var threads = process.sortedThreads(); | 257 var threads = process.sortedThreads(); |
248 for (var j = 0; j < threads.length; j++) { | 258 for (var j = 0; j < threads.length; j++) { |
249 var thread = threads[j]; | 259 var thread = threads[j]; |
250 if (thread.name() === "WebCore: Worker" && !workerMetadataEvents
.some(function(e) { return e.args["data"]["workerThreadId"] === thread.id(); })) | 260 if (thread.name() === "WebCore: Worker" && !workerMetadataEvents
.some(function(e) { return e.args["data"]["workerThreadId"] === thread.id(); })) |
251 continue; | 261 continue; |
252 this._processThreadEvents(startTime, endTime, event.thread, thre
ad); | 262 this._processThreadEvents(startTime, endTime, event.thread, thre
ad); |
253 } | 263 } |
254 } | 264 } |
255 this._resetProcessingState(); | 265 this._resetProcessingState(); |
256 | 266 |
257 this._inspectedTargetEvents.sort(WebInspector.TracingModel.Event.compare
StartTime); | 267 this._inspectedTargetEvents.sort(WebInspector.TracingModel.Event.compare
StartTime); |
258 | 268 |
259 if (this._cpuProfile) { | 269 if (this._cpuProfile) { |
260 var jsSamples = WebInspector.TimelineJSProfileProcessor.generateTrac
ingEventsFromCpuProfile(this, this._cpuProfile); | 270 this._processCpuProfile(this._cpuProfile); |
261 this._inspectedTargetEvents = this._inspectedTargetEvents.mergeOrder
ed(jsSamples, WebInspector.TracingModel.Event.orderedCompareStartTime); | |
262 this._setMainThreadEvents(this.mainThreadEvents().mergeOrdered(jsSam
ples, WebInspector.TracingModel.Event.orderedCompareStartTime)); | |
263 this._cpuProfile = null; | 271 this._cpuProfile = null; |
264 } | 272 } |
265 | |
266 this._buildTimelineRecords(); | 273 this._buildTimelineRecords(); |
267 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStopped); | 274 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStopped); |
268 }, | 275 }, |
269 | 276 |
270 /** | 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.EventPaylo
ad} */ ({ |
| 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.generateTracingE
ventsFromCpuProfile(this, cpuProfile); |
| 303 this._inspectedTargetEvents = this._inspectedTargetEvents.mergeOrdered(j
sSamples, WebInspector.TracingModel.Event.orderedCompareStartTime); |
| 304 this._setMainThreadEvents(this.mainThreadEvents().mergeOrdered(jsSamples
, WebInspector.TracingModel.Event.orderedCompareStartTime)); |
| 305 }, |
| 306 |
| 307 /** |
271 * @return {number} | 308 * @return {number} |
272 */ | 309 */ |
273 minimumRecordTime: function() | 310 minimumRecordTime: function() |
274 { | 311 { |
275 return this._tracingModel.minimumRecordTime(); | 312 return this._tracingModel.minimumRecordTime(); |
276 }, | 313 }, |
277 | 314 |
278 /** | 315 /** |
279 * @return {number} | 316 * @return {number} |
280 */ | 317 */ |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 if (this._currentScriptEvent && event.startTime > this._currentScriptEve
nt.endTime) | 548 if (this._currentScriptEvent && event.startTime > this._currentScriptEve
nt.endTime) |
512 this._currentScriptEvent = null; | 549 this._currentScriptEvent = null; |
513 | 550 |
514 switch (event.name) { | 551 switch (event.name) { |
515 case recordTypes.CallStack: | 552 case recordTypes.CallStack: |
516 var lastMainThreadEvent = this.mainThreadEvents().peekLast(); | 553 var lastMainThreadEvent = this.mainThreadEvents().peekLast(); |
517 if (lastMainThreadEvent && event.args["stack"] && event.args["stack"
].length) | 554 if (lastMainThreadEvent && event.args["stack"] && event.args["stack"
].length) |
518 lastMainThreadEvent.stackTrace = event.args["stack"]; | 555 lastMainThreadEvent.stackTrace = event.args["stack"]; |
519 break; | 556 break; |
520 | 557 |
| 558 case recordTypes.CpuProfile: |
| 559 this._cpuProfile = event.args["data"]["cpuProfile"]; |
| 560 break; |
| 561 |
521 case recordTypes.ResourceSendRequest: | 562 case recordTypes.ResourceSendRequest: |
522 this._sendRequestEvents[event.args["data"]["requestId"]] = event; | 563 this._sendRequestEvents[event.args["data"]["requestId"]] = event; |
523 event.imageURL = event.args["data"]["url"]; | 564 event.imageURL = event.args["data"]["url"]; |
524 break; | 565 break; |
525 | 566 |
526 case recordTypes.ResourceReceiveResponse: | 567 case recordTypes.ResourceReceiveResponse: |
527 case recordTypes.ResourceReceivedData: | 568 case recordTypes.ResourceReceivedData: |
528 case recordTypes.ResourceFinish: | 569 case recordTypes.ResourceFinish: |
529 event.initiator = this._sendRequestEvents[event.args["data"]["reques
tId"]]; | 570 event.initiator = this._sendRequestEvents[event.args["data"]["reques
tId"]]; |
530 if (event.initiator) | 571 if (event.initiator) |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 * @param {!WebInspector.ChunkedReader} reader | 1098 * @param {!WebInspector.ChunkedReader} reader |
1058 */ | 1099 */ |
1059 onChunkTransferred: function(reader) { }, | 1100 onChunkTransferred: function(reader) { }, |
1060 | 1101 |
1061 /** | 1102 /** |
1062 * @param {!WebInspector.ChunkedReader} reader | 1103 * @param {!WebInspector.ChunkedReader} reader |
1063 * @param {!Event} event | 1104 * @param {!Event} event |
1064 */ | 1105 */ |
1065 onError: function(reader, event) { }, | 1106 onError: function(reader, event) { }, |
1066 } | 1107 } |
OLD | NEW |