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() { | |
caseq
2016/04/13 22:19:36
{ => next line
| |
37 return this.frame.functionName; | |
38 }, | |
39 | |
40 /** | |
41 * @return {string} | |
42 */ | |
43 get scriptId() { | |
caseq
2016/04/13 22:19:36
ditto
| |
44 return this.frame.scriptId; | |
45 }, | |
46 | |
47 /** | |
48 * @return {string} | |
49 */ | |
50 get url() { | |
caseq
2016/04/13 22:19:36
ditto
| |
51 return this.frame.url; | |
52 }, | |
53 | |
54 /** | |
55 * @return {number} | |
56 */ | |
57 get lineNumber() { | |
caseq
2016/04/13 22:19:36
ditto
| |
58 return this.frame.lineNumber; | |
59 }, | |
60 | |
61 /** | |
62 * @return {number} | |
63 */ | |
64 get columnNumber() { | |
caseq
2016/04/13 22:19:36
ditto
| |
65 return this.frame.columnNumber; | |
66 } | |
67 } | |
68 | |
69 /** | |
70 * @constructor | |
71 * @param {!WebInspector.ProfileNode} root | |
72 * @param {number} begin | |
73 * @param {number} end | |
74 */ | |
75 WebInspector.ProfileTreeModel = function(root, begin, end) | |
76 { | |
77 this.root = root; | |
78 this.begin = begin; | |
79 this.end = end; | |
80 this._assignDepthsAndParents(); | |
81 this._calculateTotals(this.root); | |
82 } | |
83 | |
84 WebInspector.ProfileTreeModel.prototype = { | |
85 _assignDepthsAndParents: function() | |
86 { | |
87 var root = this.root; | |
88 root.depth = -1; | |
89 root.parent = null; | |
90 this.maxDepth = 0; | |
91 var nodesToTraverse = [ root ]; | |
caseq
2016/04/13 22:19:36
[root]
| |
92 while (nodesToTraverse.length) { | |
93 var parent = nodesToTraverse.pop(); | |
94 var depth = parent.depth + 1; | |
95 if (depth > this.maxDepth) | |
96 this.maxDepth = depth; | |
97 var children = parent.children; | |
98 var length = children.length; | |
99 for (var i = 0; i < length; ++i) { | |
100 var child = children[i]; | |
101 child.depth = depth; | |
102 child.parent = parent; | |
103 if (child.children.length) | |
104 nodesToTraverse.push(child); | |
105 } | |
106 } | |
107 }, | |
108 | |
109 /** | |
110 * @param {!WebInspector.ProfileNode} node | |
111 * @return {number} | |
112 */ | |
113 _calculateTotals: function(node) | |
114 { | |
115 node.total = node.children.reduce((acc, child) => acc + this._calculateT otals(child), node.self); | |
116 return node.total; | |
117 } | |
118 } | |
OLD | NEW |