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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 */ | 70 */ |
71 this.profiles_ = []; | 71 this.profiles_ = []; |
72 | 72 |
73 /** | 73 /** |
74 * The current profile. | 74 * The current profile. |
75 * @type {devtools.profiler.JsProfile} | 75 * @type {devtools.profiler.JsProfile} |
76 */ | 76 */ |
77 this.currentProfile_ = null; | 77 this.currentProfile_ = null; |
78 | 78 |
79 /** | 79 /** |
80 * Builder of profile views. | 80 * Builder of profile views. Created during "profiler,begin" event processing. |
81 * @type {devtools.profiler.ViewBuilder} | 81 * @type {devtools.profiler.ViewBuilder} |
82 */ | 82 */ |
83 this.viewBuilder_ = new devtools.profiler.ViewBuilder(1); | 83 this.viewBuilder_ = null; |
84 | 84 |
85 /** | 85 /** |
86 * Next profile id. | 86 * Next profile id. |
87 * @type {number} | 87 * @type {number} |
88 */ | 88 */ |
89 this.profileId_ = 1; | 89 this.profileId_ = 1; |
90 }; | 90 }; |
91 | 91 |
92 | 92 |
93 /** | 93 /** |
94 * A dispatch table for V8 profiler event log records. | 94 * A dispatch table for V8 profiler event log records. |
95 * @private | 95 * @private |
96 */ | 96 */ |
97 devtools.profiler.Processor.RecordsDispatch_ = { | 97 devtools.profiler.Processor.RecordsDispatch_ = { |
98 'code-creation': { parsers: [null, parseInt, parseInt, null], | 98 'code-creation': { parsers: [null, parseInt, parseInt, null], |
99 processor: 'processCodeCreation_', needsProfile: true }, | 99 processor: 'processCodeCreation_', needsProfile: true }, |
100 'code-move': { parsers: [parseInt, parseInt], | 100 'code-move': { parsers: [parseInt, parseInt], |
101 processor: 'processCodeMove_', needsProfile: true }, | 101 processor: 'processCodeMove_', needsProfile: true }, |
102 'code-delete': { parsers: [parseInt], | 102 'code-delete': { parsers: [parseInt], |
103 processor: 'processCodeDelete_', needsProfile: true }, | 103 processor: 'processCodeDelete_', needsProfile: true }, |
104 'tick': { parsers: [parseInt, parseInt, parseInt, 'var-args'], | 104 'tick': { parsers: [parseInt, parseInt, parseInt, 'var-args'], |
105 processor: 'processTick_', needsProfile: true }, | 105 processor: 'processTick_', needsProfile: true }, |
106 'profiler': { parsers: [null], processor: 'processProfiler_', | 106 'profiler': { parsers: [null, 'var-args'], processor: 'processProfiler_', |
107 needsProfile: false }, | 107 needsProfile: false }, |
108 // Not used in DevTools Profiler. | 108 // Not used in DevTools Profiler. |
109 'shared-library': null, | 109 'shared-library': null, |
110 // Obsolete row types. | 110 // Obsolete row types. |
111 'code-allocate': null, | 111 'code-allocate': null, |
112 'begin-code-region': null, | 112 'begin-code-region': null, |
113 'end-code-region': null | 113 'end-code-region': null |
114 }; | 114 }; |
115 | 115 |
116 | 116 |
117 /** | 117 /** |
| 118 * Returns whether a profile is currently processed. |
| 119 * @return {boolean} |
| 120 */ |
| 121 devtools.profiler.Processor.prototype.isProcessingProfile = function() { |
| 122 return this.currentProfile_ != null; |
| 123 }; |
| 124 |
| 125 |
| 126 /** |
118 * Sets new profile callback. | 127 * Sets new profile callback. |
119 * @param {function(devtools.profiler.ProfileView)} callback Callback function. | 128 * @param {function(devtools.profiler.ProfileView)} callback Callback function. |
120 */ | 129 */ |
121 devtools.profiler.Processor.prototype.setNewProfileCallback = function( | 130 devtools.profiler.Processor.prototype.setNewProfileCallback = function( |
122 callback) { | 131 callback) { |
123 this.newProfileCallback_ = callback; | 132 this.newProfileCallback_ = callback; |
124 }; | 133 }; |
125 | 134 |
126 | 135 |
127 /** | 136 /** |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 parsedFields.push(fields.slice(1 + i)); | 199 parsedFields.push(fields.slice(1 + i)); |
191 break; | 200 break; |
192 } | 201 } |
193 } | 202 } |
194 | 203 |
195 // Run the processor. | 204 // Run the processor. |
196 this[dispatch.processor].apply(this, parsedFields); | 205 this[dispatch.processor].apply(this, parsedFields); |
197 }; | 206 }; |
198 | 207 |
199 | 208 |
200 devtools.profiler.Processor.prototype.processProfiler_ = function(state) { | 209 devtools.profiler.Processor.prototype.processProfiler_ = function(state, params)
{ |
201 switch (state) { | 210 switch (state) { |
202 case "resume": | 211 case "resume": |
203 this.currentProfile_ = new devtools.profiler.JsProfile(); | 212 if (this.currentProfile_ == null) { |
204 this.profiles_.push(this.currentProfile_); | 213 this.currentProfile_ = new devtools.profiler.JsProfile(); |
| 214 this.profiles_.push(this.currentProfile_); |
| 215 } |
205 break; | 216 break; |
206 case "pause": | 217 case "pause": |
207 if (this.currentProfile_ != null) { | 218 if (this.currentProfile_ != null) { |
208 this.newProfileCallback_(this.createProfileForView()); | 219 this.newProfileCallback_(this.createProfileForView()); |
209 this.currentProfile_ = null; | 220 this.currentProfile_ = null; |
210 } | 221 } |
211 break; | 222 break; |
212 // These events are valid but are not used. | 223 case "begin": |
213 case "begin": break; | 224 var samplingRate = NaN; |
| 225 if (params.length > 0) { |
| 226 samplingRate = parseInt(params[0]); |
| 227 } |
| 228 if (isNaN(samplingRate)) { |
| 229 samplingRate = 1; |
| 230 } |
| 231 this.viewBuilder_ = new devtools.profiler.ViewBuilder(samplingRate); |
| 232 break; |
| 233 // This event is valid but isn't used. |
214 case "end": break; | 234 case "end": break; |
215 default: | 235 default: |
216 throw new Error("unknown profiler state: " + state); | 236 throw new Error("unknown profiler state: " + state); |
217 } | 237 } |
218 }; | 238 }; |
219 | 239 |
220 | 240 |
221 devtools.profiler.Processor.prototype.processCodeCreation_ = function( | 241 devtools.profiler.Processor.prototype.processCodeCreation_ = function( |
222 type, start, size, name) { | 242 type, start, size, name) { |
223 this.currentProfile_.addCode(type, name, start, size); | 243 this.currentProfile_.addCode(type, name, start, size); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 profile.title = UserInitiatedProfileName + '.' + profile.uid; | 277 profile.title = UserInitiatedProfileName + '.' + profile.uid; |
258 // A trick to cope with ProfileView.bottomUpProfileDataGridTree and | 278 // A trick to cope with ProfileView.bottomUpProfileDataGridTree and |
259 // ProfileView.topDownProfileDataGridTree behavior. | 279 // ProfileView.topDownProfileDataGridTree behavior. |
260 profile.head = profile; | 280 profile.head = profile; |
261 profile.heavyProfile = this.viewBuilder_.buildView( | 281 profile.heavyProfile = this.viewBuilder_.buildView( |
262 this.currentProfile_.getBottomUpProfile(), true); | 282 this.currentProfile_.getBottomUpProfile(), true); |
263 profile.treeProfile = this.viewBuilder_.buildView( | 283 profile.treeProfile = this.viewBuilder_.buildView( |
264 this.currentProfile_.getTopDownProfile()); | 284 this.currentProfile_.getTopDownProfile()); |
265 return profile; | 285 return profile; |
266 }; | 286 }; |
OLD | NEW |