OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * @constructor | |
7 */ | |
8 WebInspector.ProfileNode = function(functionName, scriptId, url, lineNumber, col
umnNumber) | |
9 { | |
10 /** @type {!RuntimeAgent.CallFrame} */ | |
11 this.frame = { | |
12 functionName: functionName, | |
13 scriptId: scriptId, | |
14 url: url, | |
15 lineNumber: lineNumber, | |
16 columnNumber: columnNumber | |
17 }; | |
18 /** @type {number} */ | |
19 this.callUID; | |
20 /** @type {number} */ | |
21 this.self = 0; | |
22 /** @type {number} */ | |
23 this.total = 0; | |
24 /** @type {number} */ | |
25 this.id = 0; | |
26 /** @type {?WebInspector.ProfileNode} */ | |
27 this.parent = null; | |
28 /** @type {!Array<!WebInspector.ProfileNode>} */ | |
29 this.children = []; | |
30 } | |
31 | |
32 WebInspector.ProfileNode.prototype = { | |
33 /** | |
34 * @return {string} | |
35 */ | |
36 get functionName() | |
37 { | |
38 return this.frame.functionName; | |
39 }, | |
40 | |
41 /** | |
42 * @return {string} | |
43 */ | |
44 get scriptId() | |
45 { | |
46 return this.frame.scriptId; | |
47 }, | |
48 | |
49 /** | |
50 * @return {string} | |
51 */ | |
52 get url() | |
53 { | |
54 return this.frame.url; | |
55 }, | |
56 | |
57 /** | |
58 * @return {number} | |
59 */ | |
60 get lineNumber() | |
61 { | |
62 return this.frame.lineNumber; | |
63 }, | |
64 | |
65 /** | |
66 * @return {number} | |
67 */ | |
68 get columnNumber() | |
69 { | |
70 return this.frame.columnNumber; | |
71 } | |
72 } | |
73 | |
74 /** | |
75 * @constructor | |
76 * @param {!WebInspector.ProfileNode} root | |
77 * @param {number} begin | |
78 * @param {number} end | |
79 */ | |
80 WebInspector.ProfileTreeModel = function(root, begin, end) | |
81 { | |
82 this.root = root; | |
83 this.begin = begin; | |
84 this.end = end; | |
85 this._assignDepthsAndParents(); | |
86 this._calculateTotals(this.root); | |
87 } | |
88 | |
89 WebInspector.ProfileTreeModel.prototype = { | |
90 _assignDepthsAndParents: function() | |
91 { | |
92 var root = this.root; | |
93 root.depth = -1; | |
94 root.parent = null; | |
95 this.maxDepth = 0; | |
96 var nodesToTraverse = [root]; | |
97 while (nodesToTraverse.length) { | |
98 var parent = nodesToTraverse.pop(); | |
99 var depth = parent.depth + 1; | |
100 if (depth > this.maxDepth) | |
101 this.maxDepth = depth; | |
102 var children = parent.children; | |
103 var length = children.length; | |
104 for (var i = 0; i < length; ++i) { | |
105 var child = children[i]; | |
106 child.depth = depth; | |
107 child.parent = parent; | |
108 if (child.children.length) | |
109 nodesToTraverse.push(child); | |
110 } | |
111 } | |
112 }, | |
113 | |
114 /** | |
115 * @param {!WebInspector.ProfileNode} node | |
116 * @return {number} | |
117 */ | |
118 _calculateTotals: function(node) | |
119 { | |
120 node.total = node.children.reduce((acc, child) => acc + this._calculateT
otals(child), node.self); | |
121 return node.total; | |
122 } | |
123 } | |
OLD | NEW |