OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 * @fileoverview Profiler processor is used to process log file produced | 6 * @fileoverview Profiler processor is used to process log file produced |
7 * by V8 and produce an internal profile representation which is used | 7 * by V8 and produce an internal profile representation which is used |
8 * for building profile views in 'Profiles' tab. | 8 * for building profile views in 'Profiles' tab. |
9 */ | 9 */ |
10 goog.provide('devtools.profiler.Processor'); | 10 goog.provide('devtools.profiler.Processor'); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 'end-code-region': null}); | 172 'end-code-region': null}); |
173 | 173 |
174 | 174 |
175 /** | 175 /** |
176 * Callback that is called when a new profile is encountered in the log. | 176 * Callback that is called when a new profile is encountered in the log. |
177 * @type {function()} | 177 * @type {function()} |
178 */ | 178 */ |
179 this.startedProfileProcessing_ = null; | 179 this.startedProfileProcessing_ = null; |
180 | 180 |
181 /** | 181 /** |
182 * Callback that is called periodically to display processing status. | |
183 * @type {function()} | |
184 */ | |
185 this.profileProcessingStatus_ = null; | |
186 | |
187 /** | |
182 * Callback that is called when a profile has been processed and is ready | 188 * Callback that is called when a profile has been processed and is ready |
183 * to be shown. | 189 * to be shown. |
184 * @type {function(devtools.profiler.ProfileView)} | 190 * @type {function(devtools.profiler.ProfileView)} |
185 */ | 191 */ |
186 this.finishedProfileProcessing_ = null; | 192 this.finishedProfileProcessing_ = null; |
187 | 193 |
188 /** | 194 /** |
189 * The current profile. | 195 * The current profile. |
190 * @type {devtools.profiler.JsProfile} | 196 * @type {devtools.profiler.JsProfile} |
191 */ | 197 */ |
192 this.currentProfile_ = null; | 198 this.currentProfile_ = null; |
193 | 199 |
194 /** | 200 /** |
195 * Builder of profile views. Created during "profiler,begin" event processing. | 201 * Builder of profile views. Created during "profiler,begin" event processing. |
196 * @type {devtools.profiler.WebKitViewBuilder} | 202 * @type {devtools.profiler.WebKitViewBuilder} |
197 */ | 203 */ |
198 this.viewBuilder_ = null; | 204 this.viewBuilder_ = null; |
199 | 205 |
200 /** | 206 /** |
201 * Next profile id. | 207 * Next profile id. |
202 * @type {number} | 208 * @type {number} |
203 */ | 209 */ |
204 this.profileId_ = 1; | 210 this.profileId_ = 1; |
211 | |
212 /** | |
213 * Counter for processed ticks. | |
214 * @type {number} | |
215 */ | |
216 this.ticksCount_ = 0; | |
205 }; | 217 }; |
206 goog.inherits(devtools.profiler.Processor, devtools.profiler.LogReader); | 218 goog.inherits(devtools.profiler.Processor, devtools.profiler.LogReader); |
207 | 219 |
208 | 220 |
209 /** | 221 /** |
210 * @override | 222 * @override |
211 */ | 223 */ |
212 devtools.profiler.Processor.prototype.printError = function(str) { | 224 devtools.profiler.Processor.prototype.printError = function(str) { |
213 debugPrint(str); | 225 debugPrint(str); |
214 }; | 226 }; |
215 | 227 |
216 | 228 |
217 /** | 229 /** |
218 * @override | 230 * @override |
219 */ | 231 */ |
220 devtools.profiler.Processor.prototype.skipDispatch = function(dispatch) { | 232 devtools.profiler.Processor.prototype.skipDispatch = function(dispatch) { |
221 return dispatch.needsProfile && this.currentProfile_ == null; | 233 return dispatch.needsProfile && this.currentProfile_ == null; |
222 }; | 234 }; |
223 | 235 |
224 | 236 |
225 /** | 237 /** |
226 * Sets profile processing callbacks. | 238 * Sets profile processing callbacks. |
227 * | 239 * |
228 * @param {function()} started Started processing callback. | 240 * @param {function()} started Started processing callback. |
229 * @param {function(devtools.profiler.ProfileView)} finished Finished | 241 * @param {function(devtools.profiler.ProfileView)} finished Finished |
230 * processing callback. | 242 * processing callback. |
231 */ | 243 */ |
232 devtools.profiler.Processor.prototype.setCallbacks = function( | 244 devtools.profiler.Processor.prototype.setCallbacks = function( |
233 started, finished) { | 245 started, processing, finished) { |
234 this.startedProfileProcessing_ = started; | 246 this.startedProfileProcessing_ = started; |
247 this.profileProcessingStatus_ = processing; | |
235 this.finishedProfileProcessing_ = finished; | 248 this.finishedProfileProcessing_ = finished; |
236 }; | 249 }; |
237 | 250 |
238 | 251 |
239 /** | 252 /** |
240 * An address for the fake "(program)" entry. WebKit's visualisation | 253 * An address for the fake "(program)" entry. WebKit's visualisation |
241 * has assumptions on how the top of the call tree should look like, | 254 * has assumptions on how the top of the call tree should look like, |
242 * and we need to add a fake entry as the topmost function. This | 255 * and we need to add a fake entry as the topmost function. This |
243 * address is chosen because it's the end address of the first memory | 256 * address is chosen because it's the end address of the first memory |
244 * page, which is never used for code or data, but only as a guard | 257 * page, which is never used for code or data, but only as a guard |
(...skipping 13 matching lines...) Expand all Loading... | |
258 * @param {function(devtools.profiler.ProfileView)} callback Callback function. | 271 * @param {function(devtools.profiler.ProfileView)} callback Callback function. |
259 */ | 272 */ |
260 devtools.profiler.Processor.prototype.setNewProfileCallback = function( | 273 devtools.profiler.Processor.prototype.setNewProfileCallback = function( |
261 callback) { | 274 callback) { |
262 this.newProfileCallback_ = callback; | 275 this.newProfileCallback_ = callback; |
263 }; | 276 }; |
264 | 277 |
265 | 278 |
266 devtools.profiler.Processor.prototype.processProfiler_ = function( | 279 devtools.profiler.Processor.prototype.processProfiler_ = function( |
267 state, params) { | 280 state, params) { |
281 var processingInterval = null; | |
268 switch (state) { | 282 switch (state) { |
269 case 'resume': | 283 case 'resume': |
270 if (this.currentProfile_ == null) { | 284 if (this.currentProfile_ == null) { |
271 this.currentProfile_ = new devtools.profiler.JsProfile(); | 285 this.currentProfile_ = new devtools.profiler.JsProfile(); |
272 // see the comment for devtools.profiler.Processor.PROGRAM_ENTRY | 286 // see the comment for devtools.profiler.Processor.PROGRAM_ENTRY |
273 this.currentProfile_.addCode( | 287 this.currentProfile_.addCode( |
274 'Function', '(program)', | 288 'Function', '(program)', |
275 devtools.profiler.Processor.PROGRAM_ENTRY, 1); | 289 devtools.profiler.Processor.PROGRAM_ENTRY, 1); |
276 if (this.startedProfileProcessing_) { | 290 if (this.startedProfileProcessing_) { |
277 this.startedProfileProcessing_(); | 291 this.startedProfileProcessing_(); |
278 } | 292 } |
293 this.ticksCount_ = 0; | |
294 var self = this; | |
295 if (this.profileProcessingStatus_) { | |
296 processingInterval = window.setInterval( | |
297 function() { self.profileProcessingStatus_(self.ticksCount_); }, | |
298 1000); | |
299 } | |
279 } | 300 } |
280 break; | 301 break; |
281 case 'pause': | 302 case 'pause': |
282 if (this.currentProfile_ != null) { | 303 if (this.currentProfile_ != null) { |
304 window.clearInterval(processingInterval); | |
pfeldman
2009/07/21 14:58:49
should this be checked for nullness?
mnaganov (inactive)
2009/07/21 15:06:29
window.clearInterval(null) is harmless.
| |
283 if (this.finishedProfileProcessing_) { | 305 if (this.finishedProfileProcessing_) { |
284 this.finishedProfileProcessing_(this.createProfileForView()); | 306 this.finishedProfileProcessing_(this.createProfileForView()); |
285 } | 307 } |
286 this.currentProfile_ = null; | 308 this.currentProfile_ = null; |
287 } | 309 } |
288 break; | 310 break; |
289 case 'begin': | 311 case 'begin': |
290 var samplingRate = NaN; | 312 var samplingRate = NaN; |
291 if (params.length > 0) { | 313 if (params.length > 0) { |
292 samplingRate = parseInt(params[0]); | 314 samplingRate = parseInt(params[0]); |
(...skipping 26 matching lines...) Expand all Loading... | |
319 devtools.profiler.Processor.prototype.processCodeDelete_ = function(start) { | 341 devtools.profiler.Processor.prototype.processCodeDelete_ = function(start) { |
320 this.currentProfile_.deleteCode(start); | 342 this.currentProfile_.deleteCode(start); |
321 }; | 343 }; |
322 | 344 |
323 | 345 |
324 devtools.profiler.Processor.prototype.processTick_ = function( | 346 devtools.profiler.Processor.prototype.processTick_ = function( |
325 pc, sp, vmState, stack) { | 347 pc, sp, vmState, stack) { |
326 // see the comment for devtools.profiler.Processor.PROGRAM_ENTRY | 348 // see the comment for devtools.profiler.Processor.PROGRAM_ENTRY |
327 stack.push(devtools.profiler.Processor.PROGRAM_ENTRY_STR); | 349 stack.push(devtools.profiler.Processor.PROGRAM_ENTRY_STR); |
328 this.currentProfile_.recordTick(this.processStack(pc, stack)); | 350 this.currentProfile_.recordTick(this.processStack(pc, stack)); |
351 this.ticksCount_++; | |
329 }; | 352 }; |
330 | 353 |
331 | 354 |
332 /** | 355 /** |
333 * Creates a profile for further displaying in ProfileView. | 356 * Creates a profile for further displaying in ProfileView. |
334 */ | 357 */ |
335 devtools.profiler.Processor.prototype.createProfileForView = function() { | 358 devtools.profiler.Processor.prototype.createProfileForView = function() { |
336 var profile = this.viewBuilder_.buildView( | 359 var profile = this.viewBuilder_.buildView( |
337 this.currentProfile_.getTopDownProfile()); | 360 this.currentProfile_.getTopDownProfile()); |
338 profile.uid = this.profileId_++; | 361 profile.uid = this.profileId_++; |
339 profile.title = UserInitiatedProfileName + '.' + profile.uid; | 362 profile.title = UserInitiatedProfileName + '.' + profile.uid; |
340 return profile; | 363 return profile; |
341 }; | 364 }; |
OLD | NEW |