| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 * @constructor | 6 * @constructor |
| 7 * @param {!RuntimeAgent.CallFrame} callFrame | 7 * @param {!RuntimeAgent.CallFrame} callFrame |
| 8 */ | 8 */ |
| 9 WebInspector.ProfileNode = function(callFrame) | 9 WebInspector.ProfileNode = function(callFrame) |
| 10 { | 10 { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * @constructor | 70 * @constructor |
| 71 * @param {!WebInspector.ProfileNode} root | 71 * @param {!WebInspector.ProfileNode} root |
| 72 */ | 72 */ |
| 73 WebInspector.ProfileTreeModel = function(root) | 73 WebInspector.ProfileTreeModel = function(root) |
| 74 { | 74 { |
| 75 this.root = root; | 75 this.root = root; |
| 76 this._assignDepthsAndParents(); |
| 76 this.total = this._calculateTotals(this.root); | 77 this.total = this._calculateTotals(this.root); |
| 77 this._assignDepthsAndParents(); | |
| 78 } | 78 } |
| 79 | 79 |
| 80 WebInspector.ProfileTreeModel.prototype = { | 80 WebInspector.ProfileTreeModel.prototype = { |
| 81 _assignDepthsAndParents: function() | 81 _assignDepthsAndParents: function() |
| 82 { | 82 { |
| 83 var root = this.root; | 83 var root = this.root; |
| 84 root.depth = -1; | 84 root.depth = -1; |
| 85 root.parent = null; | 85 root.parent = null; |
| 86 this.maxDepth = 0; | 86 this.maxDepth = 0; |
| 87 var nodesToTraverse = [root]; | 87 var nodesToTraverse = [root]; |
| 88 while (nodesToTraverse.length) { | 88 while (nodesToTraverse.length) { |
| 89 var parent = nodesToTraverse.pop(); | 89 var parent = nodesToTraverse.pop(); |
| 90 var depth = parent.depth + 1; | 90 var depth = parent.depth + 1; |
| 91 if (depth > this.maxDepth) | 91 if (depth > this.maxDepth) |
| 92 this.maxDepth = depth; | 92 this.maxDepth = depth; |
| 93 var children = parent.children; | 93 var children = parent.children; |
| 94 var length = children.length; | 94 var length = children.length; |
| 95 for (var i = 0; i < length; ++i) { | 95 for (var i = 0; i < length; ++i) { |
| 96 var child = children[i]; | 96 var child = children[i]; |
| 97 child.depth = depth; | 97 child.depth = depth; |
| 98 child.parent = parent; | 98 child.parent = parent; |
| 99 if (child.children.length) | 99 if (child.children.length) |
| 100 nodesToTraverse.push(child); | 100 nodesToTraverse.push(child); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 }, | 103 }, |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * @param {!WebInspector.ProfileNode} node | 106 * @param {!WebInspector.ProfileNode} root |
| 107 * @return {number} | 107 * @return {number} |
| 108 */ | 108 */ |
| 109 _calculateTotals: function(node) | 109 _calculateTotals: function(root) |
| 110 { | 110 { |
| 111 node.total = node.children.reduce((acc, child) => acc + this._calculateT
otals(child), node.self); | 111 var nodesToTraverse = [root]; |
| 112 return node.total; | 112 var dfsList = []; |
| 113 while (nodesToTraverse.length) { |
| 114 var node = nodesToTraverse.pop(); |
| 115 node.total = node.self; |
| 116 dfsList.push(node); |
| 117 nodesToTraverse.push(...node.children); |
| 118 } |
| 119 while (dfsList.length > 1) { |
| 120 var node = dfsList.pop(); |
| 121 node.parent.total += node.total; |
| 122 } |
| 123 return root.total; |
| 113 } | 124 } |
| 114 } | 125 } |
| OLD | NEW |