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.TracingModel} tracingModel | 7 * @param {!WebInspector.TracingModel} tracingModel |
8 * @param {!WebInspector.TimelineModel.Filter} recordFilter | 8 * @param {!WebInspector.TimelineModel.Filter} recordFilter |
9 * @extends {WebInspector.TimelineModel} | 9 * @extends {WebInspector.TimelineModel} |
10 */ | 10 */ |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 ConsoleTime: "ConsoleTime", | 62 ConsoleTime: "ConsoleTime", |
63 | 63 |
64 ResourceSendRequest: "ResourceSendRequest", | 64 ResourceSendRequest: "ResourceSendRequest", |
65 ResourceReceiveResponse: "ResourceReceiveResponse", | 65 ResourceReceiveResponse: "ResourceReceiveResponse", |
66 ResourceReceivedData: "ResourceReceivedData", | 66 ResourceReceivedData: "ResourceReceivedData", |
67 ResourceFinish: "ResourceFinish", | 67 ResourceFinish: "ResourceFinish", |
68 | 68 |
69 FunctionCall: "FunctionCall", | 69 FunctionCall: "FunctionCall", |
70 GCEvent: "GCEvent", | 70 GCEvent: "GCEvent", |
71 JSFrame: "JSFrame", | 71 JSFrame: "JSFrame", |
| 72 JSSample: "JSSample", |
72 | 73 |
73 UpdateCounters: "UpdateCounters", | 74 UpdateCounters: "UpdateCounters", |
74 | 75 |
75 RequestAnimationFrame: "RequestAnimationFrame", | 76 RequestAnimationFrame: "RequestAnimationFrame", |
76 CancelAnimationFrame: "CancelAnimationFrame", | 77 CancelAnimationFrame: "CancelAnimationFrame", |
77 FireAnimationFrame: "FireAnimationFrame", | 78 FireAnimationFrame: "FireAnimationFrame", |
78 | 79 |
79 WebSocketCreate : "WebSocketCreate", | 80 WebSocketCreate : "WebSocketCreate", |
80 WebSocketSendHandshakeRequest : "WebSocketSendHandshakeRequest", | 81 WebSocketSendHandshakeRequest : "WebSocketSendHandshakeRequest", |
81 WebSocketReceiveHandshakeResponse : "WebSocketReceiveHandshakeResponse", | 82 WebSocketReceiveHandshakeResponse : "WebSocketReceiveHandshakeResponse", |
(...skipping 21 matching lines...) Expand all Loading... |
103 * @param {boolean} captureMemory | 104 * @param {boolean} captureMemory |
104 * @param {boolean} capturePictures | 105 * @param {boolean} capturePictures |
105 */ | 106 */ |
106 startRecording: function(captureStacks, captureMemory, capturePictures) | 107 startRecording: function(captureStacks, captureMemory, capturePictures) |
107 { | 108 { |
108 function disabledByDefault(category) | 109 function disabledByDefault(category) |
109 { | 110 { |
110 return "disabled-by-default-" + category; | 111 return "disabled-by-default-" + category; |
111 } | 112 } |
112 var categoriesArray = ["-*", disabledByDefault("devtools.timeline"), dis
abledByDefault("devtools.timeline.frame")]; | 113 var categoriesArray = ["-*", disabledByDefault("devtools.timeline"), dis
abledByDefault("devtools.timeline.frame")]; |
113 if (captureStacks) | 114 if (captureStacks) { |
114 categoriesArray.push(disabledByDefault("devtools.timeline.stack")); | 115 categoriesArray.push(disabledByDefault("devtools.timeline.stack")); |
| 116 if (WebInspector.experimentsSettings.timelineJSCPUProfile.isEnabled(
)) { |
| 117 this._jsProfilerStarted = true; |
| 118 this._currentTarget = WebInspector.context.flavor(WebInspector.T
arget); |
| 119 this._configureCpuProfilerSamplingInterval(); |
| 120 this._currentTarget.profilerAgent().start(); |
| 121 } |
| 122 } |
115 if (capturePictures) { | 123 if (capturePictures) { |
116 categoriesArray = categoriesArray.concat([ | 124 categoriesArray = categoriesArray.concat([ |
117 disabledByDefault("devtools.timeline.layers"), | 125 disabledByDefault("devtools.timeline.layers"), |
118 disabledByDefault("devtools.timeline.picture"), | 126 disabledByDefault("devtools.timeline.picture"), |
119 disabledByDefault("blink.graphics_context_annotations")]); | 127 disabledByDefault("blink.graphics_context_annotations")]); |
120 } | 128 } |
121 var categories = categoriesArray.join(","); | 129 var categories = categoriesArray.join(","); |
122 this._startRecordingWithCategories(categories); | 130 this._startRecordingWithCategories(categories); |
123 }, | 131 }, |
124 | 132 |
125 stopRecording: function() | 133 stopRecording: function() |
126 { | 134 { |
| 135 this._stopCallbackBarrier = new CallbackBarrier(); |
| 136 if (this._jsProfilerStarted) { |
| 137 this._currentTarget.profilerAgent().stop(this._stopCallbackBarrier.c
reateCallback(this._didStopRecordingJSSamples.bind(this))); |
| 138 this._jsProfilerStarted = false; |
| 139 } |
127 this._tracingModel.stop(); | 140 this._tracingModel.stop(); |
128 }, | 141 }, |
129 | 142 |
130 /** | 143 /** |
131 * @param {string} sessionId | 144 * @param {string} sessionId |
132 * @param {!Array.<!WebInspector.TracingModel.EventPayload>} events | 145 * @param {!Array.<!WebInspector.TracingModel.EventPayload>} events |
133 */ | 146 */ |
134 setEventsForTest: function(sessionId, events) | 147 setEventsForTest: function(sessionId, events) |
135 { | 148 { |
136 this._onTracingStarted(); | 149 this._onTracingStarted(); |
137 this._tracingModel.setEventsForTest(sessionId, events); | 150 this._tracingModel.setEventsForTest(sessionId, events); |
138 this._onTracingComplete(); | 151 this._onTracingComplete(); |
139 }, | 152 }, |
140 | 153 |
| 154 _configureCpuProfilerSamplingInterval: function() |
| 155 { |
| 156 var intervalUs = WebInspector.settings.highResolutionCpuProfiling.get()
? 100 : 1000; |
| 157 this._currentTarget.profilerAgent().setSamplingInterval(intervalUs, didC
hangeInterval); |
| 158 |
| 159 function didChangeInterval(error) |
| 160 { |
| 161 if (error) |
| 162 WebInspector.console.error(error); |
| 163 } |
| 164 }, |
| 165 |
141 /** | 166 /** |
142 * @param {string} categories | 167 * @param {string} categories |
143 */ | 168 */ |
144 _startRecordingWithCategories: function(categories) | 169 _startRecordingWithCategories: function(categories) |
145 { | 170 { |
146 this.reset(); | 171 this.reset(); |
147 this._tracingModel.start(categories, ""); | 172 this._tracingModel.start(categories, ""); |
148 }, | 173 }, |
149 | 174 |
150 _onTracingStarted: function() | 175 _onTracingStarted: function() |
151 { | 176 { |
152 this.reset(); | 177 this.reset(); |
153 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStarted); | 178 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStarted); |
154 }, | 179 }, |
155 | 180 |
156 _onTracingComplete: function() | 181 _onTracingComplete: function() |
157 { | 182 { |
| 183 if (this._stopCallbackBarrier) |
| 184 this._stopCallbackBarrier.callWhenDone(this._didStopRecordingTraceEv
ents.bind(this)); |
| 185 else |
| 186 this._didStopRecordingTraceEvents(); |
| 187 }, |
| 188 |
| 189 /** |
| 190 * @param {?Protocol.Error} error |
| 191 * @param {?ProfilerAgent.CPUProfile} cpuProfile |
| 192 */ |
| 193 _didStopRecordingJSSamples: function(error, cpuProfile) |
| 194 { |
| 195 if (error) |
| 196 WebInspector.console.error(error); |
| 197 this._cpuProfile = cpuProfile; |
| 198 }, |
| 199 |
| 200 _didStopRecordingTraceEvents: function() |
| 201 { |
| 202 this._stopCallbackBarrier = null; |
158 var events = this._tracingModel.devtoolsMetadataEvents(); | 203 var events = this._tracingModel.devtoolsMetadataEvents(); |
159 events.sort(WebInspector.TracingModel.Event.compareStartTime); | 204 events.sort(WebInspector.TracingModel.Event.compareStartTime); |
160 | 205 |
161 this._resetProcessingState(); | 206 this._resetProcessingState(); |
162 for (var i = 0, length = events.length; i < length; i++) { | 207 for (var i = 0, length = events.length; i < length; i++) { |
163 var event = events[i]; | 208 var event = events[i]; |
164 var process = event.thread.process(); | 209 var process = event.thread.process(); |
165 var startTime = event.startTime; | 210 var startTime = event.startTime; |
166 | 211 |
167 var endTime = Infinity; | 212 var endTime = Infinity; |
168 if (i + 1 < length) | 213 if (i + 1 < length) |
169 endTime = events[i + 1].startTime; | 214 endTime = events[i + 1].startTime; |
170 | 215 |
171 process.sortedThreads().forEach(this._processThreadEvents.bind(this,
startTime, endTime, event.thread)); | 216 process.sortedThreads().forEach(this._processThreadEvents.bind(this,
startTime, endTime, event.thread)); |
172 } | 217 } |
173 this._resetProcessingState(); | 218 this._resetProcessingState(); |
174 | 219 |
175 this._inspectedTargetEvents.sort(WebInspector.TracingModel.Event.compare
StartTime); | 220 this._inspectedTargetEvents.sort(WebInspector.TracingModel.Event.compare
StartTime); |
176 | 221 |
| 222 if (this._cpuProfile) { |
| 223 var jsSamples = WebInspector.TimelineJSProfileProcessor.generateTrac
ingEventsFromCpuProfile(this, this._cpuProfile); |
| 224 this._inspectedTargetEvents = this._inspectedTargetEvents.mergeOrder
ed(jsSamples, WebInspector.TracingModel.Event.orderedCompareStartTime); |
| 225 this._setMainThreadEvents(this.mainThreadEvents().mergeOrdered(jsSam
ples, WebInspector.TracingModel.Event.orderedCompareStartTime)); |
| 226 this._cpuProfile = null; |
| 227 } |
| 228 |
177 this._buildTimelineRecords(); | 229 this._buildTimelineRecords(); |
178 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStopped); | 230 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStopped); |
179 }, | 231 }, |
180 | 232 |
181 /** | 233 /** |
182 * @return {number} | 234 * @return {number} |
183 */ | 235 */ |
184 minimumRecordTime: function() | 236 minimumRecordTime: function() |
185 { | 237 { |
186 return this._tracingModel.minimumRecordTime(); | 238 return this._tracingModel.minimumRecordTime(); |
(...skipping 17 matching lines...) Expand all Loading... |
204 | 256 |
205 /** | 257 /** |
206 * @return {!Array.<!WebInspector.TracingModel.Event>} | 258 * @return {!Array.<!WebInspector.TracingModel.Event>} |
207 */ | 259 */ |
208 mainThreadEvents: function() | 260 mainThreadEvents: function() |
209 { | 261 { |
210 return this._virtualThreads[WebInspector.TimelineModel.MainThreadName] |
| []; | 262 return this._virtualThreads[WebInspector.TimelineModel.MainThreadName] |
| []; |
211 }, | 263 }, |
212 | 264 |
213 /** | 265 /** |
| 266 * @param {!Array.<!WebInspector.TracingModel.Event>} events |
| 267 */ |
| 268 _setMainThreadEvents: function(events) |
| 269 { |
| 270 this._virtualThreads[WebInspector.TimelineModel.MainThreadName] = events
; |
| 271 }, |
| 272 |
| 273 /** |
214 * @return {!Object.<string, !Array.<!WebInspector.TracingModel.Event>>} | 274 * @return {!Object.<string, !Array.<!WebInspector.TracingModel.Event>>} |
215 */ | 275 */ |
216 virtualThreads: function() | 276 virtualThreads: function() |
217 { | 277 { |
218 return this._virtualThreads; | 278 return this._virtualThreads; |
219 }, | 279 }, |
220 | 280 |
221 reset: function() | 281 reset: function() |
222 { | 282 { |
223 this._virtualThreads = {}; | 283 this._virtualThreads = {}; |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 }, | 815 }, |
756 | 816 |
757 /** | 817 /** |
758 * @return {!WebInspector.TimelineModel} | 818 * @return {!WebInspector.TimelineModel} |
759 */ | 819 */ |
760 timelineModel: function() | 820 timelineModel: function() |
761 { | 821 { |
762 return this._model; | 822 return this._model; |
763 } | 823 } |
764 } | 824 } |
OLD | NEW |