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..c2f3c0aff0f37bc92412f0587e8cabe2aecf7c57 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/devtools/front_end/sdk/ProfileTreeModel.js |
| @@ -0,0 +1,118 @@ |
| +// 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 |
| + */ |
| +WebInspector.ProfileNode = function(functionName, scriptId, url, lineNumber, columnNumber) |
| +{ |
| + /** @type {!RuntimeAgent.CallFrame} */ |
| + this.frame = { |
| + functionName: functionName, |
| + scriptId: scriptId, |
| + url: url, |
| + lineNumber: lineNumber, |
| + columnNumber: 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 = []; |
| +} |
| + |
| +WebInspector.ProfileNode.prototype = { |
| + /** |
| + * @return {string} |
| + */ |
| + get functionName() { |
|
caseq
2016/04/13 22:19:36
{ => next line
|
| + return this.frame.functionName; |
| + }, |
| + |
| + /** |
| + * @return {string} |
| + */ |
| + get scriptId() { |
|
caseq
2016/04/13 22:19:36
ditto
|
| + return this.frame.scriptId; |
| + }, |
| + |
| + /** |
| + * @return {string} |
| + */ |
| + get url() { |
|
caseq
2016/04/13 22:19:36
ditto
|
| + return this.frame.url; |
| + }, |
| + |
| + /** |
| + * @return {number} |
| + */ |
| + get lineNumber() { |
|
caseq
2016/04/13 22:19:36
ditto
|
| + return this.frame.lineNumber; |
| + }, |
| + |
| + /** |
| + * @return {number} |
| + */ |
| + get columnNumber() { |
|
caseq
2016/04/13 22:19:36
ditto
|
| + return this.frame.columnNumber; |
| + } |
| +} |
| + |
| +/** |
| + * @constructor |
| + * @param {!WebInspector.ProfileNode} root |
| + * @param {number} begin |
| + * @param {number} end |
| + */ |
| +WebInspector.ProfileTreeModel = function(root, begin, end) |
| +{ |
| + this.root = root; |
| + this.begin = begin; |
| + this.end = end; |
| + this._assignDepthsAndParents(); |
| + this._calculateTotals(this.root); |
| +} |
| + |
| +WebInspector.ProfileTreeModel.prototype = { |
| + _assignDepthsAndParents: function() |
| + { |
| + var root = this.root; |
| + root.depth = -1; |
| + root.parent = null; |
| + this.maxDepth = 0; |
| + var nodesToTraverse = [ root ]; |
|
caseq
2016/04/13 22:19:36
[root]
|
| + 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} |
| + */ |
| + _calculateTotals: function(node) |
| + { |
| + node.total = node.children.reduce((acc, child) => acc + this._calculateTotals(child), node.self); |
| + return node.total; |
| + } |
| +} |