Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/sdk/ProfileTreeModel.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/ProfileTreeModel.js b/third_party/WebKit/Source/devtools/front_end/sdk/ProfileTreeModel.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cf2ec13f4f1f76807dac2285327368d8c9199627 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/devtools/front_end/sdk/ProfileTreeModel.js |
| @@ -0,0 +1,84 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @constructor |
| + * @implements {RuntimeAgent.CallFrame} |
|
caseq
2016/04/13 17:21:12
WAT?
alph
2016/04/13 19:05:07
Fixed. Encapsulated it instead and added getters t
|
| + */ |
| +WebInspector.ProfileNode = function() |
| +{ |
| + /** @type {string} */ |
| + this.functionName; |
| + /** @type {string} */ |
| + this.scriptId; |
| + /** @type {string} */ |
| + this.url; |
| + /** @type {number} */ |
| + this.lineNumber; |
| + /** @type {number} */ |
| + this.columnNumber; |
| + /** @type {number} */ |
| + this.callUID; |
| + /** @type {number} */ |
| + this.self = 0; |
| + /** @type {number} */ |
| + this.total = 0; |
| + /** @type {number} */ |
| + this.id = 0; |
| + /** @type {?WebInspector.ProfileNode} */ |
| + this.parent = null; |
| + /** @type {!Array<!WebInspector.ProfileNode>} */ |
| + this.children = []; |
| +} |
| + |
| +/** |
| + * @constructor |
| + * @param {!WebInspector.ProfileNode} head |
|
caseq
2016/04/13 17:21:12
nit: s/head/root/ everywhere?
alph
2016/04/13 19:05:07
Renamed local variables. Left the rest for now to
|
| + * @param {number} begin |
| + * @param {number} end |
| + */ |
| +WebInspector.ProfileTreeModel = function(head, begin, end) |
| +{ |
| + this.head = head; |
| + this.begin = begin; |
| + this.end = end; |
| + this._assignInfo(); |
| + this._calculateTotal(this.head); |
| +} |
| + |
| +WebInspector.ProfileTreeModel.prototype = { |
| + _assignInfo: function() |
|
caseq
2016/04/13 17:21:12
_updateDepthAndParent?
alph
2016/04/13 19:05:07
Done.
|
| + { |
| + var head = this.head; |
| + head.depth = -1; |
| + head.parent = null; |
| + this.maxDepth = 0; |
| + var nodesToTraverse = [ head ]; |
| + while (nodesToTraverse.length) { |
| + var parent = nodesToTraverse.pop(); |
| + var depth = parent.depth + 1; |
| + if (depth > this.maxDepth) |
| + this.maxDepth = depth; |
| + var children = parent.children; |
| + var length = children.length; |
| + for (var i = 0; i < length; ++i) { |
| + var child = children[i]; |
| + child.depth = depth; |
| + child.parent = parent; |
| + if (child.children.length) |
| + nodesToTraverse.push(child); |
| + } |
| + } |
| + }, |
| + |
| + /** |
| + * @param {!WebInspector.ProfileNode} node |
| + * @return {number} |
| + */ |
| + _calculateTotal: function(node) |
| + { |
| + node.total = node.children.reduce((acc, child) => acc + this._calculateTotal(child), node.self); |
| + return node.total; |
| + } |
| +} |