OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 * This class provides data access interface for dump file profiler. | 6 * This class provides data access interface for dump file profiler. |
7 * @constructor | 7 * @constructor |
8 */ | 8 */ |
9 var Profiler = function(jsonData, template) { | 9 var Profiler = function(jsonData, template) { |
10 this.jsonData_ = jsonData; | 10 this.jsonData_ = jsonData; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 * @param {Object} pos Clicked position. | 84 * @param {Object} pos Clicked position. |
85 */ | 85 */ |
86 Profiler.prototype.setSelected = function(id, pos) { | 86 Profiler.prototype.setSelected = function(id, pos) { |
87 this.selected_ = id; | 87 this.selected_ = id; |
88 this.emit('changed:selected', id, pos); | 88 this.emit('changed:selected', id, pos); |
89 }; | 89 }; |
90 | 90 |
91 /** | 91 /** |
92 * Get all models throughout the whole timeline of given id. | 92 * Get all models throughout the whole timeline of given id. |
93 * @param {string} id Model id. | 93 * @param {string} id Model id. |
94 * @return {Array.<Object>} model array of given id. | 94 * @return {Array<Object>} model array of given id. |
95 */ | 95 */ |
96 Profiler.prototype.getModelsbyId = function(id) { | 96 Profiler.prototype.getModelsbyId = function(id) { |
97 function find(model) { | 97 function find(model) { |
98 if (model.id === id) | 98 if (model.id === id) |
99 return model; | 99 return model; |
100 if ('children' in model) | 100 if ('children' in model) |
101 return model.children.reduce(function(previous, current) { | 101 return model.children.reduce(function(previous, current) { |
102 var matched = find(current); | 102 var matched = find(current); |
103 if (matched) | 103 if (matched) |
104 previous = matched; | 104 previous = matched; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 169 |
170 // Recalculate new template. | 170 // Recalculate new template. |
171 this.reparse(); | 171 this.reparse(); |
172 }; | 172 }; |
173 | 173 |
174 /** | 174 /** |
175 * Calculate the model of certain snapshot. | 175 * Calculate the model of certain snapshot. |
176 * @param {string} template Local template. | 176 * @param {string} template Local template. |
177 * @param {Object} snapshot Current snapshot. | 177 * @param {Object} snapshot Current snapshot. |
178 * @param {Object} worldUnits Mapping of world units. | 178 * @param {Object} worldUnits Mapping of world units. |
179 * @param {Array.<number>} localUnits Array of local units. | 179 * @param {Array<number>} localUnits Array of local units. |
180 * @param {string} name Local node path. | 180 * @param {string} name Local node path. |
181 * @return {Object} Return model, total size and remaining units. | 181 * @return {Object} Return model, total size and remaining units. |
182 * @private | 182 * @private |
183 */ | 183 */ |
184 Profiler.prototype.accumulate_ = function( | 184 Profiler.prototype.accumulate_ = function( |
185 template, snapshot, worldUnits, localUnits, name) { | 185 template, snapshot, worldUnits, localUnits, name) { |
186 var self = this; | 186 var self = this; |
187 var totalSize = 0; | 187 var totalSize = 0; |
188 var worldName = template[0]; | 188 var worldName = template[0]; |
189 var breakdownName = template[1]; | 189 var breakdownName = template[1]; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 292 |
293 return { | 293 return { |
294 model: model, | 294 model: model, |
295 totalSize: totalSize, | 295 totalSize: totalSize, |
296 remainderUnits: remainderUnits | 296 remainderUnits: remainderUnits |
297 }; | 297 }; |
298 }; | 298 }; |
299 | 299 |
300 /** | 300 /** |
301 * Parse template and calculate models of the whole timeline. | 301 * Parse template and calculate models of the whole timeline. |
302 * @return {Array.<Object>} Models of the whole timeline. | 302 * @return {Array<Object>} Models of the whole timeline. |
303 * @private | 303 * @private |
304 */ | 304 */ |
305 Profiler.prototype.parseTemplate_ = function() { | 305 Profiler.prototype.parseTemplate_ = function() { |
306 function calModelId(model, localPath) { | 306 function calModelId(model, localPath) { |
307 // Create unique id for every model. | 307 // Create unique id for every model. |
308 model.id = localPath.length ? | 308 model.id = localPath.length ? |
309 localPath.join() + ',' + model.name : model.name; | 309 localPath.join() + ',' + model.name : model.name; |
310 | 310 |
311 if ('children' in model) { | 311 if ('children' in model) { |
312 model.children.forEach(function(child, index) { | 312 model.children.forEach(function(child, index) { |
(...skipping 18 matching lines...) Expand all Loading... |
331 localUnits = localUnits.map(function(unitID) { | 331 localUnits = localUnits.map(function(unitID) { |
332 return parseInt(unitID, 10); | 332 return parseInt(unitID, 10); |
333 }); | 333 }); |
334 | 334 |
335 var retVal = | 335 var retVal = |
336 self.accumulate_(self.template_, snapshot, worldUnits, localUnits); | 336 self.accumulate_(self.template_, snapshot, worldUnits, localUnits); |
337 calModelId(retVal.model, []); | 337 calModelId(retVal.model, []); |
338 return retVal.model; | 338 return retVal.model; |
339 }); | 339 }); |
340 }; | 340 }; |
OLD | NEW |